use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DefaultDbImportActionTest method testSaveLoadedWithEmptyProject.
@Test
public void testSaveLoadedWithEmptyProject() 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-testProject2.map.xml");
File projectFile = new File(projectURL.toURI());
projectFile.delete();
assertFalse(projectFile.exists());
when(params.getCayenneProject()).thenReturn(projectFile);
DefaultDbImportAction action = (DefaultDbImportAction) i.getInstance(DbImportAction.class);
URL dataMapURL = new URL(getPackageURL(), "dbimport/testSaveLoaded2.map.xml");
File dataMapFile = new File(dataMapURL.toURI());
dataMapFile.delete();
assertFalse(dataMapFile.exists());
DataMap map = new DataMap("testSaveLoaded2");
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=\"testSaveLoaded2\"/>"));
}
use of org.apache.cayenne.di.Injector 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.di.Injector in project cayenne by apache.
the class ModuleLoaderTest method testLoad.
@Test
public void testLoad() {
List<Module> modules = new ModuleLoader().load(ModuleProvider.class);
assertEquals(4, modules.size());
assertTrue(String.valueOf(modules.get(0)), modules.get(0) instanceof Module3);
assertTrue(String.valueOf(modules.get(1)), modules.get(1) instanceof Module4);
assertTrue(String.valueOf(modules.get(2)), modules.get(2) instanceof Module2);
assertTrue(String.valueOf(modules.get(3)), modules.get(3) instanceof Module1);
Injector i = DIBootstrap.createInjector(modules);
assertEquals("a", i.getInstance(String.class));
assertEquals(Integer.valueOf(56), i.getInstance(Integer.class));
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class CgenTask method generate.
@TaskAction
public void generate() {
File dataMapFile = getDataMapFile();
Injector injector = DIBootstrap.createInjector(new ToolsModule(LoggerFactory.getLogger(CgenTask.class)));
CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction(injector);
loaderAction.setMainDataMapFile(dataMapFile);
CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
filterAction.setClient(client);
filterAction.setNameFilter(NamePatternMatcher.build(getLogger(), includeEntities, excludeEntities));
try {
loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
ClassGenerationAction generator = this.createGenerator();
DataMap dataMap = loaderAction.getMainDataMap();
generator.setLogger(getLogger());
if (this.force || getProject().hasProperty("force")) {
generator.setForce(true);
}
generator.setTimestamp(dataMapFile.lastModified());
generator.setDataMap(dataMap);
generator.addEntities(filterAction.getFilteredEntities(dataMap));
generator.addEmbeddables(dataMap.getEmbeddables());
generator.addQueries(dataMap.getQueryDescriptors());
generator.execute();
} catch (Exception exception) {
throw new GradleException("Error generating classes: ", exception);
}
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class DbGenerateTask method createDbAdapter.
DbAdapter createDbAdapter() {
Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(getLogger()));
AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
return (adapter == null) ? objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName()) : objectFactory.newInstance(DbAdapter.class, adapter);
}
Aggregations