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.methods.GetMethod; 38 39 48 public class TestHttpUrlMethod extends TestCase { 49 50 public TestHttpUrlMethod(String testName) { 52 super(testName); 53 } 54 55 public static void main(String args[]) { 57 String [] testCaseName = { TestHttpUrlMethod.class.getName() }; 58 junit.textui.TestRunner.main(testCaseName); 59 } 60 61 63 public static Test suite() { 64 return new TestSuite(TestHttpUrlMethod.class); 65 } 66 67 68 70 72 public void testUrlGetMethodWithPathQuery() { 73 GetMethod method = new GetMethod("http://www.fubar.com/path1/path2?query=string"); 74 try { 75 assertEquals( 76 "Get URL", 77 "http://www.fubar.com/path1/path2?query=string", 78 method.getURI().toString() 79 ); 80 } catch ( URIException e ) { 81 fail( "trouble getting URI: " + e ); 82 } 83 assertEquals("Get Path", "/path1/path2", method.getPath()); 84 assertEquals("Get query string", "query=string", method.getQueryString()); 85 86 } 87 88 public void testUrlGetMethodWithPath() { 89 GetMethod method = new GetMethod("http://www.fubar.com/path1/path2"); 90 try { 91 assertEquals( 92 "Get URL", 93 "http://www.fubar.com/path1/path2", 94 method.getURI().toString() 95 ); 96 } catch ( URIException e ) { 97 fail( "trouble getting URI: " + e ); 98 } 99 assertEquals("Get Path", "/path1/path2", method.getPath()); 100 assertEquals("Get query string", null, method.getQueryString()); 101 102 } 103 104 public void testUrlGetMethod() { 105 GetMethod method = new GetMethod("http://www.fubar.com/"); 106 try { 107 assertEquals( 108 "Get URL", 109 "http://www.fubar.com/", 110 method.getURI().toString() 111 ); 112 } catch ( URIException e ) { 113 fail( "trouble getting URI: " + e ); 114 } 115 assertEquals("Get Path", "/", method.getPath()); 116 assertEquals("Get query string", null, method.getQueryString()); 117 118 } 119 120 121 public void testUrlGetMethodWithInvalidProtocol() { 122 try 123 { 124 GetMethod method = new GetMethod("crap://www.fubar.com/"); 125 fail("The use of invalid protocol must have resulted in an IllegalStateException"); 126 } 127 catch(IllegalStateException e) 128 { 129 } 131 } 132 } 133 | Popular Tags |