Search in sources :

Example 21 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class TestReadAggregateEntityU1MMapMapping method verify.

@Override
public void verify() {
    if (holders == null || holders.size() != 1) {
        throw new TestErrorException("Incorrect number of MapHolders was read.");
    }
    AggregateEntityU1MMapHolder holder = (AggregateEntityU1MMapHolder) holders.get(0);
    if (!((IndirectMap) holder.getAggregateToEntityMap()).getValueHolder().isInstantiated() && fetchJoinRelationship > 0) {
        throw new TestErrorException("Relationship was not properly joined.");
    }
    if (holder.getAggregateToEntityMap().size() != 2) {
        throw new TestErrorException("Incorrect Number of MapEntityValues was read.");
    }
    AggregateMapKey mapKey = new AggregateMapKey();
    mapKey.setKey(11);
    EntityMapValue value = (EntityMapValue) holder.getAggregateToEntityMap().get(mapKey);
    if (value.getId() != 1) {
        throw new TestErrorException("Incorrect MapEntityValues was read.");
    }
}
Also used : EntityMapValue(org.eclipse.persistence.testing.models.collections.map.EntityMapValue) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) AggregateMapKey(org.eclipse.persistence.testing.models.collections.map.AggregateMapKey) AggregateEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateEntityU1MMapHolder)

Example 22 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class TestReadAggregateEntityU1MMapMapping method reset.

@Override
public void reset() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Iterator i = holders.iterator();
    while (i.hasNext()) {
        AggregateEntityU1MMapHolder holder = (AggregateEntityU1MMapHolder) i.next();
        Iterator j = holder.getAggregateToEntityMap().keySet().iterator();
        while (j.hasNext()) {
            uow.deleteObject(holder.getAggregateToEntityMap().get(j.next()));
        }
    }
    uow.deleteAllObjects(holders);
    uow.commit();
    if (!verifyDelete(holders.get(0))) {
        throw new TestErrorException("Delete was unsuccessful.");
    }
    mapping.setJoinFetch(oldFetchJoinValue);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Iterator(java.util.Iterator) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) AggregateEntityU1MMapHolder(org.eclipse.persistence.testing.models.collections.map.AggregateEntityU1MMapHolder)

Example 23 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class TestReadDirectDirectMapMapping method verify.

@Override
public void verify() {
    if (holders == null || holders.size() != 1) {
        throw new TestErrorException("Incorrect number of MapHolders was read.");
    }
    DirectDirectMapHolder holder = (DirectDirectMapHolder) holders.get(0);
    if (!((IndirectMap) holder.getDirectToDirectMap()).getValueHolder().isInstantiated() && fetchJoinRelationship > 0) {
        throw new TestErrorException("Relationship was not properly joined.");
    }
    if (holder.getDirectToDirectMap().size() != 2) {
        throw new TestErrorException("Incorrect Number of Map values was read.");
    }
    Integer value = (Integer) holder.getDirectToDirectMap().get(1);
    if (value != 1) {
        throw new TestErrorException("Incorrect map value was read.");
    }
}
Also used : TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) DirectDirectMapHolder(org.eclipse.persistence.testing.models.collections.map.DirectDirectMapHolder)

Example 24 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class TestReadDirectDirectMapMapping method reset.

@Override
public void reset() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.deleteAllObjects(holders);
    uow.commit();
    if (!verifyDelete(holders.get(0))) {
        throw new TestErrorException("Delete was unsuccessful.");
    }
    mapping.setJoinFetch(oldFetchJoinValue);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 25 with TestErrorException

use of org.eclipse.persistence.testing.framework.TestErrorException in project eclipselink by eclipse-ee4j.

the class DeepMergeCloneIndirectionTest method test.

/**
 * This test creates an object and registers it with a unit of work.  It then serializes that
 * object and deserializes it.  Adds an object onto the origional then performs serialization
 * sequence again.  Then deepMergeClone is attempted and the results are compared to verify that
 * the merge worked.
 */
@Override
public void test() {
    try {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        ObjectOutputStream stream = new ObjectOutputStream(byteStream);
        // create the phoneNumber object
        Order orderClone;
        Session session = getSession();
        org.eclipse.persistence.sessions.UnitOfWork uow = session.acquireUnitOfWork();
        this.orderObject = (Order) session.readObject(Order.class);
        // force instantiations of value holders before serialization
        ((Collection) this.orderObject.getLineContainer()).size();
        // serialize object by writing to a stream
        stream.writeObject(this.orderObject);
        stream.flush();
        byte[] arr = byteStream.toByteArray();
        ByteArrayInputStream inByteStream = new ByteArrayInputStream(arr);
        ObjectInputStream inObjStream = new ObjectInputStream(inByteStream);
        Order deserialOrder;
        // deserialize the object
        try {
            deserialOrder = (Order) inObjStream.readObject();
        } catch (ClassNotFoundException e) {
            throw new TestErrorException("Could not deserialize object " + e.toString());
        }
        // add a new manager, test 1-m's
        OrderLine newLine = new OrderLine();
        ((Collection) deserialOrder.getLineContainer()).clear();
        deserialOrder.addLine(newLine);
        newLine.order = deserialOrder;
        orderClone = (Order) uow.registerObject(this.orderObject);
        orderClone = (Order) uow.deepMergeClone(deserialOrder);
        uow.commit();
    } catch (IOException e) {
        throw new TestErrorException("Error running Test " + e.toString());
    } catch (NullPointerException exception) {
        throw new TestErrorException("Test Failed.  Backup clone indirection was not triggered in mergeIntoObject.");
    }
}
Also used : Order(org.eclipse.persistence.testing.models.transparentindirection.Order) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ByteArrayInputStream(java.io.ByteArrayInputStream) OrderLine(org.eclipse.persistence.testing.models.transparentindirection.OrderLine) Collection(java.util.Collection) Session(org.eclipse.persistence.sessions.Session) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)227 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)79 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)50 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)27 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)22 Vector (java.util.Vector)20 EntityMapValue (org.eclipse.persistence.testing.models.collections.map.EntityMapValue)20 Expression (org.eclipse.persistence.expressions.Expression)19 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)18 Iterator (java.util.Iterator)17 AggregateMapKey (org.eclipse.persistence.testing.models.collections.map.AggregateMapKey)16 EntityMapKey (org.eclipse.persistence.testing.models.collections.map.EntityMapKey)15 Project (org.eclipse.persistence.sessions.Project)13 Session (org.eclipse.persistence.sessions.Session)11 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)7 QueryException (org.eclipse.persistence.exceptions.QueryException)7 TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)7 Address (org.eclipse.persistence.testing.models.employee.domain.Address)7 Test (org.junit.Test)7 BigDecimal (java.math.BigDecimal)6