Search in sources :

Example 1 with Binder

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

the class CAY_743Test method testLoad2MapsWithCrossMapInheritance.

@Test
public void testLoad2MapsWithCrossMapInheritance() throws Exception {
    Injector injector = DIBootstrap.createInjector(new ServerModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            ServerModule.contributeProjectLocations(binder).add("cay743/cayenne-domain.xml");
        }
    });
    try {
        DataDomain domain = injector.getInstance(DataDomain.class);
        assertEquals(2, domain.getDataMaps().size());
        DataMap m1 = domain.getDataMap("map1");
        DataMap m2 = domain.getDataMap("map2");
        ObjEntity oe11 = m1.getObjEntity("Entity11");
        ObjEntity oe12 = m1.getObjEntity("Entity12");
        ObjEntity oe21 = m2.getObjEntity("Entity21");
        ObjEntity oe22 = m2.getObjEntity("Entity22");
        // this causes StackOverflow per CAY-743
        ObjEntity oe21Super = oe21.getSuperEntity();
        ObjEntity oe12Super = oe12.getSuperEntity();
        assertSame(oe12Super, oe22);
        assertSame(oe21Super, oe11);
    } finally {
        injector.shutdown();
    }
}
Also used : Binder(org.apache.cayenne.di.Binder) ObjEntity(org.apache.cayenne.map.ObjEntity) DataDomain(org.apache.cayenne.access.DataDomain) Injector(org.apache.cayenne.di.Injector) ServerModule(org.apache.cayenne.configuration.server.ServerModule) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 2 with Binder

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

the class JMSBridgeProviderTest method testUseProperties.

@Test
public void testUseProperties() {
    Module module = binder -> JMSModule.contributeTopicConnectionFactory(binder, TOPIC_CONNECTION_FACTORY_TEST);
    Injector injector = DIBootstrap.createInjector(new DefaultBindings(), new JMSModule(), module);
    JMSBridge bridge = (JMSBridge) injector.getInstance(EventBridge.class);
    assertEquals(TOPIC_CONNECTION_FACTORY_TEST, bridge.getTopicConnectionFactoryName());
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) TransactionManager(org.apache.cayenne.tx.TransactionManager) Module(org.apache.cayenne.di.Module) DefaultDataDomainFlushActionFactory(org.apache.cayenne.access.flush.DefaultDataDomainFlushActionFactory) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DataDomain(org.apache.cayenne.access.DataDomain) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Binder(org.apache.cayenne.di.Binder) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DefaultDbRowOpSorter(org.apache.cayenne.access.flush.operation.DefaultDbRowOpSorter) DbRowOpSorter(org.apache.cayenne.access.flush.operation.DbRowOpSorter) DataDomainFlushActionFactory(org.apache.cayenne.access.flush.DataDomainFlushActionFactory) Assert.assertEquals(org.junit.Assert.assertEquals) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Example 3 with Binder

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

the class JMSModuleIT method testModule.

@Test
public void testModule() {
    Module configModule = new Module() {

        public void configure(Binder binder) {
            ServerModule.contributeProperties(binder).put(Constants.SERVER_DOMAIN_NAME_PROPERTY, "test");
        }
    };
    Injector injector = DIBootstrap.createInjector(new ServerModule(), new JMSModule(), configModule);
    EventBridge bridge = injector.getInstance(EventBridge.class);
    assertThat(bridge, instanceOf(JMSBridge.class));
    EventBridge bridge2 = injector.getInstance(EventBridge.class);
    assertThat(bridge2, instanceOf(JMSBridge.class));
    assertNotSame(bridge, bridge2);
}
Also used : Binder(org.apache.cayenne.di.Binder) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Example 4 with Binder

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

the class XMPPModuleIT method testModule.

