Debian Codegraph @

test/types/TestNormalizedString.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package test.types;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.types.NormalizedString;
21
22 /**
23 * Test validation of encoding.NormalizedString
24 */
25 public class TestNormalizedString extends TestCase {
26
27 public TestNormalizedString(String name) {
28 super(name);
29 }
30
31 /**
32 * Run a failure test. value should be invalid.
33 */
34 private void runFailTest(String value) throws Exception {
35 NormalizedString oNormalizedString = null;
36 try {
37 oNormalizedString = new NormalizedString(value);
38 }
39 catch (Exception e) { // catch the validation exception
40 }
41 // object is not iNstantiated on bad data value
42 assertNull("validation restriction failed [" +
43 value + "]. did not restrict bad value.", oNormalizedString);
44 }
45
46 /**
47 * Run a successful test. value should be valid.
48 */
49 private void runPassTest(String value) throws Exception {
50 NormalizedString oNormalizedString = null;
51 try {
52 oNormalizedString = new NormalizedString(value);
53 }
54 catch (Exception e) { // catch the validation exception
55 }
56 assertEquals("normalized string not equal" +
57 value, oNormalizedString.toString(), value);
58 }
59
60 /**
61 * Test that "a simple string" succeeds.
62 */
63 public void testNsSimpleString() throws Exception {
64 runPassTest("a simple string");
65 }
66
67 /**
68 * Test that "this has \r carriage return" fails.
69 */
70 public void testNsCarriageReturn() throws Exception {
71 runFailTest("this has \r carriage return");
72 }
73
74 /**
75 * Test that "this has \n line feed" fails.
76 */
77 public void testNsLineFeed() throws Exception {
78 runFailTest("this has \n line feed");
79 }
80
81 /**
82 * Test that "this has \t a tab" fails.
83 */
84 public void testNsStringWithTabs() throws Exception {
85 runFailTest("this has \t a tab");
86 }
87
88 /**
89 * differentiate from xsd:token
90 */
91 public void testNsStringWithLeadingSpaces() throws Exception {
92 runPassTest(" a failure case");
93 }
94
95 /*
96 * differentiate from xsd:token
97 */
98 public void testNsStringWithTrailingSpaces() throws Exception {
99 runPassTest("this is a ");
100 }
101
102 /*
103 * differentiate from xsd:token
104 */
105 public void testNsStringWithLeadingAndTrailingSpaces() throws Exception {
106 runPassTest(" centered ");
107 }
108
109 /*
110 * differentiate from xsd:token
111 */
112 public void testNsDoubleSpace() throws Exception {
113 runPassTest("a B"); // note: \r fails
114 }
115 }