Search in sources :

Example 1 with MeaningfulPkTest2

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testMeaningfulIntegerPK.

@Test
public void testMeaningfulIntegerPK() {
    MeaningfulPkTest2 obj1 = context.newObject(MeaningfulPkTest2.class);
    obj1.setIntegerAttribute(10);
    obj1.setPkAttribute(1);
    MeaningfulPkTest2 obj2 = context.newObject(MeaningfulPkTest2.class);
    obj2.setIntegerAttribute(20);
    obj2.setPkAttribute(2);
    context.commitChanges();
    ObjectContext context = runtime.newContext();
    List<MeaningfulPkTest2> objects = ObjectSelect.query(MeaningfulPkTest2.class).select(context);
    assertEquals(2, objects.size());
    assertEquals(Integer.valueOf(1), obj1.getPkAttribute());
    assertEquals(Integer.valueOf(2), obj2.getPkAttribute());
}
Also used : MeaningfulPkTest2(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 2 with MeaningfulPkTest2

use of org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2 in project cayenne by apache.

the class DataContextEntityWithMeaningfulPKIT method testGeneratedIntegerPK.

@Test
public void testGeneratedIntegerPK() {
    MeaningfulPkTest2 obj1 = context.newObject(MeaningfulPkTest2.class);
    obj1.setIntegerAttribute(10);
    MeaningfulPkTest2 obj2 = context.newObject(MeaningfulPkTest2.class);
    obj2.setIntegerAttribute(20);
    context.commitChanges();
    ObjectContext context = runtime.newContext();
    List<MeaningfulPkTest2> objects = ObjectSelect.query(MeaningfulPkTest2.class).select(context);
    assertEquals(2, objects.size());
    assertNotEquals(Integer.valueOf(0), obj1.getPkAttribute());
    assertNotEquals(Integer.valueOf(0), obj2.getPkAttribute());
    assertNotEquals(obj1.getPkAttribute(), obj2.getPkAttribute());
}
Also used : MeaningfulPkTest2(org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)2 MeaningfulPkTest2 (org.apache.cayenne.testdo.meaningful_pk.MeaningfulPkTest2)2 Test (org.junit.Test)2