Search in sources :

Example 1 with Item

use of org.jpwh.model.complexschemas.custom.Item in project microservices by pwillhan.

the class CustomSchema method storeLoadCheckSingleRowInvalid.

@Test(expectedExceptions = org.hibernate.exception.ConstraintViolationException.class)
public void storeLoadCheckSingleRowInvalid() throws Throwable {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        // Wrong start/end time
        Item item = new Item("Some Item", CalendarUtil.TOMORROW.getTime(), CalendarUtil.TODAY.getTime());
        em.persist(item);
        try {
            em.flush();
        } catch (Exception ex) {
            throw unwrapCauseOfType(ex, org.hibernate.exception.ConstraintViolationException.class);
        }
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.complexschemas.custom.Item) EntityManager(javax.persistence.EntityManager) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 2 with Item

use of org.jpwh.model.complexschemas.custom.Item in project microservices by pwillhan.

the class CustomSchema method storeLoadCheckSubselectValid.

@Test(expectedExceptions = org.hibernate.exception.ConstraintViolationException.class)
public void storeLoadCheckSubselectValid() throws Throwable {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        Item item = new Item("Some Item", CalendarUtil.TODAY.getTime(), CalendarUtil.TOMORROW.getTime());
        Bid bid = new Bid(new BigDecimal(1), item);
        // Out of date range of auction
        bid.setCreatedOn(CalendarUtil.AFTER_TOMORROW.getTime());
        item.getBids().add(bid);
        em.persist(item);
        em.persist(bid);
        try {
            em.flush();
        } catch (Exception ex) {
            throw unwrapCauseOfType(ex, org.hibernate.exception.ConstraintViolationException.class);
        }
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) Item(org.jpwh.model.complexschemas.custom.Item) EntityManager(javax.persistence.EntityManager) Bid(org.jpwh.model.complexschemas.custom.Bid) BigDecimal(java.math.BigDecimal) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)2 UserTransaction (javax.transaction.UserTransaction)2 JPATest (org.jpwh.env.JPATest)2 Item (org.jpwh.model.complexschemas.custom.Item)2 Test (org.testng.annotations.Test)2 BigDecimal (java.math.BigDecimal)1 Bid (org.jpwh.model.complexschemas.custom.Bid)1