Search in sources :

Example 1 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class PostofficeProviderTest method verifySingletonProviderAndInstance.

@Test
public void verifySingletonProviderAndInstance() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    PostofficeProvider provider = injector.getInstance(PostofficeProvider.class);
    // cache provider should be a singleton
    assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class)));
    assertThat(provider, sameInstance(injector.getInstance(PostofficeProvider.class)));
    Postoffice postoffice = provider.get();
    // cache should be a singleton
    assertThat(postoffice, sameInstance(provider.get()));
    assertThat(postoffice, sameInstance(injector.getInstance(Postoffice.class)));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 2 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class PostofficeProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.

@Test
public void missingImplementationThrowsExceptionOnUseNotCreate() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(PostofficeConstant.postofficeImplementation, "not_existing_implementation");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<Postoffice> provider = injector.getProvider(Postoffice.class);
    // this will not work => we expect a runtime exception...
    thrown.expect(RuntimeException.class);
    Postoffice postoffice = injector.getInstance(Postoffice.class);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 3 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class MigrationEngineProviderTest method defaultImplementation.

@Test
public void defaultImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.MIGRATION_ENGINE_IMPLEMENTATION, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<MigrationEngine> provider = injector.getProvider(MigrationEngine.class);
    assertThat(provider.get(), instanceOf(MigrationEngineFlyway.class));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) MigrationEngineFlyway(ninja.migrations.flyway.MigrationEngineFlyway) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 4 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class ImplFromPropertiesFactoryTest method missingImplementation.

@Test
public void missingImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty("i.am.a.test.implementation", "does_not_exist");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    // this will not work => we expect a runtime exception with the impl missing
    thrown.expect(RuntimeException.class);
    ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, null, false, logger);
}
Also used : Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 5 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class CacheProviderTest method missingImplementationThrowsExceptionOnUseNotCreate.

@Test
public void missingImplementationThrowsExceptionOnUseNotCreate() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, "not_existing_implementation");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<Cache> provider = injector.getProvider(Cache.class);
    // this will not work => we expect a runtime exception...
    thrown.expect(RuntimeException.class);
    Cache cache = injector.getInstance(Cache.class);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Aggregations

Injector (com.google.inject.Injector)14 BaseAndClassicModules (ninja.BaseAndClassicModules)14 Test (org.junit.Test)14 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)9 MigrationEngineFlyway (ninja.migrations.flyway.MigrationEngineFlyway)1 PostofficeMockImpl (ninja.postoffice.mock.PostofficeMockImpl)1