update datasource.properties

This commit is contained in:
azhwani 2020-06-10 18:54:37 +01:00
parent b9befff7b5
commit 5c9fbfc4c5
2 changed files with 2 additions and 41 deletions

View File

@ -1,39 +0,0 @@
package com.baeldung.jndi.datasource;
import static org.junit.Assert.assertEquals;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class SimpleJNDIUnitTest {
private InitialContext initContext;
@BeforeEach
public void setup() throws Exception {
this.initContext = new InitialContext();
}
@Test
public void whenMockJndiDataSource_thenReturnJndiDataSource() throws Exception {
String dsString = "org.h2.Driver::::jdbc:jdbc:h2:mem:testdb::::sa";
Context envContext = (Context) this.initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("datasource/ds");
assertEquals(dsString, ds.toString());
}
@AfterEach
public void tearDown() throws Exception {
if(this.initContext != null){
this.initContext.close();
this.initContext = null;
}
}
}

View File

@ -29,10 +29,10 @@ public class SimpleNamingContextBuilderUnitTest {
assertNotNull(ds.getConnection());
}
@AfterEach
public void tearDown() throws Exception {
if(this.initContext != null){
if (this.initContext != null) {
this.initContext.close();
this.initContext = null;
}