Package er.erxtest.model

Examples of er.erxtest.model.Company


    assertEquals(p1, company.employees().objectAtIndex(0));
  }

  public void testAutoSetToOneImplicitToMany() {
    EOEditingContext editingContext = ERXEC.newEditingContext();
    Company company = Company.createCompany(editingContext, "XYZ");
    Employee p1 = (Employee) EOUtilities.createAndInsertInstance(editingContext, Employee.ENTITY_NAME);
    p1.setCompany(company);

    assertEquals(company, p1.company());
    assertEquals(1, company.employees().count());
    assertEquals(p1, company.employees().objectAtIndex(0));
  }
View Full Code Here


    assertEquals(p1, company.employees().objectAtIndex(0));
  }

  public void testAutoAddToToManyImplicitToOne() {
    EOEditingContext editingContext = ERXEC.newEditingContext();
    Company company = Company.createCompany(editingContext, "XYZ");
    Employee p1 = (Employee) EOUtilities.createAndInsertInstance(editingContext, Employee.ENTITY_NAME);
    company.addToEmployees(p1);

    assertEquals(company, p1.company());
    assertEquals(1, company.employees().count());
    assertEquals(p1, company.employees().objectAtIndex(0));
  }
View Full Code Here

    assertEquals(p1, company.employees().objectAtIndex(0));
  }

  public void testAutoSetThenSetToOneToNullImplicitToMany() {
    EOEditingContext editingContext = ERXEC.newEditingContext();
    Company company = Company.createCompany(editingContext, "XYZ");
    Employee p1 = (Employee) EOUtilities.createAndInsertInstance(editingContext, Employee.ENTITY_NAME);
    p1.setCompany(company);
    p1.setCompany(null);
  
    assertEquals(null, p1.company());
    assertEquals(0, company.employees().count());
  }
View Full Code Here

    assertEquals(0, company.employees().count());
  }

  public void testAutoSetThenSetToOneToAnotherImplicitToMany() {
    EOEditingContext editingContext = ERXEC.newEditingContext();
    Company company = Company.createCompany(editingContext, "XYZ");
    Company company2 = Company.createCompany(editingContext, "XYZ");
    Employee p1 = (Employee) EOUtilities.createAndInsertInstance(editingContext, Employee.ENTITY_NAME);
    p1.setCompany(company);
    p1.setCompany(company2);

    assertEquals(company2, p1.company());
    assertEquals(0, company.employees().count());
    assertEquals(1, company2.employees().count());
    assertEquals(p1, company2.employees().objectAtIndex(0));
  }
View Full Code Here

  }

  @Test
  public void testCreateAndInsertObjectEOEditingContextClassOfT() {
    EOEditingContext ec = ERXEC.newEditingContext();
    Company co = ERXEOControlUtilities.createAndInsertObject(ec, Company.class);
    //Only testing for nullness since the above should throw a class cast ex if
    //co is not a company.
    Assert.assertNotNull(co);
    Assert.assertTrue(ec.insertedObjects().contains(co));
  }
