|
| 1 | +package com.nordstrom.common.uri; |
| 2 | + |
| 3 | +import static org.testng.Assert.assertEquals; |
| 4 | + |
| 5 | +import java.net.MalformedURLException; |
| 6 | +import java.net.URI; |
| 7 | +import java.net.URL; |
| 8 | + |
| 9 | +import org.testng.annotations.Test; |
| 10 | + |
| 11 | +public class UriUtilsTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void testUriForPath() throws MalformedURLException { |
| 15 | + URL context = URI.create("http://user:pswd@host.com:80/context/path?id=123#frag").toURL(); |
| 16 | + URI pathURI = UriUtils.uriForPath(context, "/target"); |
| 17 | + assertEquals(pathURI.getScheme(), "http", "Scheme mismatch"); |
| 18 | + assertEquals(pathURI.getUserInfo(), null, "User info mismatch"); |
| 19 | + assertEquals(pathURI.getHost(), "host.com", "Host mismatch"); |
| 20 | + assertEquals(pathURI.getPort(), 80, "Post mismatch"); |
| 21 | + assertEquals(pathURI.getPath(), "/target", "Path mismatch"); |
| 22 | + assertEquals(pathURI.getQuery(), null, "Query mismatch"); |
| 23 | + assertEquals(pathURI.getFragment(), null, "Fragment mismatch"); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testMakeBasicURI() { |
| 28 | + URI basicURI = UriUtils.makeBasicURI("http", "host.com", 80, "/target"); |
| 29 | + assertEquals(basicURI.getScheme(), "http", "Scheme mismatch"); |
| 30 | + assertEquals(basicURI.getUserInfo(), null, "User info mismatch"); |
| 31 | + assertEquals(basicURI.getHost(), "host.com", "Host mismatch"); |
| 32 | + assertEquals(basicURI.getPort(), 80, "Post mismatch"); |
| 33 | + assertEquals(basicURI.getPath(), "/target", "Path mismatch"); |
| 34 | + assertEquals(basicURI.getQuery(), null, "Query mismatch"); |
| 35 | + assertEquals(basicURI.getFragment(), null, "Fragment mismatch"); |
| 36 | + } |
| 37 | +} |
0 commit comments