Search in sources :

Example 26 with Gallery

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

the class CDOMany2OneIT method testReplace.

@Test
public void testReplace() throws Exception {
    Painting p1 = context.newObject(Painting.class);
    p1.setPaintingTitle("xa");
    Gallery g1 = context.newObject(Gallery.class);
    g1.setGalleryName("yTW");
    p1.setToGallery(g1);
    context.commitChanges();
    ObjectContext context2 = runtime.newContext();
    // test database data
    Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(Painting.class));
    Gallery g21 = p2.getToGallery();
    assertNotNull(g21);
    assertEquals("yTW", g21.getGalleryName());
    assertEquals(1, g21.getPaintingArray().size());
    assertSame(p2, g21.getPaintingArray().get(0));
    Gallery g22 = context2.newObject(Gallery.class);
    g22.setGalleryName("rE");
    p2.setToGallery(g22);
    // test before save
    assertEquals(0, g21.getPaintingArray().size());
    assertEquals(1, g22.getPaintingArray().size());
    assertSame(p2, g22.getPaintingArray().get(0));
    // do save II
    context2.commitChanges();
    ObjectContext context3 = runtime.newContext();
    Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(Painting.class));
    Gallery g3 = p3.getToGallery();
    assertNotNull(g3);
    assertEquals("rE", g3.getGalleryName());
    assertEquals(1, g3.getPaintingArray().size());
    assertSame(p3, g3.getPaintingArray().get(0));
}
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)

Example 27 with Gallery

use of org.apache.cayenne.testdo.testmap.Gallery 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();
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Gallery(org.apache.cayenne.testdo.testmap.Gallery) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) Timestamp(java.sql.Timestamp) Test(org.junit.Test) ByteArrayTypeTest(org.apache.cayenne.access.types.ByteArrayTypeTest)

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