Search in sources :

Example 1 with Fault

use of com.sun.ts.lib.harness.EETest.Fault in project tests by datanucleus.

the class Client method postLoadTest.

/*
     * @testName: postLoadTest
     * @assertion_ids:  PERSISTENCE:SPEC:695; PERSISTENCE:SPEC:719;
     *			PERSISTENCE:SPEC:720
     * @test_Strategy:
     */
public void postLoadTest() throws Fault {
    boolean status = false;
    String reason = null;
    String id = postLoadTest;
    try {
        getEntityTransaction().begin();
        product = newProduct(id);
        getEntityManager().persist(product);
        getEntityManager().flush();
        getEntityManager().refresh(product);
        Query q = getEntityManager().createQuery("select distinct p from Product p");
        java.util.List results = q.getResultList();
        // for(int i = 0, n = results.size(); i < n; i++) {
        // 
        // }
        TLogger.log(results.toString());
        if (product.isPostLoadCalled()) {
            reason = "Product: postLoad was called after the query result was returned.";
            TLogger.log(reason);
        } else {
            reason = "Product: postLoad was not called even after the query result was returned.";
            throw new Fault(reason);
        }
        getEntityTransaction().commit();
    } catch (Exception e) {
        TLogger.log("Exception caught during postLoadTest", e);
        throw new Fault(e);
    } finally {
        try {
            if (getEntityTransaction().isActive()) {
                getEntityTransaction().rollback();
            }
        } catch (Exception re) {
            TLogger.log("Exception caught while rolling back TX", re);
        }
    }
}
Also used : List(java.util.List) Query(javax.persistence.Query) Fault(com.sun.ts.lib.harness.EETest.Fault)

Example 2 with Fault

use of com.sun.ts.lib.harness.EETest.Fault in project tests by datanucleus.

the class Client method prePersistRuntimeExceptionTest.

/*
     * @testName: prePersistRuntimeExceptionTest
     * @assertion_ids:  PERSISTENCE:SPEC:695; PERSISTENCE:SPEC:704
     * @test_Strategy:
     */
public void prePersistRuntimeExceptionTest() throws Fault {
    String id = prePersistRuntimeExceptionTest;
    try {
        getEntityTransaction().begin();
        product = newProduct(id);
        txShouldRollback(product, id);
    } catch (Exception e) {
        TLogger.log("Exception caught during prePersistRuntimeExceptionTest", e);
        throw new Fault(e);
    } finally {
        try {
            if (getEntityTransaction().isActive()) {
                getEntityTransaction().rollback();
            }
        } catch (Exception re) {
            TLogger.log("Exception caught while rolling back TX", re);
        }
    }
}
Also used : Fault(com.sun.ts.lib.harness.EETest.Fault)

Example 3 with Fault

use of com.sun.ts.lib.harness.EETest.Fault in project tests by datanucleus.

the class Client method preRemoveCascadeTest.

/*
     * @testName: preRemoveCascadeTest
     * @assertion_ids:  PERSISTENCE:SPEC:695; PERSISTENCE:SPEC:708
     * @test_Strategy:
     */
public void preRemoveCascadeTest() throws Fault {
    boolean status = false;
    String reason = null;
    String id = preRemoveCascadeTest;
    try {
        getEntityTransaction().begin();
        order = newOrder(id);
        product = newProduct(id);
        lineItem = newLineItem(id);
        lineItem.setOrder(order);
        lineItem.setProduct(product);
        order.addLineItem(lineItem);
        getEntityManager().persist(product);
        getEntityManager().persist(order);
        getEntityManager().remove(order);
        boolean b = order.isPreRemoveCalled();
        order = null;
        if (b) {
            reason = "Order: preRemove was called.";
            TLogger.log(reason);
        } else {
            reason = "Order: preRemove was not called.";
            throw new Fault(reason);
        }
        if (lineItem.isPrePersistCalled()) {
            reason = "LineItem: preRemove was called.";
            TLogger.log(reason);
        } else {
            reason = "LineItem: preRemove was not called.";
            throw new Fault(reason);
        }
        getEntityTransaction().commit();
    } catch (Exception e) {
        TLogger.log("Exception caught during preRemoveCascadeTest", e);
        throw new Fault(e);
    } finally {
        try {
            if (getEntityTransaction().isActive()) {
                getEntityTransaction().rollback();
            }
        } catch (Exception re) {
            TLogger.log("Exception caught while rolling back TX", re);
        }
    }
}
Also used : Fault(com.sun.ts.lib.harness.EETest.Fault)

