Search in sources :

Example 1 with ManyOwningSideLocal

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

the class CmrMappingTests method testEjbSelectWithCMR.

public void testEjbSelectWithCMR() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final ManyOwningSideLocal owningLocal = createManyOwningSide(compoundPK_20_10, compoundPK_20_10_field1);
        owningLocal.setOneInverseSide(inverseLocal);
        completeTransaction();
        owningLocal.testEJBSelect();
    } 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) ManyOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocal) AssertionFailedError(junit.framework.AssertionFailedError)

Example 2 with ManyOwningSideLocal

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

the class CmrMappingTests method validateOneToManyRelationship.

private void validateOneToManyRelationship() throws NotSupportedException, SystemException, Exception, HeuristicMixedException, HeuristicRollbackException, RollbackException {
    try {
        final OneInverseSideLocal inverseLocal = findOneInverseSide(compoundPK_20_10_field1);
        // verify one side has a set containing the many bean
        final Set set = inverseLocal.getManyOwningSide();
        Assert.assertEquals(1, set.size());
        final ManyOwningSideLocal owningLocal = (ManyOwningSideLocal) set.iterator().next();
        Assert.assertEquals(compoundPK_20_10, owningLocal.getPrimaryKey());
        // verify the many bean has a back reference to the one
        final OneInverseSideLocal oneInverseSide = owningLocal.getOneInverseSide();
        Assert.assertNotNull(oneInverseSide);
        Assert.assertEquals(compoundPK_20_10_field1, oneInverseSide.getPrimaryKey());
        completeTransaction();
    } finally {
        completeTransaction();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) OneInverseSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal) ManyOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocal)

Example 3 with ManyOwningSideLocal

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

the class CmrMappingTests method testOneToManySetCMROnOwningSide.

public void testOneToManySetCMROnOwningSide() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final ManyOwningSideLocal owningLocal = createManyOwningSide(compoundPK_20_10, compoundPK_20_10_field1);
        owningLocal.setOneInverseSide(inverseLocal);
        completeTransaction();
        validateOneToManyRelationship();
    } 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) ManyOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocal) AssertionFailedError(junit.framework.AssertionFailedError)

Example 4 with ManyOwningSideLocal

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

the class CmrMappingTests method testOneToManySetCMROnOwningSideResetPK.

public void testOneToManySetCMROnOwningSideResetPK() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final ManyOwningSideLocal owningLocal = createManyOwningSide(compoundPK_20_20, compoundPK_20_20_field1);
        owningLocal.setOneInverseSide(inverseLocal);
        // 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) ManyOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocal) AssertionFailedError(junit.framework.AssertionFailedError)

Example 5 with ManyOwningSideLocal

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

the class CmrMappingTests method testOneToManySetCMROnInverseSideResetPK.

public void testOneToManySetCMROnInverseSideResetPK() throws Exception {
    beginTransaction();
    try {
        final OneInverseSideLocal inverseLocal = createOneInverseSide(compoundPK_20_10_field1);
        final ManyOwningSideLocal owningLocal = createManyOwningSide(compoundPK_20_20, compoundPK_20_20_field1);
        inverseLocal.setManyOwningSide(Collections.singleton(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) ManyOwningSideLocal(org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocal) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

ManyOwningSideLocal (org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocal)7 OneInverseSideLocal (org.apache.openejb.test.entity.cmr.cmrmapping.OneInverseSideLocal)6 AssertionFailedError (junit.framework.AssertionFailedError)5 TestFailureException (org.apache.openejb.test.TestFailureException)5 TransactionRolledbackLocalException (javax.ejb.TransactionRolledbackLocalException)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ManyOwningSideLocalHome (org.apache.openejb.test.entity.cmr.cmrmapping.ManyOwningSideLocalHome)1