diff --git a/src/main/webapp/main.html b/src/main/webapp/main.html
index c2e28f18e86ede920b9b3bdb675f343473452886..ad5683d41f51cbfe481535d1e7abdc6bb82b521c 100644
--- a/src/main/webapp/main.html
+++ b/src/main/webapp/main.html
@@ -1,50 +1,57 @@
-
+
-DAA Example
+ DAA Example
-
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+ var view = new PeopleView(new PeopleDAO(),
+ 'people-container', 'people-container'
+ );
+
+ view.init();
+ });
+
\ No newline at end of file
diff --git a/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java b/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java
index f5ec5a689c0746746de9b8345f8fee0a408acdf5..ebdc71758227b286765c3dabafd080ea5107ca06 100644
--- a/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java
+++ b/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java
@@ -69,14 +69,15 @@ public class PetsResourceTest extends JerseyTest {
config.property("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE);
}
- //@Test
+ @Test
public void testList() throws IOException {
final Response response = target("pets").request()
.header("Authorization", "Basic " + userToken(adminLogin()))
.get();
assertThat(response, hasOkStatus());
- final List pets = response.readEntity(new GenericType>(){});
+ final List pets = response.readEntity(new GenericType>() {
+ });
assertThat(pets, containsPetsInAnyOrder(pets()));
}
diff --git a/src/test/java/es/uvigo/esei/daa/rest/PetsResourceUnitTest.java b/src/test/java/es/uvigo/esei/daa/rest/PetsResourceUnitTest.java
index 1aeda5600e23edea4b9542bd78ecdeeacc81228c..1219e9bcb1a5d5cfebe01637f0a491cc0693e15f 100644
--- a/src/test/java/es/uvigo/esei/daa/rest/PetsResourceUnitTest.java
+++ b/src/test/java/es/uvigo/esei/daa/rest/PetsResourceUnitTest.java
@@ -1,18 +1,25 @@
package es.uvigo.esei.daa.rest;
+import es.uvigo.esei.daa.dao.DAOException;
import es.uvigo.esei.daa.dao.PetsDAO;
import es.uvigo.esei.daa.entities.Pet;
+import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.core.Response;
+import java.util.List;
-import static es.uvigo.esei.daa.dataset.PetsDataset.existentPet;
-import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasOkStatus;
+import static es.uvigo.esei.daa.dataset.PeopleDataset.newName;
+import static es.uvigo.esei.daa.dataset.PetsDataset.*;
+import static es.uvigo.esei.daa.matchers.HasHttpStatus.*;
+import static es.uvigo.esei.daa.matchers.IsEqualToPet.containsPetsInAnyOrder;
import static es.uvigo.esei.daa.matchers.IsEqualToPet.equalsToPet;
+import static java.util.Arrays.asList;
import static org.easymock.EasyMock.*;
import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class PetsResourceUnitTest {
@@ -51,5 +58,142 @@ public class PetsResourceUnitTest {
assertThat((Pet) response.getEntity(), is(equalsToPet(pet)));
}
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testList() throws Exception {
+ final List people = asList(pets());
+
+ expect(daoMock.list()).andReturn(people);
+
+ replay(daoMock);
+
+ final Response response = resource.list();
+
+ assertThat(response, hasOkStatus());
+ assertThat((List) response.getEntity(), containsPetsInAnyOrder(pets()));
+ }
+
+
+ @Test
+ public void testListDAOException() throws Exception {
+ expect(daoMock.list()).andThrow(new DAOException());
+
+ replay(daoMock);
+
+ final Response response = resource.list();
+
+ assertThat(response, hasInternalServerErrorStatus());
+ }
+
+
+ @Test
+ public void testGetDAOException() throws Exception {
+ expect(daoMock.get(anyInt())).andThrow(new DAOException());
+
+ replay(daoMock);
+ final Response response = resource.get(existentId());
+
+ assertThat(response, hasInternalServerErrorStatus());
+ }
+
+ @Test
+ public void testGetIllegalArgumentException() throws Exception {
+ expect(daoMock.get(anyInt())).andThrow(new IllegalArgumentException());
+
+ replay(daoMock);
+
+ final Response response = resource.get(existentId());
+
+ assertThat(response, hasBadRequestStatus());
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ daoMock.delete(anyInt());
+
+ replay(daoMock);
+
+ final Response response = resource.delete(1);
+
+ assertThat(response, hasOkStatus());
+ }
+
+ @Test
+ public void testDeleteDAOException() throws Exception {
+ daoMock.delete(anyInt());
+ expectLastCall().andThrow(new DAOException());
+
+ replay(daoMock);
+
+ final Response response = resource.delete(1);
+
+ assertThat(response, hasInternalServerErrorStatus());
+ }
+
+ @Test
+ public void testDeleteIllegalArgumentException() throws Exception {
+ daoMock.delete(anyInt());
+ expectLastCall().andThrow(new IllegalArgumentException());
+ replay(daoMock);
+
+ final Response response = resource.delete(1);
+
+ assertThat(response, hasBadRequestStatus());
+ }
+
+
+ // @Test
+ public void testModify() throws Exception {
+ final Pet pet = existentPet();
+ pet.setName(newName());
+ pet.setOwner(newOwner());
+
+ daoMock.modify(pet);
+
+ replay(daoMock);
+
+ final Response response = resource.modify(
+ pet.getId(), pet.getName(), pet.getOwner());
+
+ assertThat(response, hasOkStatus());
+ assertEquals(pet, response.getEntity());
+ }
+
+
+ @Test
+ public void testAdd() throws Exception {
+ expect(daoMock.add(newName(), newOwner()))
+ .andReturn(newPet());
+ replay(daoMock);
+
+
+ final Response response = resource.add(newName(), newOwner());
+
+ assertThat(response, hasOkStatus());
+ assertThat((Pet) response.getEntity(), CoreMatchers.is(equalsToPet(newPet())));
+ }
+
+
+ @Test
+ public void testAddDAOException() throws Exception {
+ expect(daoMock.add(anyString(), anyInt()))
+ .andThrow(new DAOException());
+ replay(daoMock);
+
+ final Response response = resource.add(newName(), newOwner());
+
+ assertThat(response, hasInternalServerErrorStatus());
+ }
+
+ @Test
+ public void testAddIllegalArgumentException() throws Exception {
+ expect(daoMock.add(anyString(), anyInt()))
+ .andThrow(new IllegalArgumentException());
+ replay(daoMock);
+
+ final Response response = resource.add(newName(), newOwner());
+
+ assertThat(response, hasBadRequestStatus());
+ }
}