protected Optional<JobHistoryStore> createJobHistoryStore(Properties jobProps) { boolean jobHistoryStoreEnabled = Boolean .valueOf(jobProps.getProperty(ConfigurationKeys.JOB_HISTORY_STORE_ENABLED_KEY, Boolean.FALSE.toString())); if (jobHistoryStoreEnabled) { Injector injector = Guice.createInjector(new MetaStoreModule(jobProps)); return Optional.of(injector.getInstance(JobHistoryStore.class)); } else { return Optional.absent(); } }
@Test public void testMultiConditionalBind_cat() { props.setProperty("animal.type", "cat"); Injector injector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { ConditionalMultibind.create(props, binder, Animal.class) .addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("cat"), Cat.class) .addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("dog"), Dog.class); } }); Set<Animal> animalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>() { })); Assert.assertEquals(1, animalSet.size()); Assert.assertEquals(animalSet, ImmutableSet.<Animal>of(new Cat())); }
@Test(groups = "fast") public void testAOPForClass() throws Exception { // Make sure it works as expected without any AOP magic final IAopTester simpleTester = new AopTester(); try { simpleTester.createRefund(); } catch (Exception e) { Assert.fail(e.getLocalizedMessage()); } // Now, verify the interception works configureShiro(); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ShiroModuleNoDB(configSource), new KillBillShiroAopModule(), new TestSecurityModuleNoDB(configSource), new CacheModule(configSource), new AbstractModule() { @Override protected void configure() { bind(IDBI.class).toInstance(Mockito.mock(IDBI.class)); bind(IDBI.class).annotatedWith(Names.named(MAIN_RO_DATA_SOURCE_ID)).toInstance(Mockito.mock(IDBI.class)); bind(TenantInternalApi.class).toInstance(Mockito.mock(TenantInternalApi.class)); bind(NonEntityDao.class).toInstance(Mockito.mock(NonEntityDao.class)); } }); final AopTester aopedTester = injector.getInstance(AopTester.class); verifyAopedTester(aopedTester); }
@Test public void testWithoutConfigAllIdsMatch() { Set<String> regionIds = ImmutableSet.of("us-east-1", "eu-west-1"); RegionIdFilter filter = Guice.createInjector(new AbstractModule(){ @Override protected void configure() { bindConstant().annotatedWith(Provider.class).to("aws-ec2"); } }).getInstance(AnyOrConfiguredRegionId.class); assertEquals(Sets.filter(regionIds, filter), ImmutableSet.of("us-east-1", "eu-west-1")); }
public void test() { ParseObjectFromHeadersAndHttpContent parser = Guice.createInjector().getInstance( ParseObjectFromHeadersAndHttpContent.class); AtmosObject data = parser.apply(RESPONSE); assertEquals(data, EXPECTED); } }
public void testScopeExceptions() throws Exception { Injector injector = Guice.createInjector( new AbstractModule() { @Override injector.getInstance(String.class); fail(); } catch (ProvisionException oose) { assertContains(oose.getMessage(), "Cannot access scoped [java.lang.String]."); injector.getInstance(Integer.class); fail(); } catch (ProvisionException oose) { assertContains(oose.getMessage(), "Cannot access scoped [java.lang.Integer]."); Key<?> key = Key.get(String.class, Names.named("foo")); try { injector.getInstance(key); fail(); } catch (ProvisionException oose) { assertContains(oose.getMessage(), "Cannot access scoped [" + Errors.convert(key) + "]");
public void testIsRequestScopedPositive() { final Key<String> a = Key.get(String.class, named("A")); final Key<String> b = Key.get(String.class, named("B")); final Key<String> c = Key.get(String.class, named("C")); final Key<String> d = Key.get(String.class, named("D")); final Key<Object> e = Key.get(Object.class, named("E")); assertTrue(ServletScopes.isRequestScoped(map.get(g))); Injector injector = Guice.createInjector(requestScopedBindings, new ServletModule()); assertTrue(ServletScopes.isRequestScoped(injector.getBinding(a))); assertTrue(ServletScopes.isRequestScoped(injector.getBinding(b)));
@Test public void testThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to("bar"); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), "bar"); }
@BeforeClass public static void setup() throws InterruptedException, IOException { new MockNodeProbe(); injector = Guice.createInjector(new BRTestModule()); filesystem = (FakeBackupFileSystem) injector.getInstance( Key.get(IBackupFileSystem.class, Names.named("backup"))); }
@BeforeMethod public void startUp() { Injector injector = Guice.createInjector(new JsonModule(), new HandleJsonModule()); objectMapper = injector.getInstance(ObjectMapper.class); }
@Test(groups = "fast") public void testAOPForInterface() throws Exception { // Make sure it works as expected without any AOP magic final IAopTester simpleTester = new AopTesterImpl(); try { simpleTester.createRefund(); } catch (Exception e) { Assert.fail(e.getLocalizedMessage()); } // Now, verify the interception works configureShiro(); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new ShiroModuleNoDB(configSource), new KillBillShiroAopModule(), new TestSecurityModuleNoDB(configSource), new CacheModule(configSource), new AbstractModule() { @Override public void configure() { bind(IDBI.class).toInstance(Mockito.mock(IDBI.class)); bind(IDBI.class).annotatedWith(Names.named(MAIN_RO_DATA_SOURCE_ID)).toInstance(Mockito.mock(IDBI.class)); bind(IAopTester.class).to(AopTesterImpl.class).asEagerSingleton(); bind(TenantInternalApi.class).toInstance(Mockito.mock(TenantInternalApi.class)); bind(NonEntityDao.class).toInstance(Mockito.mock(NonEntityDao.class)); } }); final IAopTester aopedTester = injector.getInstance(IAopTester.class); verifyAopedTester(aopedTester); }
public void testExcluder() { Json excluder = Guice.createInjector(new GsonModule(), new AbstractModule() { protected void configure() { bind(DefaultExclusionStrategy.class).to(ExcludeStringValue.class); } }).getInstance(Json.class); ObjectNoDefaultConstructor obj = new ObjectNoDefaultConstructor("foo", 1); assertEquals(excluder.toJson(obj), "{\"intValue\":1}"); }
public void testIsRequestScopedNegative() { final Key<String> a = Key.get(String.class, named("A")); final Key<String> b = Key.get(String.class, named("B")); final Key<String> c = Key.get(String.class, named("C")); final Key<String> d = Key.get(String.class, named("D")); final Key<String> e = Key.get(String.class, named("E")); assertFalse(ServletScopes.isRequestScoped(map.get(j))); Injector injector = Guice.createInjector(requestScopedBindings); assertFalse(ServletScopes.isRequestScoped(injector.getBinding(a))); assertFalse(ServletScopes.isRequestScoped(injector.getBinding(b)));
@Test public void testEmptyIsThere() { assertEquals(Guice.createInjector(new AbstractModule() { @Override protected void configure() { bindConstant().annotatedWith(Names.named("foo")).to(""); } }).getInstance(ValueOfConfigurationKeyOrNull.class).apply("foo"), ""); } }
@Test public void testMultiConditionalBind_cat_dog() { props.setProperty("animal.type", "pets"); Injector injector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { ConditionalMultibind.create(props, binder, Animal.class) .addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Cat.class) .addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Dog.class); } }); Set<Animal> animalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>() { })); Assert.assertEquals(2, animalSet.size()); Assert.assertEquals(animalSet, ImmutableSet.of(new Cat(), new Dog())); }
@BeforeMethod public void startUp() { Injector injector = Guice.createInjector(new JsonModule(), new HandleJsonModule()); objectMapper = injector.getInstance(ObjectMapper.class); }
@Test public void testExpand() { Properties input = new Properties(); input.setProperty("id", "1234"); input.setProperty("path", "path:${id}"); Properties output = Guice.createInjector(new BindPropertiesToExpandedValues(input)).getInstance(Properties.class); Properties expected = new Properties(); expected.setProperty("id", "1234"); expected.setProperty("path", "path:1234"); assertEquals(output, expected); } }
@Test public void testMultiConditionalBind_cat_dog_non_continuous_syntax() { props.setProperty("animal.type", "pets"); Injector injector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { ConditionalMultibind.create(props, binder, Animal.class) .addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Cat.class); ConditionalMultibind.create(props, binder, Animal.class) .addConditionBinding(ANIMAL_TYPE, Predicates.equalTo("pets"), Dog.class); } }); Set<Animal> animalSet = injector.getInstance(Key.get(new TypeLiteral<Set<Animal>>() { })); Assert.assertEquals(2, animalSet.size()); Assert.assertEquals(animalSet, ImmutableSet.of(new Cat(), new Dog())); }
@Test public void testPropertiesWithRestrictedConfigs() { Injector injector = Guice.createInjector(Collections.singletonList(new PropertiesModule(Collections.singletonList( "status.resource.test.runtime.properties")))); Map<String, String> returnedProperties = injector.getInstance(StatusResource.class).getProperties(); Set<String> hiddenProperties = new HashSet<>(); Splitter.on(",").split(returnedProperties.get("druid.server.hiddenProperties")).forEach(hiddenProperties::add); hiddenProperties.forEach((property) -> Assert.assertNull(returnedProperties.get(property))); } }
@Test public void testWithoutConfigAllIdsMatch() { Set<String> zoneIds = ImmutableSet.of("us-east-1a", "us-east-1b"); ZoneIdFilter filter = Guice.createInjector(new AbstractModule(){ @Override protected void configure() { bindConstant().annotatedWith(Provider.class).to("aws-ec2"); } }).getInstance(AnyOrConfiguredZoneId.class); assertEquals(Sets.filter(zoneIds, filter), ImmutableSet.of("us-east-1a", "us-east-1b")); }