[JAVA-2306] Moved articles from spring-persistence-simple-2

* https://www.baeldung.com/spring-jdbctemplate-testing went to spring-jdbc

* https://www.baeldung.com/spring-jdbctemplate-in-list went to spring-jdbc

* https://www.baeldung.com/spring-mock-jndi-datasource went to spring-persistence-simple

* Deleted spring-persistence-simple-2 module as all articles have been moved
This commit is contained in:
fdpro
2020-08-30 15:59:35 +02:00
parent 4e4ac650fa
commit eb4c306451
30 changed files with 224 additions and 89 deletions
@@ -0,0 +1,39 @@
package com.baeldung.spring.jndi.datasource.mock;
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;
}
}
}
@@ -0,0 +1,44 @@
package com.baeldung.spring.jndi.datasource.mock;
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;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
// marked as a manual test as the bindings in this test and
// SimpleJNDIUnitTest conflict depending on the order they are run in
@SuppressWarnings("deprecation")
public class SimpleNamingContextBuilderManualTest {
private InitialContext initContext;
@BeforeEach
public void init() throws Exception {
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
this.initContext = new InitialContext();
}
@Test
public void whenMockJndiDataSource_thenReturnJndiDataSource() throws Exception {
this.initContext.bind("java:comp/env/jdbc/datasource", new DriverManagerDataSource("jdbc:h2:mem:testdb"));
DataSource ds = (DataSource) this.initContext.lookup("java:comp/env/jdbc/datasource");
assertNotNull(ds.getConnection());
}
@AfterEach
public void tearDown() throws Exception {
if (this.initContext != null) {
this.initContext.close();
this.initContext = null;
}
}
}