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;
});
}
Aggregations