[BAEL-2749] Introduces Assertj and uses builder pattern
This commit is contained in:
parent
aaffd9614f
commit
a65c5bf202
|
@ -3,6 +3,16 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>dbunit</artifactId>
|
||||
<version>1.0</version>
|
||||
<properties>
|
||||
<h2.version>1.4.200</h2.version>
|
||||
|
||||
<maven-compiler-plugin.target>1.8</maven-compiler-plugin.target>
|
||||
<maven-compiler-plugin.source>1.8</maven-compiler-plugin.source>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
|
||||
<assertj-core.version>3.14.0</assertj-core.version>
|
||||
<dbunit.version>2.6.0</dbunit.version>
|
||||
</properties>
|
||||
<name>dbunit</name>
|
||||
|
||||
<parent>
|
||||
|
@ -22,14 +32,30 @@
|
|||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.197</version>
|
||||
<version>${h2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<dbunit.version>2.6.0</dbunit.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${maven-compiler-plugin.source}</source>
|
||||
<target>${maven-compiler-plugin.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.dbunit.JdbcDatabaseTester;
|
|||
import org.dbunit.dataset.IDataSet;
|
||||
import org.dbunit.dataset.ITable;
|
||||
import org.dbunit.dataset.xml.FlatXmlDataSet;
|
||||
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
||||
import org.dbunit.operation.DatabaseOperation;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
@ -16,6 +17,7 @@ import java.io.InputStream;
|
|||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -74,7 +76,7 @@ public class OldSchoolDbUnitTest {
|
|||
final Connection connection = tester.getConnection().getConnection();
|
||||
|
||||
final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("items_exp_delete.xml");
|
||||
ITable expectedTable = (new FlatXmlDataSet(is)).getTable("items");
|
||||
ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("items");
|
||||
//expectedTable = DefaultColumnFilter.excludedColumnsTable(expectedTable, new String[]{"produced"});
|
||||
|
||||
// Act
|
||||
|
@ -94,7 +96,7 @@ public class OldSchoolDbUnitTest {
|
|||
final Connection connection = tester.getConnection().getConnection();
|
||||
|
||||
final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("items_exp_rename.xml");
|
||||
ITable expectedTable = (new FlatXmlDataSet(is)).getTable("items");
|
||||
ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("items");
|
||||
//expectedTable = DefaultColumnFilter.excludedColumnsTable(expectedTable, new String[]{"produced"});
|
||||
|
||||
// Act
|
||||
|
@ -105,7 +107,7 @@ public class OldSchoolDbUnitTest {
|
|||
ITable actualTable = databaseDataSet.getTable("items");
|
||||
//actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[]{"produced"});
|
||||
|
||||
Assertion.assertEquals(expectedTable, actualTable);
|
||||
assertThat(actualTable).isEqualTo(actualTable);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.baeldung.dbunit;
|
||||
|
||||
import org.dbunit.*;
|
||||
import org.dbunit.DefaultPrepAndExpectedTestCase;
|
||||
import org.dbunit.IDatabaseTester;
|
||||
import org.dbunit.JdbcDatabaseTester;
|
||||
import org.dbunit.PrepAndExpectedTestCaseSteps;
|
||||
import org.dbunit.VerifyTableDefinition;
|
||||
import org.dbunit.dataset.IDataSet;
|
||||
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
||||
import org.dbunit.operation.DatabaseOperation;
|
||||
|
@ -12,6 +16,8 @@ import java.io.InputStream;
|
|||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
||||
private static final String JDBC_DRIVER = org.h2.Driver.class.getName();
|
||||
private static final String JDBC_URL = "jdbc:h2:mem:default;DB_CLOSE_DELAY=-1;init=runscript from 'classpath:schema.sql'";
|
||||
|
@ -63,8 +69,8 @@ public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
|||
final ResultSet rs = (ResultSet) super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
||||
|
||||
// or place assertions at the end
|
||||
assertTrue(rs.next());
|
||||
assertEquals("Xavier", rs.getString("last_name"));
|
||||
assertThat(rs.next()).isTrue();
|
||||
assertThat(rs.getString("last_name")).isEqualTo("Xavier");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue