Search in sources :

Example 6 with URLResource

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

the class FileProjectSaverTest method testSaveForProjectFileWithRelatedPaths.

/**
 * Method test fix for CAY-1780. If specify related fragments (for example ./../)
 * in target file path then file must be created successfully.
 *
 * @throws Exception
 */
@Test
public void testSaveForProjectFileWithRelatedPaths() throws Exception {
    File testFolder = setupTestDirectory("testSaveForProjectFileWithRelatedPaths");
    String mapFilePath = testFolder.toURI() + "../test.map.xml";
    String mapFileName = "test";
    DataMap testDataMap = new DataMap(mapFileName);
    testDataMap.setConfigurationSource(new URLResource(new URL(mapFilePath)));
    Project project = new Project(new ConfigurationTree<DataMap>(testDataMap));
    saver.save(project);
    File target = new File(testFolder.getParentFile(), mapFileName + ".map.xml");
    assertTrue(target.isFile());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) File(java.io.File) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 7 with URLResource

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

the class DefaultUpgradeServiceTest method getAdditionalDatamapResources.

@Test
public void getAdditionalDatamapResources() throws Exception {
    URL url = getClass().getResource("../cayenne-PROJECT1.xml");
    Resource resource = new URLResource(url);
    Document document = readDocument(url);
    UpgradeUnit unit = new UpgradeUnit(resource, document);
    List<Resource> resources = upgradeService.getAdditionalDatamapResources(unit);
    assertEquals(2, resources.size());
    assertTrue(resources.get(0).getURL().sameFile(getClass().getResource("../testProjectMap1_1.map.xml")));
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) Document(org.w3c.dom.Document) URL(java.net.URL) Test(org.junit.Test)

Example 8 with URLResource

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

the class BaseUpgradeHandlerTest method processDataMapDom.

Document processDataMapDom(String xmlResourceName) throws Exception {
    UpgradeUnit unit = new UpgradeUnit(new URLResource(getClass().getResource(xmlResourceName)), documentFromResource(xmlResourceName));
    handler.processDataMapDom(unit);
    return unit.getDocument();
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeUnit(org.apache.cayenne.project.upgrade.UpgradeUnit)

Example 9 with URLResource

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

the class BaseUpgradeHandlerTest method processProjectDom.

Document processProjectDom(String xmlResourceName) throws Exception {
    UpgradeUnit unit = new UpgradeUnit(new URLResource(getClass().getResource(xmlResourceName)), documentFromResource(xmlResourceName));
    handler.processProjectDom(unit);
    return unit.getDocument();
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) UpgradeUnit(org.apache.cayenne.project.upgrade.UpgradeUnit)

Example 10 with URLResource

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

the class DefaultDbImportActionTest method testSaveLoadedNoProject.

@Test
public void testSaveLoadedNoProject() throws Exception {
    Logger log = mock(Logger.class);
    Injector i = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(log), new DbImportModule());
    DbImportConfiguration params = mock(DbImportConfiguration.class);
    when(params.getCayenneProject()).thenReturn(null);
    URL outUrl = new URL(getPackageURL(), "dbimport/testSaveLoaded1.map.xml");
    DefaultDbImportAction action = (DefaultDbImportAction) i.getInstance(DbImportAction.class);
    File out = new File(outUrl.toURI());
    out.delete();
    assertFalse(out.exists());
    DataMap map = new DataMap("testSaveLoaded1");
    map.setConfigurationSource(new URLResource(outUrl));
    action.saveLoaded(map, params);
    assertTrue(out.isFile());
    String contents = Util.stringFromFile(out);
    assertTrue("Has no project version saved", contents.contains("project-version=\""));
}
Also used : Logger(org.slf4j.Logger) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) URLResource(org.apache.cayenne.resource.URLResource) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) File(java.io.File) 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