1 package org.apache.maven.plugins.site.run;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24
25 import javax.xml.parsers.DocumentBuilder;
26 import javax.xml.parsers.DocumentBuilderFactory;
27 import javax.xml.xpath.XPath;
28 import javax.xml.xpath.XPathConstants;
29 import javax.xml.xpath.XPathFactory;
30
31 import org.junit.Test;
32 import org.w3c.dom.Document;
33 import org.w3c.dom.Node;
34 import org.w3c.dom.NodeList;
35
36 public class WebXmlTest
37 {
38
39 @Test
40 public void testFilters()
41 throws Exception
42 {
43 DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
44 Document doc = docBuilder.parse( SiteRunMojo.class.getResourceAsStream( "/run/web.xml" ) );
45 XPath xPath = XPathFactory.newInstance().newXPath();
46
47 NodeList filterClasses =
48 (NodeList) xPath.compile( "/web-app/filter/filter-class" ).evaluate( doc, XPathConstants.NODESET );
49
50 assertTrue( "Expected at least one filter", filterClasses.getLength() > 0 );
51 for ( int index = 0; index < filterClasses.getLength(); index++ )
52 {
53 Node filterClass = filterClasses.item( index ).getFirstChild();
54 try
55 {
56 Class.forName( filterClass.getNodeValue() );
57 }
58 catch ( ClassNotFoundException cnfe )
59 {
60 fail( "/web-app/filter[" + index + "]/filter-class refers to " + filterClass.getNodeValue()
61 + ", which doesn't exist" );
62 }
63 }
64 }
65 }