Package com.avaje.tests.model.basic

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


      }
    }

    contactCache.getStatistics(true);

    Contact c0 = Ebean.find(Contact.class).where().eq("email", emailToSearch).findUnique();

    ServerCacheStatistics stats0 = contactCache.getStatistics(false);

    Contact c1 = Ebean.find(Contact.class).where().eq("email", emailToSearch).findUnique();

    ServerCacheStatistics stats1 = contactCache.getStatistics(false);

    Assert.assertNotNull(c0);
    Assert.assertNotNull(c1);

    Assert.assertEquals(1, stats0.getHitCount());
    Assert.assertEquals(2, stats1.getHitCount());

    c1.setEmail("mychangedemail@what.com");
    Ebean.save(c1);

    Contact c2 = Ebean.find(Contact.class).where().eq("email", "mychangedemail@what.com")
        .findUnique();

    ServerCacheStatistics stats2 = contactCache.getStatistics(false);

    Assert.assertNotNull(c2);
    Assert.assertEquals(c2.getId(), c1.getId());
    Assert.assertEquals(c0.getId(), c1.getId());
    Assert.assertTrue(stats2.getHitCount() > stats1.getHitCount());

  }
View Full Code Here


    int currentNumContacts = fetchCustomer(customer.getId());
    // Assert.assertEquals(3,
    // custManyIdsCache.getStatistics(false).getHitCount());

    Contact newContact = ResetBasicData.createContact("Check", "CollIds");
    newContact.setCustomer(customer);

    Ebean.save(newContact);

    int currentNumContacts2 = fetchCustomer(customer.getId());
    Assert.assertEquals(currentNumContacts + 1, currentNumContacts2);
View Full Code Here

    ResetBasicData.reset();

    Customer c = new Customer();
    c.setName("lazytest");

    Contact con = new Contact("jim", "slim");
    c.addContact(con);

    Ebean.save(c);

    List<Customer> list = Ebean.find(Customer.class).fetch("contacts", new FetchConfig().query(0))
