1 15 package hivemind.test.config; 16 17 import java.util.List ; 18 19 import org.apache.hivemind.Registry; 20 import org.apache.hivemind.ServiceImplementationFactory; 21 import org.apache.hivemind.xml.XmlTestCase; 22 23 31 public class TestConversion extends XmlTestCase 32 { 33 public void testBasics() throws Exception 34 { 35 Registry r = buildFrameworkRegistry("Basics.xml"); 36 37 List l = (List ) r.getConfiguration("hivemind.test.config.Basics"); 38 39 assertEquals(1, l.size()); 40 41 DataItem d = (DataItem) l.get(0); 42 43 assertEquals("builder", d.getName()); 44 assertEquals(5, d.getCount()); 45 46 ServiceImplementationFactory builderFactory = 47 (ServiceImplementationFactory) r.getService( 48 "hivemind.BuilderFactory", 49 ServiceImplementationFactory.class); 50 51 assertSame(builderFactory, d.getFactory()); 52 } 53 54 public void testParentMethod() throws Exception 55 { 56 Registry r = buildFrameworkRegistry("ConversionParentMethod.xml"); 57 58 List l = (List ) r.getConfiguration("hivemind.test.config.ConversionParentMethod"); 59 60 assertEquals(1, l.size()); 61 62 DataItem d = (DataItem) l.get(0); 63 64 assertEquals("builder", d.getName()); 65 assertEquals(5, d.getCount()); 66 67 ServiceImplementationFactory builderFactory = 68 (ServiceImplementationFactory) r.getService( 69 "hivemind.BuilderFactory", 70 ServiceImplementationFactory.class); 71 72 assertSame(builderFactory, d.getFactory()); 73 } 74 75 public void testPropertyNameDefaultsToAttributeName() throws Exception 76 { 77 Registry r = buildFrameworkRegistry("Basics2.xml"); 78 79 List l = (List ) r.getConfiguration("hivemind.test.config.Basics2"); 80 81 assertEquals(1, l.size()); 82 83 DataItem d = (DataItem) l.get(0); 84 85 assertEquals("underworld", d.getName()); 86 assertEquals(18, d.getCount()); 87 88 ServiceImplementationFactory builderFactory = 89 (ServiceImplementationFactory) r.getService( 90 "hivemind.BuilderFactory", 91 ServiceImplementationFactory.class); 92 93 assertSame(builderFactory, d.getFactory()); 94 } 95 96 public void testComplexAttributeName() throws Exception 97 { 98 Registry r = buildFrameworkRegistry("ComplexAttributeName.xml"); 99 100 List l = (List ) r.getConfiguration("hivemind.test.config.ComplexAttributeName"); 101 102 assertEquals(1, l.size()); 103 104 ComplexNameItem cni = (ComplexNameItem) l.get(0); 105 106 assertEquals("fred", cni.getComplexAttributeName()); 107 } 108 109 public void testExtraAttributeNames() throws Exception 110 { 111 interceptLogging(); 112 113 Registry r = buildFrameworkRegistry("ExtraAttributeNames.xml"); 114 115 assertLoggedMessagePattern( 116 "Mappings for unknown attribute\\(s\\) \\[extra\\] " 117 + "\\(for element data-item\\) have been ignored\\."); 118 119 List l = (List ) r.getConfiguration("hivemind.test.config.ExtraAttributeNames"); 120 121 assertEquals(1, l.size()); 122 123 DataItem d = (DataItem) l.get(0); 124 125 assertEquals("lamb", d.getName()); 126 assertEquals(95, d.getCount()); 127 128 ServiceImplementationFactory builderFactory = 129 (ServiceImplementationFactory) r.getService( 130 "hivemind.BuilderFactory", 131 ServiceImplementationFactory.class); 132 133 assertSame(builderFactory, d.getFactory()); 134 } 135 136 public void testDuplicateAttribute() throws Exception 137 { 138 interceptLogging(); 139 140 Registry r = buildFrameworkRegistry("DuplicateAttribute.xml"); 141 142 assertLoggedMessagePattern( 143 "Mapping for attribute item-name conflicts with a previous " 144 + "mapping \\(at .*\\) and has been ignored\\."); 145 146 List l = (List ) r.getConfiguration("hivemind.test.config.DuplicateAttribute"); 147 148 assertEquals(1, l.size()); 149 150 DataItem d = (DataItem) l.get(0); 151 152 assertEquals("wesley", d.getName()); 153 assertEquals(15, d.getCount()); 154 155 ServiceImplementationFactory builderFactory = 156 (ServiceImplementationFactory) r.getService( 157 "hivemind.BuilderFactory", 158 ServiceImplementationFactory.class); 159 160 assertSame(builderFactory, d.getFactory()); 161 } 162 } 163 | Popular Tags |