Search in sources :

Example 56 with Injector

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

the class ClientRuntimeBuilderTest method testDataChannel_NoChannelEvents.

@Test
public void testDataChannel_NoChannelEvents() {
    Map<String, String> properties1 = new HashMap<>();
    properties1.put(ClientConstants.ROP_CHANNEL_EVENTS_PROPERTY, "true");
    ClientModule module = new ClientModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            // use a noop connection to prevent startup errors...
            binder.bind(ClientConnection.class).to(MockClientConnection.class);
            ServerModule.contributeProperties(binder).putAll(properties1);
        }
    };
    Injector injector = DIBootstrap.createInjector(module);
    DataChannel channel = injector.getInstance(DataChannel.class);
    ClientChannel clientChannel = (ClientChannel) channel;
    assertTrue(clientChannel.isChannelEventsEnabled());
}
Also used : Binder(org.apache.cayenne.di.Binder) DataChannel(org.apache.cayenne.DataChannel) HashMap(java.util.HashMap) Injector(org.apache.cayenne.di.Injector) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) HttpClientConnection(org.apache.cayenne.rop.HttpClientConnection) ClientChannel(org.apache.cayenne.remote.ClientChannel) Test(org.junit.Test)

Example 57 with Injector

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

the class ClientRuntimeBuilderTest method testClientConnection.

@Test
public void testClientConnection() {
    Map<String, String> properties1 = new HashMap<>();
    properties1.put(ClientConstants.ROP_SERVICE_URL_PROPERTY, "http://localhost/YuM");
    ClientModule module = new ClientModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            ServerModule.contributeProperties(binder).putAll(properties1);
        }
    };
    Injector injector = DIBootstrap.createInjector(module);
    ClientConnection connection = injector.getInstance(ClientConnection.class);
    assertNotNull(connection);
    assertTrue(connection instanceof HttpClientConnection);
    assertSame("Connection must be a singleton", connection, injector.getInstance(ClientConnection.class));
}
Also used : Binder(org.apache.cayenne.di.Binder) HashMap(java.util.HashMap) Injector(org.apache.cayenne.di.Injector) HttpClientConnection(org.apache.cayenne.rop.HttpClientConnection) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) HttpClientConnection(org.apache.cayenne.rop.HttpClientConnection) Test(org.junit.Test)

Example 58 with Injector

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

the class CommitLogModuleBuilderTest method testListener_Class.

@Test
public void testListener_Class() {
    Module m = CommitLogModule.extend().addListener(L.class).module();
    Injector i = DIBootstrap.createInjector(m);
    List<CommitLogListener> listeners = i.getInstance(Key.getListOf(CommitLogListener.class));
    assertEquals(1, listeners.size());
    assertTrue(listeners.get(0) instanceof L);
}
Also used : Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 59 with Injector

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

the class CommitLogModuleBuilderTest method testListener_Object.

@Test
public void testListener_Object() {
    L listener = new L();
    Module m = CommitLogModule.extend().addListener(listener).module();
    Injector i = DIBootstrap.createInjector(m);
    List<CommitLogListener> listeners = i.getInstance(Key.getListOf(CommitLogListener.class));
    assertEquals(1, listeners.size());
    assertTrue(listeners.contains(listener));
}
Also used : Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 60 with Injector

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

the class CryptoModuleBuilderTest method testBuild_KeySource.

@Test
public void testBuild_KeySource() {
    URL ksUrl = JceksKeySourceTest.class.getResource(JceksKeySourceTest.KS1_JCEKS);
    Module m = new CryptoModuleExtender().keyStore(ksUrl, JceksKeySourceTest.TEST_KEY_PASS, "k1").valueTransformer(DefaultValueTransformerFactory.class).module();
    Injector injector = DIBootstrap.createInjector(new CryptoModule(), m);
    KeySource ks = injector.getInstance(KeySource.class);
    Key k1 = ks.getKey("k1");
    assertNotNull(k1);
    assertEquals("DES", k1.getAlgorithm());
    String dkName = ks.getDefaultKeyAlias();
    assertEquals("k1", dkName);
}
Also used : KeySource(org.apache.cayenne.crypto.key.KeySource) Injector(org.apache.cayenne.di.Injector) DefaultValueTransformerFactory(org.apache.cayenne.crypto.transformer.value.DefaultValueTransformerFactory) Module(org.apache.cayenne.di.Module) URL(java.net.URL) Key(java.security.Key) JceksKeySourceTest(org.apache.cayenne.crypto.key.JceksKeySourceTest) 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