bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r992420 [3/3] - in /incubator/bval/trunk: bval-core/src/main/java/org/apache/bval/ bval-core/src/main/java/org/apache/bval/routines/ bval-core/src/main/java/org/apache/bval/util/ bval-core/src/test/java/org/apache/bval/model/ bval-json/src/...
Date Fri, 03 Sep 2010 19:02:19 GMT
Modified: incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java
(original)
+++ incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanBuilder.java
Fri Sep  3 19:02:18 2010
@@ -32,153 +32,147 @@ import java.util.Map;
  * Time: 10:10:46<br>
  */
 public class XMLMetaBeanBuilder extends MetaBeanBuilder {
-  private XMLMetaBeanFactory xmlFactory;
+    private XMLMetaBeanFactory xmlFactory;
 
+    public XMLMetaBeanBuilder(MetaBeanFactory[] factories) {
+        setFactories(factories);
+    }
+
+    public XMLMetaBeanBuilder() {
+        setFactories(new MetaBeanFactory[] { new IntrospectorMetaBeanFactory(), new XMLMetaBeanFactory()
});
+    }
+
+    public void setFactories(MetaBeanFactory[] factories) {
+        super.setFactories(factories);
+        updateXmlFactory();
+    }
+
+    public void addLoader(XMLMetaBeanLoader loader) {
+        assertXmlFactory();
+        xmlFactory.addLoader(loader);
+    }
+
+    public MetaBean buildForId(String beanInfoId) throws Exception {
+        final XMLMetaBeanFactory.Visitor v;
+        assertXmlFactory();
+        xmlFactory.visitXMLBeanMeta(beanInfoId, v = new XMLMetaBeanFactory.Visitor() {
+            private MetaBean meta;
 
-  public XMLMetaBeanBuilder(MetaBeanFactory[] factories) {
-    setFactories(factories);
-  }
-
-  public XMLMetaBeanBuilder() {
-    setFactories(new MetaBeanFactory[]{new IntrospectorMetaBeanFactory(),
-        new XMLMetaBeanFactory()});
-  }
-
-  public void setFactories(MetaBeanFactory[] factories) {
-    super.setFactories(factories);
-    updateXmlFactory();
-  }
-
-  public void addLoader(XMLMetaBeanLoader loader) {
-    assertXmlFactory();
-    xmlFactory.addLoader(loader);
-  }
-
-  public MetaBean buildForId(String beanInfoId) throws Exception {
-    final XMLMetaBeanFactory.Visitor v;
-    assertXmlFactory();
-    xmlFactory.visitXMLBeanMeta(beanInfoId, v = new XMLMetaBeanFactory.Visitor() {
-      private MetaBean meta;
-
-      public MetaBean getMetaBean() {
-        return meta;
-      }
-
-      public void visit(XMLMetaBean xmlMeta, XMLMetaBeanInfos xmlInfos)
-          throws Exception {
-        if (meta == null) {
-          meta = createMetaBean(xmlMeta);
-        }
-        xmlFactory.enrichMetaBean(meta,
-            new XMLMetaBeanFactory.XMLResult(xmlMeta, xmlInfos));
-      }
-
-
-    });
-    if (v.getMetaBean() == null) {
-      throw new IllegalArgumentException("MetaBean " + beanInfoId + " not found");
-    }
-    return v.getMetaBean();
-  }
-
-  public Map<String, MetaBean> buildAll() throws Exception {
-    final Map<String, MetaBean> all = super.buildAll();
-    if (xmlFactory != null) {
-      xmlFactory.visitXMLBeanMeta(null, new XMLMetaBeanFactory.Visitor() {
-        public void visit(XMLMetaBean empty, XMLMetaBeanInfos xmlInfos)
-            throws Exception {
-          if (xmlInfos.getBeans() == null) return; // empty file, ignore
-          XMLMetaBeanFactory.XMLResult carrier =
-              new XMLMetaBeanFactory.XMLResult(null, xmlInfos);
-
-          for (XMLMetaBean xmlMeta : xmlInfos.getBeans()) {
-            MetaBean meta = all.get(xmlMeta.getId());
-            if (meta == null) {
-              meta = createMetaBean(xmlMeta);
-              all.put(xmlMeta.getId(), meta);
+            public MetaBean getMetaBean() {
+                return meta;
             }
-            carrier.xmlMeta = xmlMeta;
-            xmlFactory.enrichMetaBean(meta, carrier);
-          }
-        }
-
-        public MetaBean getMetaBean() {
-          return null;  // do nothing
-        }
-      });
-    }
-    return all;
-  }
-
-  public Map<String, MetaBean> enrichCopies(Map<String, MetaBean> all,
-                                            XMLMetaBeanInfos... infosArray)
-      throws Exception {
-    assertXmlFactory();
-    final Map<String, MetaBean> copies = new HashMap<String, MetaBean>(all.size());
-    boolean nothing = true;
-    XMLMetaBeanFactory.XMLResult carrier = new XMLMetaBeanFactory.XMLResult();
-    for (XMLMetaBeanInfos xmlMetaBeanInfos : infosArray) {
-      carrier.xmlInfos = xmlMetaBeanInfos;
-      if (xmlMetaBeanInfos == null) continue;
-      try {
-        for (XMLMetaBean xmlMeta : xmlMetaBeanInfos.getBeans()) {
-          nothing = false;
-          MetaBean copy = copies.get(xmlMeta.getId());
-          if (copy == null) { // ist noch nicht kopiert
-            MetaBean meta = all.get(xmlMeta.getId());
-            if (meta == null) { // gibt es nicht
-              copy = createMetaBean(xmlMeta);
-            } else { // gibt es, jetzt kopieren
-              copy = meta.copy();
+
+            public void visit(XMLMetaBean xmlMeta, XMLMetaBeanInfos xmlInfos) throws Exception
{
+                if (meta == null) {
+                    meta = createMetaBean(xmlMeta);
+                }
+                xmlFactory.enrichMetaBean(meta, new XMLMetaBeanFactory.XMLResult(xmlMeta,
xmlInfos));
             }
-            copies.put(xmlMeta.getId(), copy);
-          }
-          carrier.xmlMeta = xmlMeta;
-          xmlFactory.enrichMetaBean(copy, carrier);
-        }
-      } catch (IOException e) {
-        xmlFactory.handleLoadException(xmlMetaBeanInfos, e);
-      }
-    }
-    if (nothing) return all;
-    for (Map.Entry<String, MetaBean> entry : all.entrySet()) {
-      /*
-      * alle unveraenderten werden AUCH KOPIERT (nur zwar nur, wegen
-      * potentieller CrossReferenzen durch Relationships)
-      */
-      if (!copies.containsKey(entry.getKey())) {
-        if (entry.getValue().hasRelationships()) {
-          copies.put(entry.getKey(), (MetaBean) entry.getValue().copy());
-        } else { // no relationship: do not clone()
-          copies.put(entry.getKey(), entry.getValue());
-        }
-      }
-    }
-    return copies;
-  }
-
-  private MetaBean createMetaBean(XMLMetaBean xmlMeta) throws Exception {
-    return buildForClass(findLocalClass(xmlMeta.getImpl()));
-  }
-
-  private void updateXmlFactory() {
-    for (MetaBeanFactory each : getFactories()) {
-      if (each instanceof XMLMetaBeanFactory) { // use the first one!
-        xmlFactory = (XMLMetaBeanFactory) each;
-        return;
-      }
-    }
-    xmlFactory = null; // none
-  }
-
-  public XMLMetaBeanFactory getXmlFactory() {
-    return xmlFactory;
-  }
-
-  private void assertXmlFactory() {
-    if (xmlFactory == null) {
-      throw new IllegalStateException("no xmlFactory available");
+
+        });
+        if (v.getMetaBean() == null) {
+            throw new IllegalArgumentException("MetaBean " + beanInfoId + " not found");
+        }
+        return v.getMetaBean();
+    }
+
+    public Map<String, MetaBean> buildAll() throws Exception {
+        final Map<String, MetaBean> all = super.buildAll();
+        if (xmlFactory != null) {
+            xmlFactory.visitXMLBeanMeta(null, new XMLMetaBeanFactory.Visitor() {
+                public void visit(XMLMetaBean empty, XMLMetaBeanInfos xmlInfos) throws Exception
{
+                    if (xmlInfos.getBeans() == null)
+                        return; // empty file, ignore
+                    XMLMetaBeanFactory.XMLResult carrier = new XMLMetaBeanFactory.XMLResult(null,
xmlInfos);
+
+                    for (XMLMetaBean xmlMeta : xmlInfos.getBeans()) {
+                        MetaBean meta = all.get(xmlMeta.getId());
+                        if (meta == null) {
+                            meta = createMetaBean(xmlMeta);
+                            all.put(xmlMeta.getId(), meta);
+                        }
+                        carrier.xmlMeta = xmlMeta;
+                        xmlFactory.enrichMetaBean(meta, carrier);
+                    }
+                }
+
+                public MetaBean getMetaBean() {
+                    return null; // do nothing
+                }
+            });
+        }
+        return all;
+    }
+
+    public Map<String, MetaBean> enrichCopies(Map<String, MetaBean> all, XMLMetaBeanInfos...
infosArray)
+        throws Exception {
+        assertXmlFactory();
+        final Map<String, MetaBean> copies = new HashMap<String, MetaBean>(all.size());
+        boolean nothing = true;
+        XMLMetaBeanFactory.XMLResult carrier = new XMLMetaBeanFactory.XMLResult();
+        for (XMLMetaBeanInfos xmlMetaBeanInfos : infosArray) {
+            carrier.xmlInfos = xmlMetaBeanInfos;
+            if (xmlMetaBeanInfos == null)
+                continue;
+            try {
+                for (XMLMetaBean xmlMeta : xmlMetaBeanInfos.getBeans()) {
+                    nothing = false;
+                    MetaBean copy = copies.get(xmlMeta.getId());
+                    if (copy == null) { // ist noch nicht kopiert
+                        MetaBean meta = all.get(xmlMeta.getId());
+                        if (meta == null) { // gibt es nicht
+                            copy = createMetaBean(xmlMeta);
+                        } else { // gibt es, jetzt kopieren
+                            copy = meta.copy();
+                        }
+                        copies.put(xmlMeta.getId(), copy);
+                    }
+                    carrier.xmlMeta = xmlMeta;
+                    xmlFactory.enrichMetaBean(copy, carrier);
+                }
+            } catch (IOException e) {
+                xmlFactory.handleLoadException(xmlMetaBeanInfos, e);
+            }
+        }
+        if (nothing)
+            return all;
+        for (Map.Entry<String, MetaBean> entry : all.entrySet()) {
+            /*
+             * alle unveraenderten werden AUCH KOPIERT (nur zwar nur, wegen
+             * potentieller CrossReferenzen durch Relationships)
+             */
+            if (!copies.containsKey(entry.getKey())) {
+                if (entry.getValue().hasRelationships()) {
+                    copies.put(entry.getKey(), (MetaBean) entry.getValue().copy());
+                } else { // no relationship: do not clone()
+                    copies.put(entry.getKey(), entry.getValue());
+                }
+            }
+        }
+        return copies;
+    }
+
+    private MetaBean createMetaBean(XMLMetaBean xmlMeta) throws Exception {
+        return buildForClass(findLocalClass(xmlMeta.getImpl()));
+    }
+
+    private void updateXmlFactory() {
+        for (MetaBeanFactory each : getFactories()) {
+            if (each instanceof XMLMetaBeanFactory) { // use the first one!
+                xmlFactory = (XMLMetaBeanFactory) each;
+                return;
+            }
+        }
+        xmlFactory = null; // none
+    }
+
+    public XMLMetaBeanFactory getXmlFactory() {
+        return xmlFactory;
     }
-  }
-}
 
+    private void assertXmlFactory() {
+        if (xmlFactory == null) {
+            throw new IllegalStateException("no xmlFactory available");
+        }
+    }
+}

Modified: incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
(original)
+++ incubator/bval/trunk/bval-xstream/src/main/java/org/apache/bval/xml/XMLMetaBeanManager.java
Fri Sep  3 19:02:18 2010
@@ -27,107 +27,107 @@ import java.util.Map;
 import static org.apache.bval.model.Features.Property.REF_BEAN_ID;
 
 /**
- * Description: internal implementation class to construct
- * metabeans with factories and from xstream xml files.
- * You can register different XMLMetaBeanLoaders (see addLoader()) to register xstream-xml-files
that
- * contain meta-data.
- * You can merge + unify meta data with method enrichCopies().
- * <br/>
+ * Description: internal implementation class to construct metabeans with
+ * factories and from xstream xml files. You can register different
+ * XMLMetaBeanLoaders (see addLoader()) to register xstream-xml-files that
+ * contain meta-data. You can merge + unify meta data with method
+ * enrichCopies(). <br/>
  * User: roman.stumm<br>
  * Date: 17.06.2010<br>
  * Time: 09:47:14<br>
  */
-public class XMLMetaBeanManager extends MetaBeanManager
-    implements MetaBeanFinder, XMLMetaBeanRegistry, MetaBeanEnricher {
-  public XMLMetaBeanManager() {
-    this(new XMLMetaBeanBuilder());
-  }
-
-  public XMLMetaBeanManager(XMLMetaBeanBuilder builder) {
-    super(builder);
-  }
-
-  public void addResourceLoader(String resource) {
-    addLoader(new XMLMetaBeanURLLoader(
-        PrivilegedActions.getClassLoader(getClass()).getResource(resource)));
-  }
-
-  public synchronized void addLoader(XMLMetaBeanLoader loader) {
-    ((XMLMetaBeanBuilder) builder).addLoader(loader);
-    cache.clear(); // clear because new loaders can affect ALL MetaBeans already created!
-    complete = false;
-  }
-
-  /**
-   * @param infos - the patches to apply
-   * @return all MetaBeans for classes that have a xml descriptor and
-   *         additional the MetaBeans loaded by the given loaders.
-   *         The given loaders may also return patches for MetaBeans that have
-   *         also been returned by other loaders. The beans with patches for
-   *         references to patched beans will be copied.
-   */
-  public Map<String, MetaBean> enrichCopies(XMLMetaBeanInfos... infos) {
-    Map<String, MetaBean> cached = findAll();
-    try {
-      Map<String, MetaBean> patched = ((XMLMetaBeanBuilder) builder).enrichCopies(cached,
infos);
-      for (Object entry : patched.values()) {
-        MetaBean meta = (MetaBean) entry;
-        computeRelationships(meta, patched);
-      }
-      return patched;
-    } catch (RuntimeException e) {
-      throw e; // do not wrap runtime exceptions
-    } catch (Exception e) {
-      throw new IllegalArgumentException("error enriching beanInfos", e);
-    }
-  }
-
-  /**
-   * 
-   * @return all MetaBeans for classes that have a xml descriptor:
-   *         key = bean.id, value = MetaBean
-   */
-  public Map<String, MetaBean> findAll() {
-    if (!complete) {
-      try {
-        Map<String, MetaBean> allBuilt = builder.buildAll();
-        for (MetaBean meta : allBuilt.values()) {
-          MetaBean cached = cache.findForId(meta.getId());
-          if (cached == null) {
-            cache.cache(meta);
-          }
+public class XMLMetaBeanManager extends MetaBeanManager implements MetaBeanFinder, XMLMetaBeanRegistry,
+    MetaBeanEnricher {
+    public XMLMetaBeanManager() {
+        this(new XMLMetaBeanBuilder());
+    }
+
+    public XMLMetaBeanManager(XMLMetaBeanBuilder builder) {
+        super(builder);
+    }
+
+    public void addResourceLoader(String resource) {
+        addLoader(new XMLMetaBeanURLLoader(PrivilegedActions.getClassLoader(getClass()).getResource(resource)));
+    }
+
+    public synchronized void addLoader(XMLMetaBeanLoader loader) {
+        ((XMLMetaBeanBuilder) builder).addLoader(loader);
+        cache.clear(); // clear because new loaders can affect ALL MetaBeans
+                       // already created!
+        complete = false;
+    }
+
+    /**
+     * @param infos
+     *            - the patches to apply
+     * @return all MetaBeans for classes that have a xml descriptor and
+     *         additional the MetaBeans loaded by the given loaders. The given
+     *         loaders may also return patches for MetaBeans that have also been
+     *         returned by other loaders. The beans with patches for references
+     *         to patched beans will be copied.
+     */
+    public Map<String, MetaBean> enrichCopies(XMLMetaBeanInfos... infos) {
+        Map<String, MetaBean> cached = findAll();
+        try {
+            Map<String, MetaBean> patched = ((XMLMetaBeanBuilder) builder).enrichCopies(cached,
infos);
+            for (Object entry : patched.values()) {
+                MetaBean meta = (MetaBean) entry;
+                computeRelationships(meta, patched);
+            }
+            return patched;
+        } catch (RuntimeException e) {
+            throw e; // do not wrap runtime exceptions
+        } catch (Exception e) {
+            throw new IllegalArgumentException("error enriching beanInfos", e);
         }
-        Map<String, MetaBean> map = cache.findAll();
-        for (Object oentry : map.values()) {
-          MetaBean meta = (MetaBean) oentry;
-          computeRelationships(meta, map);
+    }
+
+    /**
+     * 
+     * @return all MetaBeans for classes that have a xml descriptor: key =
+     *         bean.id, value = MetaBean
+     */
+    public Map<String, MetaBean> findAll() {
+        if (!complete) {
+            try {
+                Map<String, MetaBean> allBuilt = builder.buildAll();
+                for (MetaBean meta : allBuilt.values()) {
+                    MetaBean cached = cache.findForId(meta.getId());
+                    if (cached == null) {
+                        cache.cache(meta);
+                    }
+                }
+                Map<String, MetaBean> map = cache.findAll();
+                for (Object oentry : map.values()) {
+                    MetaBean meta = (MetaBean) oentry;
+                    computeRelationships(meta, map);
+                }
+                complete = true;
+                return map;
+            } catch (RuntimeException e) {
+                throw e; // do not wrap runtime exceptions
+            } catch (Exception e) {
+                throw new IllegalArgumentException("error creating beanInfos", e);
+            }
+        } else {
+            return cache.findAll();
+        }
+    }
+
+    protected void computeRelationships(MetaBean beanInfo, Map<String, MetaBean> cached)
{
+        for (MetaProperty prop : beanInfo.getProperties()) {
+            String beanRef = (String) prop.getFeature(REF_BEAN_ID);
+            if (beanRef != null) {
+                prop.setMetaBean(cached.get(beanRef));
+            }
+        }
+    }
+
+    protected void computeRelatedMetaBean(MetaProperty prop, String beanRef) {
+        if (beanRef != null) {
+            prop.setMetaBean(findForId(beanRef));
+        } else {
+            super.computeRelatedMetaBean(prop, beanRef);
         }
-        complete = true;
-        return map;
-      } catch (RuntimeException e) {
-        throw e; // do not wrap runtime exceptions
-      } catch (Exception e) {
-        throw new IllegalArgumentException("error creating beanInfos", e);
-      }
-    } else {
-      return cache.findAll();
-    }
-  }
-
-  protected void computeRelationships(MetaBean beanInfo, Map<String, MetaBean> cached)
{
-    for (MetaProperty prop : beanInfo.getProperties()) {
-      String beanRef = (String) prop.getFeature(REF_BEAN_ID);
-      if (beanRef != null) {
-        prop.setMetaBean(cached.get(beanRef));
-      }
-    }
-  }
-
-  protected void computeRelatedMetaBean(MetaProperty prop, String beanRef) {
-    if (beanRef != null) {
-        prop.setMetaBean(findForId(beanRef));
-    } else {
-      super.computeRelatedMetaBean(prop, beanRef);
     }
-  }
 }

Modified: incubator/bval/trunk/bval-xstream/src/test/java/org/apache/bval/xml/XMLMetaBeanManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-xstream/src/test/java/org/apache/bval/xml/XMLMetaBeanManagerTest.java?rev=992420&r1=992419&r2=992420&view=diff
==============================================================================
--- incubator/bval/trunk/bval-xstream/src/test/java/org/apache/bval/xml/XMLMetaBeanManagerTest.java
(original)
+++ incubator/bval/trunk/bval-xstream/src/test/java/org/apache/bval/xml/XMLMetaBeanManagerTest.java
Fri Sep  3 19:02:18 2010
@@ -32,68 +32,61 @@ import java.util.Map;
  * Time: 10:28:48<br>
  */
 public class XMLMetaBeanManagerTest extends TestCase {
-  XMLMetaBeanManager mbm = new XMLMetaBeanManager();
+    XMLMetaBeanManager mbm = new XMLMetaBeanManager();
 
-  public XMLMetaBeanManagerTest(String name) {
-    super(name);
-  }
-
-  public void setUp() throws Exception {
-    super.setUp();
-    mbm.addLoader(new XMLMetaBeanURLLoader(
-        BusinessObject.class.getResource("test-beanInfos.xml")));
-  }
-
-  public void tearDown() throws Exception {
-    super.tearDown();
-  }
-
-  public void testEnrichCopies() throws Exception {
-    Map<String, MetaBean> copies = mbm.enrichCopies(new XMLMetaBeanURLLoader(
-        BusinessObject.class.getResource("test-beanInfos-custom.xml")).load());
-    assertNotNull(copies);
-    MetaBean mb = copies.get(BusinessObject.class.getName());
-    assertFalse(mb.getProperty("lastName").isMandatory());
-    MetaBean mb2 = mbm.findForClass(BusinessObject.class);
-    assertTrue(mb2.getProperty("lastName").isMandatory());
-  }
-
-  public void testCopy() {
-    MetaBean mb = mbm.findForClass(BusinessObject.class);
-    MetaBean mb2 = mb.copy();
-    assertTrue(mb2 != mb);
-    assertTrue(mb2.getProperty("dateBirth") != mb.getProperty("dateBirth"));
-  }
-
-  public void testFindForClass() throws Exception {
-    MetaBeanFinder finder = mbm;
-    MetaBean info = finder.findForClass(BusinessObject.class);
-    assertNotNull(info);
-    assertTrue(info == info.getProperty("address").getMetaBean().getProperty("owner")
-        .getMetaBean());
-    assertTrue(info == info.getProperty("addresses").getMetaBean()
-        .getProperty("owner").getMetaBean());
-    assertTrue(info.getProperty("email").getJavaScriptValidations().length > 0);
-  }
-
-
-  public void testFindAll() {
-    Map<String, MetaBean> all = mbm.findAll();
-    assertNotNull(all);
-    Map<String, MetaBean> all2 = mbm.findAll();
-    assertEquals(all.size(), all2.size());
-    assertTrue(all.get(BusinessObject.class.getName()) ==
-        all2.get(BusinessObject.class.getName()));
-    assertTrue(all.get(BusinessObject.class.getName()) != null);
-    MetaBean bean = all.get(BusinessObject.class.getName());
-    assertTrue(bean == bean.getProperty("address").getMetaBean().getProperty("owner")
-        .getMetaBean());
-    assertTrue(bean == bean.getProperty("addresses").getMetaBean()
-        .getProperty("owner").getMetaBean());
-  }
-
-
-  public static Test suite() {
-    return new TestSuite(XMLMetaBeanManagerTest.class);
-  }
+    public XMLMetaBeanManagerTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        mbm.addLoader(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos.xml")));
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testEnrichCopies() throws Exception {
+        Map<String, MetaBean> copies =
+            mbm.enrichCopies(new XMLMetaBeanURLLoader(BusinessObject.class.getResource("test-beanInfos-custom.xml"))
+                .load());
+        assertNotNull(copies);
+        MetaBean mb = copies.get(BusinessObject.class.getName());
+        assertFalse(mb.getProperty("lastName").isMandatory());
+        MetaBean mb2 = mbm.findForClass(BusinessObject.class);
+        assertTrue(mb2.getProperty("lastName").isMandatory());
+    }
+
+    public void testCopy() {
+        MetaBean mb = mbm.findForClass(BusinessObject.class);
+        MetaBean mb2 = mb.copy();
+        assertTrue(mb2 != mb);
+        assertTrue(mb2.getProperty("dateBirth") != mb.getProperty("dateBirth"));
+    }
+
+    public void testFindForClass() throws Exception {
+        MetaBeanFinder finder = mbm;
+        MetaBean info = finder.findForClass(BusinessObject.class);
+        assertNotNull(info);
+        assertTrue(info == info.getProperty("address").getMetaBean().getProperty("owner").getMetaBean());
+        assertTrue(info == info.getProperty("addresses").getMetaBean().getProperty("owner").getMetaBean());
+        assertTrue(info.getProperty("email").getJavaScriptValidations().length > 0);
+    }
+
+    public void testFindAll() {
+        Map<String, MetaBean> all = mbm.findAll();
+        assertNotNull(all);
+        Map<String, MetaBean> all2 = mbm.findAll();
+        assertEquals(all.size(), all2.size());
+        assertTrue(all.get(BusinessObject.class.getName()) == all2.get(BusinessObject.class.getName()));
+        assertTrue(all.get(BusinessObject.class.getName()) != null);
+        MetaBean bean = all.get(BusinessObject.class.getName());
+        assertTrue(bean == bean.getProperty("address").getMetaBean().getProperty("owner").getMetaBean());
+        assertTrue(bean == bean.getProperty("addresses").getMetaBean().getProperty("owner").getMetaBean());
+    }
+
+    public static Test suite() {
+        return new TestSuite(XMLMetaBeanManagerTest.class);
+    }
 }



Mime
View raw message