KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > metadata > CustomAttributesTest


1 package org.apache.ojb.broker.metadata;
2
3 import junit.framework.TestCase;
4
5 import org.apache.ojb.broker.Article;
6 import org.apache.ojb.broker.PBKey;
7
8 /**
9  * This TestClass tests the RepositoryPersitors facilities for
10  * reading and writing a valid repository.
11  */

12 public class CustomAttributesTest extends TestCase
13 {
14     public static void main(String JavaDoc[] args)
15     {
16         String JavaDoc[] arr = { CLASS.getName()};
17         junit.textui.TestRunner.main(arr);
18     }
19
20     //PersistenceBroker broker;
21
private static Class JavaDoc CLASS = CustomAttributesTest.class;
22
23     /**
24      * Insert the method's description here.
25      * Creation date: (24.12.2000 00:33:40)
26      */

27     public CustomAttributesTest(String JavaDoc name)
28     {
29         super(name);
30     }
31
32     /**
33      * Insert the method's description here.
34      * Creation date: (06.12.2000 21:58:53)
35      */

36     public void setUp()
37     {
38     }
39
40     /**
41      * Insert the method's description here.
42      * Creation date: (06.12.2000 21:59:14)
43      */

44     public void tearDown()
45     {
46
47     }
48
49     public void testCustomAttributesDescriptorRepository()
50     {
51         String JavaDoc repositoryAttribute_1 = "attribute-repository-1";
52         String JavaDoc repositoryAttribute_2 = "attribute-repository-2";
53         MetadataManager mm = MetadataManager.getInstance();
54
55         DescriptorRepository dr = mm.readDescriptorRepository(MetadataTest.TEST_REPOSITORY);
56         String JavaDoc res_1 = dr.getAttribute(repositoryAttribute_1);
57         String JavaDoc res_2 = dr.getAttribute(repositoryAttribute_2);
58         assertNotNull("No attributes found", res_1);
59         assertNotNull("No attributes found", res_2);
60         assertEquals("Found attribute does not match", "attribute-repository-test-value-1", res_1);
61         assertEquals("Found attribute does not match", "attribute-repository-test-value-2", res_2);
62
63     }
64
65     public void testCustomAttributesConnectionDescriptor()
66     {
67         String JavaDoc connectionAttribute_1 = "attribute-connection-1";
68         String JavaDoc connectionAttribute_2 = "attribute-connection-2";
69
70         MetadataManager mm = MetadataManager.getInstance();
71         ConnectionRepository cr = mm.readConnectionRepository(MetadataTest.TEST_CONNECTION_DESCRIPTOR);
72         JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey("runtime"));
73         String JavaDoc res_1 = jcd.getAttribute(connectionAttribute_1);
74         String JavaDoc res_2 = jcd.getAttribute(connectionAttribute_2);
75         assertNotNull("No attributes found", res_1);
76         assertNotNull("No attributes found", res_2);
77         assertEquals("Found attribute does not match", "attribute-connection-test-value-1", res_1);
78         assertEquals("Found attribute does not match", "attribute-connection-test-value-2", res_2);
79     }
80
81
82     /** Test storing repository.*/
83     public void testCustomAttributesClassDescriptor()
84     {
85         DescriptorRepository repository = MetadataManager.getInstance().getRepository();
86
87         ClassDescriptor cld = repository.getDescriptorFor(Article.class);
88         assertTrue("blue".equals(cld.getAttribute("color")));
89         assertTrue("big".equals(cld.getAttribute("size")));
90
91         FieldDescriptor fld = cld.getFieldDescriptorByName("isSelloutArticle");
92         assertTrue("green".equals(fld.getAttribute("color")));
93         assertTrue("small".equals(fld.getAttribute("size")));
94
95
96         ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName("productGroup");
97         assertNotNull("did not find ord for 'productGroup'!", ord);
98         assertTrue("red".equals(ord.getAttribute("color")));
99         assertTrue("tiny".equals(ord.getAttribute("size")));
100     }
101
102     /** Test using attributes on serialized/deserialized repository*/
103     public void testSerializedCustomAttributesClassDescriptor()
104     {
105         DescriptorRepository repository = MetadataManager.getInstance().copyOfGlobalRepository();
106
107         ClassDescriptor cld = repository.getDescriptorFor(Article.class);
108         assertTrue("blue".equals(cld.getAttribute("color")));
109         assertTrue("big".equals(cld.getAttribute("size")));
110
111         FieldDescriptor fld = cld.getFieldDescriptorByName("isSelloutArticle");
112         assertTrue("green".equals(fld.getAttribute("color")));
113         assertTrue("small".equals(fld.getAttribute("size")));
114
115
116         ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName("productGroup");
117         assertNotNull("did not find ord for 'productGroup'!", ord);
118         assertTrue("red".equals(ord.getAttribute("color")));
119         assertTrue("tiny".equals(ord.getAttribute("size")));
120     }
121 }
122
Popular Tags