[BAEL-2749] Uses static imports and uses code format
This commit is contained in:
parent
dc75e11440
commit
c0abc0ed35
|
@ -15,6 +15,7 @@ import org.junit.Test;
|
||||||
import org.junit.platform.commons.logging.Logger;
|
import org.junit.platform.commons.logging.Logger;
|
||||||
import org.junit.platform.commons.logging.LoggerFactory;
|
import org.junit.platform.commons.logging.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -25,10 +26,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class DataSourceDBUnitTest extends DataSourceBasedDBTestCase {
|
public class DataSourceDBUnitTest extends DataSourceBasedDBTestCase {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(DataSourceDBUnitTest.class);
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceDBUnitTest.class);
|
||||||
|
|
||||||
@Override
|
@Override protected javax.sql.DataSource getDataSource() {
|
||||||
protected javax.sql.DataSource getDataSource() {
|
|
||||||
JdbcDataSource dataSource = new JdbcDataSource();
|
JdbcDataSource dataSource = new JdbcDataSource();
|
||||||
dataSource.setURL(JDBC_URL);
|
dataSource.setURL(JDBC_URL);
|
||||||
dataSource.setUser("sa");
|
dataSource.setUser("sa");
|
||||||
|
@ -36,51 +36,38 @@ public class DataSourceDBUnitTest extends DataSourceBasedDBTestCase {
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected IDataSet getDataSet() throws Exception {
|
||||||
protected IDataSet getDataSet() throws Exception {
|
try (InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
||||||
try (java.io.InputStream resourceAsStream = getClass()
|
|
||||||
.getClassLoader()
|
|
||||||
.getResourceAsStream("dbunit/data.xml")) {
|
|
||||||
return new FlatXmlDataSetBuilder().build(resourceAsStream);
|
return new FlatXmlDataSetBuilder().build(resourceAsStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected DatabaseOperation getSetUpOperation() {
|
||||||
protected DatabaseOperation getSetUpOperation() {
|
|
||||||
return DatabaseOperation.REFRESH;
|
return DatabaseOperation.REFRESH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected DatabaseOperation getTearDownOperation() {
|
||||||
protected DatabaseOperation getTearDownOperation() {
|
|
||||||
return DatabaseOperation.DELETE_ALL;
|
return DatabaseOperation.DELETE_ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before public void setUp() throws Exception {
|
||||||
public void setUp() throws Exception {
|
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After public void tearDown() throws Exception {
|
||||||
public void tearDown() throws Exception {
|
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testSimpleDataSet() throws SQLException {
|
||||||
|
final Connection connection = getDataSource().getConnection();
|
||||||
|
|
||||||
@Test
|
final ResultSet rs = connection.createStatement().executeQuery("select * from ITEMS where id = 1");
|
||||||
public void testSimpleDataSet() throws SQLException {
|
|
||||||
final Connection connection = getDataSource()
|
|
||||||
.getConnection();
|
|
||||||
|
|
||||||
final ResultSet rs = connection
|
|
||||||
.createStatement()
|
|
||||||
.executeQuery("select * from iTEMS where id = 1");
|
|
||||||
|
|
||||||
assertThat(rs.next()).isTrue();
|
assertThat(rs.next()).isTrue();
|
||||||
assertThat(rs.getString("title")).isEqualTo("Grey T-Shirt");
|
assertThat(rs.getString("title")).isEqualTo("Grey T-Shirt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testEmptySchema() throws Exception {
|
||||||
public void testEmptySchema() throws Exception {
|
|
||||||
final IDataSet expectedDataSet = getDataSet();
|
final IDataSet expectedDataSet = getDataSet();
|
||||||
final ITable expectedTable = expectedDataSet.getTable("CLIENTS");
|
final ITable expectedTable = expectedDataSet.getTable("CLIENTS");
|
||||||
final IDataSet databaseDataSet = getConnection().createDataSet();
|
final IDataSet databaseDataSet = getConnection().createDataSet();
|
||||||
|
@ -88,32 +75,21 @@ public class DataSourceDBUnitTest extends DataSourceBasedDBTestCase {
|
||||||
Assertion.assertEquals(expectedTable, actualTable);
|
Assertion.assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testAssertByQuery() throws Exception {
|
||||||
public void testAssertByQuery() throws Exception {
|
try (final InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/expected-user.xml")) {
|
||||||
try (final java.io.InputStream is = getClass()
|
|
||||||
.getClassLoader()
|
|
||||||
.getResourceAsStream("dbunit/expected-user.xml")) {
|
|
||||||
final IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
|
final IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
|
||||||
final ITable expectedTable = expectedDataSet.getTable("CLIENTS");
|
final ITable expectedTable = expectedDataSet.getTable("CLIENTS");
|
||||||
final Connection conn = getDataSource().getConnection();
|
final Connection conn = getDataSource().getConnection();
|
||||||
|
|
||||||
conn.createStatement()
|
conn.createStatement().executeUpdate("INSERT INTO CLIENTS (first_name, last_name) VALUES ('John', 'Jansen')");
|
||||||
.executeUpdate(
|
final ITable actualData = getConnection().createQueryTable("result_name", "SELECT * FROM CLIENTS WHERE last_name='Jansen'");
|
||||||
"INSERT INTO CLIENTS (first_name, last_name) VALUES ('John', 'Jansen')");
|
|
||||||
final ITable actualData = getConnection()
|
|
||||||
.createQueryTable(
|
|
||||||
"result_name",
|
|
||||||
"SELECT * FROM CLIENTS WHERE last_name='Jansen'");
|
|
||||||
|
|
||||||
Assertion.assertEqualsIgnoreCols(expectedTable, actualData, new String[]{"id"});
|
Assertion.assertEqualsIgnoreCols(expectedTable, actualData, new String[] { "id" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testMultipleFailures() throws Exception {
|
||||||
public void testMultipleFailures() throws Exception {
|
try (final InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/expected-multiple-failures.xml")) {
|
||||||
try (final java.io.InputStream is = getClass()
|
|
||||||
.getClassLoader()
|
|
||||||
.getResourceAsStream("dbunit/expected-multiple-failures.xml")) {
|
|
||||||
final IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
|
final IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
|
||||||
final ITable expectedTable = expectedDataSet.getTable("ITEMS");
|
final ITable expectedTable = expectedDataSet.getTable("ITEMS");
|
||||||
final Connection conn = getDataSource().getConnection();
|
final Connection conn = getDataSource().getConnection();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
|
||||||
import org.dbunit.operation.DatabaseOperation;
|
import org.dbunit.operation.DatabaseOperation;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
@ -28,60 +29,54 @@ public class DbUnitTest extends DBTestCase {
|
||||||
System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, PASSWORD);
|
System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, PASSWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected IDataSet getDataSet() throws Exception {
|
||||||
protected IDataSet getDataSet() throws Exception {
|
try (final InputStream is = DbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
||||||
try (final java.io.InputStream is = DbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
|
||||||
return new FlatXmlDataSetBuilder().build(is);
|
return new FlatXmlDataSetBuilder().build(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected DatabaseOperation getSetUpOperation() {
|
||||||
protected DatabaseOperation getSetUpOperation() {
|
|
||||||
return DatabaseOperation.REFRESH;
|
return DatabaseOperation.REFRESH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override protected DatabaseOperation getTearDownOperation() {
|
||||||
protected DatabaseOperation getTearDownOperation() {
|
|
||||||
return DatabaseOperation.DELETE_ALL;
|
return DatabaseOperation.DELETE_ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testSelect() throws Exception {
|
||||||
public void testSelect() throws Exception {
|
|
||||||
final Connection connection = getConnection().getConnection();
|
final Connection connection = getConnection().getConnection();
|
||||||
|
|
||||||
final ResultSet rs = connection.createStatement().executeQuery("select * from iTEMS where id = 1");
|
final ResultSet rs = connection.createStatement().executeQuery("select * from ITEMS where id = 1");
|
||||||
|
|
||||||
assertThat(rs.next()).isTrue();
|
assertThat(rs.next()).isTrue();
|
||||||
assertThat(rs.getString("title")).isEqualTo("Grey T-Shirt");
|
assertThat(rs.getString("title")).isEqualTo("Grey T-Shirt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testDelete() throws Exception {
|
||||||
public void testDelete() throws Exception {
|
|
||||||
final Connection connection = getConnection().getConnection();
|
final Connection connection = getConnection().getConnection();
|
||||||
|
|
||||||
try (final java.io.InputStream is = DbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_delete.xml")) {
|
try (final InputStream is = DbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_delete.xml")) {
|
||||||
ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("items");
|
ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("ITEMS");
|
||||||
|
|
||||||
connection.createStatement().executeUpdate("delete from ITEMS where id = 2");
|
connection.createStatement().executeUpdate("delete from ITEMS where id = 2");
|
||||||
|
|
||||||
final IDataSet databaseDataSet = getConnection().createDataSet();
|
final IDataSet databaseDataSet = getConnection().createDataSet();
|
||||||
ITable actualTable = databaseDataSet.getTable("items");
|
ITable actualTable = databaseDataSet.getTable("ITEMS");
|
||||||
|
|
||||||
Assertion.assertEquals(expectedTable, actualTable);
|
Assertion.assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testUpdate() throws Exception {
|
||||||
public void testUpdate() throws Exception {
|
|
||||||
final Connection connection = getConnection().getConnection();
|
final Connection connection = getConnection().getConnection();
|
||||||
|
|
||||||
try (final java.io.InputStream is = DbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_rename.xml")) {
|
try (final InputStream is = DbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_rename.xml")) {
|
||||||
ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("items");
|
ITable expectedTable = (new FlatXmlDataSetBuilder().build(is)).getTable("ITEMS");
|
||||||
|
|
||||||
connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");
|
connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");
|
||||||
|
|
||||||
final IDataSet databaseDataSet = getConnection().createDataSet();
|
final IDataSet databaseDataSet = getConnection().createDataSet();
|
||||||
ITable actualTable = databaseDataSet.getTable("items");
|
ITable actualTable = databaseDataSet.getTable("ITEMS");
|
||||||
|
|
||||||
Assertion.assertEquals(expectedTable, actualTable);
|
Assertion.assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
@ -27,8 +28,7 @@ public class OldSchoolDbUnitTest {
|
||||||
|
|
||||||
private static IDatabaseTester tester = null;
|
private static IDatabaseTester tester = null;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass public static void setUp() throws Exception {
|
||||||
public static void setUp() throws Exception {
|
|
||||||
tester = initDatabaseTester();
|
tester = initDatabaseTester();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,37 +41,32 @@ public class OldSchoolDbUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IDataSet initDataSet() throws Exception {
|
private static IDataSet initDataSet() throws Exception {
|
||||||
try (final java.io.InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
try (final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
||||||
return new FlatXmlDataSetBuilder().build(is);
|
return new FlatXmlDataSetBuilder().build(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before public void setup() throws Exception {
|
||||||
public void setup() throws Exception {
|
|
||||||
tester.onSetup();
|
tester.onSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After public void tearDown() throws Exception {
|
||||||
public void tearDown() throws Exception {
|
|
||||||
tester.onTearDown();
|
tester.onTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testSelect() throws Exception {
|
||||||
public void testSelect() throws Exception {
|
|
||||||
final Connection connection = tester.getConnection().getConnection();
|
final Connection connection = tester.getConnection().getConnection();
|
||||||
|
|
||||||
final ResultSet rs = connection.createStatement().executeQuery("select * from iTEMS where id = 1");
|
final ResultSet rs = connection.createStatement().executeQuery("select * from ITEMS where id = 1");
|
||||||
|
|
||||||
assertThat(rs.next()).isTrue();
|
assertThat(rs.next()).isTrue();
|
||||||
assertThat(rs.getString("title")).isEqualTo("Grey T-Shirt");
|
assertThat(rs.getString("title")).isEqualTo("Grey T-Shirt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testIgnoringProduced() throws Exception {
|
||||||
public void testIgnoringProduced() throws Exception {
|
|
||||||
final Connection connection = tester.getConnection().getConnection();
|
final Connection connection = tester.getConnection().getConnection();
|
||||||
final String[] excludedColumns = {"id", "produced"};
|
final String[] excludedColumns = { "id", "produced" };
|
||||||
try (final java.io.InputStream is = getClass().getClassLoader()
|
try (final InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/expected-ignoring-registered_at.xml")) {
|
||||||
.getResourceAsStream("dbunit/expected-ignoring-registered_at.xml")) {
|
|
||||||
final IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
|
final IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(is);
|
||||||
final ITable expectedTable = DefaultColumnFilter.excludedColumnsTable(expectedDataSet.getTable("ITEMS"), excludedColumns);
|
final ITable expectedTable = DefaultColumnFilter.excludedColumnsTable(expectedDataSet.getTable("ITEMS"), excludedColumns);
|
||||||
|
|
||||||
|
@ -84,75 +79,63 @@ public class OldSchoolDbUnitTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testDelete() throws Exception {
|
||||||
public void testDelete() throws Exception {
|
|
||||||
final Connection connection = tester.getConnection().getConnection();
|
final Connection connection = tester.getConnection().getConnection();
|
||||||
|
|
||||||
try (final java.io.InputStream is =
|
try (final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_delete.xml")) {
|
||||||
OldSchoolDbUnitTest.class.getClassLoader()
|
ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");
|
||||||
.getResourceAsStream("dbunit/items_exp_delete.xml");) {
|
|
||||||
ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("items");
|
|
||||||
|
|
||||||
connection.createStatement().executeUpdate("delete from ITEMS where id = 2");
|
connection.createStatement().executeUpdate("delete from ITEMS where id = 2");
|
||||||
|
|
||||||
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
||||||
ITable actualTable = databaseDataSet.getTable("items");
|
ITable actualTable = databaseDataSet.getTable("ITEMS");
|
||||||
|
|
||||||
assertEquals(expectedTable, actualTable);
|
assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testDeleteWithExcludedColumns() throws Exception {
|
||||||
public void testDeleteWithExcludedColumns() throws Exception {
|
|
||||||
final Connection connection = tester.getConnection().getConnection();
|
final Connection connection = tester.getConnection().getConnection();
|
||||||
|
|
||||||
try (final java.io.InputStream is =
|
try (final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_delete_no_produced.xml")) {
|
||||||
OldSchoolDbUnitTest.class.getClassLoader()
|
final ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");
|
||||||
.getResourceAsStream("dbunit/items_exp_delete_no_produced.xml")) {
|
|
||||||
final ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("items");
|
|
||||||
|
|
||||||
connection.createStatement().executeUpdate("delete from ITEMS where id = 2");
|
connection.createStatement().executeUpdate("delete from ITEMS where id = 2");
|
||||||
|
|
||||||
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
||||||
ITable actualTable = databaseDataSet.getTable("items");
|
ITable actualTable = databaseDataSet.getTable("ITEMS");
|
||||||
actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[]{"produced"});
|
actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[] { "produced" });
|
||||||
|
|
||||||
assertEquals(expectedTable, actualTable);
|
assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testUpdate() throws Exception {
|
||||||
public void testUpdate() throws Exception {
|
|
||||||
final Connection connection = tester.getConnection().getConnection();
|
final Connection connection = tester.getConnection().getConnection();
|
||||||
|
|
||||||
try (final java.io.InputStream is =
|
try (final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_rename.xml")) {
|
||||||
OldSchoolDbUnitTest.class.getClassLoader()
|
final ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");
|
||||||
.getResourceAsStream("dbunit/items_exp_rename.xml")) {
|
|
||||||
final ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("items");
|
|
||||||
|
|
||||||
connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");
|
connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");
|
||||||
|
|
||||||
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
||||||
ITable actualTable = databaseDataSet.getTable("items");
|
ITable actualTable = databaseDataSet.getTable("ITEMS");
|
||||||
|
|
||||||
assertEquals(expectedTable, actualTable);
|
assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testUpdateWithExcludedColumns() throws Exception {
|
||||||
public void testUpdateWithExcludedColumns() throws Exception {
|
|
||||||
final Connection connection = tester.getConnection().getConnection();
|
final Connection connection = tester.getConnection().getConnection();
|
||||||
|
|
||||||
try (final java.io.InputStream is =
|
try (final InputStream is = OldSchoolDbUnitTest.class.getClassLoader().getResourceAsStream("dbunit/items_exp_rename_no_produced.xml")) {
|
||||||
OldSchoolDbUnitTest.class.getClassLoader()
|
ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("ITEMS");
|
||||||
.getResourceAsStream("dbunit/items_exp_rename_no_produced.xml")) {
|
|
||||||
ITable expectedTable = new FlatXmlDataSetBuilder().build(is).getTable("items");
|
|
||||||
|
|
||||||
connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");
|
connection.createStatement().executeUpdate("update ITEMS set title='new name' where id = 1");
|
||||||
|
|
||||||
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
final IDataSet databaseDataSet = tester.getConnection().createDataSet();
|
||||||
ITable actualTable = databaseDataSet.getTable("items");
|
ITable actualTable = databaseDataSet.getTable("ITEMS");
|
||||||
actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[]{"produced"});
|
actualTable = DefaultColumnFilter.excludedColumnsTable(actualTable, new String[] { "produced" });
|
||||||
|
|
||||||
assertEquals(expectedTable, actualTable);
|
assertEquals(expectedTable, actualTable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.dbunit.util.fileloader.DataFileLoader;
|
||||||
import org.dbunit.util.fileloader.FlatXmlDataFileLoader;
|
import org.dbunit.util.fileloader.FlatXmlDataFileLoader;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
@ -23,8 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
||||||
|
|
||||||
@Override
|
@Override public void setUp() throws Exception {
|
||||||
public void setUp() throws Exception {
|
|
||||||
setDatabaseTester(initDatabaseTester());
|
setDatabaseTester(initDatabaseTester());
|
||||||
setDataFileLoader(initDataFileLoader());
|
setDataFileLoader(initDataFileLoader());
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
@ -38,7 +38,7 @@ public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private IDataSet initDataSet() throws Exception {
|
private IDataSet initDataSet() throws Exception {
|
||||||
try (final java.io.InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
try (final InputStream is = getClass().getClassLoader().getResourceAsStream("dbunit/data.xml")) {
|
||||||
return new FlatXmlDataSetBuilder().build(is);
|
return new FlatXmlDataSetBuilder().build(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,14 +47,12 @@ public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
||||||
return new FlatXmlDataFileLoader();
|
return new FlatXmlDataFileLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testSelect() throws Exception {
|
||||||
public void testSelect() throws Exception {
|
|
||||||
final Connection connection = getConnection().getConnection();
|
final Connection connection = getConnection().getConnection();
|
||||||
final VerifyTableDefinition[] verifyTables = {new VerifyTableDefinition("CLIENTS", new String[]{})};
|
final VerifyTableDefinition[] verifyTables = { new VerifyTableDefinition("CLIENTS", new String[] {}) };
|
||||||
final String[] prepDataFiles = {"/dbunit/users.xml"};
|
final String[] prepDataFiles = { "/dbunit/users.xml" };
|
||||||
final String[] expectedDataFiles = {"/dbunit/users.xml"};
|
final String[] expectedDataFiles = { "/dbunit/users.xml" };
|
||||||
final PrepAndExpectedTestCaseSteps testSteps = () -> connection.createStatement()
|
final PrepAndExpectedTestCaseSteps testSteps = () -> connection.createStatement().executeQuery("select * from CLIENTS where id = 1");
|
||||||
.executeQuery("select * from CLIENTS where id = 1");
|
|
||||||
|
|
||||||
final ResultSet rs = (ResultSet) super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
final ResultSet rs = (ResultSet) super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
||||||
|
|
||||||
|
@ -62,26 +60,22 @@ public class PrepAndExpectedDbUnitTest extends DefaultPrepAndExpectedTestCase {
|
||||||
assertThat(rs.getString("last_name")).isEqualTo("Xavier");
|
assertThat(rs.getString("last_name")).isEqualTo("Xavier");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testUpdate() throws Exception {
|
||||||
public void testUpdate() throws Exception {
|
|
||||||
final Connection connection = getConnection().getConnection();
|
final Connection connection = getConnection().getConnection();
|
||||||
final VerifyTableDefinition[] verifyTables = {new VerifyTableDefinition("CLIENTS", new String[]{})}; // define tables to verify
|
final VerifyTableDefinition[] verifyTables = { new VerifyTableDefinition("CLIENTS", new String[] {}) }; // define tables to verify
|
||||||
final String[] prepDataFiles = {"/dbunit/users.xml"};
|
final String[] prepDataFiles = { "/dbunit/users.xml" };
|
||||||
final String[] expectedDataFiles = {"/dbunit/users_exp_rename.xml"};
|
final String[] expectedDataFiles = { "/dbunit/users_exp_rename.xml" };
|
||||||
final PrepAndExpectedTestCaseSteps testSteps = () -> connection.createStatement()
|
final PrepAndExpectedTestCaseSteps testSteps = () -> connection.createStatement().executeUpdate("update CLIENTS set first_name = 'new name' where id = 1");
|
||||||
.executeUpdate("update CLIENTS set first_name = 'new name' where id = 1");
|
|
||||||
|
|
||||||
super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test public void testDelete() throws Exception {
|
||||||
public void testDelete() throws Exception {
|
|
||||||
final Connection connection = getConnection().getConnection();
|
final Connection connection = getConnection().getConnection();
|
||||||
final VerifyTableDefinition[] verifyTables = {new VerifyTableDefinition("CLIENTS", new String[]{})};
|
final VerifyTableDefinition[] verifyTables = { new VerifyTableDefinition("CLIENTS", new String[] {}) };
|
||||||
final String[] prepDataFiles = {"/dbunit/users.xml"};
|
final String[] prepDataFiles = { "/dbunit/users.xml" };
|
||||||
final String[] expectedDataFiles = {"/dbunit/users_exp_delete.xml"};
|
final String[] expectedDataFiles = { "/dbunit/users_exp_delete.xml" };
|
||||||
final PrepAndExpectedTestCaseSteps testSteps = () -> connection.createStatement()
|
final PrepAndExpectedTestCaseSteps testSteps = () -> connection.createStatement().executeUpdate("delete from CLIENTS where id = 2");
|
||||||
.executeUpdate("delete from CLIENTS where id = 2");
|
|
||||||
|
|
||||||
super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
super.runTest(verifyTables, prepDataFiles, expectedDataFiles, testSteps);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue