KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.hivemind.Attribute;
18 import org.apache.hivemind.SymbolExpander;
19 import org.apache.hivemind.impl.AttributeImpl;
20 import org.apache.hivemind.impl.ElementImpl;
21 import org.apache.hivemind.internal.Module;
22 import org.apache.hivemind.schema.SchemaProcessor;
23 import org.apache.hivemind.schema.rules.NullTranslator;
24 import org.apache.hivemind.schema.rules.PushAttributeRule;
25 import org.apache.hivemind.test.HiveMindTestCase;
26 import org.easymock.MockControl;
27
28 public class TestPushAttributeRule extends HiveMindTestCase
29 {
30     public void testPushAttributeRule()
31     {
32         MockControl control = newControl(SchemaProcessor.class);
33
34         ElementImpl element = new ElementImpl();
35         element.setElementName("myelement");
36
37         Attribute attribute = new AttributeImpl("fred", "${flintstone}");
38
39         element.addAttribute(attribute);
40
41         PushAttributeRule rule = new PushAttributeRule();
42
43         rule.setAttributeName("fred");
44
45         SchemaProcessor mockProcessor = (SchemaProcessor) control.getMock();
46
47         mockProcessor.getContributingModule();
48
49         MockControl moduleControl = newControl(Module.class);
50         Module mockModule = (Module) moduleControl.getMock();
51
52         control.setReturnValue(mockModule);
53
54         MockControl symbolExpanderControl = newControl(SymbolExpander.class);
55         SymbolExpander symbolExpander = (SymbolExpander) symbolExpanderControl.getMock();
56         
57         mockProcessor.getSymbolExpander();
58         control.setReturnValue(symbolExpander);
59
60         mockProcessor.getAttributeTranslator("fred");
61         control.setReturnValue(new NullTranslator());
62
63         mockProcessor.getContributingModule();
64         control.setReturnValue(mockModule);
65
66         symbolExpander.expandSymbols("${flintstone}", element.getLocation());
67         symbolExpanderControl.setReturnValue("FLINTSTONE");
68
69         mockProcessor.push("FLINTSTONE");
70         mockProcessor.pop();
71
72         control.setReturnValue("FLINTSTONE");
73
74         replayControls();
75
76         rule.begin(mockProcessor, element);
77         rule.end(mockProcessor, element);
78
79         verifyControls();
80     }
81 }
82
Popular Tags