Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/hivemind/schema/rules/TestCreateObjectRule.java


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