use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class CompatibilityDataChannelDescriptorLoaderIT method testLoad.
@Test
public void testLoad() throws Exception {
Injector injector = getInjector();
DataChannelDescriptorLoader loader = injector.getInstance(DataChannelDescriptorLoader.class);
assertTrue(loader instanceof CompatibilityDataChannelDescriptorLoader);
URL resourceUrl = getClass().getResource("../../project/compatibility/cayenne-project-v6.xml");
Resource resource = new URLResource(resourceUrl);
ConfigurationTree<DataChannelDescriptor> configurationTree = loader.load(resource);
assertNotNull(configurationTree.getRootNode());
assertTrue(configurationTree.getLoadFailures().isEmpty());
assertEquals(1, configurationTree.getRootNode().getDataMaps().size());
DataMap dataMap = configurationTree.getRootNode().getDataMaps().iterator().next();
assertEquals(1, dataMap.getDbEntities().size());
assertEquals(1, dataMap.getObjEntities().size());
assertNotNull(dataMap.getObjEntity("Artist"));
assertNotNull(dataMap.getDbEntity("Artist"));
assertEquals(2, dataMap.getDbEntity("Artist").getAttributes().size());
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class CompatibilityUpgradeServiceIT method testUpgradeFullProjectDom.
@Test
public void testUpgradeFullProjectDom() throws Exception {
Injector injector = getInjector();
CompatibilityUpgradeService upgradeService = (CompatibilityUpgradeService) injector.getInstance(UpgradeService.class);
DocumentProvider documentProvider = injector.getInstance(DocumentProvider.class);
URL resourceUrl = getClass().getResource("cayenne-project-v6.xml");
Resource resource = new URLResource(resourceUrl);
upgradeService.upgradeProject(resource);
Document domainDocument = documentProvider.getDocument(resourceUrl);
assertNotNull(domainDocument);
assertEquals("10", domainDocument.getDocumentElement().getAttribute("project-version"));
URL dataMapUrl = getClass().getResource("test-map-v6.map.xml");
Document dataMapDocument = documentProvider.getDocument(dataMapUrl);
assertNotNull(dataMapDocument);
assertEquals("10", dataMapDocument.getDocumentElement().getAttribute("project-version"));
assertEquals(1, dataMapDocument.getElementsByTagName("obj-entity").getLength());
assertEquals(1, dataMapDocument.getElementsByTagName("db-entity").getLength());
assertEquals(2, dataMapDocument.getElementsByTagName("db-attribute").getLength());
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class FileProjectSaver method saveCommit.
void saveCommit(Collection<SaveUnit> units) {
for (SaveUnit unit : units) {
File targetFile = unit.targetFile;
// Per CAY-2119, this is an ugly hack to force Windows to unlock the file that was previously locked by
// our process. Without it, the delete operation downstream would fail
System.gc();
if (targetFile.exists()) {
if (!targetFile.delete()) {
throw new CayenneRuntimeException("Unable to remove old master file '%s'", targetFile.getAbsolutePath());
}
}
File tempFile = unit.targetTempFile;
if (!tempFile.renameTo(targetFile)) {
throw new CayenneRuntimeException("Unable to move '%s' to '%s'", tempFile.getAbsolutePath(), targetFile.getAbsolutePath());
}
unit.targetTempFile = null;
try {
if (unit.delegate == null) {
unit.node.acceptVisitor(new ConfigurationSourceSetter(new URLResource(targetFile.toURI().toURL())));
}
} catch (MalformedURLException e) {
throw new CayenneRuntimeException("Malformed URL for file '%s'", e, targetFile.getAbsolutePath());
}
}
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class DataChannelProjectLoaderTest method testLoad.
@Test
public void testLoad() {
DataChannelProjectLoader loader = new DataChannelProjectLoader();
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
binder.bind(DataChannelDescriptorLoader.class).to(XMLDataChannelDescriptorLoader.class);
binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
};
Injector injector = DIBootstrap.createInjector(testModule);
injector.injectMembers(loader);
String testConfigName = "PROJECT1";
String baseUrl = getClass().getPackage().getName().replace('.', '/');
URL url = getClass().getClassLoader().getResource(baseUrl + "/cayenne-" + testConfigName + ".xml");
Resource rootSource = new URLResource(url);
Project project = loader.loadProject(rootSource);
assertNotNull(project);
DataChannelDescriptor rootNode = (DataChannelDescriptor) project.getRootNode();
assertNotNull(rootNode);
assertSame(rootSource, rootNode.getConfigurationSource());
assertNotNull(project.getConfigurationResource());
assertEquals(project.getConfigurationResource(), rootSource);
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class DataChannelProjectSaverTest method testSaveAs.
@Test
public void testSaveAs() throws Exception {
FileProjectSaver saver = new FileProjectSaver(Collections.<ProjectExtension>emptyList());
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
binder.bind(DataChannelDescriptorLoader.class).to(XMLDataChannelDescriptorLoader.class);
binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class);
binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
};
Injector injector = DIBootstrap.createInjector(testModule);
injector.injectMembers(saver);
String testConfigName = "PROJECT2";
String baseUrl = getClass().getPackage().getName().replace('.', '/');
URL url = getClass().getClassLoader().getResource(baseUrl + "/cayenne-" + testConfigName + ".xml");
Resource source = new URLResource(url);
Project project = injector.getInstance(ProjectLoader.class).loadProject(source);
File outFile = setupTestDirectory("testSave");
saver.saveAs(project, new URLResource(outFile.toURI().toURL()));
File rootFile = new File(outFile, "cayenne-PROJECT2.xml");
assertTrue(rootFile.exists());
assertTrue(rootFile.length() > 0);
File map1File = new File(outFile, "testProjectMap2_1.map.xml");
assertTrue(map1File.exists());
assertTrue(map1File.length() > 0);
File map2File = new File(outFile, "testProjectMap2_2.map.xml");
assertTrue(map2File.exists());
assertTrue(map2File.length() > 0);
}
Aggregations