Package com.avaje.tests.model.basic

Examples of com.avaje.tests.model.basic.Customer


public class TestBasicNavOnEmpty extends BaseTestCase {

  @Test
  public void test() {
   
    Customer c = new Customer();
    c.setName("HelloRob");
   
    Ebean.save(c);
   
    c = Ebean.find(Customer.class, c.getId());
   
    List<Contact> contacts = c.getContacts();
    Assert.assertEquals(0,contacts.size());
  }
View Full Code Here


public class TestSecondQueryNoRows extends BaseTestCase {

  @Test
  public void test() {

    Customer cnew = new Customer();
    cnew.setName("testSecQueryNoRows");

    Ebean.save(cnew);

    Customer c = Ebean.find(Customer.class).setAutofetch(false).setId(cnew.getId())
        .fetch("contacts", new FetchConfig().query()).findUnique();

    Assert.assertNotNull(c);
  }
View Full Code Here

    ResetBasicData.reset();

    List<Customer> custs = Ebean.find(Customer.class).findList();

    Customer customer = Ebean.find(Customer.class).setId(custs.get(0).getId()).select("name")
        .setUseCache(false)
        .findUnique();

    BeanState beanState = Ebean.getBeanState(customer);
    Assert.assertTrue(!beanState.isNew());
    Assert.assertTrue(!beanState.isDirty());
    Assert.assertTrue(!beanState.isNewOrDirty());
    Assert.assertNotNull(beanState.getLoadedProps());

    customer.setName("dirtyNameProp");
    Assert.assertTrue(beanState.isDirty());
    Assert.assertTrue(beanState.getChangedProps().contains("name"));
    Assert.assertEquals(1, beanState.getChangedProps().size());

    customer.setStatus(Customer.Status.INACTIVE);

    Assert.assertTrue(beanState.isDirty());
    Assert.assertTrue(beanState.getChangedProps().contains("status"));
    Assert.assertTrue(beanState.getChangedProps().contains("name"));
    Assert.assertEquals(2, beanState.getChangedProps().size());
View Full Code Here

        .fetch("customer", "+lazy(10) name, status").fetch("customer.contacts");

    List<Order> list = query.findList();

    Order order = list.get(0);
    Customer customer = order.getCustomer();

    // this invokes lazy loading on a property that is
    // not one of the selected ones (name, status) ... and
    // therefore the lazy load query selects all properties
    // in the customer (not just name and status)
    Address billingAddress = customer.getBillingAddress();

    Assert.assertNotNull(billingAddress);
  }
View Full Code Here

    ResetBasicData.reset();

    List<Customer> custList = Ebean.find(Customer.class).select("id").findList();

    Customer c = custList.get(0);

    List<Contact> contacts2 = c.getContacts();
    Assert.assertEquals(3, Ebean.getBeanState(c).getLoadedProps().size());

    // now lazy load the contacts
    contacts2.size();

    Customer c2 = Ebean.getReference(Customer.class, c.getId());

    // we only "loaded" the contacts BeanList and not all of c2
    List<Contact> contacts = c2.getContacts();
    // Set<String> loadedProps = Ebean.getBeanState(c2).getLoadedProps();
    // assertEquals(1, loadedProps.size());

    // now lazy load the contacts
    contacts.size();
View Full Code Here

      .order().asc("orderDate")
      .setMaxRows(40)
      .findList();
   
    for (Order order : orders) {
      Customer customer = order.getCustomer();
      Address billingAddress = customer.getBillingAddress();
      if (billingAddress != null) {
        billingAddress.getCity();
      }
      Address shippingAddress = customer.getShippingAddress();
      if (shippingAddress != null) {
        shippingAddress.getCity();
      }
      List<OrderDetail> details = order.getDetails();
      for (OrderDetail orderDetail : details) {
View Full Code Here

public class TestInsertCollection extends BaseTestCase {

  @Test
  public void test() {
   
    Customer cust1 = new Customer();
    cust1.setName("jim");
   
    Customer cust2 = new Customer();
    cust2.setName("bob");
   
    List<Customer> customers = new ArrayList<Customer>();
    customers.add(cust1);
    customers.add(cust2);
   
    Ebean.insert(customers);
   
    Assert.assertNotNull(cust1.getId());
    Assert.assertNotNull(cust2.getId());
   
    Customer cust1Check = Ebean.find(Customer.class, cust1.getId());
    Assert.assertEquals(cust1.getName(), cust1Check.getName());
    Customer cust2Check = Ebean.find(Customer.class, cust2.getId());
    Assert.assertEquals(cust2.getName(), cust2Check.getName());
 
    cust1.setName("jim-changed");
    cust2.setName("bob-changed");
   
    Ebean.update(customers);

    Customer cust1Check2 = Ebean.find(Customer.class, cust1.getId());
    Assert.assertEquals("jim-changed", cust1Check2.getName());
    Customer cust2Check2 = Ebean.find(Customer.class, cust2.getId());
    Assert.assertEquals("bob-changed", cust2Check2.getName());


    cust1Check2.setName("jim-updated");
    Customer cust3 = new Customer();
    cust3.setName("mac");

    List<Customer> saveList = new ArrayList<Customer>();
    saveList.add(cust1Check2);
    saveList.add(cust3);
   
    Ebean.save(saveList);
   

    Customer cust1Check3 = Ebean.find(Customer.class, cust1.getId());
    Assert.assertEquals("jim-updated", cust1Check3.getName());
    Customer cust3Check = Ebean.find(Customer.class, cust3.getId());
    Assert.assertEquals("mac", cust3Check.getName());

  }
View Full Code Here

    int count = 0;

    QueryIterator<Customer> it = query.findIterate();
    try {
      while (it.hasNext()) {
        Customer customer = it.next();
        customer.hashCode();
        count++;
      }
    } finally {
      it.close();
    }
View Full Code Here

        .setMaxRows(2);

    QueryIterator<Customer> it = query.findIterate();
    try {
      while (it.hasNext()) {
        Customer customer = it.next();
        if (customer != null) {
          throw new IllegalStateException("cause an exception");
        }
      }
     
View Full Code Here

   * see: {@link com.avaje.tests.update.TestUpdatePartial#testWithoutChangesAndVersionColumn()}
   */
  @Test
  public void testWithoutChangesAndVersionColumnAndIgnoreNullValues() {
    // arrange
    Customer customer = new Customer();
    customer.setName("something");

    server.save(customer);

    // act
    Customer customerWithoutChanges = new Customer();
    customerWithoutChanges.setId(customer.getId());
    server.update(customerWithoutChanges);

    Customer result = Ebean.find(Customer.class, customer.getId());

    // assert
    Assert.assertEquals(customer.getUpdtime().getTime(), result.getUpdtime().getTime());
  }
View Full Code Here

TOP

Related Classes of com.avaje.tests.model.basic.Customer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.