use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class XMLDataChannelDescriptorLoaderTest method testLoad_MissingConfig.
@Test
public void testLoad_MissingConfig() throws Exception {
// create and initialize loader instance to test
XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
injector.injectMembers(loader);
try {
loader.load(new URLResource(new URL("file:///no_such_resource")));
fail("No exception was thrown on bad absent config name");
} catch (ConfigurationException e) {
// expected
}
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class XMLDataMapLoaderTest method loadFullDataMap.
@Test
public void loadFullDataMap() {
URL url = getClass().getResource("testConfigMap4.map.xml");
DataMap map = loader.load(new URLResource(url));
assertNotNull(map);
assertEquals("testConfigMap4", map.getName());
// check general state
assertEquals(12, map.getDbEntities().size());
assertEquals(17, map.getObjEntities().size());
assertEquals(4, map.getProcedures().size());
assertEquals(14, map.getQueryDescriptors().size());
assertEquals(1, map.getEmbeddables().size());
assertEquals("TEST_CATALOG", map.getDefaultCatalog());
assertNull(map.getDefaultSchema());
assertEquals("org.apache.cayenne.testdo.testmap", map.getDefaultPackage());
assertTrue(map.isClientSupported());
// check some loaded content
assertEquals("org.apache.cayenne.testdo.testmap.Artist", map.getObjEntity("Artist").getClassName());
assertEquals(5, map.getObjEntity("CompoundPainting").getAttributes().size());
assertEquals(3, map.getObjEntity("Artist").getRelationships().size());
assertEquals(7, map.getObjEntity("ArtistCallback").getCallbackMethods().size());
assertEquals("name = \"test\"", map.getDbEntity("ARTGROUP").getQualifier().toString());
assertEquals(4, map.getDbEntity("EXHIBIT").getAttributes().size());
assertEquals(3, map.getDbEntity("PAINTING").getRelationships().size());
assertEquals("gallery_seq", map.getDbEntity("GALLERY").getPrimaryKeyGenerator().getGeneratorName());
DbAttribute pk1 = map.getDbEntity("EXHIBIT").getAttribute("EXHIBIT_ID");
assertFalse(pk1.isGenerated());
assertTrue(pk1.isPrimaryKey());
DbAttribute pk2 = map.getDbEntity("GENERATED_COLUMN").getAttribute("GENERATED_COLUMN");
assertTrue(pk2.isGenerated());
assertTrue(pk2.isPrimaryKey());
assertEquals(true, map.getProcedure("cayenne_tst_out_proc").isReturningValue());
assertEquals(1, map.getProcedure("cayenne_tst_out_proc").getCallOutParameters().size());
assertEquals(2, map.getProcedure("cayenne_tst_out_proc").getCallParameters().size());
assertEquals("true", map.getQueryDescriptor("EjbqlQueryTest").getProperty("cayenne.GenericSelectQuery.fetchingDataRows"));
SQLTemplateDescriptor descriptor = (SQLTemplateDescriptor) map.getQueryDescriptor("NonSelectingQuery");
assertEquals("INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE) " + "VALUES (512, 'No Painting Like This', 12.5)", descriptor.getAdapterSql().get("org.apache.cayenne.dba.db2.DB2Adapter"));
assertEquals("TEST", map.getEmbeddable("org.apache.cayenne.testdo.Embeddable").getAttribute("test").getDbAttributeName());
}
use of org.apache.cayenne.resource.URLResource 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.resource.URLResource in project cayenne by apache.
the class XMLDataChannelDescriptorLoaderTest method loadInvalidVersion.
@Test(expected = CayenneRuntimeException.class)
public void loadInvalidVersion() throws Exception {
XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
injector.injectMembers(loader);
URL url = getClass().getResource("cayenne-testConfig4.xml");
loader.load(new URLResource(url));
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class XMLDataChannelDescriptorLoaderTest method testLoadEmpty.
@Test
public void testLoadEmpty() {
// create and initialize loader instance to test
XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
injector.injectMembers(loader);
String testConfigName = "testConfig1";
URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
assertNotNull(tree);
assertNotNull(tree.getRootNode());
assertEquals(testConfigName, tree.getRootNode().getName());
}
Aggregations