use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CayenneDataObjectValidationIT method testValidateForSaveMandatoryToOneMissing.
@Test
public void testValidateForSaveMandatoryToOneMissing() throws Exception {
Exhibit exhibit = context.newObject(Exhibit.class);
exhibit.setOpeningDate(new Date());
exhibit.setClosingDate(new Date());
ValidationResult result = new ValidationResult();
exhibit.validateForSave(result);
assertTrue("Validation of 'toGallery' should've failed.", result.hasFailures());
assertTrue(result.hasFailures(exhibit));
List<ValidationFailure> failures = result.getFailures();
assertEquals(1, failures.size());
BeanValidationFailure failure = (BeanValidationFailure) failures.get(0);
assertEquals(Exhibit.TO_GALLERY.getName(), failure.getProperty());
// fix the problem and see if it goes away
Gallery gallery = context.newObject(Gallery.class);
exhibit.setToGallery(gallery);
result = new ValidationResult();
exhibit.validateForSave(result);
assertFalse("No failures expected: " + result, result.hasFailures());
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextDeleteRulesIT method testDenyToMany.
@Test
public void testDenyToMany() {
// Gallery paintingArray
Gallery gallery = (Gallery) context.newObject("Gallery");
gallery.setGalleryName("A Name");
Painting painting = (Painting) context.newObject("Painting");
painting.setPaintingTitle("A Title");
gallery.addToPaintingArray(painting);
context.commitChanges();
try {
context.deleteObjects(gallery);
fail("Should have thrown an exception");
} catch (Exception e) {
// GOOD!
}
context.commitChanges();
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class DataContextEJBQLFetchJoinIT method testSeveralEntitiesAndScalarFetchOuterJoins.
@Test
public void testSeveralEntitiesAndScalarFetchOuterJoins() throws Exception {
createMultipleFetchJoinsDataSet();
String ejbql = "SELECT DISTINCT a, a.artistName , g " + "FROM Artist a LEFT JOIN FETCH a.paintingArray, Gallery g LEFT JOIN FETCH g.exhibitArray " + "ORDER BY a.artistName, g.galleryName";
EJBQLQuery query = new EJBQLQuery(ejbql);
final List<?> objects = context.performQuery(query);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(6, objects.size());
Object[] row = (Object[]) objects.get(0);
Artist a1 = (Artist) row[0];
assertEquals("A1", a1.getArtistName());
List<Painting> paintings = a1.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()));
}
String artistName1 = (String) row[1];
assertEquals("A1", artistName1);
Gallery g1 = (Gallery) row[2];
assertEquals("gallery1", g1.getGalleryName());
List<?> exibits = g1.getExhibitArray();
assertNotNull(exibits);
assertFalse(((ValueHolder) exibits).isFault());
assertEquals(2, exibits.size());
row = (Object[]) objects.get(1);
assertEquals(a1, row[0]);
assertEquals(artistName1, row[1]);
Gallery g2 = (Gallery) row[2];
assertEquals("gallery2", g2.getGalleryName());
exibits = g2.getExhibitArray();
assertTrue(exibits.isEmpty());
row = (Object[]) objects.get(2);
Artist a2 = (Artist) row[0];
assertEquals("A2", a2.getArtistName());
paintings = a2.getPaintingArray();
assertNotNull(paintings);
assertEquals(1, paintings.size());
Painting p = paintings.get(0);
assertEquals(PersistenceState.COMMITTED, p.getPersistenceState());
assertNotNull(p.getPaintingTitle());
assertEquals("P2", p.getPaintingTitle());
String artistName2 = (String) row[1];
assertEquals("A2", artistName2);
assertEquals(g1, row[2]);
row = (Object[]) objects.get(3);
assertEquals(a2, row[0]);
assertEquals(artistName2, row[1]);
assertEquals(g2, row[2]);
row = (Object[]) objects.get(4);
Artist a3 = (Artist) row[0];
assertEquals("A3", a3.getArtistName());
paintings = a3.getPaintingArray();
assertTrue(paintings.isEmpty());
String artistName3 = (String) row[1];
assertEquals("A3", artistName3);
assertEquals(g1, row[2]);
row = (Object[]) objects.get(5);
assertEquals(a3, row[0]);
assertEquals(artistName3, row[1]);
assertEquals(g2, row[2]);
}
});
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOMany2OneIT method testMultipleToOneDeletion.
@Test
public void testMultipleToOneDeletion() throws Exception {
// was a problem per CAY-901
Painting p = context.newObject(Painting.class);
p.setPaintingTitle("P1");
Artist a = context.newObject(Artist.class);
a.setArtistName("A1");
Gallery g = context.newObject(Gallery.class);
g.setGalleryName("G1");
p.setToArtist(a);
p.setToGallery(g);
context.commitChanges();
p.setToArtist(null);
p.setToGallery(null);
context.commitChanges();
SQLTemplate q = new SQLTemplate(Painting.class, "SELECT * from PAINTING");
q.setColumnNamesCapitalization(CapsStrategy.UPPER);
q.setFetchingDataRows(true);
Map<String, ?> row = (Map<String, ?>) Cayenne.objectForQuery(context, q);
assertEquals("P1", row.get("PAINTING_TITLE"));
assertEquals(null, row.get("ARTIST_ID"));
assertEquals(null, row.get("GALLERY_ID"));
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOMany2OneIT method testRemove.
@Test
public void testRemove() throws Exception {
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("xa");
Gallery g1 = context.newObject(Gallery.class);
g1.setGalleryName("yT");
p1.setToGallery(g1);
// do save
context.commitChanges();
ObjectContext context2 = runtime.newContext();
// test database data
Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(Painting.class));
Gallery g2 = p2.getToGallery();
p2.setToGallery(null);
// test before save
assertEquals(0, g2.getPaintingArray().size());
assertNull(p2.getToGallery());
// do save II
context2.commitChanges();
ObjectContext context3 = runtime.newContext();
Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(Painting.class));
assertNull(p3.getToGallery());
}
Aggregations