diff --git a/persistence-modules/spring-persistence-simple-2/src/main/resources/jndi.properties b/persistence-modules/spring-persistence-simple-2/src/main/resources/jndi.properties new file mode 100644 index 0000000000..d976f16c02 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-2/src/main/resources/jndi.properties @@ -0,0 +1,6 @@ +java.naming.factory.initial=org.osjava.sj.SimpleContextFactory +org.osjava.sj.jndi.shared=true +org.osjava.sj.delimiter=. +jndi.syntax.separator=/ +org.osjava.sj.space=java:/comp/env +org.osjava.sj.root=src/main/resources/jndi diff --git a/persistence-modules/spring-persistence-simple-2/src/main/resources/jndi/datasource.properties b/persistence-modules/spring-persistence-simple-2/src/main/resources/jndi/datasource.properties new file mode 100644 index 0000000000..8be94daf36 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-2/src/main/resources/jndi/datasource.properties @@ -0,0 +1,5 @@ +ds.type=javax.sql.DataSource +ds.driver=org.h2.Driver +ds.url=jdbc:jdbc:h2:mem:testdb +ds.user=sa +ds.password=password diff --git a/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jndi/datasource/SimpleJNDIUnitTest.java b/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jndi/datasource/SimpleJNDIUnitTest.java deleted file mode 100644 index 138db10a30..0000000000 --- a/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jndi/datasource/SimpleJNDIUnitTest.java +++ /dev/null @@ -1,48 +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 { - System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory"); - System.setProperty("org.osjava.sj.root", "file://src/test/resources"); - System.setProperty("org.osjava.sj.delimiter", "."); - System.setProperty("jndi.syntax.separator", "/"); - System.setProperty("org.osjava.sj.space", "java:/comp/env"); - - 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 { - System.clearProperty("java.naming.factory.initial"); - System.clearProperty("org.osjava.sj.root"); - System.clearProperty("org.osjava.sj.delimiter"); - System.clearProperty("jndi.syntax.separator"); - System.clearProperty("org.osjava.sj.space"); - - this.initContext = null; - } - -} \ No newline at end of file