01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.test;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import org.w3c.dom.Document;
24: import junit.framework.AssertionFailedError;
25:
26: import org.apache.cxf.helpers.DOMUtils;
27: import org.junit.Assert;
28: import org.junit.Test;
29:
30: public class XPathAssertTest extends Assert {
31:
32: @Test
33: public void testAssert() throws Exception {
34: Document document = DOMUtils.readXml(getClass()
35: .getResourceAsStream("test.xml"));
36:
37: XPathAssert.assertValid("//a", document, null);
38: XPathAssert.assertInvalid("//aasd", document, null);
39:
40: try {
41: XPathAssert.assertInvalid("//a", document, null);
42: fail("Expression is valid!");
43: } catch (AssertionFailedError e) {
44: // this is correct
45: }
46:
47: try {
48: XPathAssert.assertValid("//aa", document, null);
49: fail("Expression is invalid!");
50: } catch (AssertionFailedError e) {
51: // this is correct
52: }
53:
54: XPathAssert.assertXPathEquals("//b", "foo", document, null);
55: }
56:
57: @Test
58: public void testAssertNamespace() throws Exception {
59: Document document = DOMUtils.readXml(getClass()
60: .getResourceAsStream("test2.xml"));
61:
62: Map<String, String> namespaces = new HashMap<String, String>();
63: namespaces.put("a", "urn:foo");
64: namespaces.put("z", "urn:z");
65:
66: XPathAssert.assertValid("//a:a", document, namespaces);
67: XPathAssert.assertValid("//z:b", document, namespaces);
68: }
69: }
|