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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations