Search in sources :

Example 1 with Department

use of org.apache.cayenne.testdo.inheritance_people.Department in project cayenne by apache.

the class DeepMergeOperationInheritanceIT method testDeepMergeExistingSubclass.

@Test
public void testDeepMergeExistingSubclass() {
    final Department d1 = context.newObject(Department.class);
    d1.setName("D1");
    // need to do double commit as Ashwood sorter blows on Employees/Departments ordering...
    context.commitChanges();
    Employee e1 = context.newObject(Employee.class);
    e1.setName("E1");
    e1.setPersonType("EE");
    d1.addToEmployees(e1);
    Manager e2 = context.newObject(Manager.class);
    e2.setName("E2");
    e2.setPersonType("EM");
    d1.addToEmployees(e2);
    context.commitChanges();
    // need to make sure source relationship is resolved as a result of some Ashwood strangeness...
    d1.getEmployees().size();
    // resolve Employees
    context1.performQuery(new SelectQuery<>(Employee.class));
    final DeepMergeOperation op = new DeepMergeOperation(context1);
    assertMergeResult(d1, op);
}
Also used : Department(org.apache.cayenne.testdo.inheritance_people.Department) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Test(org.junit.Test)

Example 2 with Department

use of org.apache.cayenne.testdo.inheritance_people.Department in project cayenne by apache.

the class DataContextEJBQLConditionsPeopleIT method setUp.

@Before
public void setUp() {
    // TODO: use TableHelper to create test data
    Department d1 = context.newObject(Department.class);
    d1.setName("d1");
    Department d2 = context.newObject(Department.class);
    d2.setName("d2");
    Department d3 = context.newObject(Department.class);
    d3.setName("d3");
    context.commitChanges();
    Manager m1 = context.newObject(Manager.class);
    m1.setName("m1");
    m1.setPersonType("EM");
    Manager m2 = context.newObject(Manager.class);
    m2.setName("m2");
    m2.setPersonType("EM");
    Manager m3 = context.newObject(Manager.class);
    m3.setName("m3");
    m3.setPersonType("EM");
    Address a1 = context.newObject(Address.class);
    m1.addToAddresses(a1);
    Address a2 = context.newObject(Address.class);
    m2.addToAddresses(a2);
    Address a3 = context.newObject(Address.class);
    m3.addToAddresses(a3);
    d1.addToEmployees(m1);
    d1.addToEmployees(m2);
    d3.addToEmployees(m3);
    context.commitChanges();
    d1.setToManager(m1);
    d2.setToManager(m2);
    d3.setToManager(m3);
    context.commitChanges();
}
Also used : Department(org.apache.cayenne.testdo.inheritance_people.Department) Address(org.apache.cayenne.testdo.inheritance_people.Address) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Before(org.junit.Before)

Example 3 with Department

use of org.apache.cayenne.testdo.inheritance_people.Department in project cayenne by apache.

the class SingleTableInheritanceIT method testDepartmentEmployees.

/**
 * Tests that to-many relationship produces correct subclasses.
 */
@Test
public void testDepartmentEmployees() throws Exception {
    createDepartmentEmployeesDataSet();
    List<?> departments = context.performQuery(new SelectQuery(Department.class));
    assertEquals(1, departments.size());
    Department dept = (Department) departments.get(0);
    List<?> employees = dept.getEmployees();
    assertEquals(3, employees.size());
    assertEquals(3, countObjectOfClass(employees, Employee.class));
    assertEquals(1, countObjectOfClass(employees, Manager.class));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Department(org.apache.cayenne.testdo.inheritance_people.Department) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Test(org.junit.Test)

Example 4 with Department

use of org.apache.cayenne.testdo.inheritance_people.Department in project cayenne by apache.

the class DeepMergeOperationInheritanceIT method assertMergeResult.

private void assertMergeResult(Department d1, DeepMergeOperation op) {
    queryInterceptor.runWithQueriesBlocked(() -> {
        Department d2 = op.merge(d1);
        assertNotNull(d2);
        assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
        for (Employee ex : d2.getEmployees()) {
            if ("E2".equals(ex.getName())) {
                assertThat(ex, is(instanceOf(Manager.class)));
            } else {
                assertThat(ex, is(not(instanceOf(Manager.class))));
            }
        }
    });
}
Also used : Department(org.apache.cayenne.testdo.inheritance_people.Department) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Manager(org.apache.cayenne.testdo.inheritance_people.Manager)

Example 5 with Department

use of org.apache.cayenne.testdo.inheritance_people.Department in project cayenne by apache.

the class DeepMergeOperationInheritanceIT method testDeepMergeNonExistentSubclass.

@Test
public void testDeepMergeNonExistentSubclass() {
    final Department d1 = context.newObject(Department.class);
    d1.setName("D1");
    // need to do double commit as Ashwood sorter blows on Employees/Departments ordering...
    context.commitChanges();
    Employee e1 = context.newObject(Employee.class);
    e1.setName("E1");
    e1.setPersonType("EE");
    d1.addToEmployees(e1);
    Manager e2 = context.newObject(Manager.class);
    e2.setName("E2");
    e2.setPersonType("EM");
    d1.addToEmployees(e2);
    context.commitChanges();
    // need to make sure source relationship is resolved as a result of some Ashwood strangeness...
    d1.getEmployees().size();
    final DeepMergeOperation op = new DeepMergeOperation(context1);
    assertMergeResult(d1, op);
}
Also used : Department(org.apache.cayenne.testdo.inheritance_people.Department) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) Manager(org.apache.cayenne.testdo.inheritance_people.Manager) Test(org.junit.Test)

Aggregations

Department (org.apache.cayenne.testdo.inheritance_people.Department)5 Manager (org.apache.cayenne.testdo.inheritance_people.Manager)5 Employee (org.apache.cayenne.testdo.inheritance_people.Employee)4 Test (org.junit.Test)3 SelectQuery (org.apache.cayenne.query.SelectQuery)1 Address (org.apache.cayenne.testdo.inheritance_people.Address)1 Before (org.junit.Before)1