ConnectionConfigurator { public void configureFactory(Class<?> clazz) { ConnectionConfiguration connectionConfiguration = resolveConnectionConfiguration(clazz); if (connectionConfiguration == null) { return; } connectionFactory.setHost(connectionConfiguration.host()); connectionFactory.setVirtualHost(connectionConfiguration.virtualHost()); connectionFactory.setPort(connectionConfiguration.port()); connectionFactory.setConnectionTimeout(connectionConfiguration.timeout()); connectionFactory.setRequestedHeartbeat(connectionConfiguration.heartbeat()); connectionFactory.setUsername(connectionConfiguration.username()); connectionFactory.setPassword(connectionConfiguration.password()); connectionFactory.setRequestedFrameMax(connectionConfiguration.frameMax()); }  void configureFactory(Class<?> clazz);  }
@Test public void testConfigureFactoryForSingleConfig() { ConnectionConfigurator configurator = instancePool.select(ConnectionConfigurator.class).get(); configurator.configureFactory(TestEventBinderOne.class); ConnectionFactory connectionFactory = configurator.connectionFactory; Assert.assertEquals("hostOne", connectionFactory.getHost()); Assert.assertEquals("vHostOne", connectionFactory.getVirtualHost()); Assert.assertEquals(1111, connectionFactory.getPort()); Assert.assertEquals(111, connectionFactory.getRequestedFrameMax()); Assert.assertEquals(11, connectionFactory.getRequestedHeartbeat()); Assert.assertEquals(1, connectionFactory.getConnectionTimeout()); Assert.assertEquals("userOne", connectionFactory.getUsername()); Assert.assertEquals("passOne", connectionFactory.getPassword()); }
@Test public void testConfigureFactoryForMultiConfigsWithNoProfile() { ConnectionConfigurator configurator = instancePool.select(ConnectionConfigurator.class).get(); configurator.configureFactory(TestEventBinderTwo.class); ConnectionFactory connectionFactory = configurator.connectionFactory; Assert.assertEquals("defaultHost", connectionFactory.getHost()); Assert.assertEquals(1234, connectionFactory.getPort()); }
@Test public void testConfigureFactoryForMultiConfigsWithProfileOne() { System.setProperty(ConnectionConfiguration.PROFILE_PROPERTY, "profileOne"); ConnectionConfigurator configurator = instancePool.select(ConnectionConfigurator.class).get(); configurator.configureFactory(TestEventBinderTwo.class); ConnectionFactory connectionFactory = configurator.connectionFactory; Assert.assertEquals("hostOne", connectionFactory.getHost()); Assert.assertEquals(1111, connectionFactory.getPort()); }
@Test public void testConfigureFactoryForMultiConfigsWithProfileTwo() { System.setProperty(ConnectionConfiguration.PROFILE_PROPERTY, "profileTwo"); ConnectionConfigurator configurator = instancePool.select(ConnectionConfigurator.class).get(); configurator.configureFactory(TestEventBinderTwo.class); ConnectionFactory connectionFactory = configurator.connectionFactory; Assert.assertEquals("hostTwo", connectionFactory.getHost()); Assert.assertEquals(2222, connectionFactory.getPort()); }