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
+82
@@ -0,0 +1,82 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.common.BeanList;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
public class BeanPropertyAssocManyTest extends BaseTestCase {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = spiEbeanServer().descriptor(Customer.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private BeanPropertyAssocMany<Customer> contacts() {
|
||||
return (BeanPropertyAssocMany<Customer>) customerDesc.beanProperty("contacts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReferenceIfNull_when_notBeanCollection_expect_null() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(new ArrayList<>());
|
||||
|
||||
BeanCollection<?> ref = contacts().createReferenceIfNull((EntityBean) customer);
|
||||
assertNull(ref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReferenceIfNull_when_null_expect_ref() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(null);
|
||||
|
||||
BeanCollection<?> ref = contacts().createReferenceIfNull((EntityBean) customer);
|
||||
assertNotNull(ref);
|
||||
assertTrue(ref.isReference());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lazyLoadMany_addsToParentCollection() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(new BeanList<>());
|
||||
|
||||
Contact contact = new Contact();
|
||||
contact.setCustomer(customer);
|
||||
|
||||
contacts().lazyLoadMany((EntityBean) contact);
|
||||
|
||||
assertThat(customer.getContacts()).hasSize(1);
|
||||
assertThat(customer.getContacts().get(0)).isSameAs(contact);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findIdsByParentId() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> customerIds = new ArrayList<>();
|
||||
customerIds.add(1L);
|
||||
customerIds.add(2L);
|
||||
|
||||
List<Object> contactIdsForOne = contacts().findIdsByParentId(1L, null, null, null, true);
|
||||
|
||||
List<Object> contactIdsForMultiple = contacts().findIdsByParentId(null, customerIds, null, null, true);
|
||||
|
||||
assertThat(contactIdsForOne).isNotEmpty();
|
||||
assertThat(contactIdsForMultiple).isNotEmpty();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user