[BAEL-14850] - Changed to live test

This commit is contained in:
amit2103 2019-06-08 20:05:31 +05:30
parent 1dfc7e8244
commit 2155cb7ac6
1 changed files with 4 additions and 11 deletions

View File

@ -1,6 +1,5 @@
package com.baeldung.jdbc.joins; package com.baeldung.jdbc.joins;
import org.h2.tools.Server;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -13,19 +12,15 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
public class ArticleWithAuthorDAOIntegrationTest { public class ArticleWithAuthorDAOLiveTest {
private Connection connection; private Connection connection;
private ArticleWithAuthorDAO articleWithAuthorDAO; private ArticleWithAuthorDAO articleWithAuthorDAO;
private Server server;
@Before @Before
public void setup() throws ClassNotFoundException, SQLException { public void setup() throws ClassNotFoundException, SQLException {
Class.forName("org.postgresql.Driver");
server = Server.createTcpServer().start(); connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/myDb", "user", "pass");
Class.forName("org.h2.Driver");
connection = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "");
articleWithAuthorDAO = new ArticleWithAuthorDAO(connection); articleWithAuthorDAO = new ArticleWithAuthorDAO(connection);
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
String createAuthorSql = "CREATE TABLE IF NOT EXISTS AUTHOR (ID int NOT NULL PRIMARY KEY, FIRST_NAME varchar(255), LAST_NAME varchar(255));"; String createAuthorSql = "CREATE TABLE IF NOT EXISTS AUTHOR (ID int NOT NULL PRIMARY KEY, FIRST_NAME varchar(255), LAST_NAME varchar(255));";
@ -60,8 +55,7 @@ public class ArticleWithAuthorDAOIntegrationTest {
assertThat(articleWithAuthorList).anyMatch(row -> row.getTitle() == null); assertThat(articleWithAuthorList).anyMatch(row -> row.getTitle() == null);
} }
// Commenting JUNIT as currently H2 doesn't support FULL JOIN, please switch to other live database to run FULL JOIN queries @Test
//@Test
public void whenQueryWithFullJoin_thenShouldReturnProperRows() { public void whenQueryWithFullJoin_thenShouldReturnProperRows() {
List<ArticleWithAuthor> articleWithAuthorList = articleWithAuthorDAO.articleFullJoinAuthor(); List<ArticleWithAuthor> articleWithAuthorList = articleWithAuthorDAO.articleFullJoinAuthor();
@ -75,7 +69,6 @@ public class ArticleWithAuthorDAOIntegrationTest {
connection.createStatement().execute("DROP TABLE ARTICLE"); connection.createStatement().execute("DROP TABLE ARTICLE");
connection.createStatement().execute("DROP TABLE AUTHOR"); connection.createStatement().execute("DROP TABLE AUTHOR");
connection.close(); connection.close();
server.stop();
} }
public void insertTestData(Statement statement) throws SQLException { public void insertTestData(Statement statement) throws SQLException {