updating jndi.properties
This commit is contained in:
parent
ecf97d79ea
commit
b9befff7b5
|
@ -0,0 +1,39 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
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;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
@ -29,4 +30,12 @@ public class SimpleNamingContextBuilderUnitTest {
|
|||
assertNotNull(ds.getConnection());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
if(this.initContext != null){
|
||||
this.initContext.close();
|
||||
this.initContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue