use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class XMLDataMapLoaderTest 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 = DIBootstrap.createInjector(testModule);
loader = injector.getInstance(DataMapLoader.class);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class ToolsModuleTest method testModuleContents.
@Test
public void testModuleContents() {
Logger log = mock(Logger.class);
Injector i = DIBootstrap.createInjector(new ToolsModule(log));
assertSame(log, i.getInstance(Logger.class));
assertTrue(i.getInstance(DataSourceFactory.class) instanceof DriverDataSourceFactory);
assertTrue(i.getInstance(AdhocObjectFactory.class) instanceof DefaultAdhocObjectFactory);
assertTrue(i.getInstance(DbAdapterFactory.class) instanceof DefaultDbAdapterFactory);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class ToolsModuleTest method testDbApdater.
@Test
public void testDbApdater() throws Exception {
Logger log = mock(Logger.class);
Injector i = DIBootstrap.createInjector(new ToolsModule(log));
DbAdapterFactory factory = i.getInstance(DbAdapterFactory.class);
DataNodeDescriptor nodeDescriptor = mock(DataNodeDescriptor.class);
DataSource dataSource = mock(DataSource.class);
assertTrue(factory.createAdapter(nodeDescriptor, dataSource) instanceof AutoAdapter);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DefaultDbImportActionTest method testSaveLoadedWithNonEmptyProject.
@Test
public void testSaveLoadedWithNonEmptyProject() throws Exception {
Logger log = mock(Logger.class);
Injector i = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(log), new DbImportModule());
DbImportConfiguration params = mock(DbImportConfiguration.class);
URL projectURL = new URL(getPackageURL(), "dbimport/cayenne-testProject3.map.xml");
File projectFile = new File(projectURL.toURI());
projectFile.delete();
assertFalse(projectFile.exists());
Files.write(projectFile.toPath(), ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<domain xmlns=\"http://cayenne.apache.org/schema/10/domain\"\n" + "\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "\t xsi:schemaLocation=\"http://cayenne.apache.org/schema/10/domain http://cayenne.apache.org/schema/10/domain.xsd\"\n" + "\t project-version=\"10\">\n" + "</domain>").getBytes(Charset.forName("UTF-8")));
assertTrue(projectFile.isFile());
when(params.getCayenneProject()).thenReturn(projectFile);
DefaultDbImportAction action = (DefaultDbImportAction) i.getInstance(DbImportAction.class);
URL dataMapURL = new URL(getPackageURL(), "dbimport/testSaveLoaded3.map.xml");
File dataMapFile = new File(dataMapURL.toURI());
dataMapFile.delete();
assertFalse(dataMapFile.exists());
DataMap map = new DataMap("testSaveLoaded3");
map.setConfigurationSource(new URLResource(dataMapURL));
action.saveLoaded(map, params);
assertTrue(dataMapFile.isFile());
assertTrue(projectFile.isFile());
String dataMapContents = Util.stringFromFile(dataMapFile);
assertTrue("Has no project version saved", dataMapContents.contains("project-version=\""));
String projectContents = Util.stringFromFile(projectFile);
assertTrue("Has no project version saved", projectContents.contains("project-version=\""));
assertTrue("Has no datamap in project", projectContents.contains("<map name=\"testSaveLoaded3\"/>"));
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DefaultDbImportActionTest method testSaveLoadedWithNonEmptyProjectAndNonEmptyDataMap.
@Test
public void testSaveLoadedWithNonEmptyProjectAndNonEmptyDataMap() throws Exception {
Logger log = mock(Logger.class);
Injector i = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(log), new DbImportModule());
DbImportConfiguration params = mock(DbImportConfiguration.class);
URL projectURL = new URL(getPackageURL(), "dbimport/cayenne-testProject4.map.xml");
File projectFile = new File(projectURL.toURI());
projectFile.delete();
assertFalse(projectFile.exists());
Files.write(projectFile.toPath(), ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<domain xmlns=\"http://cayenne.apache.org/schema/10/domain\"\n" + "\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "\t xsi:schemaLocation=\"http://cayenne.apache.org/schema/10/domain http://cayenne.apache.org/schema/10/domain.xsd\"\n" + "\t project-version=\"10\">\n" + "\t<map name=\"testSaveLoaded4\"/>\n" + "</domain>").getBytes(Charset.forName("UTF-8")));
assertTrue(projectFile.isFile());
when(params.getCayenneProject()).thenReturn(projectFile);
DefaultDbImportAction action = (DefaultDbImportAction) i.getInstance(DbImportAction.class);
URL dataMapURL = new URL(getPackageURL(), "dbimport/testSaveLoaded4.map.xml");
File dataMapFile = new File(dataMapURL.toURI());
dataMapFile.delete();
assertFalse(dataMapFile.exists());
Files.write(dataMapFile.toPath(), ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<data-map xmlns=\"http://cayenne.apache.org/schema/10/modelMap\"\n" + "\t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "\t xsi:schemaLocation=\"http://cayenne.apache.org/schema/10/modelMap http://cayenne.apache.org/schema/10/modelMap.xsd\"\n" + "\t project-version=\"10\">\n" + "\t<db-entity name=\"test\">\n" + "\t\t<db-attribute name=\"test\" type=\"INT\"/>\n" + "\t</db-entity>\n" + "</data-map>").getBytes(Charset.forName("UTF-8")));
assertTrue(dataMapFile.isFile());
DataMap map = new DataMap("testSaveLoaded4");
map.setConfigurationSource(new URLResource(dataMapURL));
action.saveLoaded(map, params);
assertTrue(dataMapFile.isFile());
assertTrue(projectFile.isFile());
String dataMapContents = Util.stringFromFile(dataMapFile);
assertTrue("Has no project version saved", dataMapContents.contains("project-version=\""));
assertFalse(dataMapContents.contains("<db-entity"));
String projectContents = Util.stringFromFile(projectFile);
assertTrue("Has no project version saved", projectContents.contains("project-version=\""));
assertEquals("Has no or too many datamaps in project", 1, Util.countMatches(projectContents, "<map name=\"testSaveLoaded4\"/>"));
}
Aggregations