1 package dst.ass1.jpa.tests;
3 import static org.hamcrest.Matchers.greaterThan;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertThat;
9 import javax.persistence.EntityManager;
10 import javax.persistence.EntityTransaction;
12 import org.junit.Rule;
13 import org.junit.Test;
15 import dst.ass1.jpa.ORMService;
16 import dst.ass1.jpa.model.IMaterial;
18 public class Ass1_3_1Test {
21 public ORMService orm = new ORMService();
24 public void entityListener_prePersistSetsPropertiesCorrectly() throws InterruptedException {
25 Date then = new Date();
28 EntityManager em = orm.getEntityManager();
30 IMaterial material1 = orm.getModelFactory().createMaterial();
32 material1.setUrn("material1");
37 tx = em.getTransaction();
39 em.persist(material1);
43 assertNotNull(material1.getUploaded());
44 assertNotNull(material1.getLastUpdate());
46 assertThat(material1.getUploaded(), greaterThan(then));
47 assertThat(material1.getLastUpdate(), greaterThan(then));
51 public void entityListener_preUpdateSetsPropertiesCorrectly() throws InterruptedException {
52 EntityManager em = orm.getEntityManager();
54 IMaterial material1 = orm.getModelFactory().createMaterial();
56 material1.setUrn("material1");
60 tx = em.getTransaction();
62 em.persist(material1);
66 Date then = new Date();
71 tx = em.getTransaction();
73 material1.setType("sometype");
74 em.persist(material1);
78 assertNotNull(material1.getLastUpdate());
79 assertThat(material1.getLastUpdate(), greaterThan(then));