Package er.erxtest.model

Examples of er.erxtest.model.Company


  public void testAddToUnfaultedToMany() {
    // Create Company1 in OSC1
    String companyName = "Company" + ERXRandomGUID.newGid();
    EOEditingContext editingContext_osc1 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc1 = Company.createCompany(editingContext_osc1, companyName);
    editingContext_osc1.saveChanges();

    // Fetch Company1 in OSC2
    EOEditingContext editingContext_osc2 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc2 = Company.fetchCompany(editingContext_osc2, Company.NAME_KEY, companyName);
    assertNotNull(company_osc2);

    // Create and Save Employee1 in Company1 in OSC1
    String employeeFirstName = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName = "Jones";
    Employee employee_osc1 = Employee.createEmployee(editingContext_osc1, employeeFirstName, employeeLastName, Boolean.FALSE, company_osc1);
    editingContext_osc1.saveChanges();

    // Fetch employees relationship of Company1 in OSC1
    assertContainsExactlyEOs(new NSArray<Employee>(employee_osc1), company_osc1.employees());

    // Fetch employees relationship of Company1 in OSC2
    assertContainsExactlyEOs(new NSArray<Employee>(employee_osc1), company_osc2.employees());
  }
View Full Code Here


  public void testAddToFaultedToMany() {
    // Create Company1 in OSC1
    String companyName = "Company" + ERXRandomGUID.newGid();
    EOEditingContext editingContext_osc1 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc1 = Company.createCompany(editingContext_osc1, companyName);
    editingContext_osc1.saveChanges();
    sleep();

    // Fetch employees for Company1 in OSC1
    @SuppressWarnings("unused")
  NSArray employees_osc1 = company_osc1.employees();

    // Fetch Company1 in OSC2
    EOEditingContext editingContext_osc2 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc2 = Company.fetchCompany(editingContext_osc2, Company.NAME_KEY, companyName);
    assertNotNull(company_osc2);

    // Fetch employees for Company1 in OSC2
    @SuppressWarnings("unused")
  NSArray employees_osc2 = company_osc2.employees();

    // Create and Save Employee1 for Company1 in OSC1
    String employeeFirstName = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName = "Jones";
    Employee employee_osc1 = Employee.createEmployee(editingContext_osc1, employeeFirstName, employeeLastName, Boolean.FALSE, company_osc1);
    editingContext_osc1.saveChanges();
    sleep();

    // Check employees for Company1 in OSC1
    assertContainsExactlyEOs(new NSArray<Employee>(employee_osc1), company_osc1.employees());

    // Check employees for Company1 in OSC2
    assertContainsExactlyEOs(new NSArray<Employee>(employee_osc1), company_osc2.employees());

    // Create employee for Company1 in OSC2 and Save
    String employeeFirstName2 = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName2 = "Jones";
    Employee employee_osc2 = Employee.createEmployee(editingContext_osc2, employeeFirstName2, employeeLastName2, Boolean.FALSE, company_osc2);
    editingContext_osc2.saveChanges();
    sleep();

    // Check employees for Company1 in OSC1
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee_osc1, employee_osc2 }), company_osc1.employees());

    // Check employees for Company1 in OSC2
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee_osc1, employee_osc2 }), company_osc2.employees());
  }
View Full Code Here

  public void testAddToFaultedToManyWithUncommittedToManyEntries() {
    // Create Company1 in OSC1
    String companyName = "Company" + ERXRandomGUID.newGid();
    EOEditingContext editingContext_osc1 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc1 = Company.createCompany(editingContext_osc1, companyName);
    editingContext_osc1.saveChanges();
    sleep();

    // Fetch Company1 in OSC2
    EOEditingContext editingContext_osc2 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc2 = Company.fetchCompany(editingContext_osc2, Company.NAME_KEY, companyName);
    assertNotNull(company_osc2);

    // Create (but do not save) Employee1 for Company1 in OSC2
    String employeeFirstName1 = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName1 = "Jones";
    Employee employee1_osc2 = Employee.createEmployee(editingContext_osc2, employeeFirstName1, employeeLastName1, Boolean.FALSE, company_osc2);

    // Check employees for Company1 in OSC1 (should contain uncommitted Employee)
    NSArray employees_osc2_BeforeInsert = company_osc2.employees();
    assertEquals(1, employees_osc2_BeforeInsert.count());
    assertEOEquals(employee1_osc2, employees_osc2_BeforeInsert.objectAtIndex(0));

    // Create and save Employee2 for Company1 in OSC1
    String employeeFirstName2 = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName2 = "Jones";
    Employee employee2_osc1 = Employee.createEmployee(editingContext_osc1, employeeFirstName2, employeeLastName2, Boolean.FALSE, company_osc1);
    editingContext_osc1.saveChanges();
    sleep();

    // Check employees for Company1 in OSC2 (should contain both Employees)
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee1_osc2, employee2_osc1 }), company_osc2.employees());

    // Check employees for Company1 in OSC1 (should contain only Employee2)
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee2_osc1 }), company_osc1.employees());

    // Save Employee1 in OSC2
    editingContext_osc2.saveChanges();
    sleep();

    // Check employees for Company1 in OSC2 (should contain both Employees)
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee1_osc2, employee2_osc1 }), company_osc2.employees());

    // Check employees for Company1 in OSC1 (should contain both Employees)
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee1_osc2, employee2_osc1 }), company_osc1.employees());
  }
