001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * PolicyUtilsTest.java
039: * JUnit based test
040: *
041: * Created on January 30, 2007, 2:07 PM
042: */
043:
044: package com.sun.xml.ws.policy.privateutil;
045:
046: import com.sun.xml.ws.policy.spi.PolicyAssertionCreator;
047: import junit.framework.*;
048: import java.io.Closeable;
049: import javax.xml.stream.XMLStreamReader;
050:
051: /**
052: *
053: * @author Marek Potociar (marek.potociar at sun.com)
054: */
055: public class PolicyUtilsTest extends TestCase {
056: private static final PolicyLogger LOGGER = PolicyLogger
057: .getLogger(PolicyUtilsTest.class);
058:
059: public PolicyUtilsTest(String testName) {
060: super (testName);
061: }
062:
063: protected void setUp() throws Exception {
064: }
065:
066: protected void tearDown() throws Exception {
067: }
068:
069: /**
070: * Test of getStackMethodName method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Commons.
071: */
072: public void testCommonsGetStackMethodName() {
073: int index;
074: String expResult, result;
075:
076: index = 0;
077: expResult = "dumpThreads";
078: result = PolicyUtils.Commons.getStackMethodName(index);
079: assertEquals(expResult, result);
080:
081: index = 1;
082: expResult = "getStackTrace";
083: result = PolicyUtils.Commons.getStackMethodName(index);
084: assertEquals(expResult, result);
085:
086: index = 2;
087: expResult = "getStackMethodName";
088: result = PolicyUtils.Commons.getStackMethodName(index);
089: assertEquals(expResult, result);
090:
091: index = 3;
092: expResult = "testCommonsGetStackMethodName";
093: result = PolicyUtils.Commons.getStackMethodName(index);
094: assertEquals(expResult, result);
095: }
096:
097: public void testGetCallerMethodName() {
098: class TestCall {
099: public void testCall() {
100: String expResult, result;
101:
102: expResult = "testGetCallerMethodName";
103: result = PolicyUtils.Commons.getCallerMethodName();
104: assertEquals(expResult, result);
105: }
106: }
107: ;
108:
109: TestCall tc = new TestCall();
110: tc.testCall();
111: }
112:
113: /**
114: * Test of closeResource method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.IO.
115: */
116: public void testIOCloseResource() {
117: PolicyUtils.IO.closeResource((Closeable) null);
118: PolicyUtils.IO.closeResource((XMLStreamReader) null);
119:
120: // TODO: add more testing code
121: }
122:
123: /**
124: * Test of createIndent method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Text.
125: */
126: public void testTextCreateIndent() {
127: int indentLevel;
128: String expResult, result;
129:
130: indentLevel = 0;
131: expResult = "";
132: result = PolicyUtils.Text.createIndent(indentLevel);
133: assertEquals(expResult, result);
134:
135: indentLevel = 1;
136: expResult = " ";
137: result = PolicyUtils.Text.createIndent(indentLevel);
138: assertEquals(expResult, result);
139:
140: indentLevel = 2;
141: expResult = " ";
142: result = PolicyUtils.Text.createIndent(indentLevel);
143: assertEquals(expResult, result);
144: }
145:
146: /**
147: * Test of compareBoolean method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Comparison.
148: */
149: public void testComparisonCompareBoolean() {
150: boolean b1, b2;
151: int expResult, result;
152:
153: b1 = true;
154: b2 = true;
155: expResult = 0;
156: result = PolicyUtils.Comparison.compareBoolean(b1, b2);
157: assertEquals(expResult, result);
158:
159: b1 = false;
160: b2 = false;
161: expResult = 0;
162: result = PolicyUtils.Comparison.compareBoolean(b1, b2);
163: assertEquals(expResult, result);
164:
165: b1 = false;
166: b2 = true;
167: expResult = -1;
168: result = PolicyUtils.Comparison.compareBoolean(b1, b2);
169: assertEquals(expResult, result);
170:
171: b1 = true;
172: b2 = false;
173: expResult = 1;
174: result = PolicyUtils.Comparison.compareBoolean(b1, b2);
175: assertEquals(expResult, result);
176: }
177:
178: /**
179: * Test of compareNullableStrings method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Comparison.
180: */
181: public void testComparisonCompareNullableStrings() {
182: String s1, s2;
183: int expResult, result;
184:
185: s1 = null;
186: s2 = null;
187: expResult = 0;
188: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
189: assertEquals(expResult, result);
190:
191: s1 = "";
192: s2 = "";
193: expResult = 0;
194: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
195: assertEquals(expResult, result);
196:
197: s1 = "abc";
198: s2 = "abc";
199: expResult = 0;
200: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
201: assertEquals(expResult, result);
202:
203: s1 = null;
204: s2 = "";
205: expResult = -1;
206: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
207: assertEquals(expResult, result);
208:
209: s1 = null;
210: s2 = "abc";
211: expResult = -1;
212: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
213: assertEquals(expResult, result);
214:
215: s1 = "abc";
216: s2 = "abd";
217: expResult = -1;
218: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
219: assertEquals(expResult, result);
220:
221: s1 = "";
222: s2 = null;
223: expResult = 1;
224: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
225: assertEquals(expResult, result);
226:
227: s1 = "abc";
228: s2 = null;
229: expResult = 1;
230: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
231: assertEquals(expResult, result);
232:
233: s1 = "abd";
234: s2 = "abc";
235: expResult = 1;
236: result = PolicyUtils.Comparison.compareNullableStrings(s1, s2);
237: assertEquals(expResult, result);
238: }
239:
240: /**
241: * Test of combine method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Collections.
242: */
243: public void testCollectionsCombine() {
244: // TODO review the generated test code and remove the default call to fail.
245: // fail("The test case is a prototype.");
246: }
247:
248: /**
249: * Test of invoke method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Reflection.
250: */
251: public void testReflectionInvoke() throws Exception {
252:
253: // TODO review the generated test code and remove the default call to fail.
254: // fail("The test case is a prototype.");
255: }
256:
257: /**
258: * Test of generateFullName method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.ConfigFile.
259: */
260: public void testConfigFileGenerateFullName() {
261: System.out.println("generateFullName");
262:
263: String configFileIdentifier = "test";
264:
265: String expResult = "wsit-test.xml";
266: String result = PolicyUtils.ConfigFile
267: .generateFullName(configFileIdentifier);
268: assertEquals(expResult, result);
269: }
270:
271: /**
272: * Test of loadFromContext method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.ConfigFile.
273: */
274: public void testConfigFileLoadFromContext() throws Exception {
275: // TODO review the generated test code and remove the default call to fail.
276: // fail("The test case is a prototype.");
277: }
278:
279: /**
280: * Test of loadFromClasspath method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.ConfigFile.
281: */
282: public void testConfigFileLoadFromClasspath() {
283: // TODO review the generated test code and remove the default call to fail.
284: // fail("The test case is a prototype.");
285: }
286:
287: /**
288: * Test of load method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.ServiceProvider.
289: */
290: public void testServiceProviderLoad() {
291: System.out.println("load");
292:
293: PolicyAssertionCreator[] result = PolicyUtils.ServiceProvider
294: .load(PolicyAssertionCreator.class, this .getClass()
295: .getClassLoader());
296: assertEquals(9, result.length);
297: }
298:
299: public void testRtf2396Unquote() {
300: assertEquals("hello Vasku", PolicyUtils.Rfc2396
301: .unquote("hello%20Vasku"));
302: }
303: }
|