KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > legacy > NonReflectiveBinderTest


1 //$Id: NonReflectiveBinderTest.java,v 1.3 2004/09/26 05:28:50 oneovthafew Exp $
2
package org.hibernate.test.legacy;
3
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import junit.framework.Test;
8 import junit.framework.TestCase;
9 import junit.framework.TestSuite;
10
11 import org.hibernate.MappingException;
12 import org.hibernate.cfg.Configuration;
13 import org.hibernate.mapping.MetaAttribute;
14 import org.hibernate.mapping.PersistentClass;
15 import org.hibernate.mapping.Property;
16
17
18 public class NonReflectiveBinderTest extends TestCase {
19
20     Configuration cfg;
21     private Class JavaDoc lastTestClass;
22
23     public static Test suite() {
24         return new TestSuite(NonReflectiveBinderTest.class);
25     }
26
27     Configuration getCfg() {
28         return cfg;
29     }
30
31     public String JavaDoc[] getMappings() {
32         return new String JavaDoc[] { "legacy/Wicked.hbm.xml" };
33     }
34
35     void buildConfiguration(String JavaDoc[] files) throws MappingException {
36
37             try {
38                 setCfg( new Configuration() );
39
40                 for (int i=0; i<files.length; i++) {
41                     if ( !files[i].startsWith("net/") ) files[i] = "org/hibernate/test/" + files[i];
42                     getCfg().addResource( files[i], TestCase.class.getClassLoader() );
43                 }
44             } catch (MappingException e) {
45                 throw e;
46             }
47
48
49     }
50
51     protected void setUp() throws Exception JavaDoc {
52         if ( getCfg()==null || lastTestClass!=getClass() ) {
53             buildConfiguration( getMappings() );
54             lastTestClass = getClass();
55         }
56     }
57
58     /**
59      * @param configuration
60      */

61     private void setCfg(Configuration configuration) {
62         cfg = configuration;
63     }
64
65     public void testMetaInheritance() {
66         Configuration cfg = getCfg();
67         cfg.buildMappings();
68         PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
69         Map JavaDoc m = cm.getMetaAttributes();
70         assertNotNull(m);
71         assertNotNull(cm.getMetaAttribute("global"));
72         assertNull(cm.getMetaAttribute("globalnoinherit"));
73         
74         MetaAttribute metaAttribute = cm.getMetaAttribute("implements");
75         assertNotNull(metaAttribute);
76         assertEquals("implements", metaAttribute.getName());
77         assertTrue(metaAttribute.isMultiValued());
78         assertEquals(3, metaAttribute.getValues().size());
79         assertEquals("java.lang.Observer",metaAttribute.getValues().get(0));
80         assertEquals("java.lang.Observer",metaAttribute.getValues().get(1));
81         assertEquals("org.foo.BogusVisitor",metaAttribute.getValues().get(2));
82         
83         /*Property property = cm.getIdentifierProperty();
84         property.getMetaAttribute(null);*/

85         
86         Iterator JavaDoc propertyIterator = cm.getPropertyIterator();
87         while (propertyIterator.hasNext()) {
88             Property element = (Property) propertyIterator.next();
89             System.out.println(element);
90             Map JavaDoc ma = element.getMetaAttributes();
91             assertNotNull(ma);
92             assertNotNull(element.getMetaAttribute("global"));
93             MetaAttribute metaAttribute2 = element.getMetaAttribute("implements");
94             assertNotNull(metaAttribute2);
95             assertNull(element.getMetaAttribute("globalnoinherit"));
96         }
97         
98         Property element = cm.getProperty("component");
99         Map JavaDoc ma = element.getMetaAttributes();
100         assertNotNull(ma);
101         assertNotNull(element.getMetaAttribute("global"));
102         assertNotNull(element.getMetaAttribute("componentonly"));
103         assertNotNull(element.getMetaAttribute("allcomponent"));
104         assertNotNull(element.getMetaAttribute("implements"));
105         assertNull(element.getMetaAttribute("globalnoinherit"));
106     
107         
108     }
109
110 }
111
Popular Tags