Search in sources :

Example 1 with OneOwningSideLocal

use of org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal in project tomee by apache.

the class CmrMappingTests method testOneToOneSetCMROnInverseSide.

public void testOneToOneSetCMROnInverseSide() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final OneOwningSideLocal owningLocal = createOneOwningSide(compoundPK_20_10, compoundPK_20_10_field1);
        inverseLocal.setOneOwningSide(owningLocal);
        completeTransaction();
        validateOneToOneRelationship();
    } catch (final Throwable e) {
        e.printStackTrace();
        throw new TestFailureException(new AssertionFailedError("Received Exception " + e.getClass() + " : " + e.getMessage()));
    } finally {
        completeTransaction();
        cleanDb();
    }
}
Also used : OneInverseSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) OneOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal)

Example 2 with OneOwningSideLocal

use of org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal in project tomee by apache.

the class CmrMappingTests method createOneOwningSide.

private OneOwningSideLocal createOneOwningSide(final Integer id, final Integer field1) throws Exception {
    final OneOwningSideLocalHome home = oneOwningHome;
    final OneOwningSideLocal oneOwningSideLocal = home.create(id, field1);
    oneOwningCreated.add(id);
    return oneOwningSideLocal;
}
Also used : OneOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal) OneOwningSideLocalHome(org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocalHome)

Example 3 with OneOwningSideLocal

use of org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal in project tomee by apache.

the class CmrMappingTests method testOneToOneSetCMROnOwningSide.

public void testOneToOneSetCMROnOwningSide() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final OneOwningSideLocal owningLocal = createOneOwningSide(compoundPK_20_10, compoundPK_20_10_field1);
        owningLocal.setOneInverseSide(inverseLocal);
        completeTransaction();
        validateOneToOneRelationship();
    } catch (final Throwable e) {
        e.printStackTrace();
        throw new TestFailureException(new AssertionFailedError("Received Exception " + e.getClass() + " : " + e.getMessage()));
    } finally {
        completeTransaction();
        cleanDb();
    }
}
Also used : OneInverseSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) OneOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal)

Example 4 with OneOwningSideLocal

use of org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal in project tomee by apache.

the class CmrMappingTests method validateOneToOneRelationship.

private void validateOneToOneRelationship() throws Exception {
    try {
        final OneInverseSideLocal inverseLocal = findOneInverseSide(compoundPK_20_10_field1);
        final OneOwningSideLocal oneOwningSide = inverseLocal.getOneOwningSide();
        Assert.assertNotNull(oneOwningSide);
        Assert.assertEquals(compoundPK_20_10, oneOwningSide.getPrimaryKey());
        final OneInverseSideLocal inverseBackRef = oneOwningSide.getOneInverseSide();
        Assert.assertNotNull(inverseBackRef);
        Assert.assertEquals(compoundPK_20_10_field1, inverseBackRef.getPrimaryKey());
        completeTransaction();
    } finally {
        completeTransaction();
    }
}
Also used : OneInverseSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal) OneOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal)

Example 5 with OneOwningSideLocal

use of org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal in project tomee by apache.

the class CmrMappingTests method testOneToOneSetCMROnInverseSideResetPK.

public void testOneToOneSetCMROnInverseSideResetPK() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final OneOwningSideLocal owningLocal = createOneOwningSide(compoundPK_20_20, compoundPK_20_20_field1);
        inverseLocal.setOneOwningSide(owningLocal);
        // todo should fail when we have fk as part of pk
        //            Assert.fail();
        completeTransaction();
    } catch (final TransactionRolledbackLocalException e) {
        if (!(e.getCause() instanceof IllegalStateException)) {
            e.printStackTrace();
            throw new TestFailureException(new AssertionFailedError("Received Exception " + e.getClass() + " : " + e.getMessage()));
        }
    } catch (final Throwable e) {
        e.printStackTrace();
        throw new TestFailureException(new AssertionFailedError("Received Exception " + e.getClass() + " : " + e.getMessage()));
    } finally {
        completeTransaction();
        cleanDb();
    }
}
Also used : TransactionRolledbackLocalException(javax.ejb.TransactionRolledbackLocalException) OneInverseSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) OneOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal)

Aggregations

OneOwningSideLocal (org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocal)6 OneInverseSideLocal (org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal)5 AssertionFailedError (junit.framework.AssertionFailedError)4 TestFailureException (org.apache.openejb.test.TestFailureException)4 TransactionRolledbackLocalException (javax.ejb.TransactionRolledbackLocalException)2 OneOwningSideLocalHome (org.apache.openejb.test.entity.cmr.cmrmapping.OneOwningSideLocalHome)1