mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +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,71 @@
|
||||
package org.tests.el;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanFkeyProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import io.ebeaninternal.server.el.ElPropertyChain;
|
||||
import io.ebeaninternal.server.el.ElPropertyDeploy;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestELBasic extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testEl() {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) DB.getDefault();
|
||||
BeanDescriptor<Customer> descriptor = server.descriptor(Customer.class);
|
||||
|
||||
ElPropertyDeploy elId = descriptor.elPropertyDeploy("id");
|
||||
assertTrue(elId instanceof BeanProperty);
|
||||
|
||||
ElPropertyDeploy elBillAddress = descriptor.elPropertyDeploy("billingAddress");
|
||||
assertTrue(elBillAddress instanceof BeanPropertyAssocOne<?>);
|
||||
|
||||
ElPropertyDeploy elBillAddressId = descriptor.elPropertyDeploy("billingAddress.id");
|
||||
assertTrue(elBillAddressId instanceof BeanFkeyProperty);
|
||||
assertEquals("billing_address_id", elBillAddressId.dbColumn());
|
||||
assertEquals("billingAddress.id", elBillAddressId.name());
|
||||
assertNull(elBillAddressId.elPrefix());
|
||||
|
||||
|
||||
ElPropertyDeploy elBillAddressCity = descriptor.elPropertyDeploy("billingAddress.city");
|
||||
assertTrue(elBillAddressCity instanceof ElPropertyChain);
|
||||
assertEquals("billingAddress", elBillAddressCity.elPrefix());
|
||||
assertEquals("city", elBillAddressCity.name());
|
||||
assertEquals("${billingAddress}city", elBillAddressCity.elPlaceholder(false));
|
||||
assertEquals("city", elBillAddressCity.dbColumn());
|
||||
|
||||
// ElPropertyDeploy elBillAddressCountry = descriptor.getElPropertyDeploy("billingAddress.country");
|
||||
|
||||
|
||||
ElPropertyDeploy elOrders = descriptor.elPropertyDeploy("orders");
|
||||
assertTrue(elOrders instanceof BeanPropertyAssocMany<?>);
|
||||
|
||||
ElPropertyDeploy elOrderStatus = descriptor.elPropertyDeploy("orders.status");
|
||||
assertTrue(elOrderStatus instanceof ElPropertyChain);
|
||||
assertEquals("orders", elOrderStatus.elPrefix());
|
||||
assertEquals("status", elOrderStatus.name());
|
||||
assertEquals("${orders}status", elOrderStatus.elPlaceholder(false));
|
||||
assertEquals("status", elOrderStatus.dbColumn());
|
||||
|
||||
ElPropertyDeploy elOrderCust = descriptor.elPropertyDeploy("orders.customer");
|
||||
assertTrue(elOrderCust instanceof ElPropertyChain);
|
||||
|
||||
ElPropertyDeploy elOrderDetails = descriptor.elPropertyDeploy("orders.details");
|
||||
assertTrue(elOrderDetails instanceof ElPropertyChain);
|
||||
|
||||
ElPropertyDeploy elOrderDetailsId = descriptor.elPropertyDeploy("orders.details.id");
|
||||
assertTrue(elOrderDetailsId instanceof ElPropertyChain);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.tests.el;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.plugin.BeanType;
|
||||
import io.ebean.plugin.ExpressionPath;
|
||||
import io.ebean.plugin.SpiServer;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Country;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestPathExpression {
|
||||
|
||||
final BeanType<Customer> beanType;
|
||||
final ExpressionPath billingId;
|
||||
final ExpressionPath line1;
|
||||
final ExpressionPath city;
|
||||
|
||||
public TestPathExpression() {
|
||||
SpiServer server = DB.getDefault().pluginApi();
|
||||
beanType = server.beanType(Customer.class);
|
||||
billingId = beanType.expressionPath("billingAddress.id");
|
||||
line1 = beanType.expressionPath("billingAddress.line1");
|
||||
city = beanType.expressionPath("billingAddress.city");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathSet() {
|
||||
|
||||
Customer c1 = new Customer();
|
||||
line1.pathSet(c1, "12 someplace");
|
||||
city.pathSet(c1, "Auckland");
|
||||
billingId.pathSet(c1, 4);
|
||||
|
||||
beanType.expressionPath("id").pathSet(c1, 42L);
|
||||
beanType.expressionPath("name").pathSet(c1, "jimmy");
|
||||
beanType.expressionPath("status").pathSet(c1, "ACTIVE");
|
||||
beanType.expressionPath("billingAddress.country.code").pathSet(c1, "NZ");
|
||||
beanType.expressionPath("billingAddress.country.name").pathSet(c1, "New Zealand");
|
||||
|
||||
|
||||
assertEquals(c1.getId(), Integer.valueOf(42));
|
||||
assertEquals(c1.getName(), "jimmy");
|
||||
assertEquals(c1.getStatus(), Customer.Status.ACTIVE);
|
||||
assertEquals(c1.getBillingAddress().getLine1(), "12 someplace");
|
||||
assertEquals(c1.getBillingAddress().getCity(), "Auckland");
|
||||
assertEquals(c1.getBillingAddress().getId(), Integer.valueOf("4"));
|
||||
|
||||
assertEquals(c1.getBillingAddress().getCountry().getCode(), "NZ");
|
||||
assertEquals(c1.getBillingAddress().getCountry().getName(), "New Zealand");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathGet() {
|
||||
|
||||
Address billingAddress = new Address();
|
||||
billingAddress.setId(12);
|
||||
billingAddress.setLine1("line1");
|
||||
billingAddress.setCity("Auckland");
|
||||
|
||||
Country nz = new Country();
|
||||
nz.setCode("NZ");
|
||||
nz.setName("New Zealand");
|
||||
billingAddress.setCountry(nz);
|
||||
|
||||
Customer c0 = new Customer();
|
||||
c0.setBillingAddress(billingAddress);
|
||||
|
||||
EntityBean e0 = (EntityBean) c0;
|
||||
assertEquals(line1.pathGet(e0), "line1");
|
||||
assertEquals(city.pathGet(e0), "Auckland");
|
||||
assertEquals(billingId.pathGet(e0), Integer.valueOf("12"));
|
||||
|
||||
|
||||
assertEquals(beanType.expressionPath("billingAddress.country.code").pathGet(e0), "NZ");
|
||||
assertEquals(beanType.expressionPath("billingAddress.country.name").pathGet(e0), "New Zealand");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.tests.el;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestUnderscoreParam extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Query<Customer> query = DB.find(Customer.class)
|
||||
.where().raw("name like ?", "Rob%")
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
|
||||
assertSql(query).contains("where t0.name like ?");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user