Search in sources :

Example 1 with FlattenedTest5

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest5 in project cayenne by apache.

the class FlattenedRelationshipsIT method testNullFlattenedComplexToOneRelationship.

/**
 * Should be able to save/insert an object with null flattened (complex) toOne relationship
 * @throws Exception
 */
@Test
public void testNullFlattenedComplexToOneRelationship() throws Exception {
    FlattenedTest5 ft5 = context.newObject(FlattenedTest5.class);
    ft5.setName("FT5");
    // should be valid for save
    ValidationResult validationResult = new ValidationResult();
    ft5.validateForSave(validationResult);
    assertTrue(validationResult.toString(), validationResult.getFailures().isEmpty());
    context.commitChanges();
    assertEquals(1, ObjectSelect.query(FlattenedTest5.class).selectCount(context));
}
Also used : ValidationResult(org.apache.cayenne.validation.ValidationResult) FlattenedTest5(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest5) Test(org.junit.Test)

Example 2 with FlattenedTest5

use of org.apache.cayenne.testdo.relationships_flattened.FlattenedTest5 in project cayenne by apache.

the class FlattenedRelationshipsIT method testFlattenedComplexToOneRelationship.

/**
 * Should be able to save/insert an object with flattened (complex) toOne relationship
 * @throws Exception
 */
@Test
public void testFlattenedComplexToOneRelationship() throws Exception {
    FlattenedTest1 ft1 = context.newObject(FlattenedTest1.class);
    ft1.setName("FT1");
    FlattenedTest5 ft5 = context.newObject(FlattenedTest5.class);
    ft5.setName("FT5");
    ft5.setToFT1(ft1);
    context.commitChanges();
    FlattenedTest5 ft5Persisted = ObjectSelect.query(FlattenedTest5.class).selectFirst(context);
    assertEquals(ft1, ft5Persisted.getToFT1());
}
Also used : FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) FlattenedTest5(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest5) Test(org.junit.Test)

Aggregations

FlattenedTest5 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest5)2 Test (org.junit.Test)2 FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)1 ValidationResult (org.apache.cayenne.validation.ValidationResult)1