Refactor move tests from ebean-core to ebean-test

This commit is contained in:
rbygrave committed 2021-09-08 22:49:23 +12:00
1 parent 0b00a14fd3
commit eab56d323b
1650 files changed
+185 -147

No files matched your search

@@ -0,0 +1,65 @@
package org.tests.transaction;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Transaction;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.EBasicVer;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
import static org.assertj.core.api.Assertions.assertThat;
public class TestSavepoint extends BaseTestCase {
@ForPlatform({Platform.POSTGRES, Platform.H2})
@Test
public void test() throws SQLException {
EBasicVer basicVer = new EBasicVer("save1");
basicVer.setOther("other1");
DB.save(basicVer);
try (Transaction transaction = DB.beginTransaction()) {
Connection connection = transaction.connection();
Savepoint savepoint = connection.setSavepoint();
basicVer.setOther("changeOther");
DB.save(basicVer);
connection.rollback(savepoint);
transaction.commit();
}
EBasicVer found = DB.find(EBasicVer.class, basicVer.getId());
assertThat(found.getOther()).isEqualTo("other1");
}
@ForPlatform({Platform.POSTGRES, Platform.H2})
@Test
public void rollbackOnly_expect_similarResult() {
EBasicVer basicVer = new EBasicVer("save2");
basicVer.setOther("other2");
DB.save(basicVer);
try (Transaction transaction = DB.beginTransaction()) {
transaction.setRollbackOnly();
basicVer.setOther("changeOther");
DB.save(basicVer);
transaction.commit();
}
EBasicVer found = DB.find(EBasicVer.class, basicVer.getId());
assertThat(found.getOther()).isEqualTo("other2");
}
}