mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2068 - Add ebean-test as module
This commit is contained in:
1 parent
ab283efed7
commit
bc055fea25
47 files changed
+2730
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package org.test;
|
||||
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.Version;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Entity
|
||||
public class BSimpleWithGen {
|
||||
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Transient
|
||||
private Map<String, List<String>> someMap;
|
||||
|
||||
@WhenModified
|
||||
private Instant whenModified;
|
||||
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
public BSimpleWithGen(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getSomeMap() {
|
||||
return someMap;
|
||||
}
|
||||
|
||||
public void setSomeMap(Map<String, List<String>> someMap) {
|
||||
this.someMap = someMap;
|
||||
}
|
||||
|
||||
public Instant getWhenModified() {
|
||||
return whenModified;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.test;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.test.ForTests;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class ForTestsBeforeAfterTest {
|
||||
|
||||
private ForTests.RollbackAll rollbackAll;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
rollbackAll = ForTests.createRollbackAll();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
rollbackAll.close();
|
||||
assertThat(getCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void createRollbackAll() {
|
||||
|
||||
doInsert();
|
||||
assertThat(getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private int getCount() {
|
||||
return DB.find(BSimpleWithGen.class)
|
||||
.where().eq("name", "ForTestsBeforeAfterTest")
|
||||
.findCount();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void doInsert() {
|
||||
|
||||
BSimpleWithGen bean = new BSimpleWithGen("ForTestsBeforeAfterTest");
|
||||
DB.save(bean);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.test;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import io.ebean.test.ForTests;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ForTestsTest {
|
||||
|
||||
@Test
|
||||
public void noTransactional_expect_noTransactionEnterExitCalled() {
|
||||
|
||||
ForTests.noTransactional(this::checkForTransactional);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enableTransactional() {
|
||||
|
||||
ForTests.enableTransactional(false);
|
||||
|
||||
checkForTransactional();
|
||||
|
||||
ForTests.enableTransactional(true);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void checkForTransactional() {
|
||||
|
||||
final Transaction transaction = DB.currentTransaction();
|
||||
assertThat(transaction).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rollbackTransactions() {
|
||||
|
||||
DB.find(BSimpleWithGen.class).delete();
|
||||
|
||||
ForTests.rollbackAll(this::doInsert);
|
||||
|
||||
final int count = DB.find(BSimpleWithGen.class).findCount();
|
||||
assertThat(count).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void doInsert() {
|
||||
|
||||
BSimpleWithGen bean = new BSimpleWithGen("doInsert");
|
||||
DB.save(bean);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user