public static io.vertx.amqpbridge.AmqpBridge create(io.vertx.amqpbridge.AmqpBridge j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.amqpbridge.AmqpBridge.create(vertx, options != null ? new io.vertx.amqpbridge.AmqpBridgeOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } }
private void doConnectWithGivenCredentialsTestImpl(TestContext context, String username, String password, boolean expectConnectToSucceed) { doStartWithGivenCredentialsTestImpl(context, new AmqpBridgeOptions(), username, password, expectConnectToSucceed); }
@Test public void testEqualsItself() { AmqpBridgeOptions options = new AmqpBridgeOptions(); assertEquals("Options should be equal to itself", options, options); }
@Test public void testDifferentObjectsNotEqual() { AmqpBridgeOptions options1 = new AmqpBridgeOptions(); options1.setReplyHandlingSupport(true); AmqpBridgeOptions options2 = new AmqpBridgeOptions(); options2.setReplyHandlingSupport(false); assertNotSame("Options should be different objects", options1, options2); assertNotEquals("Options should not be equal", options1, options2); options1 = new AmqpBridgeOptions(); options1.setVhost("vhost1"); options2 = new AmqpBridgeOptions(); options2.setVhost("vhost2"); assertNotSame("Options should be different objects", options1, options2); assertNotEquals("Options should not be equal", options1, options2); options1 = new AmqpBridgeOptions(); options1.setContainerId("containerId1"); options2 = new AmqpBridgeOptions(); options2.setContainerId("containerId2"); assertNotSame("Options should be different objects", options1, options2); assertNotEquals("Options should not be equal", options1, options2); }
@Test public void testEqualsNull() { AmqpBridgeOptions options = new AmqpBridgeOptions(); assertFalse("Options should not equal null", options.equals(null)); }
@Test public void testHashCodeReturnsSameValueOnRepeatedCall() { AmqpBridgeOptions options = new AmqpBridgeOptions(); options.addEnabledSaslMechanism("PLAIN"); assertEquals("Options should have same hash code for both calls", options.hashCode(), options.hashCode()); }
@Test public void testDifferentObjectsEqual() { boolean replyHandlingSupport = true; String vhost = "vhost"; String containerId = "container"; AmqpBridgeOptions options1 = new AmqpBridgeOptions(); options1.setReplyHandlingSupport(replyHandlingSupport); options1.setVhost(vhost); options1.setContainerId(containerId); AmqpBridgeOptions options2 = new AmqpBridgeOptions(); options2.setReplyHandlingSupport(replyHandlingSupport); options2.setVhost(vhost); options2.setContainerId(containerId); assertNotSame("Options should be different objects", options1, options2); assertEquals("Options should be equal", options1, options2); }
@Test public void testEqualObjectsReturnSameHashCode() { AmqpBridgeOptions options1 = new AmqpBridgeOptions(); boolean replyHandlingSupport = true; options1.setReplyHandlingSupport(replyHandlingSupport); AmqpBridgeOptions options2 = new AmqpBridgeOptions(); options2.setReplyHandlingSupport(replyHandlingSupport); assertNotSame("Options should be different objects", options1, options2); assertEquals("Options should be equal", options1, options2); assertEquals("Options should have same hash code", options1.hashCode(), options2.hashCode()); String vhost = "vhost"; options1 = new AmqpBridgeOptions(); options1.setVhost(vhost); options2 = new AmqpBridgeOptions(); options2.setVhost(vhost); assertNotSame("Options should be different objects", options1, options2); assertEquals("Options should be equal", options1, options2); assertEquals("Options should have same hash code", options1.hashCode(), options2.hashCode()); String containerId = "containerId"; options1 = new AmqpBridgeOptions(); options1.setContainerId(containerId); options2 = new AmqpBridgeOptions(); options2.setContainerId(containerId); assertNotSame("Options should be different objects", options1, options2); assertEquals("Options should be equal", options1, options2); assertEquals("Options should have same hash code", options1.hashCode(), options2.hashCode()); }
@Test public void testVhost() { AmqpBridgeOptions options = new AmqpBridgeOptions(); assertNull("No default should be present", options.getVhost()); String vhost = "vhost"; options.setVhost(vhost); assertEquals("Vhost option was not as expected", vhost, options.getVhost()); } }
@Test public void testReplyHandlingSupportEnabled() { AmqpBridgeOptions options = new AmqpBridgeOptions(); assertTrue("Reply Handler Support should be enabled", options.isReplyHandlingSupport()); options.setReplyHandlingSupport(false); assertFalse("Reply Handler Support should not be enabled", options.isReplyHandlingSupport()); }
@Test public void testContainerId() { AmqpBridgeOptions options = new AmqpBridgeOptions(); assertNull("No default should be present", options.getContainerId()); String containerId = "container"; options.setContainerId(containerId); assertEquals("ContainerId option was not as expected", containerId, options.getContainerId()); }
@Test(timeout = 20000) public void testRestrictSaslMechanisms(TestContext context) throws Exception { AmqpBridgeOptions options = new AmqpBridgeOptions(); // Try with the wrong password, with anonymous access disabled, expect start to fail doStartWithGivenCredentialsTestImpl(context, options, USERNAME_GUEST, "wrongpassword", false); // Try with the wrong password, with anonymous access enabled, expect start still to fail anonymousAccessAllowed = true; restartBroker(); doStartWithGivenCredentialsTestImpl(context, options, USERNAME_GUEST, "wrongpassword", false); // Now restrict the allows SASL mechanisms to ANONYMOUS, then expect start to succeed as it wont use the invalid // credentials options.addEnabledSaslMechanism("ANONYMOUS"); doStartWithGivenCredentialsTestImpl(context, options, USERNAME_GUEST, "wrongpassword", true); }
String content = "myStringContent" + destinationName; AmqpBridgeOptions options = new AmqpBridgeOptions().setReplyHandlingSupport(false); AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.start("localhost", getBrokerAmqpConnectorPort(), startResult -> {
AmqpBridgeOptions options = new AmqpBridgeOptions().setReplyHandlingSupport(false); AmqpBridge bridge = AmqpBridge.create(vertx, options); bridge.endHandler(x -> {
@Test(timeout = 20000) public void testConnectWithSslToNonSslServerFails(TestContext context) throws Exception { Async async = context.async(); // Create a server that doesn't use ssl ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(false); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Try to start the bridge and expect it to fail AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions pfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD); bridgeOptions.setPfxTrustOptions(pfxOptions); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to fail due to remote peer not doing SSL context.assertFalse(res.succeeded(), "expected start to fail due to server not using secure transport"); async.complete(); }); async.awaitSuccess(); }
@Test(timeout = 20000) public void testConnectWithSslToServerWhileUsingTrustAll(TestContext context) throws Exception { Async async = context.async(); ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Try to start the bridge and expect it to succeed due to trusting all certs AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); bridgeOptions.setTrustAll(true); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to succeed context.assertTrue(res.succeeded(), "expected start to suceed due to trusting all certs"); async.complete(); }); async.awaitSuccess(); }
AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD);
@Test(timeout = 20000) public void testConnectWithSslSucceeds(TestContext context) throws Exception { Async async = context.async(); ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Start the bridge and verify is succeeds AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD); bridgeOptions.setPfxTrustOptions(clientPfxOptions); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to succeed context.assertTrue(res.succeeded(), "expected start to suceed"); async.complete(); }); async.awaitSuccess(); }
@Test(timeout = 20000) public void testConnectWithSslToServerWithUntrustedKeyFails(TestContext context) throws Exception { Async async = context.async(); ProtonServerOptions serverOptions = new ProtonServerOptions(); serverOptions.setSsl(true); PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD); serverOptions.setPfxKeyCertOptions(serverPfxOptions); mockServer = new MockServer(vertx, conn -> { handleBridgeStartupProcess(conn, context); }, serverOptions); // Try to start the bridge and expect it to fail due to not trusting the server AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); PfxOptions pfxOptions = new PfxOptions().setPath(OTHER_CA_TRUSTSTORE).setPassword(PASSWORD); bridgeOptions.setPfxTrustOptions(pfxOptions); AmqpBridge bridge = AmqpBridge.create(vertx, bridgeOptions); bridge.start("localhost", mockServer.actualPort(), res -> { // Expect start to fail due to remote peer not being trusted context.assertFalse(res.succeeded(), "expected start to fail due to untrusted server"); async.complete(); }); async.awaitSuccess(); }
AmqpBridgeOptions bridgeOptions = new AmqpBridgeOptions(); bridgeOptions.setSsl(true); bridgeOptions.setPfxTrustOptions(pfxOptions);