mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
Refactor move tests from ebean-core to ebean-test
This commit is contained in:
1 parent
0b00a14fd3
commit
eab56d323b
1650 files changed
+185
-147
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package org.tests.iud;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.tests.model.info.InfoCompany;
|
||||
import org.tests.model.info.InfoCustomer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TestInfoOneToOne extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_cascade_oneToOne() {
|
||||
|
||||
InfoCompany company = new InfoCompany();
|
||||
company.setName("info company");
|
||||
|
||||
InfoCustomer customer = new InfoCustomer();
|
||||
customer.setName("first info cust");
|
||||
customer.setCompany(company);
|
||||
|
||||
customer.save();
|
||||
|
||||
// assert JsonIgnore working as expected
|
||||
String asJson = DB.json().toJson(company);
|
||||
assertThat(asJson).doesNotContain("contacts");
|
||||
|
||||
// assert both are inserted
|
||||
assertNotNull(customer.getId());
|
||||
assertNotNull(company.getId());
|
||||
|
||||
// both can be fetched
|
||||
assertNotNull(InfoCustomer.find.byId(customer.getId()));
|
||||
assertNotNull(InfoCompany.find.byId(company.getId()));
|
||||
|
||||
|
||||
// just update the customer
|
||||
customer.setName("first mod");
|
||||
customer.update();
|
||||
|
||||
// update the customer and company
|
||||
customer.getCompany().setName("2nd mod company");
|
||||
customer.setName("2nd mod customer");
|
||||
customer.update();
|
||||
|
||||
// fetch and then update both
|
||||
InfoCustomer fetchedCustomer = InfoCustomer.find.byId(customer.getId());
|
||||
fetchedCustomer.getCompany().setName("3rd mod company");
|
||||
fetchedCustomer.setName("3rd mod customer");
|
||||
fetchedCustomer.update();
|
||||
|
||||
|
||||
// delete both customer and company
|
||||
fetchedCustomer.delete();
|
||||
assertNull(InfoCustomer.find.byId(customer.getId()));
|
||||
assertNull(InfoCompany.find.byId(company.getId()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user