1 package dst.ass1.jpa.examples;
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.hamcrest.CoreMatchers.notNullValue;
5 import static org.junit.Assert.assertThat;
9 import javax.persistence.EntityManager;
11 import org.junit.ClassRule;
12 import org.junit.FixMethodOrder;
13 import org.junit.Test;
14 import org.junit.runners.MethodSorters;
16 import dst.ass1.jpa.ORMService;
17 import dst.ass1.jpa.dao.ICoursePlatformDAO;
18 import dst.ass1.jpa.dao.IDAOFactory;
19 import dst.ass1.jpa.model.ICoursePlatform;
20 import dst.ass1.jpa.model.IModelFactory;
23 * This test has no test fixture and dependencies between tests. This is possible by declaring {@link ORMService} as a
24 * static class-level rule via {@link ClassRule}.
26 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
27 public class ExampleTestWithDependencies {
30 public static ORMService orm = new ORMService();
33 public void t01_insert() throws Exception {
34 EntityManager em = orm.getEntityManager();
35 IModelFactory modelFactory = orm.getModelFactory();
37 ICoursePlatform cp1 = modelFactory.createCoursePlatform();
39 cp1.setUrl("http://cp1.example");
41 ICoursePlatform cp2 = modelFactory.createCoursePlatform();
43 cp2.setUrl("http://cp1.example");
48 em.getTransaction().begin();
50 em.getTransaction().commit();
52 assertThat(cp1.getId(), notNullValue());
53 assertThat(cp2.getId(), notNullValue());
57 public void t02_query() throws Exception {
58 IDAOFactory daoFactory = orm.getDaoFactory();
59 ICoursePlatformDAO coursePlatformDAO = daoFactory.createCoursePlatformDAO();
61 List<ICoursePlatform> all = coursePlatformDAO.findAll();
63 assertThat(all.isEmpty(), is(false));
64 assertThat(all.size(), is(2));
66 System.out.println(all);