use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany in project cayenne by apache.
the class CayenneDataObjectSetToManyCollectionIT method testReadToMany.
@Test
public void testReadToMany() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertNotNull(targets);
assertTrue(((ValueHolder) targets).isFault());
assertEquals(3, targets.size());
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 1)));
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 2)));
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 3)));
}
use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany in project cayenne by apache.
the class CDOCollectionRelationshipIT method testReadToManyPrefetching.
@Test
public void testReadToManyPrefetching() throws Exception {
SelectQuery query = new SelectQuery(CollectionToMany.class, ExpressionFactory.matchDbExp(CollectionToMany.ID_PK_COLUMN, 1));
query.addPrefetch(CollectionToMany.TARGETS.disjoint());
CollectionToMany o1 = (CollectionToMany) Cayenne.objectForQuery(context, query);
Collection<?> targets = o1.getTargets();
assertFalse(((ValueHolder) targets).isFault());
assertNotNull(targets);
assertEquals(3, targets.size());
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 1)));
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 2)));
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 3)));
}
use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany in project cayenne by apache.
the class CDOCollectionRelationshipIT method testAddToMany.
@Test
public void testAddToMany() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertNotNull(targets);
assertEquals(3, targets.size());
CollectionToManyTarget newTarget = o1.getObjectContext().newObject(CollectionToManyTarget.class);
o1.addToTargets(newTarget);
assertEquals(4, targets.size());
assertTrue(o1.getTargets().contains(newTarget));
assertSame(o1, newTarget.getCollectionToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(4, o1.getTargets().size());
}
use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany in project cayenne by apache.
the class CayenneDataObjectSetToManyCollectionIT method testRelationCollectionTypeCollection.
/**
* Testing if collection type is Collection, everything should work fine without an
* runtimexception
*
* @throws Exception
*/
@Test
public void testRelationCollectionTypeCollection() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
assertTrue(o1.readProperty(CollectionToMany.TARGETS.getName()) instanceof Collection);
boolean catchedSomething = false;
try {
o1.setToManyTarget(CollectionToMany.TARGETS.getName(), new ArrayList<CollectionToMany>(0), true);
} catch (RuntimeException e) {
catchedSomething = true;
}
assertEquals(catchedSomething, false);
assertEquals(o1.getTargets().size(), 0);
}
use of org.apache.cayenne.testdo.relationships_collection_to_many.CollectionToMany in project cayenne by apache.
the class CDOCollectionRelationshipIT method testReadToMany.
@Test
public void testReadToMany() throws Exception {
CollectionToMany o1 = Cayenne.objectForPK(context, CollectionToMany.class, 1);
Collection<?> targets = o1.getTargets();
assertNotNull(targets);
assertTrue(((ValueHolder) targets).isFault());
assertEquals(3, targets.size());
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 1)));
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 2)));
assertTrue(targets.contains(Cayenne.objectForPK(o1.getObjectContext(), CollectionToManyTarget.class, 3)));
}
Aggregations