1 15 package org.apache.hivemind.schema.rules; 16 17 import org.apache.hivemind.Element; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.internal.Module; 20 import org.apache.hivemind.schema.SchemaProcessor; 21 import org.apache.hivemind.test.AggregateArgumentsMatcher; 22 import org.apache.hivemind.test.ArgumentMatcher; 23 import org.apache.hivemind.test.HiveMindTestCase; 24 import org.easymock.MockControl; 25 26 32 public class TestCreateObjectRule extends HiveMindTestCase 33 { 34 private Module newModule(String className, Class result) 35 { 36 MockControl control = newControl(Module.class); 37 Module module = (Module) control.getMock(); 38 39 module.resolveType(className); 40 control.setReturnValue(result); 41 42 return module; 43 } 44 45 private Element newElement(Location location) 46 { 47 MockControl control = newControl(Element.class); 48 Element element = (Element) control.getMock(); 49 50 element.getLocation(); 51 control.setReturnValue(location); 52 53 return element; 54 } 55 56 public void testCreateWithInitializer() 57 { 58 final Location l = newLocation(); 59 Module module = newModule("Bean", Bean.class); 60 Element element = newElement(l); 61 62 MockControl control = newControl(SchemaProcessor.class); 63 SchemaProcessor processor = (SchemaProcessor) control.getMock(); 64 65 processor.getDefiningModule(); 66 control.setReturnValue(module); 67 68 processor.push(new Bean()); 69 control.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher() 70 { 71 public boolean compareArguments(Object expected, Object actual) 72 { 73 Bean b = (Bean) actual; 74 75 assertEquals("HiveMind", b.getValue()); 76 assertSame(l, b.getLocation()); 77 78 return true; 79 } 80 })); 81 82 replayControls(); 83 84 CreateObjectRule rule = new CreateObjectRule("Bean,value=HiveMind"); 85 86 rule.begin(processor, element); 87 88 verifyControls(); 89 90 processor.pop(); 91 control.setReturnValue(null); 92 93 replayControls(); 94 95 rule.end(processor, element); 96 97 verifyControls(); 98 } 99 } | Popular Tags |