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());
}
}
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());
}
}
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());
}
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);
}
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");
}
}
Aggregations