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