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.helpers;
19:
20: import org.junit.Assert;
21: import org.junit.Test;
22:
23: public class NameSpaceTest extends Assert {
24:
25: private final String myURL1 = "http://test.apache.org/testurl1";
26: private final String myURL2 = "http://test.apache.org/testurl2";
27: private final String myCustomURL = "http://test.apache.org/custom-prefix-url";
28: private final String myOwnPrefix = "myown-prefix";
29:
30: @Test
31: public void testNSStackOperations() throws Exception {
32: NSStack nsStackObj = new NSStack();
33:
34: nsStackObj.push();
35:
36: nsStackObj.add(myURL1);
37: nsStackObj.add(myOwnPrefix, myCustomURL);
38: nsStackObj.add(myURL2);
39:
40: assertEquals(myURL1, nsStackObj.getURI("ns1"));
41: assertEquals(myCustomURL, nsStackObj.getURI(myOwnPrefix));
42: assertEquals(myURL2, nsStackObj.getURI("ns2"));
43: assertNull(nsStackObj.getURI("non-existent-prefix"));
44:
45: assertEquals("ns2", nsStackObj.getPrefix(myURL2));
46: assertEquals(myOwnPrefix, nsStackObj.getPrefix(myCustomURL));
47: assertEquals("ns1", nsStackObj.getPrefix(myURL1));
48: assertNull(nsStackObj.getPrefix("non-existent-prefix"));
49:
50: nsStackObj.pop();
51: assertNull(nsStackObj.getPrefix("non-existent-prefix"));
52: assertNull(nsStackObj.getPrefix(myCustomURL));
53: }
54:
55: @Test
56: public void testNSDeclOperaions() throws Exception {
57: NSDecl nsDecl1 = new NSDecl(myOwnPrefix, myCustomURL);
58: NSDecl nsDecl2 = new NSDecl("ns2", myURL2);
59: NSDecl nsDecl3 = new NSDecl(myOwnPrefix, myCustomURL);
60:
61: assertFalse(nsDecl2.equals(nsDecl1));
62: assertTrue(nsDecl3.equals(nsDecl1));
63:
64: }
65: }
|