Search in sources :

Example 16 with URLResource

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
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) ConfigurationException(org.apache.cayenne.ConfigurationException) URL(java.net.URL) Test(org.junit.Test)

Example 17 with URLResource

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());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) SQLTemplateDescriptor(org.apache.cayenne.map.SQLTemplateDescriptor) DbAttribute(org.apache.cayenne.map.DbAttribute) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 18 with URLResource

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());
}
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 19 with URLResource

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));
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) URL(java.net.URL) Test(org.junit.Test)

Example 20 with URLResource

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());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) URL(java.net.URL) Test(org.junit.Test)

Aggregations

URLResource (org.apache.cayenne.resource.URLResource)40 URL (java.net.URL)31 Test (org.junit.Test)29 DataMap (org.apache.cayenne.map.DataMap)19 File (java.io.File)12 Injector (org.apache.cayenne.di.Injector)12 Resource (org.apache.cayenne.resource.Resource)11 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)10 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)7 XMLDataChannelDescriptorLoader (org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader)5 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)5 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)4 ConfigurationNameMapper (org.apache.cayenne.configuration.ConfigurationNameMapper)4 DefaultConfigurationNameMapper (org.apache.cayenne.configuration.DefaultConfigurationNameMapper)4 DataChannelMetaData (org.apache.cayenne.configuration.xml.DataChannelMetaData)4 DefaultHandlerFactory (org.apache.cayenne.configuration.xml.DefaultHandlerFactory)4 HandlerFactory (org.apache.cayenne.configuration.xml.HandlerFactory)4 NoopDataChannelMetaData (org.apache.cayenne.configuration.xml.NoopDataChannelMetaData)4 XMLReaderProvider (org.apache.cayenne.configuration.xml.XMLReaderProvider)4 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)4