1 30 31 package org.apache.commons.httpclient; 32 33 import junit.framework.Test; 34 import junit.framework.TestCase; 35 import junit.framework.TestSuite; 36 37 import org.apache.commons.httpclient.util.URIUtil; 38 39 47 public class TestURIUtil extends TestCase { 48 URITestCase pathTests[] = {new URITestCase("http://www.server.com/path1/path2", "/path1/path2"), 50 new URITestCase("http://www.server.com/path1/path2/", "/path1/path2/"), 51 new URITestCase("http://www.server.com/path1/path2?query=string", "/path1/path2"), 52 new URITestCase("http://www.server.com/path1/path2/?query=string", "/path1/path2/"), 53 new URITestCase("www.noscheme.com/path1/path2", "/path1/path2"), 54 new URITestCase("www.noscheme.com/path1/path2#anchor?query=string", "/path1/path2"), 55 new URITestCase("/noscheme/nohost/path", "/noscheme/nohost/path"), 56 new URITestCase("http://www.server.com", "/"), 57 new URITestCase("https://www.server.com:443/ssl/path", "/ssl/path"), 58 new URITestCase("http://www.server.com:8080/path/with/port", "/path/with/port"), 59 new URITestCase("http://www.server.com/path1/path2?query1=string?1&query2=string2", "/path1/path2")}; 60 61 URITestCase queryTests[] = {new URITestCase("http://www.server.com/path1/path2", null), 62 new URITestCase("http://www.server.com/path1/path2?query=string", "query=string"), 63 new URITestCase("http://www.server.com/path1/path2/?query=string", "query=string"), 64 new URITestCase("www.noscheme.com/path1/path2#anchor?query=string", "query=string"), 65 new URITestCase("/noscheme/nohost/path?query1=string1&query2=string2", "query1=string1&query2=string2"), 66 new URITestCase("https://www.server.com:443/ssl/path?query1=string1&query2=string2", "query1=string1&query2=string2"), 67 new URITestCase("http://www.server.com:8080/path/with/port?query1=string1&query2=string2", "query1=string1&query2=string2"), 68 new URITestCase("http://www.server.com/path1/path2?query1=string?1&query2=string2", "query1=string?1&query2=string2")}; 69 70 71 72 public TestURIUtil(String testName) { 74 super(testName); 75 } 76 77 public static void main(String args[]) { 79 String [] testCaseName = { TestURIUtil.class.getName() }; 80 junit.textui.TestRunner.main(testCaseName); 81 } 82 83 85 public static Test suite() { 86 return new TestSuite(TestURIUtil.class); 87 } 88 89 90 public void testGetPath() 92 { 93 String testValue = ""; 94 String expectedResult = ""; 95 96 for(int i=0;i<pathTests.length;i++){ 97 testValue = pathTests[i].getTestValue(); 98 expectedResult = pathTests[i].getExpectedResult(); 99 assertEquals("Path test", expectedResult, URIUtil.getPath(testValue)); 100 } 101 } 102 103 public void testGetQueryString() 104 { 105 String testValue = ""; 106 String expectedResult = ""; 107 108 for(int i=0;i<queryTests.length;i++){ 109 testValue = queryTests[i].getTestValue(); 110 expectedResult = queryTests[i].getExpectedResult(); 111 assertEquals("Path test", expectedResult, URIUtil.getQuery(testValue)); 112 } 113 } 114 115 private class URITestCase{ 116 private String testValue; 117 private String expectedResult; 118 119 public URITestCase(String testValue, String expectedResult){ 120 this.testValue = testValue; 121 this.expectedResult = expectedResult; 122 } 123 124 public String getTestValue(){ 125 return testValue; 126 } 127 128 public String getExpectedResult(){ 129 return expectedResult; 130 } 131 } 132 } 133 | Popular Tags |