use of org.datanucleus.samples.validation.ValidatedPerson in project tests by datanucleus.
the class BeanValidationTest method testNotNull.
/**
* Test for not null annotation.
*/
public void testNotNull() {
Properties userProps = new Properties();
userProps.setProperty(PropertyNames.PROPERTY_VALIDATION_MODE, "auto");
PersistenceManagerFactory validationPMF = getPMF(1, userProps);
try {
PersistenceManager pm = validationPMF.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ValidatedPerson p1 = new ValidatedPerson("John", null);
pm.makePersistent(p1);
tx.commit();
fail("Should have thrown validation exception on persist but didnt");
} catch (ConstraintViolationException cve) {
// expected
LOG.info("Exception correctly thrown : " + cve.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
}
}
use of org.datanucleus.samples.validation.ValidatedPerson in project tests by datanucleus.
the class BeanValidationTest method testInsertSize.
public void testInsertSize() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ValidatedPerson p1 = new ValidatedPerson(1, "Fred", "Smith");
p1.setLogin("012345678901");
em.persist(p1);
tx.commit();
fail("Should have thrown ConstraintViolationException");
} catch (ConstraintViolationException cve) {
// Expected
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ValidatedPerson.class);
}
}
use of org.datanucleus.samples.validation.ValidatedPerson in project tests by datanucleus.
the class BeanValidationTest method testInsertNotNull.
public void testInsertNotNull() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ValidatedPerson p1 = new ValidatedPerson(1, "Fred", null);
em.persist(p1);
tx.commit();
fail("Should have thrown ConstraintViolationException");
} catch (ConstraintViolationException cve) {
// Expected
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ValidatedPerson.class);
}
}
use of org.datanucleus.samples.validation.ValidatedPerson in project tests by datanucleus.
the class BeanValidationTest method testUpdateNotNull.
public void testUpdateNotNull() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
ValidatedPerson p1 = new ValidatedPerson(1, "Fred", "Smith");
em.persist(p1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
em = getEM();
tx = em.getTransaction();
try {
tx.begin();
ValidatedPerson p1 = (ValidatedPerson) em.find(ValidatedPerson.class, new Long(1));
p1.setSurname(null);
tx.commit();
fail("Should have thrown a ConstraintViolationException on update");
} catch (ConstraintViolationException cve) {
// Expected
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(ValidatedPerson.class);
}
}
use of org.datanucleus.samples.validation.ValidatedPerson in project tests by datanucleus.
the class BeanValidationTest method testSize.
/**
* Test for @Size annotation.
*/
public void testSize() {
Properties userProps = new Properties();
userProps.setProperty(PropertyNames.PROPERTY_VALIDATION_MODE, "auto");
PersistenceManagerFactory validationPMF = getPMF(1, userProps);
try {
PersistenceManager pm = validationPMF.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ValidatedPerson p1 = new ValidatedPerson("John", "Smith");
p1.setLogin("12345678901");
LOG.info(">> Calling persist");
pm.makePersistent(p1);
tx.commit();
fail("Should have thrown validation exception on persist but didnt");
} catch (ConstraintViolationException cve) {
// expected
LOG.info("Exception correctly thrown : " + cve.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
}
}
Aggregations