Search in sources :

Example 1 with User

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

the class CustomSchema method storeLoadDomainInvalid.

// All these tests are testing for failure
@Test(expectedExceptions = org.hibernate.exception.ConstraintViolationException.class)
public void storeLoadDomainInvalid() throws Throwable {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        // This will fail and therefore validate that we actually
        // have a custom SQL datatype in the DDL
        User user = new User();
        user.setEmail("@invalid.address");
        user.setUsername("someuser");
        em.persist(user);
        try {
            em.flush();
        } catch (Exception ex) {
            throw unwrapCauseOfType(ex, org.hibernate.exception.ConstraintViolationException.class);
        }
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.complexschemas.custom.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 2 with User

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

the class CustomSchema method storeLoadCheckColumnInvalid.

@Test(expectedExceptions = org.hibernate.exception.ConstraintViolationException.class)
public void storeLoadCheckColumnInvalid() throws Throwable {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        User user = new User();
        user.setEmail("valid@test.com");
        user.setUsername("adminPretender");
        em.persist(user);
        try {
            em.flush();
        } catch (Exception ex) {
            throw unwrapCauseOfType(ex, org.hibernate.exception.ConstraintViolationException.class);
        }
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.complexschemas.custom.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 3 with User

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

the class CustomSchema method storeLoadValid.

// The control
@Test
public void storeLoadValid() throws Exception {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        User user = new User();
        user.setEmail("valid@test.com");
        user.setUsername("someuser");
        em.persist(user);
        user = new User();
        user.setEmail("valid2@test.com");
        user.setUsername("otheruser");
        em.persist(user);
        tx.commit();
        em.close();
        tx.begin();
        em = JPA.createEntityManager();
        user = em.find(User.class, user.getId());
        assertEquals(user.getUsername(), "otheruser");
        tx.commit();
        em.close();
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.complexschemas.custom.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Example 4 with User

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

the class CustomSchema method storeLoadUniqueMultiColumnValid.

@Test(expectedExceptions = org.hibernate.exception.ConstraintViolationException.class)
public void storeLoadUniqueMultiColumnValid() throws Throwable {
    UserTransaction tx = TM.getUserTransaction();
    try {
        tx.begin();
        EntityManager em = JPA.createEntityManager();
        User user = new User();
        user.setEmail("valid@test.com");
        user.setUsername("someuser");
        em.persist(user);
        user = new User();
        user.setEmail("valid@test.com");
        user.setUsername("someuser");
        em.persist(user);
        try {
            em.flush();
        } catch (Exception ex) {
            throw unwrapCauseOfType(ex, org.hibernate.exception.ConstraintViolationException.class);
        }
    } finally {
        TM.rollback();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) EntityManager(javax.persistence.EntityManager) User(org.jpwh.model.complexschemas.custom.User) JPATest(org.jpwh.env.JPATest) Test(org.testng.annotations.Test)

Aggregations

EntityManager (javax.persistence.EntityManager)4 UserTransaction (javax.transaction.UserTransaction)4 JPATest (org.jpwh.env.JPATest)4 User (org.jpwh.model.complexschemas.custom.User)4 Test (org.testng.annotations.Test)4