Search in sources :

Example 6 with XMLReaderProvider

use of org.apache.cayenne.configuration.xml.XMLReaderProvider 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);
    }
}
Also used : Injector(org.apache.cayenne.di.Injector) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) Project2Case(org.apache.cayenne.project.unit.Project2Case) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) URL(java.net.URL) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) Module(org.apache.cayenne.di.Module) DataChannelDescriptorLoader(org.apache.cayenne.configuration.DataChannelDescriptorLoader) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) XMLReader(org.xml.sax.XMLReader) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) DIBootstrap(org.apache.cayenne.di.DIBootstrap) ProjectExtension(org.apache.cayenne.project.extension.ProjectExtension) PrintWriter(java.io.PrintWriter) URLResource(org.apache.cayenne.resource.URLResource) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) File(java.io.File) Resource(org.apache.cayenne.resource.Resource) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Assert(org.junit.Assert) Collections(java.util.Collections) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) URL(java.net.URL) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) URLResource(org.apache.cayenne.resource.URLResource) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) File(java.io.File) XMLReader(org.xml.sax.XMLReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ConfigurationNameMapper (org.apache.cayenne.configuration.ConfigurationNameMapper)6 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)6 DefaultConfigurationNameMapper (org.apache.cayenne.configuration.DefaultConfigurationNameMapper)6 DataChannelMetaData (org.apache.cayenne.configuration.xml.DataChannelMetaData)6 DefaultHandlerFactory (org.apache.cayenne.configuration.xml.DefaultHandlerFactory)6 HandlerFactory (org.apache.cayenne.configuration.xml.HandlerFactory)6 NoopDataChannelMetaData (org.apache.cayenne.configuration.xml.NoopDataChannelMetaData)6 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)6 XMLReaderProvider (org.apache.cayenne.configuration.xml.XMLReaderProvider)6 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)6 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)6 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)6 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)6 XMLDataChannelDescriptorLoader (org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader)5 URL (java.net.URL)4 DataChannelDescriptorLoader (org.apache.cayenne.configuration.DataChannelDescriptorLoader)4 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 DefaultObjectMapRetainStrategy (org.apache.cayenne.access.DefaultObjectMapRetainStrategy)2 ObjectMapRetainStrategy (org.apache.cayenne.access.ObjectMapRetainStrategy)2