1 45 package org.exolab.jms.net.tcp.connector; 46 47 import junit.framework.TestCase; 48 49 import org.exolab.jms.net.tcp.TCPSRequestInfo; 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 import org.exolab.jms.net.socket.SocketRequestInfo; 54 import org.exolab.jms.net.socket.SocketRequestInfoTest; 55 56 57 63 public class TCPSRequestInfoTest extends TestCase { 64 65 70 public TCPSRequestInfoTest(String name) { 71 super(name); 72 } 73 74 82 public void testAccessors() throws Exception { 83 final String uri = "tcps://localhost:8050"; 84 final SSLProperties ssl = new SSLProperties(); 85 final boolean clientAuthReqd = true; 86 final boolean clientAuthNotReqd = false; 87 88 TCPSRequestInfo info = populate(uri, null, true, 10, ssl, 89 clientAuthReqd); 90 91 assertEquals(ssl, info.getSSLProperties()); 92 assertEquals(clientAuthReqd, info.getNeedClientAuth()); 93 94 info.setNeedClientAuth(clientAuthNotReqd); 95 assertEquals(clientAuthNotReqd, info.getNeedClientAuth()); 96 } 97 98 103 public void testEquals() throws Exception { 104 final String uri = "tcp://localhost:8050"; 105 final String alternativeURI = "tcp://foo.org:9090"; 106 final boolean bindAll = true; 107 final int maxThreads = 23; 108 final SSLProperties ssl = new SSLProperties(); 109 final boolean clientAuthReqd = true; 110 final boolean clientAuthNotReqd = false; 111 112 TCPSRequestInfo info1 = populate(uri, alternativeURI, bindAll, 113 maxThreads, ssl, clientAuthReqd); 114 TCPSRequestInfo info2 = populate(uri, alternativeURI, bindAll, 115 maxThreads, ssl, clientAuthReqd); 116 assertEquals(info1, info2); 117 118 TCPSRequestInfo info3 = populate(uri, alternativeURI, bindAll, 119 maxThreads, null, clientAuthReqd); 120 assertFalse(info1.equals(info3)); 121 122 TCPSRequestInfo info4 = populate(uri, alternativeURI, bindAll, 123 maxThreads, ssl, clientAuthNotReqd); 124 assertFalse(info1.equals(info4)); 125 } 126 127 132 public void testProperties() throws Exception { 133 final String prefix = "org.exolab.jms.net.tcps."; 134 final String uri = "tcps://exolab.org:4040/"; 135 final String alternativeURI = "tcps://localhost:4040/"; 136 final boolean bindAll = false; 137 final int maxThreads = 24; 138 final SSLProperties ssl = new SSLProperties(); 139 final boolean clientAuthReqd = true; 140 141 ssl.setKeyStore("keyStore"); 142 ssl.setKeyStorePassword("keyStorePassword"); 143 ssl.setKeyStoreType("JKS"); 144 ssl.setTrustStore("trustStore"); 145 ssl.setTrustStorePassword("trustStorePassword"); 146 ssl.setTrustStoreType("PCKS12"); 147 148 Properties properties = new Properties(prefix); 149 TCPSRequestInfo info1 = populate(uri, alternativeURI, bindAll, 150 maxThreads, ssl, clientAuthReqd); 151 info1.export(properties); 152 153 TCPSRequestInfo info2 = new TCPSRequestInfo(new URI(uri), 154 properties); 155 assertEquals(info1, info2); 156 157 assertEquals(ssl, info2.getSSLProperties()); 158 assertEquals(clientAuthReqd, info2.getNeedClientAuth()); 159 } 160 161 176 private TCPSRequestInfo populate(String uri, String alternativeURI, 177 boolean bindAll, int maxThreads, 178 SSLProperties ssl, boolean needClientAuth) 179 throws Exception { 180 TCPSRequestInfo info = new TCPSRequestInfo(new URI(uri)); 181 if (alternativeURI != null) { 182 info.setAlternativeURI(new URI(alternativeURI)); 183 } 184 info.setBindAll(bindAll); 185 info.setMaxThreads(maxThreads); 186 info.setSSLProperties(ssl); 187 info.setNeedClientAuth(needClientAuth); 188 return info; 189 } 190 191 } 192 | Popular Tags |