1 45 package org.exolab.jms.net.http.connector; 46 47 import junit.framework.TestCase; 48 49 import org.exolab.jms.net.http.HTTPRequestInfo; 50 import org.exolab.jms.net.uri.URI; 51 import org.exolab.jms.net.util.Properties; 52 import org.exolab.jms.net.util.SSLProperties; 53 54 55 61 public class HTTPRequestInfoTest extends TestCase { 62 63 68 public HTTPRequestInfoTest(String name) { 69 super(name); 70 } 71 72 77 public void testAccessors() throws Exception { 78 final String uri = "http://localhost:80"; 79 final String proxyHost = "foo"; 80 final int proxyPort = 1030; 81 final String proxyUser = "bar"; 82 final String proxyPassword = "fly"; 83 final SSLProperties ssl = new SSLProperties(); 84 85 HTTPRequestInfo info = populate(uri, proxyHost, proxyPort, proxyUser, 86 proxyPassword, ssl); 87 88 assertEquals(uri, info.getURI().toString()); 89 assertEquals(proxyHost, info.getProxyHost()); 90 assertEquals(proxyPort, info.getProxyPort()); 91 assertEquals(proxyUser, info.getProxyUser()); 92 assertEquals(proxyPassword, info.getProxyPassword()); 93 assertEquals(ssl, info.getSSLProperties()); 94 } 95 96 101 public void testEquals() throws Exception { 102 final String uri = "http://exolab.org:80"; 103 final String proxyHost = "boo"; 104 final int proxyPort = 9090; 105 final String proxyUser = "hoo"; 106 final String proxyPassword = "shoo"; 107 final SSLProperties ssl = new SSLProperties(); 108 109 HTTPRequestInfo info1 = populate(uri, proxyHost, proxyPort, proxyUser, 110 proxyPassword, null); 111 HTTPRequestInfo info2 = populate(uri, proxyHost, proxyPort, proxyUser, 112 proxyPassword, null); 113 114 assertEquals(info1, info2); 115 116 info2.setSSLProperties(ssl); 117 assertFalse(info1.equals(info2)); 118 } 119 120 125 public void testProperties() throws Exception { 126 final String prefix = "org.exolab.jms.net.https."; 127 final String uri = "https://exolab.org"; 128 final String proxyHost = "binky"; 129 final int proxyPort = 1032; 130 final String proxyUser = "gum"; 131 final String proxyPassword = "ball"; 132 final SSLProperties ssl = new SSLProperties(); 133 ssl.setKeyStore("keyStore"); 134 ssl.setKeyStorePassword("keyStorePassword"); 135 ssl.setKeyStoreType("JKS"); 136 ssl.setTrustStore("trustStore"); 137 ssl.setTrustStorePassword("trustStorePassword"); 138 ssl.setTrustStoreType("PCKS12"); 139 140 Properties properties = new Properties(prefix); 141 HTTPRequestInfo info1 = populate(uri, proxyHost, proxyPort, proxyUser, 142 proxyPassword, ssl); 143 info1.export(properties); 144 HTTPRequestInfo info2 = new HTTPRequestInfo(new URI(uri), properties); 145 assertEquals(info1, info2); 146 147 assertEquals(uri, info2.getURI().toString()); 148 assertEquals(proxyHost, info2.getProxyHost()); 149 assertEquals(proxyPort, info2.getProxyPort()); 150 assertEquals(proxyUser, info2.getProxyUser()); 151 assertEquals(proxyPassword, info2.getProxyPassword()); 152 assertEquals(ssl, info2.getSSLProperties()); 153 } 154 155 167 private HTTPRequestInfo populate(String uri, String host, int port, 168 String user, String password, 169 SSLProperties ssl) 170 throws Exception { 171 HTTPRequestInfo info = new HTTPRequestInfo(new URI(uri)); 172 info.setProxyHost(host); 173 info.setProxyPort(port); 174 info.setProxyUser(user); 175 info.setProxyPassword(password); 176 info.setSSLProperties(ssl); 177 return info; 178 } 179 180 } 181 | Popular Tags |