001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.http.client;
017:
018: import com.google.gwt.junit.client.GWTTestCase;
019:
020: /**
021: * Tests for the URL utility class.
022: */
023: public class URLTest extends GWTTestCase {
024:
025: private final String DECODED_URL = "http://www.foo \u00E9 bar.com/1_!~*'();/?@&=+$,#";
026: private final String DECODED_URL_COMPONENT = "-_.!~*'():/#?@ \u00E9 ";
027: private final String ENCODED_URL = "http://www.foo%20%C3%A9%20bar.com/1_!~*'();/?@&=+$,#";
028: private final String ENCODED_URL_COMPONENT = "-_.!~*'()%3A%2F%23%3F%40+%C3%A9+";
029:
030: public String getModuleName() {
031: return "com.google.gwt.http.HttpSuite";
032: }
033:
034: /**
035: * Test method for
036: * {@link com.google.gwt.http.client.URL#decode(java.lang.String)}.
037: */
038: public void testDecode() {
039: try {
040: URL.decode(null);
041: fail("Expected NullPointerException");
042: } catch (NullPointerException ex) {
043: // expected exception was thrown
044: }
045:
046: assertEquals("", URL.decode(""));
047: assertEquals(" ", URL.decode(" "));
048:
049: String actualURL = URL.decode(ENCODED_URL);
050: assertEquals(DECODED_URL, actualURL);
051: }
052:
053: /**
054: * Test method for
055: * {@link com.google.gwt.http.client.URL#decodeComponent(java.lang.String)}.
056: */
057: public void testDecodeComponent() {
058: try {
059: URL.decodeComponent(null);
060: fail("Expected NullPointerException");
061: } catch (NullPointerException ex) {
062: // expected exception was thrown
063: }
064:
065: assertEquals("", URL.decodeComponent(""));
066: assertEquals(" ", URL.decodeComponent(" "));
067:
068: String actualURLComponent = URL
069: .decodeComponent(ENCODED_URL_COMPONENT);
070: assertEquals(DECODED_URL_COMPONENT, actualURLComponent);
071: }
072:
073: /**
074: * Test method for
075: * {@link com.google.gwt.http.client.URL#encode(java.lang.String)}.
076: */
077: public void testEncode() {
078: try {
079: URL.encode(null);
080: fail("Expected NullPointerException");
081: } catch (NullPointerException ex) {
082: // expected exception was thrown
083: }
084:
085: assertEquals("", URL.encode(""));
086: assertEquals("%20", URL.encode(" "));
087:
088: String actualURL = URL.encode(DECODED_URL);
089: assertEquals(ENCODED_URL, actualURL);
090: }
091:
092: /**
093: * Test method for
094: * {@link com.google.gwt.http.client.URL#encodeComponent(java.lang.String)}.
095: */
096: public void testEncodeComponent() {
097: try {
098: URL.encodeComponent(null);
099: fail("Expected NullPointerException");
100: } catch (NullPointerException ex) {
101: // expected exception was thrown
102: }
103:
104: assertEquals("", URL.encodeComponent(""));
105: assertEquals("+", URL.encodeComponent(" "));
106:
107: String actualURLComponent = URL
108: .encodeComponent(DECODED_URL_COMPONENT);
109: assertEquals(ENCODED_URL_COMPONENT, actualURLComponent);
110: }
111: }
|