diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-05-26 17:43:14 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-05-27 17:39:37 (GMT) |
commit | a790b9a2cf6c138e6fecf614f346993153aabc82 (patch) | |
tree | c5f314cab0c2778686cade97c3b6a1d502dfe8c5 /test | |
parent | 9416cec9c245e8998f29071635be4e416946e1a4 (diff) | |
download | stroke-a790b9a2cf6c138e6fecf614f346993153aabc82.zip stroke-a790b9a2cf6c138e6fecf614f346993153aabc82.tar.bz2 |
Add the functionality for processing of URL.
Adds functionalities for URL processing such as extracting parameters from URL, decoding URL.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Corresponding tests are added for each function which passes.
Change-Id: I1d54b86167b4f368c365f16c63641a6e6a91cbb8
Diffstat (limited to 'test')
-rw-r--r-- | test/com/isode/stroke/base/URLTest.java | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/test/com/isode/stroke/base/URLTest.java b/test/com/isode/stroke/base/URLTest.java new file mode 100644 index 0000000..257bab7 --- /dev/null +++ b/test/com/isode/stroke/base/URLTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2012 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ +/* + * Copyright (c) 2015 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +package com.isode.stroke.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.BeforeClass; +import org.junit.Test; +import com.isode.stroke.base.URL; + +public class URLTest { + + @Test + public void testFromString() { + URL url = URL.fromString("http://foo.bar/baz/bam"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertTrue(url.getPort() == null); + assertEquals("/baz/bam", url.getPath()); + } + + @Test + public void testFromString_WithoutPath() { + URL url = URL.fromString("http://foo.bar"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertTrue(url.getPort() == null); + assertEquals("", url.getPath()); + } + + @Test + public void testFromString_WithRootPath() { + URL url = URL.fromString("http://foo.bar/"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertTrue(url.getPort() == null); + assertEquals("/", url.getPath()); + } + + @Test + public void testFromString_WithPort() { + URL url = URL.fromString("http://foo.bar:1234/baz/bam"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertEquals(Integer.valueOf(1234), url.getPort()); + assertEquals("/baz/bam", url.getPath()); + } + + @Test + public void testFromString_WithPortOnePartPath() { + URL url = URL.fromString("http://foo.bar:11440/http-bind/"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertEquals(Integer.valueOf(11440), url.getPort()); + assertEquals("/http-bind/", url.getPath()); + } + + @Test + public void testFromString_WithPortWithoutPath() { + URL url = URL.fromString("http://foo.bar:1234"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertEquals(Integer.valueOf(1234), url.getPort()); + assertEquals("", url.getPath()); + } + + @Test + public void testFromString_WithUserInfo() { + URL url = URL.fromString("http://user:pass@foo.bar/baz/bam"); + + assertEquals("http", url.getScheme()); + assertEquals("foo.bar", url.getHost()); + assertEquals("/baz/bam", url.getPath()); + } + + + @Test + public void testFromString_NonASCIIHost() { + URL url = URL.fromString("http://www.tron%C3%A7on.be/baz/bam"); + + assertEquals("www.tron\u00E7on.be", url.getHost()); + } + + @Test + public void testFromString_NonASCIIPath() { + URL url = URL.fromString("http://foo.bar/baz/tron%C3%A7on/bam"); + + assertEquals("/baz/tron\u00E7on/bam", url.getPath()); + } + + @Test + public void testToString() { + assertEquals("http://foo.bar/baz/bam", new URL("http", "foo.bar", "/baz/bam").toString()); + } + + @Test + public void testToString_WithPort() { + assertEquals("http://foo.bar:1234/baz/bam", new URL("http", "foo.bar", 1234, "/baz/bam").toString()); + } +}
\ No newline at end of file |