01: /*
02: * Copyright 2006 Dan Shellman
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.iscreen.impl.xml;
17:
18: import junit.framework.TestCase;
19:
20: /**
21: *
22: * @author Shellman, Dan
23: */
24: public class PositionContextTest extends TestCase {
25:
26: public PositionContextTest(String name) {
27: super (name);
28: } //end PositionContextTest()
29:
30: /**
31: * Tests the pushing of a node.
32: */
33: public void testNode() {
34: PositionContext context = new PositionContext("some_file");
35:
36: context.pushNode("node1");
37: context.pushNode("node2");
38:
39: assertEquals("/node1/node2/", context.getLocation());
40: } //end testSimpleNode()
41:
42: /**
43: * Tests the setting of an attribute.
44: */
45: public void testAttribute() {
46: PositionContext context = new PositionContext("some_file");
47:
48: context.pushNode("node1");
49: context.pushAttr("attr", "value");
50:
51: assertEquals("/node1[attr=value]/", context.getLocation());
52: } //end testAttribute()
53:
54: /**
55: * Tests a more complex set of nodes and attributes.
56: */
57: public void testComplexNodeAttributes() {
58: PositionContext context = new PositionContext("some_file");
59:
60: context.pushNode("node1");
61: context.pushAttr("attr", "value");
62: context.pushNode("node2");
63: context.pushNode("node3");
64: context.pushAttr("attr1", "value");
65: context.pushAttr("attr2", "value");
66:
67: assertEquals(
68: "/node1[attr=value]/node2/node3[attr1=value][attr2=value]/",
69: context.getLocation());
70: } //end testComplexNodeAttributes()
71:
72: /**
73: * Tests the popping of nodes.
74: */
75: public void testPoppingNodes() {
76: PositionContext context = new PositionContext("some_file");
77:
78: context.pushNode("node1");
79: context.pushAttr("attr", "value");
80: context.popNode();
81: context.pushNode("node2");
82: context.pushNode("node3");
83: context.pushAttr("attr1", "value");
84: context.pushAttr("attr2", "value");
85: context.popNode();
86: context.pushNode("node4");
87:
88: assertEquals("/node2/node4/", context.getLocation());
89: } //end testPoppingNodes()
90: } //end PositionContextTest
|