Search in sources :

Example 31 with DataNodeDescriptor

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

the class JNDIDataSourceFactoryIT method testGetDataSource_NameBoundWithPrefix.

@Test
public void testGetDataSource_NameBoundWithPrefix() throws Exception {
    DataNodeDescriptor descriptor = new DataNodeDescriptor();
    descriptor.setParameters("jdbc/TestDS");
    JNDISetup.doSetup();
    MockDataSource dataSource = new MockDataSource();
    InitialContext context = new InitialContext();
    context.bind("java:comp/env/" + descriptor.getParameters(), dataSource);
    try {
        JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
        injector.injectMembers(factory);
        assertSame(dataSource, factory.getDataSource(descriptor));
    } finally {
        // since the context is shared, must clear it after the test
        context.unbind("java:comp/env/" + descriptor.getParameters());
    }
}
Also used : MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 32 with DataNodeDescriptor

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

the class JNDIDataSourceFactoryIT method testGetDataSource_NameBound.

@Test
public void testGetDataSource_NameBound() throws Exception {
    DataNodeDescriptor descriptor = new DataNodeDescriptor();
    descriptor.setParameters("jdbc/TestDS");
    JNDISetup.doSetup();
    MockDataSource dataSource = new MockDataSource();
    InitialContext context = new InitialContext();
    context.bind(descriptor.getParameters(), dataSource);
    try {
        JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
        injector.injectMembers(factory);
        assertSame(dataSource, factory.getDataSource(descriptor));
    } finally {
        // since the context is shared, must clear it after the test
        context.unbind(descriptor.getParameters());
    }
}
Also used : MockDataSource(com.mockrunner.mock.jdbc.MockDataSource) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 33 with DataNodeDescriptor

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

the class XMLDataChannelDescriptorLoaderTest method testLoadDataEverything.

@Test
public void testLoadDataEverything() {
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "testConfig3";
    URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    assertNotNull(tree);
    DataChannelDescriptor descriptor = tree.getRootNode();
    assertNotNull(descriptor);
    assertEquals(testConfigName, descriptor.getName());
    Collection<DataMap> maps = descriptor.getDataMaps();
    assertEquals(2, maps.size());
    Iterator<DataMap> mapsIt = maps.iterator();
    DataMap map1 = mapsIt.next();
    DataMap map2 = mapsIt.next();
    assertEquals("testConfigMap3_1", map1.getName());
    assertEquals("testConfigMap3_2", map2.getName());
    Collection<DataNodeDescriptor> nodes = descriptor.getNodeDescriptors();
    assertEquals(1, nodes.size());
    DataNodeDescriptor node1 = nodes.iterator().next();
    assertEquals("testConfigNode3", node1.getName());
    assertNull(node1.getParameters());
    assertNotNull(node1.getDataSourceDescriptor());
    assertEquals(1, node1.getDataSourceDescriptor().getMinConnections());
    assertEquals(1, node1.getDataSourceDescriptor().getMaxConnections());
    assertEquals("org.example.test.Adapter", node1.getAdapterType());
    assertEquals("org.example.test.DataSourceFactory", node1.getDataSourceFactoryType());
    assertEquals("org.example.test.SchemaUpdateStartegy", node1.getSchemaUpdateStrategyType());
    assertNotNull(node1.getDataMapNames());
    assertEquals(1, node1.getDataMapNames().size());
    assertEquals("testConfigMap3_2", node1.getDataMapNames().iterator().next());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 34 with DataNodeDescriptor

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

the class ToolsModuleTest method testDbApdater.

@Test
public void testDbApdater() throws Exception {
    Logger log = mock(Logger.class);
    Injector i = DIBootstrap.createInjector(new ToolsModule(log));
    DbAdapterFactory factory = i.getInstance(DbAdapterFactory.class);
    DataNodeDescriptor nodeDescriptor = mock(DataNodeDescriptor.class);
    DataSource dataSource = mock(DataSource.class);
    assertTrue(factory.createAdapter(nodeDescriptor, dataSource) instanceof AutoAdapter);
}
Also used : DefaultDbAdapterFactory(org.apache.cayenne.configuration.server.DefaultDbAdapterFactory) DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) Injector(org.apache.cayenne.di.Injector) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Logger(org.slf4j.Logger) AutoAdapter(org.apache.cayenne.dba.AutoAdapter) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 35 with DataNodeDescriptor

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

the class DataMapValidator method validateNodeLinks.

private void validateNodeLinks(DataMap map, ValidationResult validationResult) {
    DataChannelDescriptor domain = map.getDataChannelDescriptor();
    if (domain == null) {
        return;
    }
    boolean unlinked = true;
    int nodeCount = 0;
    for (DataNodeDescriptor node : domain.getNodeDescriptors()) {
        nodeCount++;
        if (node.getDataMapNames().contains(map.getName())) {
            unlinked = false;
            break;
        }
    }
    if (unlinked && nodeCount > 0) {
        addFailure(validationResult, map, "DataMap is not linked to any DataNodes");
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Aggregations

DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)58 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)28 DataMap (org.apache.cayenne.map.DataMap)23 Test (org.junit.Test)22 DbEntity (org.apache.cayenne.map.DbEntity)11 ArrayList (java.util.ArrayList)8 Injector (org.apache.cayenne.di.Injector)8 Constants (org.apache.cayenne.configuration.Constants)7 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)7 DbAdapter (org.apache.cayenne.dba.DbAdapter)7 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)7 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)7 DIBootstrap (org.apache.cayenne.di.DIBootstrap)7 Key (org.apache.cayenne.di.Key)7 Module (org.apache.cayenne.di.Module)7 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)7 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)7 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)7 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)7 ObjEntity (org.apache.cayenne.map.ObjEntity)7