fixed failing test

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@449045 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-09-22 18:40:43 +00:00
parent f6d4f9f148
commit 6e34afc293
2 changed files with 67 additions and 50 deletions

View File

@ -296,10 +296,6 @@
<!-- see http://issues.apache.org/activemq/browse/AMQ-826 --> <!-- see http://issues.apache.org/activemq/browse/AMQ-826 -->
<!-- have not yet figured out the way to configure ApacheDS via Spring --> <!-- have not yet figured out the way to configure ApacheDS via Spring -->
<exclude>**/LDAPAuthorizationMapTest.*</exclude> <exclude>**/LDAPAuthorizationMapTest.*</exclude>
<!-- TODO fix ASAP -->
<exclude>**/SslTransportFactoryTest.*</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -19,7 +19,6 @@
package org.apache.activemq.transport.tcp; package org.apache.activemq.transport.tcp;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.activemq.openwire.OpenWireFormat; import org.apache.activemq.openwire.OpenWireFormat;
import java.io.IOException; import java.io.IOException;
@ -29,7 +28,8 @@ import java.util.Map;
public class SslTransportFactoryTest extends TestCase { public class SslTransportFactoryTest extends TestCase {
private SslTransportFactory factory; private SslTransportFactory factory;
private boolean verbose;
protected void setUp() throws Exception { protected void setUp() throws Exception {
factory = new SslTransportFactory(); factory = new SslTransportFactory();
} }
@ -37,93 +37,114 @@ public class SslTransportFactoryTest extends TestCase {
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
} }
public void testBindServerOptions() throws IOException { public void testBindServerOptions() throws IOException {
SslTransportServer sslTransportServer = null; SslTransportServer sslTransportServer = null;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
final boolean wantClientAuth = ((i & 0x1) == 1); final boolean wantClientAuth = ((i & 0x1) == 1);
final boolean needClientAuth = ((i & 0x2) == 1); final boolean needClientAuth = ((i & 0x2) == 1);
String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") + String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") +
"&needClientAuth=" + (needClientAuth ? "true" : "false"); "&needClientAuth=" + (needClientAuth ? "true" : "false");
try { try {
sslTransportServer = (SslTransportServer) sslTransportServer = (SslTransportServer)
factory.doBind("brokerId", new URI("ssl://localhost:61616?" + options)); factory.doBind("brokerId", new URI("ssl://localhost:61616?" + options));
} catch (Exception e) { }
catch (Exception e) {
fail("Unable to bind to address: " + e.getMessage()); fail("Unable to bind to address: " + e.getMessage());
} }
assertEquals("Created ServerSocket did not have correct wantClientAuth status.", assertEquals("Created ServerSocket did not have correct wantClientAuth status.",
sslTransportServer.getWantClientAuth(), wantClientAuth); sslTransportServer.getWantClientAuth(), wantClientAuth);
assertEquals("Created ServerSocket did not have correct needClientAuth status.", assertEquals("Created ServerSocket did not have correct needClientAuth status.",
sslTransportServer.getNeedClientAuth(), needClientAuth); sslTransportServer.getNeedClientAuth(), needClientAuth);
try { try {
sslTransportServer.stop(); sslTransportServer.stop();
} catch (Exception e) { }
catch (Exception e) {
fail("Unable to stop TransportServer: " + e.getMessage()); fail("Unable to stop TransportServer: " + e.getMessage());
} }
} }
} }
private int getMthNaryDigit(int number, int digitIdx, int numBase) { private int getMthNaryDigit(int number, int digitIdx, int numBase) {
return (number / ((int)Math.pow(numBase, digitIdx)) ) % numBase; return (number / ((int) Math.pow(numBase, digitIdx))) % numBase;
} }
public void testCompositeConfigure() throws IOException { public void testCompositeConfigure() throws IOException {
// The 5 options being tested. // The 5 options being tested.
int optionSettings[] = new int[5]; int optionSettings[] = new int[5];
String optionNames[] = { String optionNames[] = {
"wantClientAuth", "wantClientAuth",
"needClientAuth", "needClientAuth",
"socket.wantClientAuth", "socket.wantClientAuth",
"socket.needClientAuth", "socket.needClientAuth",
"socket.useClientMode" "socket.useClientMode"
}; };
// Using a trinary interpretation of i to set all possible values of stub options for socket and transport. // Using a trinary interpretation of i to set all possible values of stub options for socket and transport.
// 2 transport options, 3 socket options, 3 settings for each option => 3^5 = 243 combos. // 2 transport options, 3 socket options, 3 settings for each option => 3^5 = 243 combos.
for (int i = 0; i < 243; ++i) { for (int i = 0; i < 243; ++i) {
Map options = new HashMap(); Map options = new HashMap();
for (int j = 0; j < 5; ++j) { for (int j = 0; j < 5; ++j) {
// -1 since the option range is [-1,1], not [0,2]. // -1 since the option range is [-1,1], not [0,2].
optionSettings[j] = getMthNaryDigit(i, j, 3) - 1; optionSettings[j] = getMthNaryDigit(i, j, 3) - 1;
if ( optionSettings[j] != -1) { if (optionSettings[j] != -1) {
options.put(optionNames[j], (optionSettings[j] == 1 ? "true" : "false")); options.put(optionNames[j], (optionSettings[j] == 1 ? "true" : "false"));
} }
} }
StubSSLSocket socketStub = new StubSSLSocket(null); StubSSLSocket socketStub = new StubSSLSocket(null);
StubSslTransport transport = null; StubSslTransport transport = null;
try { try {
transport = new StubSslTransport(null, socketStub); transport = new StubSslTransport(null, socketStub);
} catch (Exception e) { }
catch (Exception e) {
fail("Unable to create StubSslTransport: " + e.getMessage()); fail("Unable to create StubSslTransport: " + e.getMessage());
} }
if (verbose) {
System.out.println();
System.out.println("Iteration: " + i);
System.out.println("Map settings: " + options);
for (int x = 0; x < optionSettings.length; x++) {
System.out.println("optionSetting[" + x + "] = " + optionSettings[x]);
}
}
factory.compositeConfigure(transport, new OpenWireFormat(), options); factory.compositeConfigure(transport, new OpenWireFormat(), options);
if (socketStub.getWantClientAuthStatus() != optionSettings[2]) // lets start the transport to force the introspection
try {
transport.start();
}
catch (Exception e) {
// ignore bad connection
}
if (socketStub.getWantClientAuthStatus() != optionSettings[2]) {
System.out.println("sheiite"); System.out.println("sheiite");
}
assertEquals("wantClientAuth was not properly set",
optionSettings[0], transport.getWantClientAuthStatus()); assertEquals("wantClientAuth was not properly set for iteration: " + i,
assertEquals("needClientAuth was not properly set", optionSettings[0], transport.getWantClientAuthStatus());
optionSettings[1], transport.getNeedClientAuthStatus()); assertEquals("needClientAuth was not properly set for iteration: " + i,
assertEquals("socket.wantClientAuth was not properly set", optionSettings[1], transport.getNeedClientAuthStatus());
optionSettings[2], socketStub.getWantClientAuthStatus()); assertEquals("socket.wantClientAuth was not properly set for iteration: " + i,
assertEquals("socket.needClientAuth was not properly set", optionSettings[2], socketStub.getWantClientAuthStatus());
optionSettings[3], socketStub.getNeedClientAuthStatus()); assertEquals("socket.needClientAuth was not properly set for iteration: " + i,
assertEquals("socket.useClientMode was not properly set", optionSettings[3], socketStub.getNeedClientAuthStatus());
optionSettings[4], socketStub.getUseClientModeStatus()); assertEquals("socket.useClientMode was not properly set for iteration: " + i,
optionSettings[4], socketStub.getUseClientModeStatus());
} }
} }
} }