Search in sources :

Example 6 with Exhibit

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

the class DataContextIT method testSelectDate.

@Test
public void testSelectDate() throws Exception {
    createGalleriesAndExhibitsDataSet();
    List<Exhibit> objects = context.performQuery(new SelectQuery(Exhibit.class));
    assertFalse(objects.isEmpty());
    Exhibit e1 = objects.get(0);
    assertEquals(java.util.Date.class, e1.getClosingDate().getClass());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) Test(org.junit.Test)

Example 7 with Exhibit

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

the class DataContextPrefetchMultistepIT method testToManyToManyFirstStepResolved.

@Test
public void testToManyToManyFirstStepResolved() throws Exception {
    createTwoArtistsWithExhibitsDataSet();
    Expression e = ExpressionFactory.exp("galleryName = $name");
    SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections.singletonMap("name", "gallery2")));
    q.addPrefetch("exhibitArray");
    q.addPrefetch("exhibitArray.artistExhibitArray");
    List<Gallery> galleries = context.select(q);
    assertEquals(1, galleries.size());
    Gallery g2 = galleries.get(0);
    // this relationship should be resolved
    assertTrue(g2.readPropertyDirectly("exhibitArray") instanceof ValueHolder);
    List<Exhibit> exhibits = (List<Exhibit>) g2.readPropertyDirectly("exhibitArray");
    assertFalse(((ValueHolder) exhibits).isFault());
    assertEquals(1, exhibits.size());
    Exhibit e1 = exhibits.get(0);
    assertEquals(PersistenceState.COMMITTED, e1.getPersistenceState());
    // this to-many must also be resolved
    assertTrue(e1.readPropertyDirectly("artistExhibitArray") instanceof ValueHolder);
    List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1.readPropertyDirectly("artistExhibitArray");
    assertFalse(((ValueHolder) aexhibits).isFault());
    assertEquals(1, exhibits.size());
    ArtistExhibit ae1 = aexhibits.get(0);
    assertEquals(PersistenceState.COMMITTED, ae1.getPersistenceState());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Gallery(org.apache.cayenne.testdo.testmap.Gallery) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) ArtistExhibit(org.apache.cayenne.testdo.testmap.ArtistExhibit) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Test(org.junit.Test)

Example 8 with Exhibit

use of org.apache.cayenne.testdo.testmap.Exhibit 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 9 with Exhibit

use of org.apache.cayenne.testdo.testmap.Exhibit 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

Exhibit (org.apache.cayenne.testdo.testmap.Exhibit)9 Test (org.junit.Test)9 Gallery (org.apache.cayenne.testdo.testmap.Gallery)7 ArtistExhibit (org.apache.cayenne.testdo.testmap.ArtistExhibit)6 List (java.util.List)3 ValueHolder (org.apache.cayenne.ValueHolder)3 Expression (org.apache.cayenne.exp.Expression)3 Artist (org.apache.cayenne.testdo.testmap.Artist)3 Date (java.util.Date)2 Timestamp (java.sql.Timestamp)1 DataRow (org.apache.cayenne.DataRow)1 Fault (org.apache.cayenne.Fault)1 ObjectId (org.apache.cayenne.ObjectId)1 ByteArrayTypeTest (org.apache.cayenne.access.types.ByteArrayTypeTest)1 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 BeanValidationFailure (org.apache.cayenne.validation.BeanValidationFailure)1 ValidationFailure (org.apache.cayenne.validation.ValidationFailure)1 ValidationResult (org.apache.cayenne.validation.ValidationResult)1