@Test
public void testModule() {
    Module configModule = new Module() {

        public void configure(Binder binder) {
            ServerModule.contributeProperties(binder).put(Constants.SERVER_DOMAIN_NAME_PROPERTY, "test");
        }
    };
    Injector injector = DIBootstrap.createInjector(new ServerModule(), new XMPPModule(), configModule);
    EventBridge bridge = injector.getInstance(EventBridge.class);
    assertThat(bridge, instanceOf(XMPPBridge.class));
    EventBridge bridge2 = injector.getInstance(EventBridge.class);
    assertThat(bridge2, instanceOf(XMPPBridge.class));
    assertNotSame(bridge, bridge2);
}
Also used : Binder(org.apache.cayenne.di.Binder) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) ServerModule(org.apache.cayenne.configuration.server.ServerModule) Test(org.junit.Test)

Example 5 with Binder

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

the class XMPPBridgeProviderTest method testUseProperties.

@Test
public void testUseProperties() throws Exception {
    Module module = binder -> {
        XMPPModule.contributeSecureConnection(binder, SECURE_CONNECTION_TEST);
        XMPPModule.contributeHost(binder, HOST_TEST);
        XMPPModule.contributePort(binder, PORT_TEST);
        XMPPModule.contributeLogin(binder, LOGIN_TEST, PASSWORD_TEST);
        XMPPModule.contributeChatService(binder, CHAT_SERVICE_TEST);
    };
    Injector injector = DIBootstrap.createInjector(new DefaultBindings(), new XMPPModule(), module);
    XMPPBridge bridge = (XMPPBridge) injector.getInstance(EventBridge.class);
    assertEquals(HOST_TEST, bridge.getXmppHost());
    assertEquals(CHAT_SERVICE_TEST, bridge.getChatService());
    assertEquals(LOGIN_TEST, bridge.getLoginId());
    assertEquals(PASSWORD_TEST, bridge.getPassword());
    assertEquals(SECURE_CONNECTION_TEST, bridge.isSecureConnection());
    assertEquals(PORT_TEST, bridge.getXmppPort());
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) TransactionManager(org.apache.cayenne.tx.TransactionManager) Module(org.apache.cayenne.di.Module) DefaultDataDomainFlushActionFactory(org.apache.cayenne.access.flush.DefaultDataDomainFlushActionFactory) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DataDomain(org.apache.cayenne.access.DataDomain) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Binder(org.apache.cayenne.di.Binder) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DefaultDbRowOpSorter(org.apache.cayenne.access.flush.operation.DefaultDbRowOpSorter) Assert.assertFalse(org.junit.Assert.assertFalse) DbRowOpSorter(org.apache.cayenne.access.flush.operation.DbRowOpSorter) DataDomainFlushActionFactory(org.apache.cayenne.access.flush.DataDomainFlushActionFactory) Assert.assertEquals(org.junit.Assert.assertEquals) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) Test(org.junit.Test)

Aggregations

Binder (org.apache.cayenne.di.Binder)14 Test (org.junit.Test)14 Injector (org.apache.cayenne.di.Injector)11 Module (org.apache.cayenne.di.Module)8 HashMap (java.util.HashMap)7 ClientConnection (org.apache.cayenne.remote.ClientConnection)7 MockClientConnection (org.apache.cayenne.remote.MockClientConnection)7 ServerModule (org.apache.cayenne.configuration.server.ServerModule)6 Constants (org.apache.cayenne.configuration.Constants)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 DataChannel (org.apache.cayenne.DataChannel)4 DataDomain (org.apache.cayenne.access.DataDomain)4 ClientChannel (org.apache.cayenne.remote.ClientChannel)4 CayenneContext (org.apache.cayenne.CayenneContext)3 ObjectContext (org.apache.cayenne.ObjectContext)3 DataDomainFlushActionFactory (org.apache.cayenne.access.flush.DataDomainFlushActionFactory)3 DefaultDataDomainFlushActionFactory (org.apache.cayenne.access.flush.DefaultDataDomainFlushActionFactory)3 DbRowOpSorter (org.apache.cayenne.access.flush.operation.DbRowOpSorter)3 DefaultDbRowOpSorter (org.apache.cayenne.access.flush.operation.DefaultDbRowOpSorter)3