Search in sources :

Example 1 with C3p0DataSourceFactory

use of org.umlg.sqlg.structure.ds.C3p0DataSourceFactory in project sqlg by pietermartin.

the class TestJNDIInitialization method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties");
    configuration = new PropertiesConfiguration(sqlProperties);
    if (!configuration.containsKey("jdbc.url")) {
        throw new IllegalArgumentException(String.format("SqlGraph configuration requires that the %s be set", "jdbc.url"));
    }
    String url = configuration.getString("jdbc.url");
    // obtain the connection that we will later supply from JNDI
    SqlgPlugin p = findSqlgPlugin(url);
    Assert.assertNotNull(p);
    ds = new C3p0DataSourceFactory().setup(p.getDriverFor(url), configuration).getDatasource();
    // change the connection url to be a JNDI one
    configuration.setProperty("jdbc.url", "jndi:testConnection");
    // set up the initial context
    NamingManager.setInitialContextFactoryBuilder(environment -> {
        InitialContextFactory mockFactory = mock(InitialContextFactory.class);
        Context mockContext = mock(Context.class);
        when(mockFactory.getInitialContext(any())).thenReturn(mockContext);
        when(mockContext.lookup("testConnection")).thenReturn(ds);
        return mockFactory;
    });
}
Also used : Context(javax.naming.Context) C3p0DataSourceFactory(org.umlg.sqlg.structure.ds.C3p0DataSourceFactory) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) SqlgPlugin(org.umlg.sqlg.SqlgPlugin) InitialContextFactory(javax.naming.spi.InitialContextFactory) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Aggregations

URL (java.net.URL)1 Context (javax.naming.Context)1 InitialContextFactory (javax.naming.spi.InitialContextFactory)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 BeforeClass (org.junit.BeforeClass)1 SqlgPlugin (org.umlg.sqlg.SqlgPlugin)1 C3p0DataSourceFactory (org.umlg.sqlg.structure.ds.C3p0DataSourceFactory)1