Package org.apache.cayenne.configuration

Examples of org.apache.cayenne.configuration.RuntimeProperties


                ((MockDataSourceFactory1) factory).getInjector());
    }

    public void testGetDataSourceFactory_Property() throws Exception {

        final RuntimeProperties properties = mock(RuntimeProperties.class);
        when(properties.get(PropertyDataSourceFactory.JDBC_DRIVER_PROPERTY)).thenReturn(
                "x");
        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY)).thenReturn("y");

        DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
        channelDescriptor.setName("X");
        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
        nodeDescriptor.setName("node1");
        nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
        nodeDescriptor.setDataChannelDescriptor(channelDescriptor);

        Module testModule = new Module() {

            public void configure(Binder binder) {
                binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
                binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
                binder.bind(RuntimeProperties.class).toInstance(properties);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);

        DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
        injector.injectMembers(factoryLoader);

        DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);

        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY))
                .thenReturn(null);
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertFalse(factory instanceof PropertyDataSourceFactory);

        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY + ".X.node2"))
                .thenReturn("y");
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertFalse(factory instanceof PropertyDataSourceFactory);

        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY + ".X.node1"))
                .thenReturn("y");
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);
    }
View Full Code Here


                ((MockDataSourceFactory1) factory).getInjector());
    }

    public void testGetDataSourceFactory_Property() throws Exception {

        final RuntimeProperties properties = mock(RuntimeProperties.class);
        when(properties.get(PropertyDataSourceFactory.JDBC_DRIVER_PROPERTY)).thenReturn(
                "x");
        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY)).thenReturn("y");

        DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
        channelDescriptor.setName("X");
        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
        nodeDescriptor.setName("node1");
        nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
        nodeDescriptor.setDataChannelDescriptor(channelDescriptor);

        Module testModule = new Module() {

            public void configure(Binder binder) {
                binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
                binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
                binder.bind(RuntimeProperties.class).toInstance(properties);
                binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);

        DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
        injector.injectMembers(factoryLoader);

        DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);

        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY))
                .thenReturn(null);
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertFalse(factory instanceof PropertyDataSourceFactory);

        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY + ".X.node2"))
                .thenReturn("y");
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertFalse(factory instanceof PropertyDataSourceFactory);

        when(properties.get(PropertyDataSourceFactory.JDBC_URL_PROPERTY + ".X.node1"))
                .thenReturn("y");
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);
    }
View Full Code Here

                ((MockDataSourceFactory1) factory).getInjector());
    }

    public void testGetDataSourceFactory_Property() throws Exception {

        final RuntimeProperties properties = mock(RuntimeProperties.class);
        when(properties.get(Constants.JDBC_DRIVER_PROPERTY)).thenReturn(
                "x");
        when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn("y");

        DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
        channelDescriptor.setName("X");
        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
        nodeDescriptor.setName("node1");
        nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
        nodeDescriptor.setDataChannelDescriptor(channelDescriptor);

        Module testModule = new Module() {

            public void configure(Binder binder) {
                binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
                binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
                binder.bind(RuntimeProperties.class).toInstance(properties);
                binder.bind(JdbcEventLogger.class).to(CommonsJdbcEventLogger.class);
            }
        };

        Injector injector = DIBootstrap.createInjector(testModule);

        DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
        injector.injectMembers(factoryLoader);

        DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);

        when(properties.get(Constants.JDBC_URL_PROPERTY))
                .thenReturn(null);
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertFalse(factory instanceof PropertyDataSourceFactory);

        when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node2"))
                .thenReturn("y");
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertFalse(factory instanceof PropertyDataSourceFactory);

        when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node1"))
                .thenReturn("y");
        factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
        assertNotNull(factory);
        assertTrue(factory instanceof PropertyDataSourceFactory);
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.configuration.RuntimeProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.