View Full Code Here

   */
  public void testObjectCountForToManyRelationship_NewEO() {
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      Company c = (Company) EOUtilities.createAndInsertInstance(ec, Company.ENTITY_NAME);

      // No employees
      Integer count = ERXEOControlUtilities.objectCountForToManyRelationship(c, Company.EMPLOYEES_KEY);
      assertEquals(0, count.intValue());
     
      @SuppressWarnings("unused")
      Employee e1 = c.createEmployeesRelationship();
      @SuppressWarnings("unused")
      Employee e2 = c.createEmployeesRelationship();
      @SuppressWarnings("unused")
      Employee e3 = c.createEmployeesRelationship();
      // Expecting a new object for this call
      assertTrue(ERXEOControlUtilities.isNewObject(c));
      count = ERXEOControlUtilities.objectCountForToManyRelationship(c, Company.EMPLOYEES_KEY);
      assertEquals(3, count.intValue());
    } finally {
View Full Code Here

    EOGlobalID cGid = ERXTestUtilities.createCompanyAnd3Employees();
   
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      Company c = (Company) ec.faultForGlobalID(cGid, ec);
      // Add a new item to employees relationship
      @SuppressWarnings("unused")
      Employee e4 = c.createEmployeesRelationship();
      // I expect relationship to NOT be a fault
      Object relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
      assertFalse(EOFaultHandler.isFault(relationshipValue));
      Integer count = ERXEOControlUtilities.objectCountForToManyRelationship(c, Company.EMPLOYEES_KEY);
      assertEquals(4, count.intValue());
    } finally {
      ec.unlock();
    }
   
    cGid = ERXTestUtilities.createCompanyAndNoEmployees();
    ec.lock();
    try {
      Company c = (Company) ec.faultForGlobalID(cGid, ec);
      // Fire the fault
      Object relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
      assertTrue(EOFaultHandler.isFault(relationshipValue));
      EOFaulting fault = (EOFaulting) relationshipValue;
      // Fire the fault
      fault.faultHandler().completeInitializationOfObject(fault);
     
View Full Code Here

   
    EOEditingContext ec1 = ERXEC.newEditingContext(osc);
    EOEditingContext ec2 = ERXEC.newEditingContext(osc);
   
    // Fetch again into this ec to ensure snapshots are in the database
    Company c;
    // Expect relationship to be a fault
    Object relationshipValue;
    ec1.lock();
    try {
      // Fetch Company with cGid
      c = (Company) ec1.faultForGlobalID(cGid, ec1);
      // c will be a fault
      assertTrue(EOFaultHandler.isFault(c));
     
      relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
     
      // c will no longer be a fault
      assertFalse(EOFaultHandler.isFault(c));
     
      // relationshipValue will be a fault
      assertTrue(EOFaultHandler.isFault(relationshipValue));
      // Fire the fault to fetch and to ensure snapshot is registered in eodb
      ERXTestUtilities.fireFault(relationshipValue);

      // -----------------------------------------
      // Fetch Company with cGid0
      c = (Company) ec1.faultForGlobalID(cGid0, ec1);
      relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
      assertTrue(EOFaultHandler.isFault(relationshipValue));
      // Fire the fault to fetch and to ensure snapshot is registered in eodb
      ERXTestUtilities.fireFault(relationshipValue);

    } finally {
      ec1.unlock();
    }
   
   
    // Fetch
    ec2.lock();
    try {
      // Fetch Company with cGid
      c = (Company) ec2.faultForGlobalID(cGid, ec2);
      // Expect relationship to be a fault
      relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
      assertTrue(EOFaultHandler.isFault(relationshipValue));
     
      // There will be a snapshot in the db
      NSArray toManySnapshot = ERXTestUtilities.snapshotArrayForRelationshipInObject(c, Company.EMPLOYEES_KEY);
      assertNotNull(toManySnapshot);
     
      // Count will come from snapshot cache
      Integer count = ERXEOControlUtilities.objectCountForToManyRelationship(c, Company.EMPLOYEES_KEY);
      assertEquals(3, count.intValue());
     
      // -----------------------------------------
      // Fetch Company with cGid0
      c = (Company) ec2.faultForGlobalID(cGid0, ec2);
      // Expect relationship to be a fault
      relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
      assertTrue(EOFaultHandler.isFault(relationshipValue));

      // There will be a snapshot in the db
      toManySnapshot = ERXTestUtilities.snapshotArrayForRelationshipInObject(c, Company.EMPLOYEES_KEY);
      assertNotNull(toManySnapshot);
View Full Code Here

    // Virgin OSC with no snapshots
    EOObjectStoreCoordinator osc = new EOObjectStoreCoordinator();
    EOEditingContext ec1 = ERXEC.newEditingContext(osc);
    ec1.lock();
    try {
      Company c = (Company) ec1.faultForGlobalID(cGid, ec1);
      // We expect relationship to be a fault
      Object relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
      assertTrue(EOFaultHandler.isFault(relationshipValue));
     
      // There will be no snapshot in the db
      NSArray toManySnapshot = ERXTestUtilities.snapshotArrayForRelationshipInObject(c, Company.EMPLOYEES_KEY);
      assertNull(toManySnapshot);
View Full Code Here

        assertEquals(
            "The attribute named 'company' in the entity named 'Employee' is not a toMany relationship! Expected an NSArray, but got null.",
            exception.getMessage());
      }

      Company c = (Company) EOUtilities.createAndInsertInstance(ec, Company.ENTITY_NAME);
      e.setCompanyRelationship(c);

      try {
        // Company is not null
        count = ERXEOControlUtilities.objectCountForToManyRelationship(e, Employee.COMPANY_KEY);
      } catch (IllegalArgumentException exception) {
        assertEquals(
            "The attribute named 'company' in the entity named 'Employee' is not a toMany relationship! Expected an NSArray, but got a er.erxtest.model.Company",
            exception.getMessage());
      }

      // ----------------------------------------------------------
      // Test using a key that is not a toMany on an existing object

      c = (Company) ec.faultForGlobalID(cGid, ec);

      try {
        // address1 attribute is null
        count = ERXEOControlUtilities.objectCountForToManyRelationship(c, Company.ADDRESS1_KEY);
      } catch (IllegalArgumentException exception) {
        assertEquals(
            "The attribute named 'address1' in the entity named 'Company' is not a toMany relationship! Expected an NSArray, but got null.",
            exception.getMessage());
      }

      e = c.employees().objectAtIndex(0);

      EOGlobalID eGid = ec.globalIDForObject(e);
      try {
        // Company is not null
        count = ERXEOControlUtilities.objectCountForToManyRelationship(e, Employee.COMPANY_KEY);
View Full Code Here

TOP

Related Classes of er.erxtest.model.Company

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.