use of org.apache.cayenne.di.Injector 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.di.Injector in project cayenne by apache.
the class FileProjectSaverTest method setUp.
@Before
public void setUp() throws Exception {
Module testModule = binder -> binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
saver = new FileProjectSaver(Collections.<ProjectExtension>emptyList());
Injector injector = DIBootstrap.createInjector(testModule);
injector.injectMembers(saver);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class JCacheCase method setupInjector.
@BeforeClass
public static void setupInjector() {
final DefaultScope testScope = new DefaultScope();
injector = DIBootstrap.createInjector(new ServerCaseModule(testScope), binder -> binder.bind(ServerRuntime.class).toProvider(CacheServerRuntimeProvider.class).in(testScope));
injector.getInstance(SchemaBuilder.class).rebuildSchema();
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class JavaGroupsBridgeProviderTest method testGetJavaGroupsBridge.
@Test
public void testGetJavaGroupsBridge() throws Exception {
Injector injector = DIBootstrap.createInjector(new DefaultBindings(), new JGroupsModule());
EventBridge bridge = injector.getInstance(EventBridge.class);
assertNotNull(bridge);
assertTrue(bridge instanceof JavaGroupsBridge);
}
use of org.apache.cayenne.di.Injector in project cayenne by apache.
the class JavaGroupsBridgeProviderTest method testUseProperties.
@Test
public void testUseProperties() throws Exception {
Module module = binder -> {
JGroupsModule.contributeMulticastAddress(binder, MCAST_ADDRESS_TEST);
JGroupsModule.contributeMulticastPort(binder, Integer.parseInt(MCAST_PORT_TEST));
JGroupsModule.contributeConfigUrl(binder, CONFIG_URL_TEST);
};
Injector injector = DIBootstrap.createInjector(new DefaultBindings(), new JGroupsModule(), module);
JavaGroupsBridge bridge = (JavaGroupsBridge) injector.getInstance(EventBridge.class);
assertEquals(MCAST_ADDRESS_TEST, bridge.getMulticastAddress());
assertEquals(MCAST_PORT_TEST, bridge.getMulticastPort());
assertEquals(CONFIG_URL_TEST, bridge.getConfigURL());
}
Aggregations