1
2
3
4
5
6
7 package nl.mineleni.cbsviewer.servlet.wms;
8
9 import static org.junit.Assert.assertEquals;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12 import static org.junit.Assume.assumeNotNull;
13
14 import java.io.File;
15
16 import javax.xml.transform.Source;
17 import javax.xml.transform.stream.StreamSource;
18
19 import org.custommonkey.xmlunit.XMLUnit;
20 import org.custommonkey.xmlunit.exceptions.ConfigurationException;
21 import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException;
22 import org.custommonkey.xmlunit.jaxp13.Validator;
23 import org.junit.Before;
24 import org.junit.Test;
25
26
27
28
29
30
31 public class AttributeValuesFilterTest {
32
33 private AttributeValuesFilter filter;
34
35
36
37
38
39
40
41 @Before
42 public void setUp() throws Exception {
43 XMLUnit.setIgnoreWhitespace(true);
44 XMLUnit.setIgnoreComments(true);
45 this.filter = new AttributeValuesFilter();
46 }
47
48
49
50
51 @Test
52 public void testHasFilters() {
53 assertTrue(this.filter.hasFilters());
54 }
55
56
57
58
59 @Test
60 public void testFilterValue() {
61 assertEquals("expected", this.filter.filterValue("expected"));
62 assertEquals("geheim", this.filter.filterValue(-99997));
63 }
64
65
66
67
68
69 @Test
70 public void testAttributeValuesFilterXML() {
71
72 final Validator v = new Validator();
73 final Source schema = new StreamSource(this.getClass().getClassLoader()
74 .getResourceAsStream("AttributeValuesFilter.xsd"));
75 v.addSchemaSource(schema);
76
77
78 final Source validdoc = new StreamSource(this.getClass()
79 .getClassLoader()
80 .getResourceAsStream("validAttributeValuesFilter.xml"));
81 assertTrue(v.isInstanceValid(validdoc));
82
83 final Source invaliddoc = new StreamSource(this.getClass()
84 .getClassLoader()
85 .getResourceAsStream("invalidAttributeValuesFilter.xml"));
86 try {
87 v.isInstanceValid(invaliddoc);
88 fail("Expected excepion did not occur.");
89 } catch (final XMLUnitRuntimeException x) {
90 assertEquals("Schema is invalid", x.getMessage());
91 }
92 }
93
94
95
96
97 @Test
98 public void testAttributeValuesFilterXSD() {
99 try {
100
101 final Source schema = new StreamSource(this.getClass()
102 .getClassLoader()
103 .getResourceAsStream("AttributeValuesFilter.xsd"));
104 final Validator v = new Validator();
105 v.addSchemaSource(schema);
106 assertTrue(v.isSchemaValid());
107 } catch (final ConfigurationException e) {
108 fail(e.getMessage());
109 }
110 }
111
112
113
114
115 @Test
116 public void testDeploymentAttributeValuesFilterXML() {
117
118 final Validator v = new Validator();
119 final Source schema = new StreamSource(this.getClass().getClassLoader()
120 .getResourceAsStream("AttributeValuesFilter.xsd"));
121 v.addSchemaSource(schema);
122
123
124
125
126 final Source doc = new StreamSource(new File(
127 "target/classes/AttributeValuesFilter.xml"));
128 assumeNotNull(doc);
129 assertTrue(v.isInstanceValid(doc));
130
131 }
132 }