@Test
public void jmsSslRuntimeFactoryAndBuilderTest() throws Exception {
String hostName = "host-local";
int port = 12345;
RemoteJmsRuntimeEngineBuilder builder = RemoteRuntimeEngineFactory.newJmsBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName(hostName)
.addJmsConnectorPort(port)
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.useSsl(true);
// this doesn't really test what I want.. but it's better than nothing? Maybe?
{
Field hostNameField =
Class.forName("org.kie.services.client.api.RemoteJmsRuntimeEngineBuilderImpl")
.getDeclaredField("hostName");
hostNameField.setAccessible(true);
assertEquals( hostName, hostNameField.get(builder) );
}
{
Field portField =
Class.forName("org.kie.services.client.api.RemoteJmsRuntimeEngineBuilderImpl")
.getDeclaredField("jmsConnectorPort");
portField.setAccessible(true);
assertEquals( port, portField.get(builder) );
}
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
// .addHostName("localhost")
.addJmsConnectorPort(5446)
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "JMS ConnectionFactory"));
}
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
// .addJmsConnectorPort(5446)
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "JMS ConnectionFactory"));
}
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
// SSL
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.useSsl(true)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
// expected
}
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.useSsl(true)
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "SSL"));
}
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
.addTruststorePassword("D")
.addTruststoreLocation("ssl/truststore.jts")
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/DOES_NOT_EXIST.jks")
.addTruststorePassword("D")
.addTruststoreLocation("ssl/truststore.jts")
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "could be found on the classpath"));
}
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
.addTruststorePassword("D")
.addTruststoreLocation("/ssl/truststore.jts")
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "could be found at"));
}
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
// .addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
.addTruststorePassword("D")
.addTruststoreLocation("/ssl/truststore.jts")
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "password is required"));
}
try {
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
// .addTruststorePassword("D")
.addTruststoreLocation("/ssl/truststore.jts")
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue)
.buildFactory();
fail( "Should have thrown exception");
} catch( InsufficientInfoToBuildException iitbe ) {
assertTrue( iitbe.getMessage().contains( "password is required"));
}
// remote initial context
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
.addTruststorePassword("D")
.addTruststoreLocation("ssl/truststore.jts")
.addRemoteInitialContext(remoteInitialContext)
.buildFactory();
// jboss server url
RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
.addTruststorePassword("D")
.addTruststoreLocation("ssl/truststore.jts")
.addJbossServerUrl(new URL("http://localhost:8080/kie-wb"))
.buildFactory();
// useKeystoreAsTruststore
builder = RemoteJmsRuntimeEngineFactory.newBuilder()
.addUserName("H")
.addPassword("gummy bears")
.addHostName("localhost")
.addJmsConnectorPort(5446)
.addKeystorePassword("R")
.addKeystoreLocation("ssl/client_keystore.jks")
.useKeystoreAsTruststore()
.addKieSessionQueue(ksessionQueue)
.addResponseQueue(responseQueue);
builder.buildFactory();
}