@Test(expected=CreationException.class) public void testNamedNoEmptyUri() { Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.enabled", "true")); Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); }
@Override protected void configure() { final Named connectionNamed; final AmqpConfig amqpConfig; connectionNamed = Names.named(connectionName); bind(new TypeLiteral<PublisherCallback<Object>>() {}).annotatedWith(JsonMapper.class).to(JsonPublisherCallback.class).in(Scopes.SINGLETON); bind(new TypeLiteral<PublisherCallback<String>>() {}).to(StringPublisherCallback.class).in(Scopes.SINGLETON); amqpConfig = config.getBean(AmqpConfig.class, ImmutableMap.of("name", connectionName)); bind(AmqpConfig.class).annotatedWith(connectionNamed).toInstance(amqpConfig); if (amqpConfig.isEnabled()) { LOG.info("Enabling AMQP for '%s'", connectionName); bind(ConnectionFactory.class).annotatedWith(connectionNamed).toProvider(new AmqpFactoryProvider(amqpConfig)).in(Scopes.SINGLETON); bind(AmqpRunnableFactory.class).annotatedWith(connectionNamed).toInstance(new AmqpRunnableFactory(connectionNamed)); } else { LOG.info("Disabled AMQP for '%s'", connectionName); } }
@Test public void testMultipleModules() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.enabled", "true", "ness.amqp.connection-url", "amqp://unknown-host/")); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test"), new AmqpModule(config, "test2")); final AmqpConfig AmqpConfig = injector.getInstance(Key.get(AmqpConfig.class, Names.named("test2"))); Assert.assertNotNull(AmqpConfig); Assert.assertTrue(AmqpConfig.isEnabled()); final ConnectionFactory factory = injector.getInstance(Key.get(ConnectionFactory.class, Names.named("test2"))); Assert.assertNotNull(factory); Assert.assertNotNull(injector.getInstance(Key.get(ConnectionFactory.class, Names.named("test")))); } }
@Test(expected=CreationException.class) public void testNoEmptyUri() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.enabled", "true")); Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); }
@Test public void testNamedWorksWithLocalUri() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.test.enabled", "true", "ness.amqp.test.connection-url", "amqp://unknown-host/")); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); final AmqpConfig amqpConfig = injector.getInstance(Key.get(AmqpConfig.class, Names.named("test"))); Assert.assertNotNull(amqpConfig); Assert.assertTrue(amqpConfig.isEnabled()); final ConnectionFactory factory = injector.getInstance(Key.get(ConnectionFactory.class, Names.named("test"))); Assert.assertNotNull(factory); }
@Test public void testNamedWorksWithGlobalUri() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.test.enabled", "true", "ness.amqp.connection-url", "amqp://unknown-host/")); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); final AmqpConfig amqpConfig = injector.getInstance(Key.get(AmqpConfig.class, Names.named("test"))); Assert.assertNotNull(amqpConfig); Assert.assertTrue(amqpConfig.isEnabled()); final ConnectionFactory factory = injector.getInstance(Key.get(ConnectionFactory.class, Names.named("test"))); Assert.assertNotNull(factory); }
@Test public void testNamedWorksLocalDisabled() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.enabled", "true", "ness.amqp.test.enabled", "false")); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); final AmqpConfig amqpConfig = injector.getInstance(Key.get(AmqpConfig.class, Names.named("test"))); Assert.assertNotNull(amqpConfig); Assert.assertFalse(amqpConfig.isEnabled()); Assert.assertNull(injector.getExistingBinding(Key.get(ConnectionFactory.class, Names.named("test")))); }
@Test public void testNamedWorksGlobalDisabled() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.enabled", "false")); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); final AmqpConfig amqpConfig = injector.getInstance(Key.get(AmqpConfig.class, Names.named("test"))); Assert.assertNotNull(amqpConfig); Assert.assertFalse(amqpConfig.isEnabled()); Assert.assertNull(injector.getExistingBinding(Key.get(ConnectionFactory.class, Names.named("test")))); }
@Before public void setUp() { final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.test.enabled", "true", "ness.amqp.test.connection-url", BROKER_URI)); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new Module() { @Override public void configure(final Binder binder) { binder.disableCircularProxies(); binder.requireExplicitBindings(); } }, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); injector.injectMembers(this); Assert.assertNotNull(exchangeRunnableFactory); }
@Before public void setUp() throws Exception { getProvider().startup(); final String brokerUri = getProvider().getUri(); final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.test.enabled", "true", "ness.amqp.test.connection-url", brokerUri)); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new Module() { @Override public void configure(final Binder binder) { binder.disableCircularProxies(); binder.requireExplicitBindings(); } }, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); injector.injectMembers(this); Assert.assertNotNull(queueRunnableFactory); }
@Before public void setUp() throws Exception { getProvider().startup(); final String brokerUri = getProvider().getUri(); final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.test.enabled", "true", "ness.amqp.test.connection-url", brokerUri)); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new Module() { @Override public void configure(final Binder binder) { binder.disableCircularProxies(); binder.requireExplicitBindings(); } }, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); injector.injectMembers(this); Assert.assertNotNull(exchangeRunnableFactory); }
@Before public void setUp() throws Exception { getProvider().startup(); final String brokerUri = getProvider().getUri(); final Config config = Config.getFixedConfig(ImmutableMap.of("ness.amqp.test.enabled", "true", "ness.amqp.test.connection-url", brokerUri)); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new Module() { @Override public void configure(final Binder binder) { binder.disableCircularProxies(); binder.requireExplicitBindings(); } }, new ConfigModule(config), new NessJacksonModule(), new AmqpModule(config, "test")); injector.injectMembers(this); Assert.assertNotNull(exchangeRunnableFactory); }