KickJava   Java API By Example, From Geeks To Geeks.

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


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