KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > rules > TestInvokeParentRule


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package hivemind.test.rules;
16
17 import java.util.List JavaDoc;
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 JavaDoc
30     {
31         Registry r = buildFrameworkRegistry("InvokeFailure.xml");
32
33         try
34         {
35             List JavaDoc l = (List JavaDoc) 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 JavaDoc inner = findNestedException(ex);
48             assertExceptionSubstring(inner, "failure");
49         }
50
51     }
52
53     public void testNullParameter() throws Exception JavaDoc
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 JavaDoc.class);
64         List JavaDoc list = (List JavaDoc) 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 JavaDoc.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