View Full Code Here

   */
  @Test
  public void testStatelessUpdateIgnoreNullCollection() {

    // arrange
    Contact contact = new Contact();
    contact.setFirstName("wobu :P");

    Customer customer = new Customer();
    customer.setName("something");
    customer.setContacts(new ArrayList<Contact>());
    customer.getContacts().add(contact);
View Full Code Here

   */
  @Test
  public void testStatelessUpdateIgnoreEmptyBeanCollection() {

    // arrange
    Contact contact = new Contact();
    contact.setFirstName("wobu :P");

    Customer customer = new Customer();
    customer.setName("something");
    customer.setContacts(new ArrayList<Contact>());
    customer.getContacts().add(contact);
View Full Code Here

 
  @Test
  public void testStatelessUpdateDeleteChildrenForNonBeanCollection() {

    // arrange
    Contact contact = new Contact();
    contact.setFirstName("wobu :P");

    Customer customer = new Customer();
    customer.setName("something");
    customer.setContacts(new ArrayList<Contact>());
    customer.getContacts().add(contact);
View Full Code Here

   * although an ID has been set.
   */
  @Test
  public void testStatelessRecursiveUpdateWithVersionField() {
    // arrange
    Contact contact1 = new Contact();
    contact1.setLastName("contact1");

    Contact contact2 = new Contact();
    contact2.setLastName("contact2");

    Customer customer = new Customer();
    customer.setName("something");
    customer.getContacts().add(contact1);
    customer.getContacts().add(contact2);

    server.save(customer);

    // act
    Contact updateContact1 = new Contact();
    updateContact1.setId(contact1.getId());

    Contact updateContact2 = new Contact();
    updateContact2.setId(contact2.getId());
   
    Customer updateCustomer = new Customer();
    updateCustomer.setId(customer.getId());
    updateCustomer.getContacts().add(updateContact1);
    updateCustomer.getContacts().add(updateContact2);
View Full Code Here

  }
 
  @Test
  public void testStatelessRecursiveUpdateWithChangesInDetailOnly() {
    // arrange
    Contact contact1 = new Contact();
    contact1.setLastName("contact1");

    Contact contact2 = new Contact();
    contact2.setLastName("contact2");

    Customer customer = new Customer();
    customer.setName("something");
    customer.getContacts().add(contact1);
    customer.getContacts().add(contact2);

    server.save(customer);
   


    // act
    Contact updateContact1 = new Contact();
    updateContact1.setId(contact1.getId());
    updateContact1.setLastName("contact1-changed");

   
    Contact updateContact3 = new Contact();
    //updateContact3.setId(contact3.getId());
    updateContact3.setLastName("contact3-added");
   
    Customer updateCustomer = new Customer();
    updateCustomer.setId(customer.getId());
    updateCustomer.getContacts().add(updateContact1);
    updateCustomer.getContacts().add(updateContact3);

    // not adding contact2 so it will get deleted
    //updateCustomer.getContacts().add(updateContact2);
   
    server.update(updateCustomer);

   
    // assert
    Customer assCustomer = server.find(Customer.class, customer.getId());
    List<Contact> assContacts = assCustomer.getContacts();
    Assert.assertEquals(2, assContacts.size());
    Set<Integer> ids = new LinkedHashSet<Integer>();
    Set<String> names = new LinkedHashSet<String>();
    for (Contact contact : assContacts) {
      ids.add(contact.getId());
      names.add(contact.getLastName());
    }
    Assert.assertTrue(ids.contains(contact1.getId()));
    Assert.assertTrue(ids.contains(updateContact3.getId()));
    Assert.assertFalse(ids.contains(contact2.getId()));
   
    Assert.assertTrue(names.contains(updateContact1.getLastName()));
    Assert.assertTrue(names.contains(updateContact3.getLastName()));
  }
View Full Code Here

 
 
  @Test
  public void testStatelessRecursiveUpdateWithChangesInDetailOnlyAnd() {
    // arrange
    Contact contact1 = new Contact();
    contact1.setLastName("contact1");

    Contact contact2 = new Contact();
    contact2.setLastName("contact2");

    Customer customer = new Customer();
    customer.setName("something");
    customer.getContacts().add(contact1);
    customer.getContacts().add(contact2);

    server.save(customer);
   

    // act
    Contact updateContact1 = new Contact();
    updateContact1.setId(contact1.getId());
    updateContact1.setLastName("contact1-changed");

   
    Contact updateContact3 = new Contact();
    updateContact3.setLastName("contact3-added");
   
    Customer updateCustomer = new Customer();
    updateCustomer.setId(customer.getId());
    updateCustomer.getContacts().add(updateContact1);
    updateCustomer.getContacts().add(updateContact3);

    // not adding contact2 but it won't be deleted in this case
    boolean deleteMissingChildren = false;
    server.update(updateCustomer, null, deleteMissingChildren);

   
    // assert
    Customer assCustomer = server.find(Customer.class, customer.getId());
    List<Contact> assContacts = assCustomer.getContacts();
   
    // contact 2 was not deleted this time
    Assert.assertEquals(3, assContacts.size());
   
    Set<Integer> ids = new LinkedHashSet<Integer>();
    Set<String> names = new LinkedHashSet<String>();
    for (Contact contact : assContacts) {
      ids.add(contact.getId());
      names.add(contact.getLastName());
    }
    Assert.assertTrue(ids.contains(contact1.getId()));
    Assert.assertTrue(ids.contains(updateContact3.getId()));
    Assert.assertTrue(ids.contains(contact2.getId()));
   
    Assert.assertTrue(names.contains(updateContact1.getLastName()));
    Assert.assertTrue(names.contains(contact2.getLastName()));
    Assert.assertTrue(names.contains(updateContact3.getLastName()));
  }
View Full Code Here

TOP

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

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.