Search in sources :

Example 11 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class ImplFromPropertiesFactoryTest method implementationNotAnInstanceOfTarget.

@Test
public void implementationNotAnInstanceOfTarget() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty("i.am.a.test.implementation", "java.lang.Object");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    ImplFromPropertiesFactory<MockInterface> factory = new ImplFromPropertiesFactory<>(injector, ninjaProperties, "i.am.a.test.implementation", MockInterface.class, null, true, logger);
    thrown.expect(RuntimeException.class);
    MockInterface mockObject = factory.create();
}
Also used : Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 12 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class CacheProviderTest method verifySingletonProviderAndInstance.

@Test
public void verifySingletonProviderAndInstance() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, CacheMockImpl.class.getCanonicalName());
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    CacheProvider cacheProvider = injector.getInstance(CacheProvider.class);
    // cache provider should be a singleton
    assertThat(cacheProvider, sameInstance(injector.getInstance(CacheProvider.class)));
    assertThat(cacheProvider, sameInstance(injector.getInstance(CacheProvider.class)));
    Cache cache = cacheProvider.get();
    // cache should be a singleton
    assertThat(cache, sameInstance(cacheProvider.get()));
    assertThat(cache, sameInstance(injector.getInstance(Cache.class)));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 13 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class CacheProviderTest method defaultImplementation.

@Test
public void defaultImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, null);
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    CacheProvider cacheProvider = injector.getInstance(CacheProvider.class);
    assertThat(cacheProvider.get(), instanceOf(CacheEhCacheImpl.class));
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Injector(com.google.inject.Injector) BaseAndClassicModules(ninja.BaseAndClassicModules) Test(org.junit.Test)

Example 14 with BaseAndClassicModules

use of ninja.BaseAndClassicModules in project ninja by ninjaframework.

the class CacheProviderTest method configuredImplementation.

@Test
public void configuredImplementation() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    ninjaProperties.setProperty(NinjaConstant.CACHE_IMPLEMENTATION, CacheMemcachedImpl.class.getName());
    // just a dummy to test that loading works
    ninjaProperties.setProperty(NinjaConstant.MEMCACHED_HOST, "127.0.0.1:1234");
    Injector injector = Guice.createInjector(new BaseAndClassicModules(ninjaProperties));
    Provider<Cache> cacheProvider = injector.getProvider(Cache.class);
    assertThat(cacheProvider.get(), instanceOf(CacheMemcachedImpl.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