diff --git a/README.md b/README.md index 35ed10d5b77f15d49ad7b365e7dc3007eb58c7d4..db1ae4dd128558090e4c69a5c0e2080e17fe798f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ comandos (desde la raíz el proyecto): Una vez configurada la base de datos podemos lanzar la ejecución con el comando: -`mvn -Prun-tomcat-mysql -DskipTests=true package cargo:run` +`mvn -Prun -DskipTests=true package cargo:run` La aplicación se servirá en la URL local: http://localhost:9080/DAAExample @@ -38,7 +38,7 @@ 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-tomcat-mysql -DskipTests=true package cargo:start fizzed-watcher:run` +`mvn -Prun -DskipTests=true package cargo:start fizzed-watcher:run` La aplicación se servirá en la URL local: http://localhost:9080/DAAExample @@ -57,16 +57,3 @@ memoria. El comando para lanzar esta construcción es: `mvn install` - -### Construcción con tests de unidad, integración y aceptación - -Esta construcción es similar a la previa, añadiendo las **pruebas de -aceptación**, que comprueban que las fucionalidades de la aplicación están -correctamente implementadas. - -En estas pruebas se descarga y arranca el un servidor Tomcat 8 en el que se -despliega la aplicación configurada para utilizar una base de datos HSQL. Las -pruebas se hacen sobre la interfaz web con Selenium, que iniciará un Firefox -local de forma automática. - -`mvn -Pacceptance-tests-cargo install` diff --git a/pom.xml b/pom.xml index ccf5f9784d3bd429b00d99c5dbae77e9e286b10b..4ec0377177174b6f7ed530f79424d232ebbb41f9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ es.uvigo.esei.daa example war - 0.1.13 + 0.1.14 DAA Example @@ -44,7 +44,6 @@ 1.3.0 2.3.3 5.1.45 - v0.24.0 2.4.2 @@ -296,6 +295,7 @@ + - fr.avianey.mojo - hsqldb-maven-plugin - ${hsqldb-maven-plugin.version} - - - - org.hsqldb.jdbc.JDBCDriver - mem:daatestdb -
localhost
- daatestdb - sa - -
- - - - - start-hsqldb - pre-integration-test - - start - - - - stop-hsqldb - post-integration-test - - stop - - - - - - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - - tomcat8x - - https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/${tomcat.version}/tomcat-${tomcat.version}.zip - ${project.servers.directory}/downloads - ${project.servers.directory}/extracts - - - - org.hsqldb - hsqldb - - - - - - ${project.build.directory}/catalina-base - - - tomcat/server.hsqldb.xml - conf/server.xml - - - - ${jacoco.agent.itArgLine},output=tcpserver,port=${jacoco.port} - -Drunmode=TEST - 9080 - - cargo.datasource.jndi=jdbc/daaexample| - cargo.datasource.driver=org.hsqldb.jdbc.JDBCDriver| - cargo.datasource.url=jdbc:hsqldb:hsql://localhost/daatestdb| - cargo.datasource.username=sa| - cargo.datasource.password=| - cargo.datasource.maxActive=8| - cargo.datasource.maxIdle=4| - cargo.datasource.maxWait=10000 - - - - - - - start-tomcat - pre-integration-test - - start - - - ${cargo.tomcat.start.skip} - - - - run-tomcat - pre-integration-test - - run - - - ${cargo.tomcat.run.skip} - - - - stop-tomcat - post-integration-test - - stop - - - - -
- - - - - run-tomcat-mysql + run false @@ -585,190 +408,5 @@ - - - geckodriver-download-unix - - - unix - - - - https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz - ${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch}${file.separator}${project.build.directory}${file.separator} - ${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz - ${geckodriver.basepath}${file.separator}geckodriver - - - - - org.apache.maven.plugins - maven-antrun-plugin - ${maven-antrun-plugin.version} - - - download-geckodriver - process-test-resources - - - - - - - - - - run - - - - - - - - - - geckodriver-download-windows - - - windows - - - - https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip - ${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch} - ${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.zip - ${geckodriver.basepath}${file.separator}geckodriver.exe - - - - - org.apache.maven.plugins - maven-antrun-plugin - ${maven-antrun-plugin.version} - - - download-geckodriver - process-test-resources - - - - - - - - - - run - - - - - - - - - - geckodriver-properties-unix-amd64 - - - unix - amd64 - - - - linux64 - - - - - geckodriver-properties-unix-x86 - - - unix - x86 - - - - linux86 - - - - - geckodriver-properties-windows-amd64 - - - windows - amd64 - - - - win64 - - - - - geckodriver-properties-windows-x86 - - - windows - x86 - - - - win32 - - - - - geckodriver-properties-and-download-mac - - - mac - - - - macos - https://github.com/mozilla/geckodriver/releases/download/${geckodriver.version}/geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz - ${settings.localRepository}${file.separator}geckodriver${file.separator}${os.name}${file.separator}${os.arch} - ${geckodriver.basepath}${file.separator}geckodriver-${geckodriver.version}-${geckodriver.suffix}.tar.gz - ${geckodriver.basepath}${file.separator}geckodriver - - - - - org.apache.maven.plugins - maven-antrun-plugin - ${maven-antrun-plugin.version} - - - download-geckodriver - process-test-resources - - - - - - - - - - run - - - - - - - diff --git a/src/test/java/es/uvigo/esei/daa/dao/PeopleDAOTest.java b/src/test/java/es/uvigo/esei/daa/dao/PeopleDAOTest.java deleted file mode 100644 index 68d93675fe9e7004aa2f7a29d50fa33d51da1a3e..0000000000000000000000000000000000000000 --- a/src/test/java/es/uvigo/esei/daa/dao/PeopleDAOTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package es.uvigo.esei.daa.dao; - -import static es.uvigo.esei.daa.dataset.PeopleDataset.existentId; -import static es.uvigo.esei.daa.dataset.PeopleDataset.existentPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newName; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newSurname; -import static es.uvigo.esei.daa.dataset.PeopleDataset.nonExistentId; -import static es.uvigo.esei.daa.dataset.PeopleDataset.nonExistentPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.people; -import static es.uvigo.esei.daa.dataset.PeopleDataset.peopleWithout; -import static es.uvigo.esei.daa.matchers.IsEqualToPerson.containsPeopleInAnyOrder; -import static es.uvigo.esei.daa.matchers.IsEqualToPerson.equalsToPerson; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import javax.sql.DataSource; - -import org.junit.Before; -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.github.springtestdbunit.DbUnitTestExecutionListener; -import com.github.springtestdbunit.annotation.DatabaseSetup; -import com.github.springtestdbunit.annotation.ExpectedDatabase; - -import es.uvigo.esei.daa.entities.Person; -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 PeopleDAOTest { - private PeopleDAO dao; - - @Before - public void setUp() throws Exception { - this.dao = new PeopleDAO(); - } - - @Test - public void testList() throws DAOException { - assertThat(this.dao.list(), containsPeopleInAnyOrder(people())); - } - - @Test - public void testGet() throws DAOException { - final Person person = this.dao.get(existentId()); - - assertThat(person, is(equalsToPerson(existentPerson()))); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetNonExistentId() throws DAOException { - this.dao.get(nonExistentId()); - } - - @Test - @ExpectedDatabase("/datasets/dataset-delete.xml") - public void testDelete() throws DAOException { - this.dao.delete(existentId()); - - assertThat(this.dao.list(), containsPeopleInAnyOrder(peopleWithout(existentId()))); - } - - @Test(expected = IllegalArgumentException.class) - public void testDeleteNonExistentId() throws DAOException { - this.dao.delete(nonExistentId()); - } - - @Test - @ExpectedDatabase("/datasets/dataset-modify.xml") - public void testModify() throws DAOException { - final Person person = existentPerson(); - person.setName(newName()); - person.setSurname(newSurname()); - - this.dao.modify(person); - - final Person persistentPerson = this.dao.get(person.getId()); - - assertThat(persistentPerson, is(equalsToPerson(person))); - } - - @Test(expected = IllegalArgumentException.class) - public void testModifyNonExistentId() throws DAOException { - this.dao.modify(nonExistentPerson()); - } - - @Test(expected = IllegalArgumentException.class) - public void testModifyNullPerson() throws DAOException { - this.dao.modify(null); - } - - @Test - @ExpectedDatabase("/datasets/dataset-add.xml") - public void testAdd() throws DAOException { - final Person person = this.dao.add(newName(), newSurname()); - - assertThat(person, is(equalsToPerson(newPerson()))); - - final Person persistentPerson = this.dao.get(person.getId()); - - assertThat(persistentPerson, is(equalsToPerson(newPerson()))); - } - - @Test(expected = IllegalArgumentException.class) - public void testAddNullName() throws DAOException { - this.dao.add(null, newSurname()); - } - - @Test(expected = IllegalArgumentException.class) - public void testAddNullSurname() throws DAOException { - this.dao.add(newName(), null); - } -} diff --git a/src/test/java/es/uvigo/esei/daa/dao/PeopleDAOUnitTest.java b/src/test/java/es/uvigo/esei/daa/dao/PeopleDAOUnitTest.java deleted file mode 100644 index 94ac74b92a0cf20ef651f4f7e4cdd7b908f0ee50..0000000000000000000000000000000000000000 --- a/src/test/java/es/uvigo/esei/daa/dao/PeopleDAOUnitTest.java +++ /dev/null @@ -1,259 +0,0 @@ -package es.uvigo.esei.daa.dao; - -import static es.uvigo.esei.daa.dataset.PeopleDataset.existentId; -import static es.uvigo.esei.daa.dataset.PeopleDataset.existentPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newName; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newSurname; -import static es.uvigo.esei.daa.dataset.PeopleDataset.people; -import static es.uvigo.esei.daa.matchers.IsEqualToPerson.containsPeopleInAnyOrder; -import static es.uvigo.esei.daa.matchers.IsEqualToPerson.equalsToPerson; -import static org.easymock.EasyMock.anyString; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.reset; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.sql.SQLException; - -import org.junit.Test; - -import com.mysql.jdbc.Statement; - -import es.uvigo.esei.daa.entities.Person; -import es.uvigo.esei.daa.util.DatabaseQueryUnitTest; - -public class PeopleDAOUnitTest extends DatabaseQueryUnitTest { - @Test - public void testList() throws Exception { - final Person[] people = people(); - - for (Person person : people) { - expectPersonRow(person); - } - expect(result.next()).andReturn(false); - result.close(); - - replayAll(); - final PeopleDAO peopleDAO = new PeopleDAO(); - - assertThat(peopleDAO.list(), containsPeopleInAnyOrder(people)); - } - - @Test(expected = DAOException.class) - public void testListUnexpectedException() throws Exception { - expect(result.next()).andThrow(new SQLException()); - result.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.list(); - } - - @Test - public void testGet() throws Exception { - final Person existentPerson = existentPerson(); - - expectPersonRow(existentPerson); - result.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - - assertThat(peopleDAO.get(existentId()), is(equalTo(existentPerson))); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetMissing() throws Exception { - expect(result.next()).andReturn(false); - result.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.get(existentId()); - } - - @Test(expected = DAOException.class) - public void testGetUnexpectedException() throws Exception { - expect(result.next()).andThrow(new SQLException()); - result.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.get(existentId()); - } - - @Test - public void testAdd() throws Exception { - final Person person = newPerson(); - reset(connection); - expect(connection.prepareStatement(anyString(), eq(Statement.RETURN_GENERATED_KEYS))) - .andReturn(statement); - expect(statement.executeUpdate()).andReturn(1); - expect(statement.getGeneratedKeys()).andReturn(result); - - // Key retrieval - expect(result.next()).andReturn(true); - expect(result.getInt(1)).andReturn(person.getId()); - connection.close(); - result.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - final Person newPerson = peopleDAO.add(person.getName(), person.getSurname()); - - assertThat(newPerson, is(equalsToPerson(person))); - } - - @Test(expected = IllegalArgumentException.class) - public void testAddNullName() throws Exception { - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - - resetAll(); // No expectations - - peopleDAO.add(null, newSurname()); - } - - @Test(expected = IllegalArgumentException.class) - public void testAddNullSurname() throws Exception { - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - - resetAll(); // No expectations - - peopleDAO.add(newName(), null); - } - - @Test(expected = DAOException.class) - public void testAddZeroUpdatedRows() throws Exception { - reset(connection); - expect(connection.prepareStatement(anyString(), eq(1))) - .andReturn(statement); - expect(statement.executeUpdate()).andReturn(0); - connection.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.add(newName(), newSurname()); - } - - @Test(expected = DAOException.class) - public void testAddNoGeneratedKey() throws Exception { - reset(connection); - expect(connection.prepareStatement(anyString(), eq(1))) - .andReturn(statement); - expect(statement.executeUpdate()).andReturn(1); - expect(statement.getGeneratedKeys()).andReturn(result); - expect(result.next()).andReturn(false); - result.close(); - connection.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.add(newName(), newSurname()); - } - - @Test(expected = DAOException.class) - public void testAddUnexpectedException() throws Exception { - reset(connection); - expect(connection.prepareStatement(anyString(), eq(1))) - .andReturn(statement); - expect(statement.executeUpdate()).andThrow(new SQLException()); - connection.close(); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.add(newName(), newSurname()); - } - - @Test - public void testDelete() throws Exception { - expect(statement.executeUpdate()).andReturn(1); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.delete(existentId()); - } - - @Test(expected = IllegalArgumentException.class) - public void testDeleteInvalidId() throws Exception { - expect(statement.executeUpdate()).andReturn(0); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.delete(existentId()); - } - - @Test(expected = DAOException.class) - public void testDeleteUnexpectedException() throws Exception { - expect(statement.executeUpdate()).andThrow(new SQLException()); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.delete(existentId()); - } - - @Test - public void testModify() throws Exception { - expect(statement.executeUpdate()).andReturn(1); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.modify(existentPerson()); - } - - @Test(expected = IllegalArgumentException.class) - public void testModifyNullPerson() throws Exception { - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - - resetAll(); // No expectations - - peopleDAO.modify(null); - } - - @Test(expected = IllegalArgumentException.class) - public void testModifyZeroUpdatedRows() throws Exception { - expect(statement.executeUpdate()).andReturn(0); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.modify(existentPerson()); - } - - @Test(expected = DAOException.class) - public void testModifyUnexpectedException() throws Exception { - expect(statement.executeUpdate()).andThrow(new SQLException()); - - replayAll(); - - final PeopleDAO peopleDAO = new PeopleDAO(); - peopleDAO.modify(existentPerson()); - } - - private void expectPersonRow(Person person) throws SQLException { - expect(result.next()).andReturn(true); - expect(result.getInt("id")).andReturn(person.getId()); - expect(result.getString("name")).andReturn(person.getName()); - expect(result.getString("surname")).andReturn(person.getSurname()); - } -} diff --git a/src/test/java/es/uvigo/esei/daa/rest/PeopleResourceUnitTest.java b/src/test/java/es/uvigo/esei/daa/rest/PeopleResourceUnitTest.java deleted file mode 100644 index 5cb75654a8eca50305099a1cf3959f052e8f1e38..0000000000000000000000000000000000000000 --- a/src/test/java/es/uvigo/esei/daa/rest/PeopleResourceUnitTest.java +++ /dev/null @@ -1,242 +0,0 @@ -package es.uvigo.esei.daa.rest; - -import static es.uvigo.esei.daa.dataset.PeopleDataset.existentId; -import static es.uvigo.esei.daa.dataset.PeopleDataset.existentPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newName; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newPerson; -import static es.uvigo.esei.daa.dataset.PeopleDataset.newSurname; -import static es.uvigo.esei.daa.dataset.PeopleDataset.people; -import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasBadRequestStatus; -import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasInternalServerErrorStatus; -import static es.uvigo.esei.daa.matchers.HasHttpStatus.hasOkStatus; -import static es.uvigo.esei.daa.matchers.IsEqualToPerson.containsPeopleInAnyOrder; -import static es.uvigo.esei.daa.matchers.IsEqualToPerson.equalsToPerson; -import static java.util.Arrays.asList; -import static org.easymock.EasyMock.anyInt; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.anyString; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.List; - -import javax.ws.rs.core.Response; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import es.uvigo.esei.daa.dao.DAOException; -import es.uvigo.esei.daa.dao.PeopleDAO; -import es.uvigo.esei.daa.entities.Person; - -public class PeopleResourceUnitTest { - private PeopleDAO daoMock; - private PeopleResource resource; - - @Before - public void setUp() throws Exception { - daoMock = createMock(PeopleDAO.class); - resource = new PeopleResource(daoMock); - } - - @After - public void tearDown() throws Exception { - try { - verify(daoMock); - } finally { - daoMock = null; - resource = null; - } - } - - @Test - @SuppressWarnings("unchecked") - public void testList() throws Exception { - final List people = asList(people()); - - expect(daoMock.list()).andReturn(people); - - replay(daoMock); - - final Response response = resource.list(); - - assertThat(response, hasOkStatus()); - assertThat((List) response.getEntity(), containsPeopleInAnyOrder(people())); - } - - @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 testGet() throws Exception { - final Person person = existentPerson(); - - expect(daoMock.get(person.getId())).andReturn(person); - - replay(daoMock); - - final Response response = resource.get(person.getId()); - - assertThat(response, hasOkStatus()); - assertThat((Person) response.getEntity(), is(equalsToPerson(person))); - } - - @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 Person person = existentPerson(); - person.setName(newName()); - person.setSurname(newSurname()); - - daoMock.modify(person); - - replay(daoMock); - - final Response response = resource.modify( - person.getId(), person.getName(), person.getSurname()); - - assertThat(response, hasOkStatus()); - assertEquals(person, response.getEntity()); - } - - @Test - public void testModifyDAOException() throws Exception { - daoMock.modify(anyObject()); - expectLastCall().andThrow(new DAOException()); - - replay(daoMock); - - final Response response = resource.modify(existentId(), newName(), newSurname()); - - assertThat(response, hasInternalServerErrorStatus()); - } - - @Test - public void testModifyIllegalArgumentException() throws Exception { - daoMock.modify(anyObject()); - expectLastCall().andThrow(new IllegalArgumentException()); - - replay(daoMock); - - final Response response = resource.modify(existentId(), newName(), newSurname()); - - assertThat(response, hasBadRequestStatus()); - } - - @Test - public void testModifyNullPointerException() throws Exception { - daoMock.modify(anyObject()); - expectLastCall().andThrow(new NullPointerException()); - - replay(daoMock); - - final Response response = resource.modify(existentId(), newName(), newSurname()); - - assertThat(response, hasBadRequestStatus()); - } - - @Test - public void testAdd() throws Exception { - expect(daoMock.add(newName(), newSurname())) - .andReturn(newPerson()); - replay(daoMock); - - - final Response response = resource.add(newName(), newSurname()); - - assertThat(response, hasOkStatus()); - assertThat((Person) response.getEntity(), is(equalsToPerson(newPerson()))); - } - - @Test - public void testAddDAOException() throws Exception { - expect(daoMock.add(anyString(), anyString())) - .andThrow(new DAOException()); - replay(daoMock); - - final Response response = resource.add(newName(), newSurname()); - - assertThat(response, hasInternalServerErrorStatus()); - } - - @Test - public void testAddIllegalArgumentException() throws Exception { - expect(daoMock.add(anyString(), anyString())) - .andThrow(new IllegalArgumentException()); - replay(daoMock); - - final Response response = resource.add(newName(), newSurname()); - - assertThat(response, hasBadRequestStatus()); - } -} diff --git a/src/test/java/es/uvigo/esei/daa/suites/AcceptanceTestSuite.java b/src/test/java/es/uvigo/esei/daa/suites/AcceptanceTestSuite.java deleted file mode 100644 index 9e7fcdae98a373f1c05365a54f4c40f3166f0ba4..0000000000000000000000000000000000000000 --- a/src/test/java/es/uvigo/esei/daa/suites/AcceptanceTestSuite.java +++ /dev/null @@ -1,15 +0,0 @@ -package es.uvigo.esei.daa.suites; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import es.uvigo.esei.daa.web.PeopleWebTest; - -@SuiteClasses({ - PeopleWebTest.class -}) -@RunWith(Suite.class) -public class AcceptanceTestSuite { - -} diff --git a/src/test/java/es/uvigo/esei/daa/suites/IntegrationTestSuite.java b/src/test/java/es/uvigo/esei/daa/suites/IntegrationTestSuite.java index 822c83f44b63c0c998e6b17c1ab25bddbd750a63..3f0c667c53d5328167d72f6d3b183451637862e3 100644 --- a/src/test/java/es/uvigo/esei/daa/suites/IntegrationTestSuite.java +++ b/src/test/java/es/uvigo/esei/daa/suites/IntegrationTestSuite.java @@ -4,12 +4,10 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import es.uvigo.esei.daa.dao.PeopleDAOTest; import es.uvigo.esei.daa.rest.PeopleResourceTest; import es.uvigo.esei.daa.rest.UsersResourceTest; @SuiteClasses({ - PeopleDAOTest.class, PeopleResourceTest.class, UsersResourceTest.class }) diff --git a/src/test/java/es/uvigo/esei/daa/suites/UnitTestSuite.java b/src/test/java/es/uvigo/esei/daa/suites/UnitTestSuite.java index a21ca3663b624f6cf2ea326a347de55ae8f96ca9..a08e9656929697d95a0416f42d04f70d257d6843 100644 --- a/src/test/java/es/uvigo/esei/daa/suites/UnitTestSuite.java +++ b/src/test/java/es/uvigo/esei/daa/suites/UnitTestSuite.java @@ -4,14 +4,10 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import es.uvigo.esei.daa.dao.PeopleDAOUnitTest; import es.uvigo.esei.daa.entities.PersonUnitTest; -import es.uvigo.esei.daa.rest.PeopleResourceUnitTest; @SuiteClasses({ - PersonUnitTest.class, - PeopleDAOUnitTest.class, - PeopleResourceUnitTest.class + PersonUnitTest.class }) @RunWith(Suite.class) public class UnitTestSuite {