1
|
|
package junit.extensions.xml.elements;
|
2
|
|
|
3
|
|
import org.w3c.dom.Element;
|
4
|
|
import junit.extensions.xml.IXMLTestCase;
|
5
|
|
import junit.extensions.xml.XMLException;
|
6
|
|
import junit.framework.TestCase;
|
7
|
|
import junit.extensions.xml.XMLTagResourceBundle;
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
public class TokenizeTagHandlerT
|
17
|
|
extends TestCase {
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
private TokenizeTagHandler m_tokenizeTagHandler = null;
|
23
|
|
|
24
|
|
|
25
|
|
|
26
|
|
|
27
|
|
private ElementFixture m_fixture;
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
|
|
32
|
|
private IXMLTestCase m_testCase;
|
33
|
|
|
34
|
|
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
2
|
public TokenizeTagHandlerT(final String name) {
|
39
|
2
|
super(name);
|
40
|
|
}
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
2
|
protected void setUp() throws Exception {
|
47
|
2
|
super.setUp();
|
48
|
2
|
m_fixture = new ElementFixture(this);
|
49
|
2
|
m_fixture.setUp();
|
50
|
2
|
m_testCase = m_fixture.getTestCase();
|
51
|
|
|
52
|
|
}
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
2
|
protected void tearDown() throws Exception {
|
59
|
2
|
m_tokenizeTagHandler = null;
|
60
|
2
|
m_fixture.tearDown();
|
61
|
|
|
62
|
2
|
m_testCase = null;
|
63
|
2
|
m_fixture = null;
|
64
|
2
|
super.tearDown();
|
65
|
|
}
|
66
|
|
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
1
|
public void testProcessElement() throws XMLException {
|
72
|
1
|
Element element = m_fixture.newElement("tokenize", new String[] {
|
73
|
|
"id", "first",
|
74
|
|
"refid", "data",
|
75
|
|
"delimiter", ":"
|
76
|
|
});
|
77
|
|
|
78
|
1
|
m_tokenizeTagHandler = new TokenizeTagHandler(element, m_testCase);
|
79
|
1
|
m_testCase.addProperty("data", "test1:test2:test3");
|
80
|
|
|
81
|
1
|
m_tokenizeTagHandler.processElement();
|
82
|
1
|
String first = (String) m_testCase.getProperty("first");
|
83
|
1
|
String data = (String) m_testCase.getProperty("data");
|
84
|
1
|
assertEquals("test1", first);
|
85
|
1
|
assertEquals("test2:test3", data);
|
86
|
|
|
87
|
1
|
m_tokenizeTagHandler.processElement();
|
88
|
1
|
first = (String) m_testCase.getProperty("first");
|
89
|
1
|
data = (String) m_testCase.getProperty("data");
|
90
|
1
|
assertEquals("test2", first);
|
91
|
1
|
assertEquals("test3", data);
|
92
|
|
|
93
|
1
|
m_tokenizeTagHandler.processElement();
|
94
|
1
|
first = (String) m_testCase.getProperty("first");
|
95
|
1
|
data = (String) m_testCase.getProperty("data");
|
96
|
1
|
assertEquals("test3", first);
|
97
|
1
|
assertNull(data);
|
98
|
|
|
99
|
|
|
100
|
1
|
m_testCase.addProperty("data", ":::test");
|
101
|
1
|
m_tokenizeTagHandler.processElement();
|
102
|
1
|
first = (String) m_testCase.getProperty("first");
|
103
|
1
|
data = (String) m_testCase.getProperty("data");
|
104
|
1
|
assertEquals("first token", "", first);
|
105
|
1
|
assertEquals("::test", data);
|
106
|
|
|
107
|
1
|
m_testCase.addProperty("debug", "true");
|
108
|
1
|
m_tokenizeTagHandler.processElement();
|
109
|
1
|
first = (String) m_testCase.getProperty("first");
|
110
|
1
|
data = (String) m_testCase.getProperty("data");
|
111
|
1
|
assertEquals("second token", "", first);
|
112
|
1
|
assertEquals(":test", data);
|
113
|
|
|
114
|
1
|
m_tokenizeTagHandler.processElement();
|
115
|
1
|
first = (String) m_testCase.getProperty("first");
|
116
|
1
|
data = (String) m_testCase.getProperty("data");
|
117
|
1
|
assertEquals("third token", "", first);
|
118
|
1
|
assertEquals("test", data);
|
119
|
|
|
120
|
1
|
m_tokenizeTagHandler.processElement();
|
121
|
1
|
first = (String) m_testCase.getProperty("first");
|
122
|
1
|
data = (String) m_testCase.getProperty("data");
|
123
|
1
|
assertEquals("third token", "test", first);
|
124
|
1
|
assertNull("test", data);
|
125
|
|
|
126
|
|
}
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
|
|
131
|
1
|
public void testLookup() {
|
132
|
1
|
Element element = m_fixture.newElement("tokenize", new String[] {
|
133
|
|
"id", "first",
|
134
|
|
"refid", "data",
|
135
|
|
"delimiter", ":"
|
136
|
|
});
|
137
|
1
|
Object o = XMLTagResourceBundle.getTagHandler(element, m_testCase, "tokenize");
|
138
|
1
|
assertNotNull(o);
|
139
|
|
}
|
140
|
|
}
|
141
|
|
|