use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testPropagateToDependent.
@Test
public void testPropagateToDependent() throws Exception {
GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
idObject.setName("aaa");
GeneratedColumnDep dependent = idObject.getObjectContext().newObject(GeneratedColumnDep.class);
dependent.setName("aaa");
dependent.setToMaster(idObject);
context.commitChanges();
// this will throw an exception if id wasn't generated
int id1 = Cayenne.intPKForObject(idObject);
assertTrue(id1 >= 0);
int id2 = Cayenne.intPKForObject(dependent);
assertTrue(id2 >= 0);
assertEquals(id1, id2);
// refetch from DB
context.invalidateObjects(idObject, dependent);
assertNotNull(Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id1));
assertNotNull(Cayenne.objectForPK(context, GeneratedColumnDep.class, id2));
}
use of org.apache.cayenne.testdo.generated.GeneratedColumnTestEntity in project cayenne by apache.
the class IdentityColumnsIT method testNewObject.
@Test
public void testNewObject() throws Exception {
GeneratedColumnTestEntity idObject = context.newObject(GeneratedColumnTestEntity.class);
String name = "n_" + System.currentTimeMillis();
idObject.setName(name);
idObject.getObjectContext().commitChanges();
// this will throw an exception if id wasn't generated one way or
// another
int id = Cayenne.intPKForObject(idObject);
assertTrue(id >= 0);
// make sure that id is the same as id in the DB
context.invalidateObjects(idObject);
GeneratedColumnTestEntity object = Cayenne.objectForPK(context, GeneratedColumnTestEntity.class, id);
assertNotNull(object);
assertEquals(name, object.getName());
}
Aggregations