Search in sources :

Example 1 with ROArtist

use of org.apache.cayenne.testdo.testmap.ROArtist in project cayenne by apache.

the class DataContextIT method testCommitChangesRO2.

@Test
public void testCommitChangesRO2() throws Exception {
    createArtistsDataSet();
    SelectQuery query = new SelectQuery(ROArtist.class, Artist.ARTIST_NAME.eq("artist1"));
    ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
    a1.writeProperty(ROArtist.ARTIST_NAME.getName(), "abc");
    try {
        context.commitChanges();
        fail("Updating a 'read-only' object must fail.");
    } catch (Exception ex) {
    // exception is expected,
    // must blow on saving new "read-only" object.
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ROArtist(org.apache.cayenne.testdo.testmap.ROArtist) Test(org.junit.Test)

Example 2 with ROArtist

use of org.apache.cayenne.testdo.testmap.ROArtist in project cayenne by apache.

the class DataContextIT method testCommitChangesRO1.

@Test
public void testCommitChangesRO1() throws Exception {
    ROArtist a1 = (ROArtist) context.newObject("ROArtist");
    a1.writePropertyDirectly("artistName", "abc");
    a1.setPersistenceState(PersistenceState.MODIFIED);
    try {
        context.commitChanges();
        fail("Inserting a 'read-only' object must fail.");
    } catch (Exception ex) {
    // exception is expected,
    // must blow on saving new "read-only" object.
    }
}
Also used : ROArtist(org.apache.cayenne.testdo.testmap.ROArtist) Test(org.junit.Test)

Example 3 with ROArtist

use of org.apache.cayenne.testdo.testmap.ROArtist in project cayenne by apache.

the class DataContextIT method testCommitChangesRO4.

@Test
public void testCommitChangesRO4() throws Exception {
    createArtistsDataSet();
    SelectQuery query = new SelectQuery(ROArtist.class, Artist.ARTIST_NAME.eq("artist1"));
    ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
    Painting painting = context.newObject(Painting.class);
    painting.setPaintingTitle("paint");
    a1.addToPaintingArray(painting);
    assertEquals(PersistenceState.MODIFIED, a1.getPersistenceState());
    try {
        context.commitChanges();
    } catch (Exception ex) {
        fail("Updating 'read-only' object's to-many must succeed, instead an exception was thrown: " + ex);
    }
    assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ROArtist(org.apache.cayenne.testdo.testmap.ROArtist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 4 with ROArtist

use of org.apache.cayenne.testdo.testmap.ROArtist in project cayenne by apache.

the class DataContextIT method testCommitChangesRO3.

@Test
public void testCommitChangesRO3() throws Exception {
    createArtistsDataSet();
    SelectQuery query = new SelectQuery(ROArtist.class, Artist.ARTIST_NAME.eq("artist1"));
    ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
    context.deleteObjects(a1);
    try {
        context.commitChanges();
        fail("Deleting a 'read-only' object must fail.");
    } catch (Exception ex) {
    // exception is expected,
    // must blow on saving new "read-only" object.
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ROArtist(org.apache.cayenne.testdo.testmap.ROArtist) Test(org.junit.Test)

Aggregations

ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)4 Test (org.junit.Test)4 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Painting (org.apache.cayenne.testdo.testmap.Painting)1