fixed test

pull/539/head
Nitin
parent 9daa51313f
commit c362e8bb35

@ -67,27 +67,27 @@ public class HikariJNDIFactory implements ObjectFactory
return createDataSource(properties, nameCtx); return createDataSource(properties, nameCtx);
} }
private DataSource createDataSource(Properties properties, Context context) throws NamingException private DataSource createDataSource(final Properties properties, final Context context) throws NamingException
{ {
if (properties.getProperty("dataSourceJNDI") != null) { String jndiName = properties.getProperty("dataSourceJNDI");
return lookupJndiDataSource(properties, context); if (jndiName != null) {
return lookupJndiDataSource(properties, context, jndiName);
} }
return new HikariDataSource(new HikariConfig(properties)); return new HikariDataSource(new HikariConfig(properties));
} }
private DataSource lookupJndiDataSource(Properties properties, Context context) throws NamingException private DataSource lookupJndiDataSource(final Properties properties, final Context context, final String jndiName) throws NamingException
{ {
String jndiName = properties.getProperty("dataSourceJNDI");
if (context == null) { if (context == null) {
throw new RuntimeException("JNDI context does not found for dataSourceJNDI : " + jndiName); throw new RuntimeException("JNDI context does not found for dataSourceJNDI : " + jndiName);
} }
DataSource jndiDS = (DataSource) context.lookup(jndiName); DataSource jndiDS = (DataSource) context.lookup(jndiName);
if (jndiDS == null) { if (jndiDS == null) {
context = new InitialContext(); Context initContext = new InitialContext();
jndiDS = (DataSource) context.lookup(jndiName); jndiDS = (DataSource) initContext.lookup(jndiName);
//context.close(); //it should remain open for global contexts? //context.close(); // questionable
} }
if (jndiDS != null) { if (jndiDS != null) {

@ -84,7 +84,7 @@ public class TestJNDI
Assert.fail(); Assert.fail();
} }
catch (RuntimeException e) { catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().contains("JNDI context is null")); Assert.assertTrue(e.getMessage().contains("JNDI context does not found"));
} }
} }

Loading…
Cancel
Save