#919 - io.ebean package initial

This commit is contained in:
Rob Bygrave
2016-12-11 23:23:22 +13:00
parent 5821dc96b9
commit 971e2dc91b
2134 changed files with 10721 additions and 8652 deletions
@@ -0,0 +1,70 @@
package org.tests.el;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
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.Assert;
import org.junit.Test;
public class TestELBasic extends BaseTestCase {
@Test
public void testEl() {
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
ElPropertyDeploy elId = descriptor.getElPropertyDeploy("id");
Assert.assertTrue(elId instanceof BeanProperty);
ElPropertyDeploy elBillAddress = descriptor.getElPropertyDeploy("billingAddress");
Assert.assertTrue(elBillAddress instanceof BeanPropertyAssocOne<?>);
ElPropertyDeploy elBillAddressId = descriptor.getElPropertyDeploy("billingAddress.id");
Assert.assertTrue(elBillAddressId instanceof BeanFkeyProperty);
Assert.assertEquals("billing_address_id", elBillAddressId.getDbColumn());
Assert.assertEquals("billingAddress.id", elBillAddressId.getName());
Assert.assertNull(elBillAddressId.getElPrefix());
ElPropertyDeploy elBillAddressCity = descriptor.getElPropertyDeploy("billingAddress.city");
Assert.assertTrue(elBillAddressCity instanceof ElPropertyChain);
Assert.assertEquals("billingAddress", elBillAddressCity.getElPrefix());
Assert.assertEquals("city", elBillAddressCity.getName());
Assert.assertEquals("${billingAddress}city", elBillAddressCity.getElPlaceholder(false));
Assert.assertEquals("city", elBillAddressCity.getDbColumn());
// ElPropertyDeploy elBillAddressCountry = descriptor.getElPropertyDeploy("billingAddress.country");
ElPropertyDeploy elOrders = descriptor.getElPropertyDeploy("orders");
Assert.assertTrue(elOrders instanceof BeanPropertyAssocMany<?>);
ElPropertyDeploy elOrderStatus = descriptor.getElPropertyDeploy("orders.status");
Assert.assertTrue(elOrderStatus instanceof ElPropertyChain);
Assert.assertEquals("orders", elOrderStatus.getElPrefix());
Assert.assertEquals("status", elOrderStatus.getName());
Assert.assertEquals("${orders}status", elOrderStatus.getElPlaceholder(false));
Assert.assertEquals("status", elOrderStatus.getDbColumn());
ElPropertyDeploy elOrderCust = descriptor.getElPropertyDeploy("orders.customer");
Assert.assertTrue(elOrderCust instanceof ElPropertyChain);
ElPropertyDeploy elOrderDetails = descriptor.getElPropertyDeploy("orders.details");
Assert.assertTrue(elOrderDetails instanceof ElPropertyChain);
ElPropertyDeploy elOrderDetailsId = descriptor.getElPropertyDeploy("orders.details.id");
Assert.assertTrue(elOrderDetailsId instanceof ElPropertyChain);
}
}
@@ -0,0 +1,81 @@
package org.tests.el;
import io.ebean.Ebean;
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.Test;
import static org.junit.Assert.assertEquals;
public class TestPathExpression {
final BeanType<Customer> beanType;
final ExpressionPath billingId;
final ExpressionPath line1;
final ExpressionPath city;
public TestPathExpression() {
SpiServer server = Ebean.getDefaultServer().getPluginApi();
beanType = server.getBeanType(Customer.class);
billingId = beanType.getExpressionPath("billingAddress.id");
line1 = beanType.getExpressionPath("billingAddress.line1");
city = beanType.getExpressionPath("billingAddress.city");
}
@Test
public void pathSet() {
Customer c1 = new Customer();
line1.pathSet(c1, "12 someplace");
city.pathSet(c1, "Auckland");
billingId.pathSet(c1, 4);
beanType.getExpressionPath("id").pathSet(c1, 42L);
beanType.getExpressionPath("name").pathSet(c1, "jimmy");
beanType.getExpressionPath("status").pathSet(c1, "ACTIVE");
beanType.getExpressionPath("billingAddress.country.code").pathSet(c1, "NZ");
beanType.getExpressionPath("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(), Short.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((short) 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), Short.valueOf("12"));
assertEquals(beanType.getExpressionPath("billingAddress.country.code").pathGet(e0), "NZ");
assertEquals(beanType.getExpressionPath("billingAddress.country.name").pathGet(e0), "New Zealand");
}
}
@@ -0,0 +1,25 @@
package org.tests.el;
import io.ebean.Ebean;
import io.ebean.Query;
import org.tests.model.basic.Customer;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestUnderscoreParam {
@Test
public void test() {
Query<Customer> query = Ebean.find(Customer.class)
.where().raw("name like ?", "Rob%")
.query();
query.findList();
assertThat(query.getGeneratedSql()).contains("where t0.name like ?");
}
}