use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextValidationIT method testValidate.
@Test
public void testValidate() throws Exception {
ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("G1");
o1.resetValidation(false);
// this one is not validating
ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
o2.setTable1(o1);
context.commitChanges();
assertTrue(o1.isValidatedForInsert());
assertFalse(o1.isValidatedForDelete());
assertFalse(o1.isValidatedForUpdate());
o1.resetValidation(false);
o1.setGlobalAttribute1("G2");
context.commitChanges();
assertFalse(o1.isValidatedForInsert());
assertFalse(o1.isValidatedForDelete());
assertTrue(o1.isValidatedForUpdate());
o1.resetValidation(false);
context.deleteObjects(o1);
context.deleteObjects(o2);
context.commitChanges();
assertFalse(o1.isValidatedForInsert());
assertTrue(o1.isValidatedForDelete());
assertFalse(o1.isValidatedForUpdate());
ClientMtTable1 o11 = context.newObject(ClientMtTable1.class);
o11.setGlobalAttribute1("G1");
o11.resetValidation(true);
try {
context.commitChanges();
fail("Validation failure must have prevented commit");
} catch (ValidationException e) {
// expected
}
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPrefetchingToMany.
@Test
public void testPrefetchingToMany() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<ClientMtTable1> results = clientContext.performQuery(q);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o1 = results.get(0);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(clientContext, o1.getObjectContext());
List<?> children1 = o1.getTable2Array();
assertEquals(2, children1.size());
Iterator<?> it = children1.iterator();
while (it.hasNext()) {
ClientMtTable2 o = (ClientMtTable2) it.next();
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(clientContext, o.getObjectContext());
// TODO: fixme... reverse relationship is not connected and will
// cause a fetch
// assertEquals(o1, o.getTable1());
}
}
});
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testSetValueHolder.
@Test
public void testSetValueHolder() throws Exception {
ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
t2.setTable1(t1);
assertEquals(1, t1.getTable2Array().size());
assertSame(t1, t2.getTable1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testAddToList.
@Test
public void testAddToList() throws Exception {
ClientMtTable1 t1 = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 t2 = clientContext.newObject(ClientMtTable2.class);
t1.addToTable2Array(t2);
assertEquals(1, t1.getTable2Array().size());
assertSame(t1, t2.getTable1());
// do it again to make sure action can handle series of changes
ClientMtTable1 t3 = clientContext.newObject(ClientMtTable1.class);
ClientMtTable2 t4 = clientContext.newObject(ClientMtTable2.class);
t3.addToTable2Array(t4);
assertEquals(1, t3.getTable2Array().size());
assertSame(t3, t4.getTable1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable2 in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPrefetchingToOneNull.
@Test
public void testPrefetchingToOneNull() throws Exception {
tMtTable2.insert(15, null, "g3");
SelectQuery q = new SelectQuery(ClientMtTable2.class);
q.addPrefetch(ClientMtTable2.TABLE1_PROPERTY);
final List<ClientMtTable2> results = clientContext.performQuery(q);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, results.size());
ClientMtTable2 o = results.get(0);
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(clientContext, o.getObjectContext());
assertNull(o.getTable1());
}
});
}
Aggregations