Search in sources :

Example 11 with Injector

use of org.apache.cayenne.di.Injector in project cayenne by apache.

the class DbImportModuleTest method testModuleContents.

@Test
public void testModuleContents() {
    Logger log = mock(Logger.class);
    Injector i = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(log), new DbImportModule());
    assertTrue(i.getInstance(DbImportAction.class) instanceof DbImportAction);
}
Also used : Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) Logger(org.slf4j.Logger) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) Test(org.junit.Test)

Example 12 with Injector

use of org.apache.cayenne.di.Injector in project cayenne by apache.

the class DefaultDbImportActionTest method testSaveLoadedNoProject.

@Test
public void testSaveLoadedNoProject() throws Exception {
    Logger log = mock(Logger.class);
    Injector i = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(log), new DbImportModule());
    DbImportConfiguration params = mock(DbImportConfiguration.class);
    when(params.getCayenneProject()).thenReturn(null);
    URL outUrl = new URL(getPackageURL(), "dbimport/testSaveLoaded1.map.xml");
    DefaultDbImportAction action = (DefaultDbImportAction) i.getInstance(DbImportAction.class);
    File out = new File(outUrl.toURI());
    out.delete();
    assertFalse(out.exists());
    DataMap map = new DataMap("testSaveLoaded1");
    map.setConfigurationSource(new URLResource(outUrl));
    action.saveLoaded(map, params);
    assertTrue(out.isFile());
    String contents = Util.stringFromFile(out);
    assertTrue("Has no project version saved", contents.contains("project-version=\""));
}
Also used : Logger(org.slf4j.Logger) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) URLResource(org.apache.cayenne.resource.URLResource) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) File(java.io.File) Test(org.junit.Test)

Example 13 with Injector

use of org.apache.cayenne.di.Injector in project cayenne by apache.

the class ModuleLoaderTest method testLoadCustom.

@Test
public void testLoadCustom() {
    List<Module> modules = new ModuleLoader().load(CustomModuleProvider.class);
    assertEquals(2, modules.size());
    assertTrue(String.valueOf(modules.get(0)), modules.get(0) instanceof Module5);
    assertTrue(String.valueOf(modules.get(1)), modules.get(1) instanceof Module6);
    Injector i = DIBootstrap.createInjector(modules);
    assertEquals(Integer.valueOf(66), i.getInstance(Integer.class));
}
Also used : Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 14 with Injector

use of org.apache.cayenne.di.Injector in project cayenne by apache.

the class XMPPBridgeProviderTest method testUseDefaultProperties.

@Test
public void testUseDefaultProperties() throws Exception {
    Injector injector = DIBootstrap.createInjector(new DefaultBindings(), new XMPPModule());
    XMPPBridge bridge = (XMPPBridge) injector.getInstance(EventBridge.class);
    assertEquals(XMPPBridge.DEFAULT_CHAT_SERVICE, bridge.getChatService());
    assertEquals(0, bridge.getXmppPort());
    assertEquals(false, bridge.isSecureConnection());
}
Also used : Injector(org.apache.cayenne.di.Injector) Test(org.junit.Test)

Example 15 with Injector

use of org.apache.cayenne.di.Injector in project cayenne by apache.

the class XMPPBridgeProviderTest method testGetXMPPBridge.

@Test
public void testGetXMPPBridge() throws Exception {
    Injector injector = DIBootstrap.createInjector(new DefaultBindings(), new XMPPModule());
    EventBridge bridge = injector.getInstance(EventBridge.class);
    assertNotNull(bridge);
    assertTrue(bridge instanceof XMPPBridge);
}
Also used : Injector(org.apache.cayenne.di.Injector) Test(org.junit.Test)

Aggregations

Injector (org.apache.cayenne.di.Injector)64 Test (org.junit.Test)52 Module (org.apache.cayenne.di.Module)27 DIBootstrap (org.apache.cayenne.di.DIBootstrap)23 URL (java.net.URL)15 ToolsModule (org.apache.cayenne.dbsync.reverse.configuration.ToolsModule)15 DataMap (org.apache.cayenne.map.DataMap)15 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)14 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)14 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)14 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)14 URLResource (org.apache.cayenne.resource.URLResource)14 Assert (org.junit.Assert)14 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)13 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)12 DbSyncModule (org.apache.cayenne.dbsync.DbSyncModule)12 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)12 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)12 Logger (org.slf4j.Logger)11 Constants (org.apache.cayenne.configuration.Constants)10