Example 4 with Fault

use of com.sun.ts.lib.harness.EETest.Fault in project tests by datanucleus.

the class Client method preRemoveMultiCascadeTest.

/*
     * @testName: preRemoveMultiCascadeTest
     * @assertion_ids:  PERSISTENCE:SPEC:694; PERSISTENCE:SPEC:708;
     *			PERSISTENCE:SPEC:722; PERSISTENCE:SPEC:726;
     *			PERSISTENCE:SPEC:727
     * @test_Strategy:
     */
public void preRemoveMultiCascadeTest() throws Fault {
    boolean status = false;
    String reason = null;
    String id = preRemoveMultiCascadeTest;
    try {
        getEntityTransaction().begin();
        order = newOrder(id);
        product = newProduct(id);
        lineItem = newLineItem(id);
        lineItem.setOrder(order);
        lineItem.setProduct(product);
        order.addLineItem(lineItem);
        getEntityManager().persist(product);
        getEntityManager().persist(order);
        getEntityManager().remove(order);
        boolean b = order.isPreRemoveCalled();
        List actual = order.getPreRemoveCalls();
        Helper.compareResultList(LISTENER_ABC, actual);
        actual = lineItem.getPreRemoveCalls();
        Helper.compareResultList(LISTENER_BC, actual);
        order = null;
        getEntityTransaction().commit();
    } catch (Exception e) {
        TLogger.log("Exception caught during preRemoveMultiCascadeTest", e);
        throw new Fault(e);
    } finally {
        try {
            if (getEntityTransaction().isActive()) {
                getEntityTransaction().rollback();
            }
        } catch (Exception re) {
            TLogger.log("Exception caught while rolling back TX", re);
        }
    }
}
Also used : List(java.util.List) Fault(com.sun.ts.lib.harness.EETest.Fault)

Example 5 with Fault

use of com.sun.ts.lib.harness.EETest.Fault in project tests by datanucleus.

the class Client method prePersistMultiCascadeTest.

/*
     * @testName: prePersistMultiCascadeTest
     * @assertion_ids:  PERSISTENCE:SPEC:694; PERSISTENCE:SPEC:697;
     *			PERSISTENCE:SPEC:708; PERSISTENCE:JAVADOC:34;
     *			PERSISTENCE:SPEC:723; PERSISTENCE:SPEC:724;
     * @test_Strategy:
     */
public void prePersistMultiCascadeTest() throws Fault {
    boolean status = false;
    String reason = null;
    String id = prePersistMultiCascadeTest;
    try {
        getEntityTransaction().begin();
        order = newOrder(id);
        product = newProduct(id);
        lineItem = newLineItem(id);
        lineItem.setOrder(order);
        lineItem.setProduct(product);
        order.addLineItem(lineItem);
        getEntityManager().persist(product);
        getEntityManager().persist(order);
        List actual = order.getPrePersistCalls();
        Helper.compareResultList(LISTENER_ABC, actual);
        actual = lineItem.getPrePersistCalls();
        Helper.compareResultList(LISTENER_BC, actual);
        getEntityTransaction().commit();
    } catch (Exception e) {
        throw new Fault(e);
    } finally {
        try {
            if (getEntityTransaction().isActive()) {
                getEntityTransaction().rollback();
            }
        } catch (Exception re) {
            TLogger.log("Exception caught while rolling back TX", re);
        }
    }
}
Also used : List(java.util.List) Fault(com.sun.ts.lib.harness.EETest.Fault)

Aggregations

Fault (com.sun.ts.lib.harness.EETest.Fault)328 Vector (java.util.Vector)54 List (java.util.List)45 Collection (java.util.Collection)39 TransactionRequiredException (javax.persistence.TransactionRequiredException)24 Query (javax.persistence.Query)23 Iterator (java.util.Iterator)22 NoResultException (javax.persistence.NoResultException)21 NonUniqueResultException (javax.persistence.NonUniqueResultException)21 PersistenceException (javax.persistence.PersistenceException)21 ArrayList (java.util.ArrayList)19 EntityNotFoundException (javax.persistence.EntityNotFoundException)18 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 com.sun.ts.lib.util (com.sun.ts.lib.util)1 Grade (com.sun.ts.tests.ejb30.persistence.types.common.Grade)1 BigInteger (java.math.BigInteger)1 java.util (java.util)1 Calendar (java.util.Calendar)1