KickJava   Java API By Example, From Geeks To Geeks.

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


1 // Copyright 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 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 /**
29  * Tests for {@link org.apache.hivemind.schema.rules.CreateObjectRule}.
30  *
31  * @author Howard M. Lewis Ship
32  * @since 1.1
33  */

34 public class TestCreateObjectRule extends HiveMindTestCase
35 {
36     private Module newModule(String JavaDoc className, Class JavaDoc 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 JavaDoc expected, Object JavaDoc 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