1 15 package hivemind.test.rules; 16 17 import java.util.List ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.Registry; 21 import org.apache.hivemind.schema.SchemaProcessor; 22 import org.apache.hivemind.schema.rules.InvokeParentRule; 23 import org.apache.hivemind.xml.XmlTestCase; 24 import org.easymock.MockControl; 25 26 public class TestInvokeParentRule extends XmlTestCase 27 { 28 29 public void testInvokeFailure() throws Exception 30 { 31 Registry r = buildFrameworkRegistry("InvokeFailure.xml"); 32 33 try 34 { 35 List l = (List ) r.getConfiguration("hivemind.test.rules.InvokeFailure"); 36 37 l.size(); 38 39 unreachable(); 40 } 41 catch (ApplicationRuntimeException ex) 42 { 43 assertExceptionSubstring( 44 ex, 45 "Unable to construct configuration hivemind.test.rules.InvokeFailure: Error invoking method failure on java.util.ArrayList"); 46 47 Throwable inner = findNestedException(ex); 48 assertExceptionSubstring(inner, "failure"); 49 } 50 51 } 52 53 public void testNullParameter() throws Exception 54 { 55 InvokeParentRule rule = new InvokeParentRule("add"); 56 57 MockControl procControl = newControl(SchemaProcessor.class); 58 SchemaProcessor proc = (SchemaProcessor) procControl.getMock(); 59 60 proc.peek(0); 61 procControl.setReturnValue(null); 62 63 MockControl listControl = newControl(List .class); 64 List list = (List ) listControl.getMock(); 65 66 proc.peek(1); 67 procControl.setReturnValue(list); 68 69 proc.isInBackwardCompatibilityModeForMaps(); 70 procControl.setReturnValue(false); 71 72 list.add(null); 73 listControl.setReturnValue(true); 74 75 replayControls(); 76 77 rule.begin(proc, null); 78 79 verifyControls(); 80 81 resetControls(); 82 83 rule = new InvokeParentRule("get"); 84 85 proc.peek(0); 86 procControl.setReturnValue(null); 87 88 proc.peek(1); 89 procControl.setReturnValue(list); 90 91 proc.isInBackwardCompatibilityModeForMaps(); 92 procControl.setReturnValue(false); 93 94 replayControls(); 95 96 try 97 { 98 rule.begin(proc, null); 99 100 fail(); 101 } 102 catch (ApplicationRuntimeException e) 103 { 104 assertEquals(NoSuchMethodException .class, e.getCause().getClass()); 105 } 106 107 verifyControls(); 108 } 109 110 public void testGetMethod() 111 { 112 InvokeParentRule r = new InvokeParentRule(); 113 114 r.setMethodName("foo"); 115 116 assertEquals("foo", r.getMethodName()); 117 } 118 119 } 120 | Popular Tags |