Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Sep 15, 2016
1 parent 9211989 commit 486c175
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void exportDataSet(DataSetExecutor dataSetExecutor, Method method) {
try {
DataSetExporter.getInstance().export(dataSetExecutor.getDBUnitConnection(),exportConfig);
} catch (Exception e) {
log.warn("Could not export dataset after method "+method.getName(),e);
log.warn("Could not export dataset after method " + method.getName(), e);
}
}
}
Expand Down Expand Up @@ -326,7 +326,7 @@ private ConnectionHolder createConnection(DBUnitConfig dbUnitConfig, String curr
private DBUnitTestContext getTestContext(ExtensionContext context) {
Class<?> testClass = context.getTestClass().get();
Store store = context.getStore(namespace);
DBUnitTestContext testContext = store.get(testClass,DBUnitTestContext.class);
DBUnitTestContext testContext = store.get(testClass, DBUnitTestContext.class);
if(testContext == null){
testContext = new DBUnitTestContext();
store.put(testClass, testContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.github.dbunit.rules.junit5;

import com.github.dbunit.rules.junit5.model.User;
import com.github.dbunit.rules.api.connection.ConnectionHolder;
import com.github.dbunit.rules.api.dataset.DataSet;
import com.github.dbunit.rules.configuration.DataSetConfig;
import com.github.dbunit.rules.connection.ConnectionHolderImpl;
import com.github.dbunit.rules.dataset.DataSetExecutorImpl;
import com.github.dbunit.rules.junit5.model.User;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

import static com.github.dbunit.rules.util.EntityManagerProvider.em;
import static com.github.dbunit.rules.util.EntityManagerProvider.instance;
import static com.github.dbunit.rules.util.EntityManagerProvider.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

Expand All @@ -29,12 +33,15 @@ public class CleanBeforeAfterIt {


@BeforeAll
public static void before(){
em("junit5-pu").getTransaction().begin();
em().createNativeQuery("DELETE FROM USER").executeUpdate();
public static void before() throws SQLException {
DataSetExecutorImpl.
instance(new ConnectionHolderImpl(instance("junit5-pu").connection())).
clearDatabase(new DataSetConfig().tableOrdering(Arrays.asList("TWEET","USER").toArray(new String[2])));
tx().begin();
//em().createNativeQuery("DELETE FROM TWEET").executeUpdate();
//em().createNativeQuery("DELETE FROM USER").executeUpdate();
em().createNativeQuery("INSERT INTO USER VALUES (6,'user6')").executeUpdate();
em().flush();
em().getTransaction().commit();
tx().commit();
List<User> users = em().createQuery("select u from User u").getResultList();
assertThat(users).isNotNull().hasSize(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public void shouldInsertUser() {
User user = new User();
user.setName("user");
user.setName("@rmpestano");
tx().begin();
if(!tx().isActive()){
tx().begin();
}
em().persist(user);
tx().commit();
User insertedUser = (User)em().createQuery("select u from User u where u.name = '@rmpestano'").getSingleResult();
Expand Down

0 comments on commit 486c175

Please sign in to comment.