Debian Codegraph @

ssl-proxies/src/test/java/org/globus/util/UtilTest.java

raw
1 /*
2 * Copyright 1999-2010 University of Chicago
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.util;
16
17 import junit.framework.TestCase;
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.globus.util.Util;
21
22 public class UtilTest extends TestCase {
23
24 private Log logger = LogFactory.getLog(UtilTest.class);
25
26 private static final String uStr1 = "(exe = mis)";
27 private static final String qStr1 = "\"(exe = mis)\"";
28
29 private static final String uStr2 = "(exe = \"mis\")";
30 private static final String qStr2 = "\"(exe = \\\"mis\\\")\"";
31
32 private static final String uStr3 = "(exe = \"mis\"\\test)";
33 private static final String qStr3 = "\"(exe = \\\"mis\\\"\\\\test)\"";
34
35 public void testQuote1() {
36 String tStr1 = Util.quote(uStr1);
37 logger.debug(uStr1 + " : " + tStr1);
38 assertEquals("t1", qStr1, tStr1);
39
40 String tStr2 = Util.quote(uStr2);
41 logger.debug(uStr2 + " : " + tStr2);
42 assertEquals("t2", qStr2, tStr2);
43
44 String tStr3 = Util.quote(uStr3);
45 logger.debug(uStr3 + " : " + tStr3);
46 assertEquals("t3", qStr3, tStr3);
47 }
48
49 public void testUnQuote1() {
50 try {
51 String tStr0 = Util.unquote(uStr1);
52 logger.debug(uStr1 + " : " + tStr0);
53 assertEquals("t0", uStr1, tStr0);
54 } catch (Exception e) {
55 fail("Unquote failed.");
56 }
57
58 try {
59 String tStr1 = Util.unquote(qStr1);
60 logger.debug(qStr1 + " : " + tStr1);
61 assertEquals("t1", uStr1, tStr1);
62 } catch (Exception e) {
63 fail("Unquote failed.");
64 }
65
66 try {
67 String tStr2 = Util.unquote(qStr2);
68 logger.debug(qStr2 + " : " + tStr2);
69 assertEquals("t2", uStr2, tStr2);
70 } catch (Exception e) {
71 fail("Unquote failed.");
72 }
73
74 try {
75 String tStr3 = Util.unquote(qStr3);
76 logger.debug(qStr3 + " : " + tStr3);
77 assertEquals("t3", uStr3, tStr3);
78 } catch (Exception e) {
79 fail("Unquote failed.");
80 }
81 }
82 }