Search in sources :

Example 1 with ROPainting

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

the class CayenneDataObjectSetToManyListIT method testReadRO1.

@Test
public void testReadRO1() throws Exception {
    createArtistWithPaintingDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 8);
    assertEquals(a1 != null, true);
    List<ROPainting> paints = ObjectSelect.query(ROPainting.class).where(ROPainting.TO_ARTIST.eq(a1)).select(context);
    assertEquals(3, paints.size());
    ROPainting rop1 = paints.get(0);
    assertSame(a1, rop1.getToArtist());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Test(org.junit.Test)

Example 2 with ROPainting

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

the class CayenneDataObjectSetToManyListIT method testSetEmptyList1.

@Test
public void testSetEmptyList1() throws Exception {
    createArtistWithPaintingDataSet();
    Artist artist = Cayenne.objectForPK(context, Artist.class, 8);
    artist.setToManyTarget(Artist.PAINTING_ARRAY.getName(), new ArrayList<ROPainting>(0), true);
    List<Painting> paints = artist.getPaintingArray();
    assertEquals(0, paints.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 3 with ROPainting

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

the class CayenneDataObjectSetToManyListIT method testWrongRelName.

@Test
public void testWrongRelName() throws Exception {
    createArtistWithPaintingDataSet();
    Artist artist = Cayenne.objectForPK(context, Artist.class, 8);
    boolean thrown = false;
    try {
        artist.setToManyTarget("doesnotexist", new ArrayList<ROPainting>(0), true);
    } catch (IllegalArgumentException e) {
        thrown = true;
    }
    assertEquals("should throw a IllegalArgumentException, because the relName does not exist", thrown, true);
    thrown = false;
    try {
        artist.setToManyTarget("", new ArrayList<ROPainting>(0), true);
    } catch (IllegalArgumentException e) {
        thrown = true;
    }
    assertEquals("should throw a IllegalArgumentException, because the relName is an empty string", thrown, true);
    thrown = false;
    try {
        artist.setToManyTarget(null, new ArrayList<ROPainting>(0), true);
    } catch (IllegalArgumentException e) {
        thrown = true;
    }
    assertEquals("should throw a IllegalArgumentException, because the relName is NULL", thrown, true);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Test(org.junit.Test)

Example 4 with ROPainting

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

the class CDOMany2OneIT method testReadRO1.

@Test
public void testReadRO1() throws Exception {
    createArtistWithPaintingDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 8);
    Expression e = ROPainting.TO_ARTIST.eq(a1);
    SelectQuery q = new SelectQuery(ROPainting.class, e);
    List<ROPainting> paints = context.performQuery(q);
    assertEquals(1, paints.size());
    ROPainting rop1 = paints.get(0);
    assertSame(a1, rop1.getToArtist());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 5 with ROPainting

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

the class CDOMany2OneIT method testReadRO2.

@Test
public void testReadRO2() throws Exception {
    createArtistWithPaintingDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 8);
    Expression e = ROPainting.TO_ARTIST.eq(a1);
    SelectQuery q = new SelectQuery(ROPainting.class, e);
    List<ROPainting> paints = context.performQuery(q);
    assertEquals(1, paints.size());
    ROPainting rop1 = paints.get(0);
    assertNotNull(rop1.getToArtist());
    // trigger fetch
    rop1.getToArtist().getArtistName();
    assertEquals(PersistenceState.COMMITTED, rop1.getToArtist().getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Aggregations

Artist (org.apache.cayenne.testdo.testmap.Artist)5 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)5 Test (org.junit.Test)5 Expression (org.apache.cayenne.exp.Expression)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 Painting (org.apache.cayenne.testdo.testmap.Painting)1