Search in sources :

Example 1 with Cache

use of ninja.cache.Cache in project ninja by ninjaframework.

the class BootstrapTest method frameworkModuleSkipsNinjaClassicModule.

@Test
public void frameworkModuleSkipsNinjaClassicModule() {
    ninjaPropertiesImpl = Mockito.spy(new NinjaPropertiesImpl(NinjaMode.test));
    Mockito.when(ninjaPropertiesImpl.get(NinjaConstant.APPLICATION_MODULES_BASE_PACKAGE)).thenReturn("com.example.frameworkmodule");
    Bootstrap bootstrap = new Bootstrap(ninjaPropertiesImpl);
    bootstrap.boot();
    try {
        Cache cache = bootstrap.getInjector().getInstance(Cache.class);
        fail("cache should not have been found");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("No implementation for ninja.cache.Cache was bound"));
    }
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) Cache(ninja.cache.Cache) Test(org.junit.Test)

Example 2 with Cache

use of ninja.cache.Cache in project ninja by ninjaframework.

the class NinjaClassicModule method configure.

@Override
public void configure() {
    // NOTE: these are grouped to line up with third-party dependencies
    // (e.g. jackson supports templates & body parsers)
    // Text & post require no 3rd party libs
    bind(TemplateEngineText.class);
    bind(BodyParserEnginePost.class);
    // Freemarker
    if (freemarker) {
        bind(TemplateEngineFreemarker.class);
    }
    // Jackson json support
    if (json) {
        OptionalBinder.newOptionalBinder(binder(), ObjectMapper.class).setDefault().toProvider(ObjectMapperProvider.class).in(Singleton.class);
        bind(TemplateEngineJson.class);
        bind(TemplateEngineJsonP.class);
        bind(BodyParserEngineJson.class);
    }
    // Jackson xml support
    if (xml) {
        OptionalBinder.newOptionalBinder(binder(), XmlMapper.class).setDefault().toProvider(XmlMapperProvider.class).in(Singleton.class);
        bind(TemplateEngineXml.class);
        bind(BodyParserEngineXml.class);
    }
    // Postoffice
    if (postoffice) {
        bind(Postoffice.class).toProvider(PostofficeProvider.class);
    }
    // Cache
    if (cache) {
        bind(Cache.class).toProvider(CacheProvider.class);
    }
    // Migrations
    if (migrations) {
        bind(MigrationEngine.class).toProvider(MigrationEngineProvider.class);
        bind(MigrationInitializer.class).asEagerSingleton();
    }
    // JPA
    if (jpa) {
        install(new JpaModule(ninjaProperties));
    }
}
Also used : MigrationEngine(ninja.migrations.MigrationEngine) XmlMapperProvider(ninja.utils.XmlMapperProvider) Postoffice(ninja.postoffice.Postoffice) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(ninja.utils.ObjectMapperProvider) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Cache(ninja.cache.Cache) MigrationInitializer(ninja.migrations.MigrationInitializer) JpaModule(ninja.jpa.JpaModule)

Aggregations

Cache (ninja.cache.Cache)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 JpaModule (ninja.jpa.JpaModule)1 MigrationEngine (ninja.migrations.MigrationEngine)1 MigrationInitializer (ninja.migrations.MigrationInitializer)1 Postoffice (ninja.postoffice.Postoffice)1 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)1 ObjectMapperProvider (ninja.utils.ObjectMapperProvider)1 XmlMapperProvider (ninja.utils.XmlMapperProvider)1 Test (org.junit.Test)1