Search in sources :

Example 6 with DefaultRuntimeProperties

use of org.apache.cayenne.configuration.DefaultRuntimeProperties in project cayenne by apache.

the class DataContextFactoryTest method testCreateDataContextValidation.

@Test
public void testCreateDataContextValidation() throws Exception {
    final EventManager eventManager = new MockEventManager();
    final DataDomain domain = new DataDomain("d1");
    domain.setValidatingObjectsOnCommit(true);
    Module testModule = binder -> {
        binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
        binder.bind(DataDomain.class).toInstance(domain);
        binder.bind(EventManager.class).toInstance(eventManager);
        binder.bind(QueryCache.class).toInstance(new MapQueryCache(5));
        binder.bind(RuntimeProperties.class).toInstance(new DefaultRuntimeProperties(Collections.<String, String>emptyMap()));
        binder.bind(ObjectMapRetainStrategy.class).to(DefaultObjectMapRetainStrategy.class);
        binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
        binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
        binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
        binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
        binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
    };
    Injector injector = DIBootstrap.createInjector(testModule);
    domain.setDataRowStoreFactory(injector.getInstance(DataRowStoreFactory.class));
    DataContextFactory factory = new DataContextFactory();
    injector.injectMembers(factory);
    DataContext c1 = (DataContext) factory.createContext();
    assertTrue(c1.isValidatingObjectsOnCommit());
    domain.setValidatingObjectsOnCommit(false);
    DataContext c2 = (DataContext) factory.createContext();
    assertFalse(c2.isValidatingObjectsOnCommit());
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) DataContext(org.apache.cayenne.access.DataContext) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) TransactionManager(org.apache.cayenne.tx.TransactionManager) QueryCache(org.apache.cayenne.cache.QueryCache) Module(org.apache.cayenne.di.Module) ObjectMapRetainStrategy(org.apache.cayenne.access.ObjectMapRetainStrategy) ObjectStoreFactory(org.apache.cayenne.configuration.ObjectStoreFactory) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DataDomain(org.apache.cayenne.access.DataDomain) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) EventBridge(org.apache.cayenne.event.EventBridge) MockEventManager(org.apache.cayenne.event.MockEventManager) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) DefaultDataRowStoreFactory(org.apache.cayenne.access.DefaultDataRowStoreFactory) DIBootstrap(org.apache.cayenne.di.DIBootstrap) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Test(org.junit.Test) DefaultObjectMapRetainStrategy(org.apache.cayenne.access.DefaultObjectMapRetainStrategy) EventManager(org.apache.cayenne.event.EventManager) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) Assert(org.junit.Assert) Collections(java.util.Collections) DefaultObjectStoreFactory(org.apache.cayenne.configuration.DefaultObjectStoreFactory) DataDomain(org.apache.cayenne.access.DataDomain) MockEventManager(org.apache.cayenne.event.MockEventManager) EventManager(org.apache.cayenne.event.EventManager) DefaultObjectStoreFactory(org.apache.cayenne.configuration.DefaultObjectStoreFactory) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) DefaultDataRowStoreFactory(org.apache.cayenne.access.DefaultDataRowStoreFactory) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DataContext(org.apache.cayenne.access.DataContext) DefaultObjectMapRetainStrategy(org.apache.cayenne.access.DefaultObjectMapRetainStrategy) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) NoopEventBridgeProvider(org.apache.cayenne.event.NoopEventBridgeProvider) Module(org.apache.cayenne.di.Module) MockEventManager(org.apache.cayenne.event.MockEventManager) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory) DefaultDataRowStoreFactory(org.apache.cayenne.access.DefaultDataRowStoreFactory) Test(org.junit.Test)

Aggregations

DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)6 Test (org.junit.Test)5 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 DataContext (org.apache.cayenne.access.DataContext)2 DataDomain (org.apache.cayenne.access.DataDomain)2 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)2 DefaultDataRowStoreFactory (org.apache.cayenne.access.DefaultDataRowStoreFactory)2 DefaultObjectMapRetainStrategy (org.apache.cayenne.access.DefaultObjectMapRetainStrategy)2 ObjectMapRetainStrategy (org.apache.cayenne.access.ObjectMapRetainStrategy)2 MapQueryCache (org.apache.cayenne.cache.MapQueryCache)2 QueryCache (org.apache.cayenne.cache.QueryCache)2 DefaultObjectStoreFactory (org.apache.cayenne.configuration.DefaultObjectStoreFactory)2 ObjectStoreFactory (org.apache.cayenne.configuration.ObjectStoreFactory)2 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)2 DIBootstrap (org.apache.cayenne.di.DIBootstrap)2 Injector (org.apache.cayenne.di.Injector)2 Module (org.apache.cayenne.di.Module)2 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)2 EventBridge (org.apache.cayenne.event.EventBridge)2