Search in sources :

Example 1 with ClientCompany

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

the class SingleTableInheritanceIT method testSave.

@Test
public void testSave() throws Exception {
    ClientCompany company = context.newObject(ClientCompany.class);
    company.setName("Boeing");
    CustomerRepresentative rep = context.newObject(CustomerRepresentative.class);
    rep.setName("Joe Schmoe");
    rep.setToClientCompany(company);
    rep.setPersonType("C");
    Employee employee = context.newObject(Employee.class);
    employee.setName("Our Joe Schmoe");
    employee.setPersonType("E");
    context.commitChanges();
    context.invalidateObjects(company, rep, employee);
    SelectQuery query = new SelectQuery(CustomerRepresentative.class);
    List<?> reps = context2.performQuery(query);
    assertEquals(1, reps.size());
    assertEquals(1, countObjectOfClass(reps, CustomerRepresentative.class));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientCompany(org.apache.cayenne.testdo.inheritance_people.ClientCompany) Employee(org.apache.cayenne.testdo.inheritance_people.Employee) CustomerRepresentative(org.apache.cayenne.testdo.inheritance_people.CustomerRepresentative) Test(org.junit.Test)

Example 2 with ClientCompany

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

the class SingleTableInheritanceIT method testRepCompany.

/**
 * Tests that to-one relationship produces correct subclass.
 */
@Test
public void testRepCompany() throws Exception {
    createRepCompanyDataSet();
    List<?> companies = context.performQuery(new SelectQuery(ClientCompany.class));
    assertEquals(1, companies.size());
    ClientCompany company = (ClientCompany) companies.get(0);
    List<?> reps = company.getRepresentatives();
    assertEquals(1, reps.size());
    assertSame(CustomerRepresentative.class, reps.get(0).getClass());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientCompany(org.apache.cayenne.testdo.inheritance_people.ClientCompany) Test(org.junit.Test)

Aggregations

SelectQuery (org.apache.cayenne.query.SelectQuery)2 ClientCompany (org.apache.cayenne.testdo.inheritance_people.ClientCompany)2 Test (org.junit.Test)2 CustomerRepresentative (org.apache.cayenne.testdo.inheritance_people.CustomerRepresentative)1 Employee (org.apache.cayenne.testdo.inheritance_people.Employee)1