Search in sources :

Example 21 with URLResource

use of org.apache.cayenne.resource.URLResource in project cayenne by apache.

the class XMLDataChannelDescriptorLoaderTest method loadInvalidNamespace.

@Test(expected = CayenneRuntimeException.class)
public void loadInvalidNamespace() throws Exception {
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    URL url = getClass().getResource("cayenne-testConfig5.xml");
    loader.load(new URLResource(url));
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) URL(java.net.URL) Test(org.junit.Test)

Example 22 with URLResource

use of org.apache.cayenne.resource.URLResource in project cayenne by apache.

the class XMLDataChannelDescriptorLoaderTest method testLoadDataMap.

@Test
public void testLoadDataMap() {
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "testConfig2";
    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());
    Collection<DataMap> maps = tree.getRootNode().getDataMaps();
    assertEquals(1, maps.size());
    assertEquals("testConfigMap2", maps.iterator().next().getName());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 23 with URLResource

use of org.apache.cayenne.resource.URLResource in project cayenne by apache.

the class XMLDataMapLoaderTest method loadEmptyConfig.

@Test
public void loadEmptyConfig() throws Exception {
    URL url = getClass().getResource("testConfigMap2.map.xml");
    DataMap map = loader.load(new URLResource(url));
    assertNotNull(map);
    assertEquals("testConfigMap2", map.getName());
    assertTrue(map.getDbEntities().isEmpty());
    assertTrue(map.getObjEntities().isEmpty());
    assertTrue(map.getProcedures().isEmpty());
    assertTrue(map.getQueryDescriptors().isEmpty());
    assertTrue(map.getEmbeddables().isEmpty());
    assertNull(map.getDefaultCatalog());
    assertNull(map.getDefaultSchema());
    assertNull(map.getDefaultPackage());
    assertFalse(map.isClientSupported());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 24 with URLResource

use of org.apache.cayenne.resource.URLResource in project cayenne by apache.

the class XMLDataMapLoaderTest method loadWrongVersionConfig.

@Test(expected = CayenneRuntimeException.class)
public void loadWrongVersionConfig() throws Exception {
    URL url = getClass().getResource("testConfigMap5.map.xml");
    loader.load(new URLResource(url));
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) URL(java.net.URL) Test(org.junit.Test)

Example 25 with URLResource

use of org.apache.cayenne.resource.URLResource in project cayenne by apache.

the class DBCleaner method clean.

public void clean() throws SQLException {
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    URL url = getClass().getClassLoader().getResource(location);
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    for (DataMap map : tree.getRootNode().getDataMaps()) {
        List<DbEntity> entities = schemaBuilder.dbEntitiesInDeleteOrder(map);
        for (DbEntity entity : entities) {
            dbHelper.deleteAll(entity.getName());
        }
    }
}
Also used : XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DbEntity(org.apache.cayenne.map.DbEntity) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap)

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