47
47
import org .codehaus .plexus .util .xml .Xpp3Dom ;
48
48
import org .jdom2 .Document ;
49
49
import org .jdom2 .Text ;
50
+ import org .jdom2 .filter .Filters ;
50
51
import org .jdom2 .input .SAXBuilder ;
51
- import org .jdom2 .xpath .XPath ;
52
+ import org .jdom2 .input .sax .XMLReaders ;
53
+ import org .jdom2 .xpath .XPathExpression ;
54
+ import org .jdom2 .xpath .XPathFactory ;
52
55
import org .junit .Before ;
53
56
import org .junit .Rule ;
54
57
import org .junit .Test ;
@@ -147,17 +150,19 @@ public void testAddToArchive_ShouldWriteComponentWithoutHintToFile() throws Exce
147
150
148
151
assertEquals (ComponentsXmlArchiverFileFilter .COMPONENTS_XML_PATH , fca .getDestFileName ());
149
152
150
- final SAXBuilder builder = new SAXBuilder (false );
153
+ final SAXBuilder builder = new SAXBuilder (XMLReaders . NONVALIDATING );
151
154
152
155
final Document doc = builder .build (fca .getFile ());
156
+ XPathFactory xPathFactory = XPathFactory .instance ();
153
157
154
- final XPath role = XPath .newInstance ("//component[position()=1]/role/text()" );
155
- final XPath hint = XPath .newInstance ("//component[position()=1]/role-hint/text()" );
156
- final XPath implementation = XPath .newInstance ("//component[position()=1]/implementation/text()" );
158
+ XPathExpression <Text > role = xPathFactory .compile ("//component[position()=1]/role/text()" , Filters .text ());
159
+ XPathExpression <Text > hint = xPathFactory .compile ("//component[position()=1]/role-hint/text()" , Filters .text ());
160
+ XPathExpression <Text > implementation =
161
+ xPathFactory .compile ("//component[position()=1]/implementation/text()" , Filters .text ());
157
162
158
- assertEquals ("role" , (( Text ) role .selectSingleNode (doc ) ).getText ());
159
- assertNull (hint .selectSingleNode (doc ));
160
- assertEquals ("impl" , (( Text ) implementation .selectSingleNode (doc ) ).getText ());
163
+ assertEquals ("role" , role .evaluateFirst (doc ).getText ());
164
+ assertNull (hint .evaluateFirst (doc ));
165
+ assertEquals ("impl" , implementation .evaluateFirst (doc ).getText ());
161
166
}
162
167
163
168
@ Test
@@ -173,17 +178,19 @@ public void testAddToArchive_ShouldWriteComponentWithHintToFile() throws Excepti
173
178
174
179
assertEquals (ComponentsXmlArchiverFileFilter .COMPONENTS_XML_PATH , fca .getDestFileName ());
175
180
176
- final SAXBuilder builder = new SAXBuilder (false );
181
+ final SAXBuilder builder = new SAXBuilder (XMLReaders . NONVALIDATING );
177
182
178
183
final Document doc = builder .build (fca .getFile ());
184
+ XPathFactory xPathFactory = XPathFactory .instance ();
179
185
180
- final XPath role = XPath .newInstance ("//component[position()=1]/role/text()" );
181
- final XPath hint = XPath .newInstance ("//component[position()=1]/role-hint/text()" );
182
- final XPath implementation = XPath .newInstance ("//component[position()=1]/implementation/text()" );
186
+ XPathExpression <Text > role = xPathFactory .compile ("//component[position()=1]/role/text()" , Filters .text ());
187
+ XPathExpression <Text > hint = xPathFactory .compile ("//component[position()=1]/role-hint/text()" , Filters .text ());
188
+ XPathExpression <Text > implementation =
189
+ xPathFactory .compile ("//component[position()=1]/implementation/text()" , Filters .text ());
183
190
184
- assertEquals ("role" , (( Text ) role .selectSingleNode (doc ) ).getText ());
185
- assertEquals ("hint" , (( Text ) hint .selectSingleNode (doc ) ).getText ());
186
- assertEquals ("impl" , (( Text ) implementation .selectSingleNode (doc ) ).getText ());
191
+ assertEquals ("role" , role .evaluateFirst (doc ).getText ());
192
+ assertEquals ("hint" , hint .evaluateFirst (doc ).getText ());
193
+ assertEquals ("impl" , implementation .evaluateFirst (doc ).getText ());
187
194
}
188
195
189
196
@ Test
@@ -204,25 +211,29 @@ public void testAddToArchive_ShouldWriteTwoComponentToFile() throws Exception {
204
211
205
212
assertEquals (ComponentsXmlArchiverFileFilter .COMPONENTS_XML_PATH , fca .getDestFileName ());
206
213
207
- final SAXBuilder builder = new SAXBuilder (false );
214
+ final SAXBuilder builder = new SAXBuilder (XMLReaders . NONVALIDATING );
208
215
209
216
final Document doc = builder .build (fca .getFile ());
210
-
211
- final XPath role = XPath .newInstance ("//component[position()=1]/role/text()" );
212
- final XPath hint = XPath .newInstance ("//component[position()=1]/role-hint/text()" );
213
- final XPath implementation = XPath .newInstance ("//component[position()=1]/implementation/text()" );
214
-
215
- assertEquals ("role" , ((Text ) role .selectSingleNode (doc )).getText ());
216
- assertEquals ("hint" , ((Text ) hint .selectSingleNode (doc )).getText ());
217
- assertEquals ("impl" , ((Text ) implementation .selectSingleNode (doc )).getText ());
218
-
219
- final XPath role2 = XPath .newInstance ("//component[position()=2]/role/text()" );
220
- final XPath hint2 = XPath .newInstance ("//component[position()=2]/role-hint/text()" );
221
- final XPath implementation2 = XPath .newInstance ("//component[position()=2]/implementation/text()" );
222
-
223
- assertEquals ("role" , ((Text ) role2 .selectSingleNode (doc )).getText ());
224
- assertEquals ("hint2" , ((Text ) hint2 .selectSingleNode (doc )).getText ());
225
- assertEquals ("impl" , ((Text ) implementation2 .selectSingleNode (doc )).getText ());
217
+ XPathFactory xPathFactory = XPathFactory .instance ();
218
+
219
+ XPathExpression <Text > role = xPathFactory .compile ("//component[position()=1]/role/text()" , Filters .text ());
220
+ XPathExpression <Text > hint = xPathFactory .compile ("//component[position()=1]/role-hint/text()" , Filters .text ());
221
+ XPathExpression <Text > implementation =
222
+ xPathFactory .compile ("//component[position()=1]/implementation/text()" , Filters .text ());
223
+
224
+ assertEquals ("role" , role .evaluateFirst (doc ).getText ());
225
+ assertEquals ("hint" , hint .evaluateFirst (doc ).getText ());
226
+ assertEquals ("impl" , implementation .evaluateFirst (doc ).getText ());
227
+
228
+ XPathExpression <Text > role2 = xPathFactory .compile ("//component[position()=2]/role/text()" , Filters .text ());
229
+ XPathExpression <Text > hint2 =
230
+ xPathFactory .compile ("//component[position()=2]/role-hint/text()" , Filters .text ());
231
+ XPathExpression <Text > implementation2 =
232
+ xPathFactory .compile ("//component[position()=2]/implementation/text()" , Filters .text ());
233
+
234
+ assertEquals ("role" , role2 .evaluateFirst (doc ).getText ());
235
+ assertEquals ("hint2" , hint2 .evaluateFirst (doc ).getText ());
236
+ assertEquals ("impl" , implementation2 .evaluateFirst (doc ).getText ());
226
237
}
227
238
228
239
@ Test
@@ -257,25 +268,29 @@ public void testAddToArchive_ShouldWriteTwoComponentToArchivedFile() throws Exce
257
268
Files .copy (zf .getInputStream (ze ), descriptorFile .toPath ());
258
269
}
259
270
260
- final SAXBuilder builder = new SAXBuilder (false );
271
+ final SAXBuilder builder = new SAXBuilder (XMLReaders . NONVALIDATING );
261
272
262
273
final Document doc = builder .build (descriptorFile );
263
274
264
- final XPath role = XPath .newInstance ("//component[position()=1]/role/text()" );
265
- final XPath hint = XPath .newInstance ("//component[position()=1]/role-hint/text()" );
266
- final XPath implementation = XPath .newInstance ("//component[position()=1]/implementation/text()" );
267
-
268
- assertEquals ("role" , ((Text ) role .selectSingleNode (doc )).getText ());
269
- assertEquals ("hint" , ((Text ) hint .selectSingleNode (doc )).getText ());
270
- assertEquals ("impl" , ((Text ) implementation .selectSingleNode (doc )).getText ());
271
-
272
- final XPath role2 = XPath .newInstance ("//component[position()=2]/role/text()" );
273
- final XPath hint2 = XPath .newInstance ("//component[position()=2]/role-hint/text()" );
274
- final XPath implementation2 = XPath .newInstance ("//component[position()=2]/implementation/text()" );
275
-
276
- assertEquals ("role" , ((Text ) role2 .selectSingleNode (doc )).getText ());
277
- assertEquals ("hint2" , ((Text ) hint2 .selectSingleNode (doc )).getText ());
278
- assertEquals ("impl" , ((Text ) implementation2 .selectSingleNode (doc )).getText ());
275
+ XPathFactory xPathFactory = XPathFactory .instance ();
276
+ XPathExpression <Text > role = xPathFactory .compile ("//component[position()=1]/role/text()" , Filters .text ());
277
+ XPathExpression <Text > hint = xPathFactory .compile ("//component[position()=1]/role-hint/text()" , Filters .text ());
278
+ XPathExpression <Text > implementation =
279
+ xPathFactory .compile ("//component[position()=1]/implementation/text()" , Filters .text ());
280
+
281
+ assertEquals ("role" , role .evaluateFirst (doc ).getText ());
282
+ assertEquals ("hint" , hint .evaluateFirst (doc ).getText ());
283
+ assertEquals ("impl" , implementation .evaluateFirst (doc ).getText ());
284
+
285
+ XPathExpression <Text > role2 = xPathFactory .compile ("//component[position()=2]/role/text()" , Filters .text ());
286
+ XPathExpression <Text > hint2 =
287
+ xPathFactory .compile ("//component[position()=2]/role-hint/text()" , Filters .text ());
288
+ XPathExpression <Text > implementation2 =
289
+ xPathFactory .compile ("//component[position()=2]/implementation/text()" , Filters .text ());
290
+
291
+ assertEquals ("role" , role2 .evaluateFirst (doc ).getText ());
292
+ assertEquals ("hint2" , hint2 .evaluateFirst (doc ).getText ());
293
+ assertEquals ("impl" , implementation2 .evaluateFirst (doc ).getText ());
279
294
}
280
295
281
296
private Xpp3Dom createComponentDom (final ComponentDef def ) {
0 commit comments