use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class ManyToManyCandidateEntityTest method setUp.
@Before
public void setUp() throws Exception {
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(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);
// create and initialize loader instance to test
XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
injector.injectMembers(loader);
String testConfigName = "relationship-optimisation";
URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
map = tree.getRootNode().getDataMap(testConfigName);
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class DataChannelProjectSaverTest method testSaveAs_RecoverFromSaveError.
@Test
public void testSaveAs_RecoverFromSaveError() throws Exception {
FileProjectSaver saver = new FileProjectSaver(Collections.<ProjectExtension>emptyList()) {
@Override
void saveToTempFile(SaveUnit unit, PrintWriter printWriter) {
throw new CayenneRuntimeException("Test Exception");
}
};
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("testSaveAs_RecoverFromSaveError");
assertEquals(0, outFile.list().length);
try {
saver.saveAs(project, new URLResource(outFile.toURI().toURL()));
fail("No exception was thrown..");
} catch (CayenneRuntimeException e) {
// expected
assertEquals(0, outFile.list().length);
}
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class FileProjectSaverTest method testSaveAs_Sorted.
@Test
public void testSaveAs_Sorted() throws Exception {
File testFolder = setupTestDirectory("testSaveAs_Sorted");
DataChannelDescriptor rootNode = new DataChannelDescriptor();
rootNode.setName("test");
// add maps and nodes in reverse alpha order. Check that they are saved in alpha
// order
rootNode.getDataMaps().add(new DataMap("C"));
rootNode.getDataMaps().add(new DataMap("B"));
rootNode.getDataMaps().add(new DataMap("A"));
DataNodeDescriptor[] nodes = new DataNodeDescriptor[3];
nodes[0] = new DataNodeDescriptor("Z");
nodes[1] = new DataNodeDescriptor("Y");
nodes[2] = new DataNodeDescriptor("X");
nodes[0].getDataMapNames().add("C");
nodes[0].getDataMapNames().add("B");
nodes[0].getDataMapNames().add("A");
rootNode.getNodeDescriptors().addAll(Arrays.asList(nodes));
Project project = new Project(new ConfigurationTree<DataChannelDescriptor>(rootNode));
saver.saveAs(project, new URLResource(testFolder.toURI().toURL()));
File target = new File(testFolder, "cayenne-test.xml");
assertTrue(target.isFile());
assertSaveAs_Sorted(target);
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class DefaultUpgradeServiceTest method upgradeDOM.
@Test
public void upgradeDOM() throws Exception {
Resource resource = new URLResource(getClass().getResource("../cayenne-PROJECT1.xml"));
// Mock service so it will use actual reading but skip actual saving part
upgradeService = mock(DefaultUpgradeService.class);
when(upgradeService.upgradeDOM(any(Resource.class), ArgumentMatchers.<UpgradeHandler>anyList())).thenCallRealMethod();
when(upgradeService.getAdditionalDatamapResources(any(UpgradeUnit.class))).thenCallRealMethod();
upgradeService.upgradeDOM(resource, handlers);
// verify(upgradeService, times(3)).saveDocument(any(UpgradeUnit.class));
for (UpgradeHandler handler : handlers) {
verify(handler).getVersion();
verify(handler).processProjectDom(any(UpgradeUnit.class));
// two data maps
verify(handler, times(2)).processDataMapDom(any(UpgradeUnit.class));
verifyNoMoreInteractions(handler);
}
}
use of org.apache.cayenne.resource.URLResource in project cayenne by apache.
the class CompatibilityDataMapLoaderIT method testLoad.
@Test
public void testLoad() throws Exception {
Injector injector = getInjector();
DataMapLoader loader = injector.getInstance(DataMapLoader.class);
assertTrue(loader instanceof CompatibilityDataMapLoader);
URL resourceUrl = getClass().getResource("../../project/compatibility/test-map-v6.map.xml");
Resource resource = new URLResource(resourceUrl);
DataMap dataMap = loader.load(resource);
assertNotNull(dataMap);
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());
}
Aggregations