From 10d86e0e5c5cc3c1390c80dee24a6a5a93b2d7f5 Mon Sep 17 00:00:00 2001 From: Iria19 <72555396+Iria19@users.noreply.github.com> Date: Fri, 2 Apr 2021 22:33:31 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adidos=20los=20test=20de=20Pet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contiene los test de Pet --- README.md | 71 +++- .../java/es/uvigo/esei/daa/dao/PetsDAO.java | 4 +- .../java/es/uvigo/esei/daa/entities/Pet.java | 3 +- .../es/uvigo/esei/daa/rest/PetsResource.java | 14 +- src/main/webapp/js/view/pets.js | 32 +- .../uvigo/esei/daa/dataset/PetsDataset.java | 83 +++++ .../uvigo/esei/daa/entities/PetUnitTest.java | 103 ++++++ .../esei/daa/filters/AuthorizationFilter.java | 2 +- .../uvigo/esei/daa/matchers/IsEqualToPet.java | 59 ++++ .../uvigo/esei/daa/rest/PetsResourceTest.java | 319 ++++++++++++++++++ src/test/resources/datasets/dataset-add.xml | 12 + .../resources/datasets/dataset-addPet.xml | 31 ++ .../resources/datasets/dataset-delete.xml | 12 + .../resources/datasets/dataset-deletePet.xml | 29 ++ .../resources/datasets/dataset-modify.xml | 11 + .../resources/datasets/dataset-modifyPet.xml | 29 ++ src/test/resources/datasets/dataset.dtd | 9 +- src/test/resources/datasets/dataset.xml | 12 + src/test/resources/db/hsqldb-drop.sql | 5 +- src/test/resources/db/hsqldb.sql | 10 + src/test/webapp/rest/pets/add.html | 132 ++++++++ src/test/webapp/rest/pets/addNoFood.html | 107 ++++++ src/test/webapp/rest/pets/addNoName.html | 107 ++++++ src/test/webapp/rest/pets/delete.html | 77 +++++ .../webapp/rest/pets/deleteInvalidId.html | 77 +++++ src/test/webapp/rest/pets/get.html | 96 ++++++ src/test/webapp/rest/pets/list.html | 96 ++++++ src/test/webapp/rest/pets/modify.html | 132 ++++++++ .../webapp/rest/pets/modifyInvalidId.html | 107 ++++++ src/test/webapp/rest/pets/modifyNoFood.html | 107 ++++++ src/test/webapp/rest/pets/modifyNoId.html | 107 ++++++ src/test/webapp/rest/pets/modifyNoName.html | 107 ++++++ src/test/webapp/rest/pets/rest.html | 24 ++ src/test/webapp/web/pets/add.html | 71 ++++ src/test/webapp/web/pets/delete.html | 76 +++++ src/test/webapp/web/pets/edit.html | 82 +++++ src/test/webapp/web/pets/example.html | 17 + src/test/webapp/web/pets/list.html | 46 +++ 38 files changed, 2392 insertions(+), 26 deletions(-) create mode 100644 src/test/java/es/uvigo/esei/daa/dataset/PetsDataset.java create mode 100644 src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java create mode 100644 src/test/java/es/uvigo/esei/daa/matchers/IsEqualToPet.java create mode 100644 src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java create mode 100644 src/test/resources/datasets/dataset-addPet.xml create mode 100644 src/test/resources/datasets/dataset-deletePet.xml create mode 100644 src/test/resources/datasets/dataset-modifyPet.xml create mode 100644 src/test/webapp/rest/pets/add.html create mode 100644 src/test/webapp/rest/pets/addNoFood.html create mode 100644 src/test/webapp/rest/pets/addNoName.html create mode 100644 src/test/webapp/rest/pets/delete.html create mode 100644 src/test/webapp/rest/pets/deleteInvalidId.html create mode 100644 src/test/webapp/rest/pets/get.html create mode 100644 src/test/webapp/rest/pets/list.html create mode 100644 src/test/webapp/rest/pets/modify.html create mode 100644 src/test/webapp/rest/pets/modifyInvalidId.html create mode 100644 src/test/webapp/rest/pets/modifyNoFood.html create mode 100644 src/test/webapp/rest/pets/modifyNoId.html create mode 100644 src/test/webapp/rest/pets/modifyNoName.html create mode 100644 src/test/webapp/rest/pets/rest.html create mode 100644 src/test/webapp/web/pets/add.html create mode 100644 src/test/webapp/web/pets/delete.html create mode 100644 src/test/webapp/web/pets/edit.html create mode 100644 src/test/webapp/web/pets/example.html create mode 100644 src/test/webapp/web/pets/list.html diff --git a/README.md b/README.md index c6f39c4..ff8f8cd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,69 @@ -# DAAExample - DAAExample +DAAExample +========== + +Aplicación y arquitectura de ejemplo para la asignatura Desarrollo Ágil de +Aplicaciones del Grado en Ingeniería Informática de la Escuela Superior de +Ingeniería Informática de la Universidad de Vigo. + +## Dependencias +Este proyecto está diseñado para ser desarrollado en un entorno con: + +* Maven 3 +* Java 8 +* MySQL 5.7.6+ o 8+ + +Además, se recomienda emplear la última versión de Eclipse IDE for Enterprise +Java Developers. + +## Ejecución con Maven +La configuración de Maven ha sido preparada para permitir varios tipos de +ejecución. + +### Ejecución de la aplicación con Tomcat y MySQL + +El proyecto está configurado para poder ejecutar la aplicación sin tener que +realizar ninguna configuración adicional salvo tener disponible un servidor +MySQL en local. + +Los ficheros del proyecto `db/mysql.sql` y 'db/mysql-with-inserts.sql' contienen +todas las consultas necesarias para crear la base de datos y el usuario +requeridos, con o sin datos de ejemplo, respectivamente. Por lo tanto, podemos +configurar inicialmente la base de datos con cualquiera de los siguientes +comandos (desde la raíz el proyecto): + +* Sin datos: `mysql -u root -p < db/mysql.sql` +* Con datos: `mysql -u root -p < db/mysql-with-inserts.sql` + +Una vez configurada la base de datos podemos lanzar la ejecución con el comando: + +`mvn -Prun -DskipTests=true package cargo:run` + +La aplicación se servirá en la URL local: http://localhost:9080/DAAExample + +Para detener la ejecución podemos utilizar `Ctrl+C`. + +### Ejecución de la aplicación con Tomcat y MySQL con redespliegue automático + +Durante el desarrollo es interesante que la apliación se redespliegue de forma +automática cada vez que se hace un cambio. Para ello podemos utilizar el +siguiente comand: + +`mvn -Prun -DskipTests=true package cargo:start fizzed-watcher:run` + +La aplicación se servirá en la URL local: http://localhost:9080/DAAExample + +Para detener la ejecución podemos utilizar `Ctrl+C`. + +### Construcción con tests de unidad e integración + +En esta construcción se ejecutarán todos los tests relacionados con el backend: + +* **Unidad**: se utilizan para testear las entidades y las capas DAO y REST de +forma aislada. +* **Integración**: se utilizan para testear las capas REST y DAO de forma +integrada. Para este tipo de pruebas se utiliza una base de datos HSQL en +memoria. + +El comando para lanzar esta construcción es: + +`mvn install` diff --git a/src/main/java/es/uvigo/esei/daa/dao/PetsDAO.java b/src/main/java/es/uvigo/esei/daa/dao/PetsDAO.java index fe51b01..33feb92 100644 --- a/src/main/java/es/uvigo/esei/daa/dao/PetsDAO.java +++ b/src/main/java/es/uvigo/esei/daa/dao/PetsDAO.java @@ -144,11 +144,12 @@ public class PetsDAO extends DAO { throws DAOException, IllegalArgumentException { if (pet == null) { throw new IllegalArgumentException("pet can't be null"); + } try (Connection conn = this.getConnection()) { final String query = "UPDATE pets SET name=?, food=?, id_person=? WHERE id=?"; - + try (PreparedStatement statement = conn.prepareStatement(query)) { statement.setString(1, pet.getName()); statement.setString(2, pet.getFood()); @@ -160,6 +161,7 @@ public class PetsDAO extends DAO { } } } catch (SQLException e) { + LOG.log(Level.SEVERE, "Error modifying a pet", e); throw new DAOException(); } diff --git a/src/main/java/es/uvigo/esei/daa/entities/Pet.java b/src/main/java/es/uvigo/esei/daa/entities/Pet.java index 961613b..5852afd 100644 --- a/src/main/java/es/uvigo/esei/daa/entities/Pet.java +++ b/src/main/java/es/uvigo/esei/daa/entities/Pet.java @@ -26,6 +26,7 @@ public class Pet { * @param id_person id_person of the pet. */ public Pet(int id, String name, String food, int id_person) { + this.id = id; this.setName(name); this.setFood(food); @@ -95,7 +96,7 @@ public class Pet { * @throws NullPointerException if the {@code id_person} is {@code id_person}. */ public void setId_person(int id_person) { - this.id_person = requireNonNull(id_person, "Id_person can't be null"); + this.id_person = id_person; } @Override diff --git a/src/main/java/es/uvigo/esei/daa/rest/PetsResource.java b/src/main/java/es/uvigo/esei/daa/rest/PetsResource.java index ee97554..0a51b8b 100644 --- a/src/main/java/es/uvigo/esei/daa/rest/PetsResource.java +++ b/src/main/java/es/uvigo/esei/daa/rest/PetsResource.java @@ -123,9 +123,12 @@ public class PetsResource { @FormParam("name") String name, @FormParam("food") String food, @FormParam("id_person") int id_person - ) { try { + if (id_person <= 0) { + throw new IllegalArgumentException("Invalid id_person"); + } + final Pet newPet = this.dao.add(name, food, id_person); return Response.ok(newPet).build(); @@ -167,13 +170,18 @@ public class PetsResource { ) { try { + System.out.println("El id:"+id); + System.out.println("El nombre"+name); + System.out.println("En food"+food); + System.out.println("En id_person"+id_person); + final Pet modifiedPet = new Pet(id, name, food, id_person); + this.dao.modify(modifiedPet); return Response.ok(modifiedPet).build(); } catch (NullPointerException npe) { - final String message = String.format("Invalid data for peet (name: %s, food: %s, id_person: %d)", name, food); - + final String message = String.format("Invalid data for peet (name: %s, food: %s, id_person: %d)", name, food, id_person); LOG.log(Level.FINE, message); return Response.status(Response.Status.BAD_REQUEST) diff --git a/src/main/webapp/js/view/pets.js b/src/main/webapp/js/view/pets.js index adba2f0..e432e4e 100644 --- a/src/main/webapp/js/view/pets.js +++ b/src/main/webapp/js/view/pets.js @@ -41,6 +41,7 @@ var PetsView = (function() {//creo clase dao.modifyPet(pet, function(pet) { $('#pet-' + pet.id + ' td.name').text(pet.name); + $('#pet-' + pet.id + ' td.id_person').text(pet.id_person); $('#pet-' + pet.id + ' td.food').text(pet.food); self.resetForm(); }, @@ -70,8 +71,8 @@ var PetsView = (function() {//creo clase return { 'id': form.find('input[name="id"]').val(), 'name': form.find('input[name="name"]').val(), - 'food': form.find('input[name="food"]').val(), - 'id_person': form.find('input[name="id_person"]').val() + 'id_person': form.find('input[name="id_person"]').val(), + 'food': form.find('input[name="food"]').val() }; }; @@ -83,8 +84,8 @@ var PetsView = (function() {//creo clase return { 'id': id, 'name': row.find('td.name').text(), - 'food': row.find('td.food').text(), - 'id_person': row.find('td.id_person').text() + 'id_person': row.find('td.id_person').text(), + 'food': row.find('td.food').text() }; } else { @@ -93,15 +94,15 @@ var PetsView = (function() {//creo clase }; this.editPet = function(id) { - var row = $('#pet-' + id); + var pet = self.getPetInRow(id); - if (row !== undefined) { + if (pet !== undefined) { var form = $(formQuery); - form.find('input[name="id"]').val(id); - form.find('input[name="name"]').val(row.find('td.name').text()); - form.find('input[name="food"]').val(row.find('td.food').text()); - form.find('input[name="id_person"]').val(id_person); + form.find('input[name="id"]').val(pet.id); + form.find('input[name="name"]').val(pet.name); + form.find('input[name="id_person"]').val(pet.id_person); + form.find('input[name="food"]').val(pet.food); $('input#btnSubmit').val('Modificar'); } @@ -145,8 +146,9 @@ var PetsView = (function() {//creo clase '\ \ \ - \ - \ + \ + \ + \ \ \ \ @@ -170,10 +172,10 @@ var PetsView = (function() {//creo clase \ \
\ - \ + \
\
\ - \ + \
\
\ \ @@ -187,7 +189,7 @@ var PetsView = (function() {//creo clase var createPetsRow = function(pet) { return '
\ \ - \ + \ \
NombreComidaNombreId_personComida 
' + pet.name + '' + pet.id_person + '' + pet.id_person + '' + pet.food + '\ Editar\ diff --git a/src/test/java/es/uvigo/esei/daa/dataset/PetsDataset.java b/src/test/java/es/uvigo/esei/daa/dataset/PetsDataset.java new file mode 100644 index 0000000..55f700d --- /dev/null +++ b/src/test/java/es/uvigo/esei/daa/dataset/PetsDataset.java @@ -0,0 +1,83 @@ +package es.uvigo.esei.daa.dataset; + +import static java.util.Arrays.binarySearch; +import static java.util.Arrays.stream; + +import java.util.Arrays; +import java.util.function.Predicate; + +import es.uvigo.esei.daa.entities.Pet; + +public final class PetsDataset { + private PetsDataset() {} + + public static Pet[] pets() { + return new Pet[] { + new Pet(1, "Pepe", "Pienso",1), + new Pet(2, "Ali", "Pescado",2), + new Pet(3, "Nico", "Pienso",3), + new Pet(4, "Kiko", "Pienso",4), + new Pet(5, "Blanca", "Atún",7), + new Pet(6, "Copito", "Pienso",6), + new Pet(7, "Perico", "Pienso",7), + new Pet(8, "Shiro", "Carne",8), + new Pet(9, "Pancho", "Pollo",9), + new Pet(10, "Mimi", "Atun",10) + }; + } + + public static Pet[] petsOfOwner(int ownerId) { + return stream(pets()) + .filter(pet -> pet.getId_person() == ownerId) + .toArray(Pet[]::new); + } + + public static Pet[] petsWithout(int ... ids) { + Arrays.sort(ids); + + final Predicate hasValidId = pet -> + binarySearch(ids, pet.getId()) < 0; + + return stream(pets()) + .filter(hasValidId) + .toArray(Pet[]::new); + } + + public static Pet pet(int id) { + return stream(pets()) + .filter(pet -> pet.getId() == id) + .findAny() + .orElseThrow(IllegalArgumentException::new); + } + + public static int existentId() { + return 5; + } + + public static int nonExistentId() { + return 34; + } + + public static Pet existentPet() { + return pet(existentId()); + } + + public static Pet nonExistentPet() { + return new Pet(nonExistentId(), "Jane", "palitos", 18); + } + + public static String newName() { + return "John"; + } + + public static String newFood() { + return "Maiz"; + } + public static int newIdPerson() { + return 7; + } + + public static Pet newPet() { + return new Pet(pets().length + 1, newName(), newFood(),newIdPerson()); + } +} diff --git a/src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java b/src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java new file mode 100644 index 0000000..62a5a42 --- /dev/null +++ b/src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java @@ -0,0 +1,103 @@ +package es.uvigo.esei.daa.entities; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + +public class PetUnitTest { + @Test + public void testPetIntStringString() { + final int id = 1; + final String name = "John"; + final String food = "Maiz"; + final int id_person = 7; + + + final Pet pet = new Pet(id, name, food,id_person); + + assertThat(pet.getId(), is(equalTo(id))); + assertThat(pet.getName(), is(equalTo(name))); + assertThat(pet.getFood(), is(equalTo(food))); + assertThat(pet.getId_person(), is(equalTo(id_person))); + + } + + @Test(expected = NullPointerException.class) + public void testPetIntStringStringNullName() { + new Pet(1, null, "Maiz",7); + } + + @Test(expected = NullPointerException.class) + public void testPetIntStringStringNullFood() { + new Pet(1, "John", null,7); + } + + @Test + public void testSetName() { + final int id = 1; + final String food = "Maiz"; + final int id_person = 7; + + final Pet pet = new Pet(id, "John", food,id_person); + pet.setName("Juan"); + + assertThat(pet.getId(), is(equalTo(id))); + assertThat(pet.getName(), is(equalTo("Juan"))); + assertThat(pet.getFood(), is(equalTo(food))); + assertThat(pet.getId_person(), is(equalTo(id_person))); + + } + + @Test(expected = NullPointerException.class) + public void testSetNullName() { + final Pet pet = new Pet(1, "John", "Maiz",7); + + pet.setName(null); + } + + @Test + public void testSetFood() { + final int id = 1; + final String name = "John"; + final int id_person = 7; + + final Pet pet = new Pet(id, name, "Maiz",id_person); + pet.setFood("Pizza"); + + assertThat(pet.getId(), is(equalTo(id))); + assertThat(pet.getName(), is(equalTo(name))); + assertThat(pet.getFood(), is(equalTo("Pizza"))); + assertThat(pet.getId_person(), is(equalTo(id_person))); + + } + + @Test(expected = NullPointerException.class) + public void testSetNullFood() { + final Pet pet = new Pet(1, "John", "Maiz",7); + + pet.setFood(null); + } + + @Test + public void testEqualsObject() { + final Pet petA = new Pet(1, "Name A", "Food A",7); + final Pet petB = new Pet(1, "Name B", "Food B",7); + + assertTrue(petA.equals(petB)); + } + + @Test + public void testEqualsHashcode() { + EqualsVerifier.forClass(Pet.class) + .withIgnoredFields("name", "food","id_person") + .suppress(Warning.STRICT_INHERITANCE) + .suppress(Warning.NONFINAL_FIELDS) + .verify(); + } +} diff --git a/src/test/java/es/uvigo/esei/daa/filters/AuthorizationFilter.java b/src/test/java/es/uvigo/esei/daa/filters/AuthorizationFilter.java index 40400f7..1e134bc 100644 --- a/src/test/java/es/uvigo/esei/daa/filters/AuthorizationFilter.java +++ b/src/test/java/es/uvigo/esei/daa/filters/AuthorizationFilter.java @@ -31,7 +31,7 @@ import es.uvigo.esei.daa.entities.User; @Priority(Priorities.AUTHENTICATION) public class AuthorizationFilter implements ContainerRequestFilter { // Add here the list of REST paths that an administrator can access. - private final static List ADMIN_PATHS = Arrays.asList("people"); + private final static List ADMIN_PATHS = Arrays.asList("people", "pets"); private final UsersDAO dao; diff --git a/src/test/java/es/uvigo/esei/daa/matchers/IsEqualToPet.java b/src/test/java/es/uvigo/esei/daa/matchers/IsEqualToPet.java new file mode 100644 index 0000000..28de719 --- /dev/null +++ b/src/test/java/es/uvigo/esei/daa/matchers/IsEqualToPet.java @@ -0,0 +1,59 @@ +package es.uvigo.esei.daa.matchers; + +import org.hamcrest.Factory; +import org.hamcrest.Matcher; + +import es.uvigo.esei.daa.entities.Person; +import es.uvigo.esei.daa.entities.Pet; + +public class IsEqualToPet extends IsEqualToEntity { + public IsEqualToPet(Pet entity) { + super(entity); + } + + @Override + protected boolean matchesSafely(Pet actual) { + this.clearDescribeTo(); + + if (actual == null) { + this.addTemplatedDescription("actual", expected.toString()); + return false; + } else { + return checkAttribute("id", Pet::getId, actual) + && checkAttribute("name", Pet::getName, actual) + && checkAttribute("food", Pet::getFood, actual) + && checkAttribute("id_person", Pet::getId_person, actual); + } + } + + /** + * Factory method that creates a new {@link IsEqualToEntity} matcher with + * the provided {@link Person} as the expected value. + * + * @param pet the expected pet. + * @return a new {@link IsEqualToEntity} matcher with the provided + * {@link Person} as the expected value. + */ + @Factory + public static IsEqualToPet equalsToPet(Pet pet) { + return new IsEqualToPet(pet); + } + + /** + * Factory method that returns a new {@link Matcher} that includes several + * {@link IsEqualToPet} matchers, each one using an {@link Person} of the + * provided ones as the expected value. + * + * @param pets the pets to be used as the expected values. + * @return a new {@link Matcher} that includes several + * {@link IsEqualToPet} matchers, each one using an {@link Pet} of the + * provided ones as the expected value. + * @see IsEqualToEntity#containsEntityInAnyOrder(java.util.function.Function, Object...) + */ + @Factory + public static Matcher> containsPetsInAnyOrder(Pet ... petos) { + return containsEntityInAnyOrder(IsEqualToPet::equalsToPet, petos); + } + + +} diff --git a/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java b/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java new file mode 100644 index 0000000..455f316 --- /dev/null +++ b/src/test/java/es/uvigo/esei/daa/rest/PetsResourceTest.java @@ -0,0 +1,319 @@ +package es.uvigo.esei.daa.rest; + +import static es.uvigo.esei.daa.dataset.PeopleDataset.nonExistentId; +import static es.uvigo.esei.daa.dataset.PetsDataset.existentId; +import static es.uvigo.esei.daa.dataset.PetsDataset.existentPet; +import static es.uvigo.esei.daa.dataset.PetsDataset.newFood; +import static es.uvigo.esei.daa.dataset.PetsDataset.newIdPerson; +import static es.uvigo.esei.daa.dataset.PetsDataset.newName; +import static es.uvigo.esei.daa.dataset.PetsDataset.newPet; +import static es.uvigo.esei.daa.dataset.PetsDataset.petsOfOwner; +import static es.uvigo.esei.daa.dataset.UsersDataset.adminLogin; +import static es.uvigo.esei.daa.dataset.UsersDataset.normalLogin; +import static es.uvigo.esei.daa.dataset.UsersDataset.userToken; +import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasBadRequestStatus; +import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasOkStatus; +import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasUnauthorized; +import static es.uvigo.esei.daa.matchers.IsEqualToPet.containsPetsInAnyOrder; +import static es.uvigo.esei.daa.matchers.IsEqualToPet.equalsToPet; +import static javax.ws.rs.client.Entity.entity; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.IOException; +import java.util.List; + +import javax.sql.DataSource; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.client.ClientConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; +import com.github.springtestdbunit.DbUnitTestExecutionListener; +import com.github.springtestdbunit.annotation.DatabaseSetup; +import com.github.springtestdbunit.annotation.ExpectedDatabase; + +import es.uvigo.esei.daa.DAAExampleTestApplication; +import es.uvigo.esei.daa.entities.Pet; +import es.uvigo.esei.daa.listeners.ApplicationContextBinding; +import es.uvigo.esei.daa.listeners.ApplicationContextJndiBindingTestExecutionListener; +import es.uvigo.esei.daa.listeners.DbManagement; +import es.uvigo.esei.daa.listeners.DbManagementTestExecutionListener; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:contexts/mem-context.xml") +@TestExecutionListeners({ + DbUnitTestExecutionListener.class, + DbManagementTestExecutionListener.class, + ApplicationContextJndiBindingTestExecutionListener.class +}) +@ApplicationContextBinding( + jndiUrl = "java:/comp/env/jdbc/daaexample", + type = DataSource.class +) +@DbManagement( + create = "classpath:db/hsqldb.sql", + drop = "classpath:db/hsqldb-drop.sql" +) +@DatabaseSetup("/datasets/dataset.xml") +@ExpectedDatabase("/datasets/dataset.xml") +public class PetsResourceTest extends JerseyTest { + @Override + protected Application configure() { + return new DAAExampleTestApplication(); + } + + @Override + protected void configureClient(ClientConfig config) { + super.configureClient(config); + + // Enables JSON transformation in client + config.register(JacksonJsonProvider.class); + config.property("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE); + } + + @Test + public void testList() throws IOException { + int ownerId = 1; + + final Response response = target("pets") + .queryParam("id_person", ownerId) + .request() + .header("Authorization", "Basic " + userToken(adminLogin())) + .get(); + assertThat(response, hasOkStatus()); + + final List pets = response.readEntity(new GenericType>(){}); + + assertThat(pets, containsPetsInAnyOrder(petsOfOwner(ownerId))); + } + + @Test + public void testListUnauthorized() throws IOException { + final Response response = target("pets").request() + .header("Authorization", "Basic " + userToken(normalLogin())) + .get(); + assertThat(response, hasUnauthorized()); + } + + @Test + public void testGet() throws IOException { + final Response response = target("pets/" + existentId()).request() + .header("Authorization", "Basic " + userToken(adminLogin())) + .get(); + assertThat(response, hasOkStatus()); + + final Pet pet = response.readEntity(Pet.class); + + assertThat(pet, is(equalsToPet(existentPet()))); + } + + @Test + public void testGetUnauthorized() throws IOException { + final Response response = target("pets/" + existentId()).request() + .header("Authorization", "Basic " + userToken(normalLogin())) + .get(); + assertThat(response, hasUnauthorized()); + } + + @Test + public void testGetInvalidId() throws IOException { + final Response response = target("pets/" + nonExistentId()).request() + .header("Authorization", "Basic " + userToken(adminLogin())) + .get(); + + assertThat(response, hasBadRequestStatus()); + } + + @Test + @ExpectedDatabase("/datasets/dataset-addPet.xml") + public void testAdd() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("food", newFood()); + form.param("id_person", Integer.toString(newIdPerson())); + + final Response response = target("pets").request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .post(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + assertThat(response, hasOkStatus()); + + final Pet pet = response.readEntity(Pet.class); + + assertThat(pet, is(equalsToPet(newPet()))); + } + + @Test + public void testAddUnauthorized() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("food", newFood()); + form.param("id_person", newIdPerson()+""); + + final Response response = target("pets").request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(normalLogin())) + .post(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasUnauthorized()); + } + + @Test + public void testAddMissingName() throws IOException { + final Form form = new Form(); + form.param("food", newFood()); + form.param("id_person", newIdPerson()+""); + + final Response response = target("pets").request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .post(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasBadRequestStatus()); + } + + @Test + public void testAddMissingFood() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("id_person", newIdPerson()+""); + + + final Response response = target("pets").request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .post(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasBadRequestStatus()); + } + @Test + public void testAddMissingIdPerson() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("food", newFood()); + + + final Response response = target("pets").request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .post(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasBadRequestStatus()); + } + + @Test + @ExpectedDatabase("/datasets/dataset-modifyPet.xml") + public void testModify() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("food", newFood()); + form.param("id_person", newIdPerson()+""); + + final Response response = target("pets/" + existentId()).request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .put(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + assertThat(response, hasOkStatus()); + + final Pet modifiedPet = response.readEntity(Pet.class); + + final Pet pet = existentPet(); + pet.setName(newName()); + pet.setFood(newFood()); + + assertThat(modifiedPet, is(equalsToPet(pet))); + } + + @Test + public void testModifyUnauthorized() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("food", newFood()); + + final Response response = target("pets/" + existentId()).request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(normalLogin())) + .put(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasUnauthorized()); + } + + @Test + public void testModifyName() throws IOException { + + final Form form = new Form(); + form.param("name", newName()); + + final Response response = target("pets/" + existentId()).request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .put(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + assertThat(response, hasBadRequestStatus()); + + } + + @Test + public void testModifyFood() throws IOException { + final Form form = new Form(); + form.param("food", newFood()); + + final Response response = target("pets/" + existentId()).request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .put(entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasBadRequestStatus()); + } + + @Test + public void testModifyInvalidId() throws IOException { + final Form form = new Form(); + form.param("name", newName()); + form.param("food", newFood()); + form.param("id_person", newIdPerson()+""); + + + final Response response = target("pets/" + nonExistentId()).request(MediaType.APPLICATION_JSON_TYPE) + .header("Authorization", "Basic " + userToken(adminLogin())) + .put(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE)); + + assertThat(response, hasBadRequestStatus()); + } + + + @Test + @ExpectedDatabase("/datasets/dataset-deletePet.xml") + public void testDelete() throws IOException { + final Response response = target("pets/" + existentId()).request() + .header("Authorization", "Basic " + userToken(adminLogin())) + .delete(); + + assertThat(response, hasOkStatus()); + + final Integer deletedId = response.readEntity(Integer.class); + + assertThat(deletedId, is(equalTo(existentId()))); + } + + @Test + public void testDeleteUnauthorized() throws IOException { + final Response response = target("pets/" + existentId()).request() + .header("Authorization", "Basic " + userToken(normalLogin())) + .delete(); + + assertThat(response, hasUnauthorized()); + } + + @Test + public void testDeleteInvalidId() throws IOException { + final Response response = target("pets/" + nonExistentId()).request() + .header("Authorization", "Basic " + userToken(adminLogin())) + .delete(); + + assertThat(response, hasBadRequestStatus()); + } +} diff --git a/src/test/resources/datasets/dataset-add.xml b/src/test/resources/datasets/dataset-add.xml index 9a75a99..703259b 100644 --- a/src/test/resources/datasets/dataset-add.xml +++ b/src/test/resources/datasets/dataset-add.xml @@ -16,4 +16,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/datasets/dataset-addPet.xml b/src/test/resources/datasets/dataset-addPet.xml new file mode 100644 index 0000000..167d7aa --- /dev/null +++ b/src/test/resources/datasets/dataset-addPet.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/datasets/dataset-delete.xml b/src/test/resources/datasets/dataset-delete.xml index e49223d..42b69e4 100644 --- a/src/test/resources/datasets/dataset-delete.xml +++ b/src/test/resources/datasets/dataset-delete.xml @@ -14,4 +14,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/datasets/dataset-deletePet.xml b/src/test/resources/datasets/dataset-deletePet.xml new file mode 100644 index 0000000..db3bd39 --- /dev/null +++ b/src/test/resources/datasets/dataset-deletePet.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/datasets/dataset-modify.xml b/src/test/resources/datasets/dataset-modify.xml index 6e2dfc9..d5d0228 100644 --- a/src/test/resources/datasets/dataset-modify.xml +++ b/src/test/resources/datasets/dataset-modify.xml @@ -15,4 +15,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/datasets/dataset-modifyPet.xml b/src/test/resources/datasets/dataset-modifyPet.xml new file mode 100644 index 0000000..0826b58 --- /dev/null +++ b/src/test/resources/datasets/dataset-modifyPet.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/datasets/dataset.dtd b/src/test/resources/datasets/dataset.dtd index e64500f..0502151 100644 --- a/src/test/resources/datasets/dataset.dtd +++ b/src/test/resources/datasets/dataset.dtd @@ -1,7 +1,8 @@ - + + + diff --git a/src/test/resources/datasets/dataset.xml b/src/test/resources/datasets/dataset.xml index 3f48cc9..86cf76b 100644 --- a/src/test/resources/datasets/dataset.xml +++ b/src/test/resources/datasets/dataset.xml @@ -15,4 +15,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/db/hsqldb-drop.sql b/src/test/resources/db/hsqldb-drop.sql index 31f8643..edd9162 100644 --- a/src/test/resources/db/hsqldb-drop.sql +++ b/src/test/resources/db/hsqldb-drop.sql @@ -1,2 +1,3 @@ -DROP TABLE People IF EXISTS; -DROP TABLE Users IF EXISTS; +DROP TABLE pets IF EXISTS; +DROP TABLE people IF EXISTS; +DROP TABLE users IF EXISTS; diff --git a/src/test/resources/db/hsqldb.sql b/src/test/resources/db/hsqldb.sql index a629441..75a0e5d 100644 --- a/src/test/resources/db/hsqldb.sql +++ b/src/test/resources/db/hsqldb.sql @@ -10,4 +10,14 @@ CREATE TABLE users ( password VARCHAR(64) NOT NULL, role VARCHAR(5) NOT NULL, PRIMARY KEY (login) +); + +CREATE TABLE pets ( + id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL, + name VARCHAR(50) NOT NULL, + food VARCHAR(100) NOT NULL, + id_person int NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (id_person) REFERENCES people(id) + ); \ No newline at end of file diff --git a/src/test/webapp/rest/pets/add.html b/src/test/webapp/rest/pets/add.html new file mode 100644 index 0000000..c0f7b7d --- /dev/null +++ b/src/test/webapp/rest/pets/add.html @@ -0,0 +1,132 @@ + + + + + + +add + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
add
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodyname=Xián&surname=Ximénez
clicklink=POST
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value200 OK
waitForElementPresentcss=#response-body-raw > pre
storeTextcss=#response-body-raw > preresponseBody
echo${responseBody}
assertEvalJSON.parse(storedVars['responseBody']).nameXián
assertEvalJSON.parse(storedVars['responseBody']).surnameXiménez
+ + diff --git a/src/test/webapp/rest/pets/addNoFood.html b/src/test/webapp/rest/pets/addNoFood.html new file mode 100644 index 0000000..ce3e867 --- /dev/null +++ b/src/test/webapp/rest/pets/addNoFood.html @@ -0,0 +1,107 @@ + + + + + + +addNoFood + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
addNoFood
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodyname=Xián
clicklink=POST
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value400 Bad Request
+ + diff --git a/src/test/webapp/rest/pets/addNoName.html b/src/test/webapp/rest/pets/addNoName.html new file mode 100644 index 0000000..04db2e9 --- /dev/null +++ b/src/test/webapp/rest/pets/addNoName.html @@ -0,0 +1,107 @@ + + + + + + +addNoName + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
addNoName
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodysurname=Ximénez
clicklink=POST
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value400 Bad Request
+ + diff --git a/src/test/webapp/rest/pets/delete.html b/src/test/webapp/rest/pets/delete.html new file mode 100644 index 0000000..7c1a242 --- /dev/null +++ b/src/test/webapp/rest/pets/delete.html @@ -0,0 +1,77 @@ + + + + + + +delete + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
delete
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=DELETE
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people/11
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value200 OK
+ + diff --git a/src/test/webapp/rest/pets/deleteInvalidId.html b/src/test/webapp/rest/pets/deleteInvalidId.html new file mode 100644 index 0000000..8d84af4 --- /dev/null +++ b/src/test/webapp/rest/pets/deleteInvalidId.html @@ -0,0 +1,77 @@ + + + + + + +deleteInvalidId + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
deleteInvalidId
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=DELETE
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people/100
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value400 Bad Request
+ + diff --git a/src/test/webapp/rest/pets/get.html b/src/test/webapp/rest/pets/get.html new file mode 100644 index 0000000..30f59e5 --- /dev/null +++ b/src/test/webapp/rest/pets/get.html @@ -0,0 +1,96 @@ + + + + + + +rest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
rest
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=GET
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value200 OK
waitForElementPresentcss=#response-body-raw > pre
storeTextcss=#response-body-raw > preresponseBody
echo${responseBody}
assertEvalJSON.parse(storedVars['responseBody']).length10
+ + diff --git a/src/test/webapp/rest/pets/list.html b/src/test/webapp/rest/pets/list.html new file mode 100644 index 0000000..30f59e5 --- /dev/null +++ b/src/test/webapp/rest/pets/list.html @@ -0,0 +1,96 @@ + + + + + + +rest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
rest
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=GET
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value200 OK
waitForElementPresentcss=#response-body-raw > pre
storeTextcss=#response-body-raw > preresponseBody
echo${responseBody}
assertEvalJSON.parse(storedVars['responseBody']).length10
+ + diff --git a/src/test/webapp/rest/pets/modify.html b/src/test/webapp/rest/pets/modify.html new file mode 100644 index 0000000..0adc9f2 --- /dev/null +++ b/src/test/webapp/rest/pets/modify.html @@ -0,0 +1,132 @@ + + + + + + +modify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
modify
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodyname=Marta&surname=Martínez
clicklink=PUT
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people/4
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value200 OK
waitForElementPresentcss=#response-body-raw > pre
storeTextcss=#response-body-raw > preresponseBody
echo${responseBody}
assertEvalJSON.parse(storedVars['responseBody']).nameMarta
assertEvalJSON.parse(storedVars['responseBody']).surnameMartínez
+ + diff --git a/src/test/webapp/rest/pets/modifyInvalidId.html b/src/test/webapp/rest/pets/modifyInvalidId.html new file mode 100644 index 0000000..3f9d78c --- /dev/null +++ b/src/test/webapp/rest/pets/modifyInvalidId.html @@ -0,0 +1,107 @@ + + + + + + +modifyInvalidId + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
modifyInvalidId
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodyname=Marta&surname=Martínez
clicklink=PUT
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people/100
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value400 Bad Request
+ + diff --git a/src/test/webapp/rest/pets/modifyNoFood.html b/src/test/webapp/rest/pets/modifyNoFood.html new file mode 100644 index 0000000..1355433 --- /dev/null +++ b/src/test/webapp/rest/pets/modifyNoFood.html @@ -0,0 +1,107 @@ + + + + + + +modifyNoFood + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
modifyNoFood
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodyname=Marta
clicklink=PUT
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people/4
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value400 Bad Request
+ + diff --git a/src/test/webapp/rest/pets/modifyNoId.html b/src/test/webapp/rest/pets/modifyNoId.html new file mode 100644 index 0000000..ed0f3bb --- /dev/null +++ b/src/test/webapp/rest/pets/modifyNoId.html @@ -0,0 +1,107 @@ + + + + + + +modifyNoId + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
modifyNoId
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodyname=Marta&surname=Martínez
clicklink=PUT
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value405 Method Not Allowed
+ + diff --git a/src/test/webapp/rest/pets/modifyNoName.html b/src/test/webapp/rest/pets/modifyNoName.html new file mode 100644 index 0000000..c29cf81 --- /dev/null +++ b/src/test/webapp/rest/pets/modifyNoName.html @@ -0,0 +1,107 @@ + + + + + + +modifyNoName + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
modifyNoName
openchrome://restclient/content/restclient.html
clicklink=Headers
clicklink=Custom Header
typename=nameCookie
typename=valuetoken=bXJqYXRvOm1yamF0bw==
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
clicklink=Headers
clicklink=Custom Header
typename=nameContent-Type
typename=valueapplication/x-www-form-urlencoded
clickcss=#modal-custom-header > div.modal-footer > input.btn.btn-inverse
typeid=request-bodysurname=Martínez
clicklink=PUT
typeid=request-urlhttp://localhost:9080/DAAExample/rest/people/4
clickid=request-button
clicklink=×
waitForElementPresentcss=span.header-value
assertTextcss=span.header-value400 Bad Request
+ + diff --git a/src/test/webapp/rest/pets/rest.html b/src/test/webapp/rest/pets/rest.html new file mode 100644 index 0000000..4dd4a50 --- /dev/null +++ b/src/test/webapp/rest/pets/rest.html @@ -0,0 +1,24 @@ + + + + + + Test Suite + + + + + + + + + + + + + + + +
Test Suite
list
add
addNoName
addNoSurname
modify
modifyInvalidId
modifyNoId
modifyNoName
modifyNoSurname
delete
deleteInvalidId
+ + diff --git a/src/test/webapp/web/pets/add.html b/src/test/webapp/web/pets/add.html new file mode 100644 index 0000000..13d4ad6 --- /dev/null +++ b/src/test/webapp/web/pets/add.html @@ -0,0 +1,71 @@ + + + + + + +example + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
example
createCookietoken=bXJqYXRvOm1yamF0bw==
openmain.html
waitForPageToLoad
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
typename=nameHola
typename=surnameMundo
clickid=btnSubmit
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
verifyTextcss=tr:last-child > td.nameHola
verifyTextcss=tr:last-child > td.surnameMundo
deleteCookietoken
+ + diff --git a/src/test/webapp/web/pets/delete.html b/src/test/webapp/web/pets/delete.html new file mode 100644 index 0000000..d73f247 --- /dev/null +++ b/src/test/webapp/web/pets/delete.html @@ -0,0 +1,76 @@ + + + + + + +delete + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
delete
createCookietoken=bXJqYXRvOm1yamF0bw==
openmain.html
waitForPageToLoad
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
storeXpathCount//trrows
clickxpath=(//a[contains(text(),'Delete')])[last()]
assertConfirmationEstá a punto de eliminar a una persona. ¿Está seguro de que desea continuar?
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
storeXpathCount//trrowsAfterDeletion
storeEvalstoredVars['rows']-storedVars['rowsAfterDeletion']rowsDeleted
verifyExpression${rowsDeleted}1
deleteCookietoken
+ + diff --git a/src/test/webapp/web/pets/edit.html b/src/test/webapp/web/pets/edit.html new file mode 100644 index 0000000..30688fb --- /dev/null +++ b/src/test/webapp/web/pets/edit.html @@ -0,0 +1,82 @@ + + + + + + +edit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
edit
createCookietoken=bXJqYXRvOm1yamF0bw==
openmain.html
waitForPageToLoad
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
clickxpath=(//a[contains(text(),'Edit')])[last()]
storeAttribute//tr[last()]/@idpersonId
typename=nameAna
typename=surnameMaría
clickid=btnSubmit
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
verifyText//tr[@id='${personId}']/td[@class = 'name']Ana
verifyText//tr[@id='${personId}']/td[@class = 'surname']María
deleteCookietoken
+ + diff --git a/src/test/webapp/web/pets/example.html b/src/test/webapp/web/pets/example.html new file mode 100644 index 0000000..e1dbb63 --- /dev/null +++ b/src/test/webapp/web/pets/example.html @@ -0,0 +1,17 @@ + + + + + + Test Suite + + + + + + + + +
Test Suite
list
add
edit
delete
+ + diff --git a/src/test/webapp/web/pets/list.html b/src/test/webapp/web/pets/list.html new file mode 100644 index 0000000..a6b2ac4 --- /dev/null +++ b/src/test/webapp/web/pets/list.html @@ -0,0 +1,46 @@ + + + + + + +list + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
list
createCookietoken=bXJqYXRvOm1yamF0bw==
openmain.html
waitForPageToLoad
waitForConditionselenium.browserbot.getCurrentWindow().jQuery.active == 01000
verifyXpathCount//tr11
deleteCookietoken
+ + -- 2.18.1