Search in sources :

Example 21 with Gallery

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());
}
Also used : Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ValidationResult(org.apache.cayenne.validation.ValidationResult) Date(java.util.Date) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) Test(org.junit.Test)

Example 22 with Gallery

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();
}
Also used : Gallery(org.apache.cayenne.testdo.testmap.Gallery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 23 with Gallery

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]);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Gallery(org.apache.cayenne.testdo.testmap.Gallery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 24 with Gallery

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"));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SQLTemplate(org.apache.cayenne.query.SQLTemplate) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Map(java.util.Map) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 25 with Gallery

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());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

Gallery (org.apache.cayenne.testdo.testmap.Gallery)27 Test (org.junit.Test)26 Painting (org.apache.cayenne.testdo.testmap.Painting)13 Artist (org.apache.cayenne.testdo.testmap.Artist)12 List (java.util.List)9 ValueHolder (org.apache.cayenne.ValueHolder)7 ArtistExhibit (org.apache.cayenne.testdo.testmap.ArtistExhibit)7 Exhibit (org.apache.cayenne.testdo.testmap.Exhibit)7 Expression (org.apache.cayenne.exp.Expression)6 SelectQuery (org.apache.cayenne.query.SelectQuery)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)4 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)4 ArrayList (java.util.ArrayList)3 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)3 Date (java.util.Date)2 Iterator (java.util.Iterator)2 Fault (org.apache.cayenne.Fault)2 ObjectId (org.apache.cayenne.ObjectId)2 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1