Exemple #1
0
  @Test
  public void deepTest() {
    customer1 = customerFactoryInstance.createCustomerType();
    customer2 = customerFactoryInstance.createCustomerType();
    address1 = customerFactoryInstance.createUSAddr();
    address2 = customerFactoryInstance.createUSAddr();

    // differ on a String value
    assertTrue(EcoreUtil.equals(customer1, customer2));
    address1.setTown("New Orleans");
    address2.setTown("Chicago");
    customer1.setAddress(address1);
    customer2.setAddress(address2);
    assertTrue(!EcoreUtil.equals(customer1, customer2));
    address1.setTown(address2.getTown());
    assertTrue(EcoreUtil.equals(customer1, customer2));

    // differ on a Date value
    address1.setTown(address2.getTown());
    assertTrue(EcoreUtil.equals(customer1, customer2));
    long now = System.currentTimeMillis();
    XMLCalendar date1 = new XMLCalendar(new Date(now), XMLCalendar.DATETIME);
    XMLCalendar date2 = new XMLCalendar(new Date(now + 3600000), XMLCalendar.DATETIME);
    credit1.setExpireDate(date1);
    credit2.setExpireDate(date2);
    customer1.setCreditCard(credit1);
    customer2.setCreditCard(credit2);
    assertTrue(!EcoreUtil.equals(customer1, customer2));
    credit1.setExpireDate(credit2.getExpireDate());
    assertTrue(EcoreUtil.equals(customer2, customer1));

    // credit1 and credit2 don't have the same container but are areEqual anyway.
    address1.setTown("Montreal");
    assertTrue(EcoreUtil.equals(credit1, credit2));
  }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public CustomerType getCheckedOutBy() {
   if (checkedOutBy != null && checkedOutBy.eIsProxy()) {
     InternalEObject oldCheckedOutBy = (InternalEObject) checkedOutBy;
     checkedOutBy = (CustomerType) eResolveProxy(oldCheckedOutBy);
     if (checkedOutBy != oldCheckedOutBy) {
       if (eNotificationRequired())
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 DBPackage.MOVIE_TYPE__CHECKED_OUT_BY,
                 oldCheckedOutBy,
                 checkedOutBy));
     }
   }
   return checkedOutBy;
 }
Exemple #3
0
  @Test
  public void shallowTest() {
    // basic == and null comparisons
    assertTrue(EcoreUtil.equals(po1, po1));
    assertTrue(EcoreUtil.equals((EObject) null, (EObject) null));
    assertTrue(!EcoreUtil.equals(null, po1));
    assertTrue(!EcoreUtil.equals(po1, null));

    // the eClass is different.
    assertTrue(!EcoreUtil.equals(po1, supplier1));

    assertTrue(EcoreUtil.equals(po1, po2));
    // make sure copy and areEquals are consistent
    EObject po1Copy = EcoreUtil.copy(po1);
    assertTrue(EcoreUtil.equals(po1, po1Copy));

    // customer1's ID is unset
    customer2.setID("987654321");
    assertTrue(!EcoreUtil.equals(customer1, customer2));

    supplier1.setName("BlueLabel");
    // supplier2's name is unset
    assertTrue(!EcoreUtil.equals(supplier1, supplier2));

    supplier1.eUnset(supplier1.eClass().getEStructuralFeature("name"));
    assertTrue(EcoreUtil.equals(supplier1, supplier2));

    // test attribute
    address1.setTown("New Orleans");
    assertTrue(!EcoreUtil.equals(address1, address2));
    address2.setTown("Chicago");
    assertTrue(!EcoreUtil.equals(address1, address2));
    address2.setTown(null);
    assertTrue(!EcoreUtil.equals(address1, address2));
    assertTrue(!EcoreUtil.equals(address2, address1));
    address1.setTown(null);
    assertTrue(EcoreUtil.equals(address1, address2));

    // make sure copy and areEqual are consistent
    address1.setStreet("Satchmo road");
    address1.setTown("LA");
    EObject address1Copy = EcoreUtil.copy(address1);
    assertTrue(EcoreUtil.equals(address1Copy, address1));

    // test multiplicity-many attributes
    EObject employee1 = createEmployee("Mr. J. C.");
    EObject employee2 = EcoreUtil.copy(employee1);
    assertTrue(EcoreUtil.equals(employee1, employee2));
    @SuppressWarnings("unchecked")
    List<Integer> ratings1 = (List<Integer>) employee1.eGet(ratingsAttr);
    @SuppressWarnings("unchecked")
    List<Integer> ratings2 = (List<Integer>) employee2.eGet(ratingsAttr);
    ratings1.add(456);
    ratings1.add(123);
    ratings2.add(123);
    ratings2.add(456);
    assertTrue(!EcoreUtil.equals(employee1, employee2));
    ratings1.clear();
    ratings2.clear();
    ratings1.add(123);
    ratings1.add(456);
    ratings2.add(123);
    ratings2.add(456);
    assertTrue(EcoreUtil.equals(employee1, employee2));
  }