View Full Code Here

  public void testRemoveFromFaultedToMany() {
    // Create Company1 in OSC1
    String companyName = "Company" + ERXRandomGUID.newGid();
    EOEditingContext editingContext_osc1 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc1 = Company.createCompany(editingContext_osc1, companyName);
    editingContext_osc1.saveChanges();
    sleep();

    // Create and Save Employee1 and Employee2 for Company1 in OSC1
    String employeeFirstName1 = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName1 = "Jones";
    Employee employee1_osc1 = Employee.createEmployee(editingContext_osc1, employeeFirstName1, employeeLastName1, Boolean.FALSE, company_osc1);
    String employeeFirstName2 = "Employee" + ERXRandomGUID.newGid();
    String employeeLastName2 = "Jones";
    Employee employee2_osc1 = Employee.createEmployee(editingContext_osc1, employeeFirstName2, employeeLastName2, Boolean.FALSE, company_osc1);
    editingContext_osc1.saveChanges();
    sleep();

    // Fetch employees for Company1 in OSC1
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee1_osc1, employee2_osc1 }), company_osc1.employees());

    // Fetch Company1 in OSC2
    EOEditingContext editingContext_osc2 = ERXEC.newEditingContext(ERXObjectStoreCoordinatorPool._pool().nextObjectStore());
    Company company_osc2 = Company.fetchCompany(editingContext_osc2, Company.NAME_KEY, companyName);
    assertNotNull(company_osc2);
    // Fetch and check employees for Company1 in OSC2
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee1_osc1, employee2_osc1 }), company_osc2.employees());

    // gonna break
    NSArray employees_osc2 = company_osc2.employees();
    Employee employee2_osc2 = (Employee) employees_osc2.objectAtIndex(0);
    Employee employee1_osc2 = (Employee) employees_osc2.objectAtIndex(1);

    Employee secondEmployee_osc2;
    if (ERXEOControlUtilities.eoEquals(employee1_osc1, employee1_osc2)) {
      secondEmployee_osc2 = employee2_osc2;
    }
    else {
      secondEmployee_osc2 = employee1_osc2;
    }

    NSArray<Employee> holdingOnToEmployees = company_osc2.employees();
    assertEquals(2, holdingOnToEmployees.count());
    for (Employee employee : holdingOnToEmployees) {
      assertNotNull(employee);
      assertNotNull(employee.firstName());
    }

    NSArray<Employee> holdingOnToUntouchedEmployees = company_osc2.employees();
    assertEquals(2, holdingOnToUntouchedEmployees.count());
   
    // Delete Employee1 in OSC1 and Save
    editingContext_osc1.deleteObject(employee1_osc1);
    editingContext_osc1.saveChanges();
    sleep();

    // Test that the deleted object is technically still in our EC
    assertEquals(2, holdingOnToEmployees.count());
    for (Employee employee : holdingOnToEmployees) {
      assertNotNull(employee);
      assertNotNull(employee.firstName());
    }

    // Test that the deleted object is technically still in our EC
    assertEquals(2, holdingOnToUntouchedEmployees.count());
    for (Employee employee : holdingOnToUntouchedEmployees) {
      assertNotNull(employee);
      assertNotNull(employee.firstName());
    }

//    for (Employee employee : holdingOnToEmployees) {
//      employee.setName(employee.name() + " Modified");
//    }
//    try {
//      editingContext_osc2.saveChanges();
//      throw new AssertionFailedError("This should have failed.");
//    }
//    catch (EOGeneralAdaptorException e) {
//      // expected
//    }

    // Fetch and check employees for Company1 in OSC1
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee2_osc1 }), company_osc1.employees());

    // Fetch and check employees for Company1 in OSC2
    assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee2_osc1 }), company_osc2.employees());

    // ... Do someting with the deleted object in OSC2

    // Delete the remaining employee in OSC2 and Save
    editingContext_osc2.deleteObject(secondEmployee_osc2);
    editingContext_osc2.saveChanges();
    sleep();

    // Fetch and check employees for Company1 in OSC1
    assertContainsExactlyEOs(NSArray.EmptyArray, company_osc1.employees());

    // Fetch and check employees for Company1 in OSC2
    assertContainsExactlyEOs(NSArray.EmptyArray, company_osc2.employees());
  }
View Full Code Here

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

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

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

      Map map1 = null, map2 = null, map3 = null;

      EOEditingContext ec = null;

      Company c1 = null;

      //System.out.println("\n"+this+": "+System.currentTimeMillis()+": "+test+" start");

      try {
        sleep(pause);
View Full Code Here

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

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

    assertEquals(company, p1.company());
    assertEquals(company, p2.company());
    assertEquals(2, company.employees().count());
    assertTrue(company.employees().containsObject(p1));
    assertTrue(company.employees().containsObject(p2));
  }
View Full Code Here

    assertTrue(company.employees().containsObject(p2));
  }

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

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

  }
 
  public void testRevertToMany(boolean updateInverseRelationships) {
    ERXGenericRecord.InverseRelationshipUpdater.setUpdateInverseRelationships(updateInverseRelationships);
    EOEditingContext editingContext = ERXEC.newEditingContext();
    Company company = Company.createCompany(editingContext, "XYZ");
    editingContext.saveChanges();
   
    Employee p1 = (Employee) EOUtilities.createAndInsertInstance(editingContext, Employee.ENTITY_NAME);
    p1.setCompanyRelationship(company);

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

    testDelete(false);
  }

  public void testFetchWithFetchInitialValues() {
    ERXEnterpriseObjectCache<Company> cache = new ERXEnterpriseObjectCache<Company>(Company.ENTITY_NAME, Company.NAME_KEY, null, 0);
    Company c1Test = cache.objectForKey(editingContext, c1.name());
    assertSame(c1, c1Test);
    cache.stop();
  }
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.