use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.
the class CayenneDataObjectIT method testReadNestedPropertyToManyInMiddle1.
@SuppressWarnings("unchecked")
@Test
public void testReadNestedPropertyToManyInMiddle1() throws Exception {
Artist a = context.newObject(Artist.class);
ArtistExhibit ex = context.newObject(ArtistExhibit.class);
Painting p1 = context.newObject(Painting.class);
Painting p2 = context.newObject(Painting.class);
p1.setPaintingTitle("p1");
p2.setPaintingTitle("p2");
a.addToPaintingArray(p1);
a.addToPaintingArray(p2);
ex.setToArtist(a);
List<String> names = (List<String>) a.readNestedProperty("paintingArray+.paintingTitle");
assertEquals(names.size(), 2);
assertEquals(names.get(0), "p1");
assertEquals(names.get(1), "p2");
List<String> names2 = (List<String>) ex.readNestedProperty("toArtist.paintingArray+.paintingTitle");
assertEquals(names, names2);
}
use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralFetchJoins.
@Test
public void testSeveralFetchJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT a " + "FROM Artist a JOIN FETCH a.paintingArray JOIN FETCH a.artistExhibitArray " + "WHERE a.artistName = 'A1'";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(1, objects.size());
Artist a = (Artist) objects.get(0);
assertEquals("A1", a.getArtistName());
List<Painting> paintings = a.getPaintingArray();
assertNotNull(paintings);
assertFalse(((ValueHolder) paintings).isFault());
assertEquals(2, paintings.size());
List<String> expectedPaintingsNames = new ArrayList<String>();
expectedPaintingsNames.add("P11");
expectedPaintingsNames.add("P12");
Iterator<Painting> paintingsIterator = paintings.iterator();
while (paintingsIterator.hasNext()) {
Painting p = paintingsIterator.next();
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertTrue(expectedPaintingsNames.contains(p.getPaintingTitle()));
}
List<ArtistExhibit> exibits = a.getArtistExhibitArray();
assertNotNull(exibits);
assertFalse(((ValueHolder) exibits).isFault());
assertEquals(2, exibits.size());
Iterator<ArtistExhibit> exibitsIterator = exibits.iterator();
while (exibitsIterator.hasNext()) {
ArtistExhibit ae = exibitsIterator.next();
assertEquals(PersistenceState.COMMITTED, ae.getPersistenceState());
assertNotNull(ae.getObjectId());
}
}
});
}
use of org.apache.cayenne.testdo.testmap.ArtistExhibit in project cayenne by apache.
the class CDOOneDep2OneIT method testNewAdd2.
/**
* Tests how primary key is propagated from one new object to another.
*/
@Test
public void testNewAdd2() throws Exception {
Artist a1 = this.newArtist();
Gallery g1 = context.newObject(Gallery.class);
g1.setGalleryName(galleryName);
Exhibit e1 = context.newObject(Exhibit.class);
e1.setOpeningDate(new Timestamp(System.currentTimeMillis()));
e1.setClosingDate(new Timestamp(System.currentTimeMillis()));
e1.setToGallery(g1);
ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
ae1.setToArtist(a1);
ae1.setToExhibit(e1);
// *** TESTING THIS ***
context.commitChanges();
}
Aggregations