KickJava   Java API By Example, From Geeks To Geeks.

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


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