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 12 public class CustomAttributesTest extends TestCase 13 { 14 public static void main(String [] args) 15 { 16 String [] arr = { CLASS.getName()}; 17 junit.textui.TestRunner.main(arr); 18 } 19 20 private static Class CLASS = CustomAttributesTest.class; 22 23 27 public CustomAttributesTest(String name) 28 { 29 super(name); 30 } 31 32 36 public void setUp() 37 { 38 } 39 40 44 public void tearDown() 45 { 46 47 } 48 49 public void testCustomAttributesDescriptorRepository() 50 { 51 String repositoryAttribute_1 = "attribute-repository-1"; 52 String repositoryAttribute_2 = "attribute-repository-2"; 53 MetadataManager mm = MetadataManager.getInstance(); 54 55 DescriptorRepository dr = mm.readDescriptorRepository(MetadataTest.TEST_REPOSITORY); 56 String res_1 = dr.getAttribute(repositoryAttribute_1); 57 String 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 connectionAttribute_1 = "attribute-connection-1"; 68 String 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 res_1 = jcd.getAttribute(connectionAttribute_1); 74 String 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 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 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 |