diff --git a/backend/configuration.yml b/backend/configuration.yml index 95f962e..35f86dc 100644 --- a/backend/configuration.yml +++ b/backend/configuration.yml @@ -12,5 +12,9 @@ database: server: rootPath: /api/ + requestLog: + appenders: + - type: console + queueSize: 2048 adminPassword: "testPassword" \ No newline at end of file diff --git a/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java b/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java index 9a20ffb..e5d3aab 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/core/Tutor.java @@ -37,9 +37,4 @@ public class Tutor extends BaseEntity implements Serializable { inverseJoinColumns = { @JoinColumn(name = "observation_id")} ) private Set observations; - - public Tutor(long id, String name) { - super(id); - this.name = name; - } } diff --git a/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java b/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java index 8e1fd7b..d57d587 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java @@ -16,7 +16,7 @@ public class TutorDao extends AbstractDAO { } public List listAll(){ - return list(criteriaQuery()); + return currentSession().createQuery("from Tutor", Tutor.class).list(); } public Tutor persist(Tutor tutor){ diff --git a/backend/src/test/java/uk/co/neviyn/Observations/dao/DaoTestBase.java b/backend/src/test/java/uk/co/neviyn/Observations/dao/DaoTestBase.java new file mode 100644 index 0000000..5135cd3 --- /dev/null +++ b/backend/src/test/java/uk/co/neviyn/Observations/dao/DaoTestBase.java @@ -0,0 +1,12 @@ +package uk.co.neviyn.Observations.dao; + +import io.dropwizard.testing.junit.DAOTestRule; +import org.junit.Rule; +import uk.co.neviyn.Observations.core.Observation; +import uk.co.neviyn.Observations.core.Site; +import uk.co.neviyn.Observations.core.Tutor; + +public abstract class DaoTestBase { + @Rule + public DAOTestRule testRule = DAOTestRule.newBuilder().addEntityClass(Observation.class).addEntityClass(Site.class).addEntityClass(Tutor.class).build(); +} diff --git a/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java b/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java index ba6370a..d3ee4c1 100644 --- a/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java +++ b/backend/src/test/java/uk/co/neviyn/Observations/dao/ObservationDaoTest.java @@ -15,10 +15,7 @@ import java.util.List; import static org.junit.Assert.*; -public class ObservationDaoTest { - - @Rule - public DAOTestRule testRule = DAOTestRule.newBuilder().addEntityClass(Observation.class).addEntityClass(Site.class).addEntityClass(Tutor.class).build(); +public class ObservationDaoTest extends DaoTestBase { private ObservationDao dao; private SiteDao siteDao; @@ -41,6 +38,7 @@ public class ObservationDaoTest { Observation insert = testRule.inTransaction(() -> dao.persist(observation)); assertNotNull(insert); assertTrue(insert.getId() > 0); + assertNotNull(dao.get(insert.getId())); } @Test @@ -57,6 +55,13 @@ public class ObservationDaoTest { assertEquals(numberOfObservations, observations.size()); } + @Test + public void listAllWithNoObservations() { + List observations = dao.listAll(); + assertNotNull(observations); + assertEquals(0, observations.size()); + } + @Test public void averageStatsForAll() { Observation otherEntry = SerializationUtils.clone(observation); diff --git a/backend/src/test/java/uk/co/neviyn/Observations/dao/SiteDaoTest.java b/backend/src/test/java/uk/co/neviyn/Observations/dao/SiteDaoTest.java new file mode 100644 index 0000000..edfc777 --- /dev/null +++ b/backend/src/test/java/uk/co/neviyn/Observations/dao/SiteDaoTest.java @@ -0,0 +1,45 @@ +package uk.co.neviyn.Observations.dao; + +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import uk.co.neviyn.Observations.core.Site; + +import static org.junit.Assert.*; + +public class SiteDaoTest extends DaoTestBase{ + + private SiteDao dao; + + @Before + public void setUp() { + dao = new SiteDao(testRule.getSessionFactory()); + } + + @Test + public void listAll() { + testRule.inTransaction(() -> { + dao.persist(new Site("Site A")); + dao.persist(new Site("Site B")); + dao.persist(new Site("Site C")); + }); + List result = dao.listAll(); + assertNotNull(result); + assertEquals(3, result.size()); + } + + @Test + public void listAllWithNoObservations() { + List sites = dao.listAll(); + assertNotNull(sites); + assertEquals(0, sites.size()); + } + + @Test + public void persistAndGet() { + Site insert = testRule.inTransaction(() -> dao.persist(new Site("Test Site"))); + assertNotNull(insert); + assertTrue(insert.getId() > 0); + assertNotNull(dao.get(insert.getId())); + } +} \ No newline at end of file diff --git a/backend/src/test/java/uk/co/neviyn/Observations/dao/TutorDaoTest.java b/backend/src/test/java/uk/co/neviyn/Observations/dao/TutorDaoTest.java new file mode 100644 index 0000000..461eca6 --- /dev/null +++ b/backend/src/test/java/uk/co/neviyn/Observations/dao/TutorDaoTest.java @@ -0,0 +1,51 @@ +package uk.co.neviyn.Observations.dao; + +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import uk.co.neviyn.Observations.core.Observation; +import uk.co.neviyn.Observations.core.Site; +import uk.co.neviyn.Observations.core.Tutor; + +import static org.junit.Assert.*; + +public class TutorDaoTest extends DaoTestBase{ + + private TutorDao dao; + private SiteDao siteDao; + private final Site site = new Site("Test site"); + + @Before + public void setUp() { + dao = new TutorDao(testRule.getSessionFactory()); + siteDao = new SiteDao(testRule.getSessionFactory()); + testRule.inTransaction(() -> siteDao.persist(site)); + } + + @Test + public void listAll() { + testRule.inTransaction(() -> { + dao.persist(new Tutor("Mr Test", site, null)); + dao.persist(new Tutor("Mr Test2", site, null)); + dao.persist(new Tutor("Mr Test3", site, null)); + }); + List result = dao.listAll(); + assertNotNull(result); + assertEquals(3, result.size()); + } + + @Test + public void listAllWithNoObservations() { + List tutors = dao.listAll(); + assertNotNull(tutors); + assertEquals(0, tutors.size()); + } + + @Test + public void persistAndGet() { + Tutor insert = testRule.inTransaction(() -> dao.persist(new Tutor("Mr Test", site, null))); + assertNotNull(insert); + assertTrue(insert.getId() > 0); + assertNotNull(dao.get(insert.getId())); + } +} \ No newline at end of file