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 -->
<!-- have not yet figured out the way to configure ApacheDS via Spring -->
<exclude>**/LDAPAuthorizationMapTest.*</exclude>
<!-- TODO fix ASAP -->
<exclude>**/SslTransportFactoryTest.*</exclude>
</excludes>
</configuration>
</plugin>

View File

@ -19,7 +19,6 @@
package org.apache.activemq.transport.tcp;
import junit.framework.TestCase;
import org.apache.activemq.openwire.OpenWireFormat;
import java.io.IOException;
@ -29,7 +28,8 @@ import java.util.Map;
public class SslTransportFactoryTest extends TestCase {
private SslTransportFactory factory;
private boolean verbose;
protected void setUp() throws Exception {
factory = new SslTransportFactory();
}
@ -37,93 +37,114 @@ public class SslTransportFactoryTest extends TestCase {
protected void tearDown() throws Exception {
super.tearDown();
}
public void testBindServerOptions() throws IOException {
SslTransportServer sslTransportServer = null;
for (int i = 0; i < 4; ++i) {
final boolean wantClientAuth = ((i & 0x1) == 1);
final boolean needClientAuth = ((i & 0x2) == 1);
String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") +
"&needClientAuth=" + (needClientAuth ? "true" : "false");
"&needClientAuth=" + (needClientAuth ? "true" : "false");
try {
sslTransportServer = (SslTransportServer)
factory.doBind("brokerId", new URI("ssl://localhost:61616?" + options));
} catch (Exception e) {
factory.doBind("brokerId", new URI("ssl://localhost:61616?" + options));
}
catch (Exception e) {
fail("Unable to bind to address: " + e.getMessage());
}
assertEquals("Created ServerSocket did not have correct wantClientAuth status.",
sslTransportServer.getWantClientAuth(), wantClientAuth);
sslTransportServer.getWantClientAuth(), wantClientAuth);
assertEquals("Created ServerSocket did not have correct needClientAuth status.",
sslTransportServer.getNeedClientAuth(), needClientAuth);
sslTransportServer.getNeedClientAuth(), needClientAuth);
try {
sslTransportServer.stop();
} catch (Exception e) {
}
catch (Exception e) {
fail("Unable to stop TransportServer: " + e.getMessage());
}
}
}
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 {
// The 5 options being tested.
int optionSettings[] = new int[5];
String optionNames[] = {
"wantClientAuth",
"needClientAuth",
"socket.wantClientAuth",
"socket.needClientAuth",
"socket.useClientMode"
"wantClientAuth",
"needClientAuth",
"socket.wantClientAuth",
"socket.needClientAuth",
"socket.useClientMode"
};
// 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.
for (int i = 0; i < 243; ++i) {
Map options = new HashMap();
for (int j = 0; j < 5; ++j) {
// -1 since the option range is [-1,1], not [0,2].
optionSettings[j] = getMthNaryDigit(i, j, 3) - 1;
if ( optionSettings[j] != -1) {
if (optionSettings[j] != -1) {
options.put(optionNames[j], (optionSettings[j] == 1 ? "true" : "false"));
}
}
StubSSLSocket socketStub = new StubSSLSocket(null);
StubSslTransport transport = null;
try {
transport = new StubSslTransport(null, socketStub);
} catch (Exception e) {
}
catch (Exception e) {
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);
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");
assertEquals("wantClientAuth was not properly set",
optionSettings[0], transport.getWantClientAuthStatus());
assertEquals("needClientAuth was not properly set",
optionSettings[1], transport.getNeedClientAuthStatus());
assertEquals("socket.wantClientAuth was not properly set",
optionSettings[2], socketStub.getWantClientAuthStatus());
assertEquals("socket.needClientAuth was not properly set",
optionSettings[3], socketStub.getNeedClientAuthStatus());
assertEquals("socket.useClientMode was not properly set",
optionSettings[4], socketStub.getUseClientModeStatus());
}
assertEquals("wantClientAuth was not properly set for iteration: " + i,
optionSettings[0], transport.getWantClientAuthStatus());
assertEquals("needClientAuth was not properly set for iteration: " + i,
optionSettings[1], transport.getNeedClientAuthStatus());
assertEquals("socket.wantClientAuth was not properly set for iteration: " + i,
optionSettings[2], socketStub.getWantClientAuthStatus());
assertEquals("socket.needClientAuth was not properly set for iteration: " + i,
optionSettings[3], socketStub.getNeedClientAuthStatus());
assertEquals("socket.useClientMode was not properly set for iteration: " + i,
optionSettings[4], socketStub.getUseClientModeStatus());
}
}
}