001: package org.apache.ojb.broker.metadata;
002:
003: import junit.framework.TestCase;
004:
005: import org.apache.ojb.broker.Article;
006: import org.apache.ojb.broker.PBKey;
007:
008: /**
009: * This TestClass tests the RepositoryPersitors facilities for
010: * reading and writing a valid repository.
011: */
012: public class CustomAttributesTest extends TestCase {
013: public static void main(String[] args) {
014: String[] arr = { CLASS.getName() };
015: junit.textui.TestRunner.main(arr);
016: }
017:
018: //PersistenceBroker broker;
019: private static Class CLASS = CustomAttributesTest.class;
020:
021: /**
022: * Insert the method's description here.
023: * Creation date: (24.12.2000 00:33:40)
024: */
025: public CustomAttributesTest(String name) {
026: super (name);
027: }
028:
029: /**
030: * Insert the method's description here.
031: * Creation date: (06.12.2000 21:58:53)
032: */
033: public void setUp() {
034: }
035:
036: /**
037: * Insert the method's description here.
038: * Creation date: (06.12.2000 21:59:14)
039: */
040: public void tearDown() {
041:
042: }
043:
044: public void testCustomAttributesDescriptorRepository() {
045: String repositoryAttribute_1 = "attribute-repository-1";
046: String repositoryAttribute_2 = "attribute-repository-2";
047: MetadataManager mm = MetadataManager.getInstance();
048:
049: DescriptorRepository dr = mm
050: .readDescriptorRepository(MetadataTest.TEST_REPOSITORY);
051: String res_1 = dr.getAttribute(repositoryAttribute_1);
052: String res_2 = dr.getAttribute(repositoryAttribute_2);
053: assertNotNull("No attributes found", res_1);
054: assertNotNull("No attributes found", res_2);
055: assertEquals("Found attribute does not match",
056: "attribute-repository-test-value-1", res_1);
057: assertEquals("Found attribute does not match",
058: "attribute-repository-test-value-2", res_2);
059:
060: }
061:
062: public void testCustomAttributesConnectionDescriptor() {
063: String connectionAttribute_1 = "attribute-connection-1";
064: String connectionAttribute_2 = "attribute-connection-2";
065:
066: MetadataManager mm = MetadataManager.getInstance();
067: ConnectionRepository cr = mm
068: .readConnectionRepository(MetadataTest.TEST_CONNECTION_DESCRIPTOR);
069: JdbcConnectionDescriptor jcd = cr.getDescriptor(new PBKey(
070: "runtime"));
071: String res_1 = jcd.getAttribute(connectionAttribute_1);
072: String res_2 = jcd.getAttribute(connectionAttribute_2);
073: assertNotNull("No attributes found", res_1);
074: assertNotNull("No attributes found", res_2);
075: assertEquals("Found attribute does not match",
076: "attribute-connection-test-value-1", res_1);
077: assertEquals("Found attribute does not match",
078: "attribute-connection-test-value-2", res_2);
079: }
080:
081: /** Test storing repository.*/
082: public void testCustomAttributesClassDescriptor() {
083: DescriptorRepository repository = MetadataManager.getInstance()
084: .getRepository();
085:
086: ClassDescriptor cld = repository
087: .getDescriptorFor(Article.class);
088: assertTrue("blue".equals(cld.getAttribute("color")));
089: assertTrue("big".equals(cld.getAttribute("size")));
090:
091: FieldDescriptor fld = cld
092: .getFieldDescriptorByName("isSelloutArticle");
093: assertTrue("green".equals(fld.getAttribute("color")));
094: assertTrue("small".equals(fld.getAttribute("size")));
095:
096: ObjectReferenceDescriptor ord = cld
097: .getObjectReferenceDescriptorByName("productGroup");
098: assertNotNull("did not find ord for 'productGroup'!", ord);
099: assertTrue("red".equals(ord.getAttribute("color")));
100: assertTrue("tiny".equals(ord.getAttribute("size")));
101: }
102:
103: /** Test using attributes on serialized/deserialized repository*/
104: public void testSerializedCustomAttributesClassDescriptor() {
105: DescriptorRepository repository = MetadataManager.getInstance()
106: .copyOfGlobalRepository();
107:
108: ClassDescriptor cld = repository
109: .getDescriptorFor(Article.class);
110: assertTrue("blue".equals(cld.getAttribute("color")));
111: assertTrue("big".equals(cld.getAttribute("size")));
112:
113: FieldDescriptor fld = cld
114: .getFieldDescriptorByName("isSelloutArticle");
115: assertTrue("green".equals(fld.getAttribute("color")));
116: assertTrue("small".equals(fld.getAttribute("size")));
117:
118: ObjectReferenceDescriptor ord = cld
119: .getObjectReferenceDescriptorByName("productGroup");
120: assertNotNull("did not find ord for 'productGroup'!", ord);
121: assertTrue("red".equals(ord.getAttribute("color")));
122: assertTrue("tiny".equals(ord.getAttribute("size")));
123: }
124: }
|