1 package dst.ass1.jpa.tests;
3 import static org.hamcrest.CoreMatchers.isA;
4 import static org.junit.Assert.assertFalse;
6 import java.sql.SQLException;
8 import javax.persistence.PersistenceException;
10 import org.hibernate.PropertyValueException;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.ExpectedException;
15 import dst.ass1.jpa.ORMService;
16 import dst.ass1.jpa.model.IParticipant;
17 import dst.ass1.jpa.util.Constants;
20 * Tests the constraint for IParticipant email.
22 public class Ass1_1_2_02Test {
25 public ORMService orm = new ORMService();
28 public ExpectedException expectedException = ExpectedException.none();
31 public void testUniqueConstraint() {
32 new UniqueConstraintTester<>(() -> orm.getModelFactory().createParticipant(), e -> e.setEmail("unique@example.com"))
33 .run(orm.getEntityManager());
37 public void testNotNullConstraint() {
38 expectedException.expect(PersistenceException.class);
39 expectedException.expectCause(isA(PropertyValueException.class));
40 expectedException.expectMessage("not-null property");
42 IParticipant e1 = orm.getModelFactory().createParticipant();
44 orm.em().getTransaction().begin();
50 public void testPersonEmailNotNullConstraintJdbc() throws SQLException {
51 assertFalse(orm.getDatabaseGateway().isNullable(Constants.T_PARTICIPANT, Constants.M_PERSON_EMAIL));