From 4e7227ab2651fd6a1e2d2ed1007d3c4d303a9f05 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 16 Feb 2011 20:17:05 +0100 Subject: [PATCH] improve user integration tests --- .../scm/{ic => it}/AbstractITCaseBase.java | 2 +- .../scm/{ic => it}/AuthenticationITCase.java | 2 +- .../java/sonia/scm/{ic => it}/UserITCase.java | 133 ++++++++++++++++-- 3 files changed, 125 insertions(+), 12 deletions(-) rename scm-webapp/src/test/java/sonia/scm/{ic => it}/AbstractITCaseBase.java (99%) rename scm-webapp/src/test/java/sonia/scm/{ic => it}/AuthenticationITCase.java (99%) rename scm-webapp/src/test/java/sonia/scm/{ic => it}/UserITCase.java (60%) diff --git a/scm-webapp/src/test/java/sonia/scm/ic/AbstractITCaseBase.java b/scm-webapp/src/test/java/sonia/scm/it/AbstractITCaseBase.java similarity index 99% rename from scm-webapp/src/test/java/sonia/scm/ic/AbstractITCaseBase.java rename to scm-webapp/src/test/java/sonia/scm/it/AbstractITCaseBase.java index 7af6a8d38c..eca4059f46 100644 --- a/scm-webapp/src/test/java/sonia/scm/ic/AbstractITCaseBase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/AbstractITCaseBase.java @@ -31,7 +31,7 @@ -package sonia.scm.ic; +package sonia.scm.it; //~--- non-JDK imports -------------------------------------------------------- diff --git a/scm-webapp/src/test/java/sonia/scm/ic/AuthenticationITCase.java b/scm-webapp/src/test/java/sonia/scm/it/AuthenticationITCase.java similarity index 99% rename from scm-webapp/src/test/java/sonia/scm/ic/AuthenticationITCase.java rename to scm-webapp/src/test/java/sonia/scm/it/AuthenticationITCase.java index 743e341ab3..88184ca868 100644 --- a/scm-webapp/src/test/java/sonia/scm/ic/AuthenticationITCase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/AuthenticationITCase.java @@ -31,7 +31,7 @@ -package sonia.scm.ic; +package sonia.scm.it; //~--- non-JDK imports -------------------------------------------------------- diff --git a/scm-webapp/src/test/java/sonia/scm/ic/UserITCase.java b/scm-webapp/src/test/java/sonia/scm/it/UserITCase.java similarity index 60% rename from scm-webapp/src/test/java/sonia/scm/ic/UserITCase.java rename to scm-webapp/src/test/java/sonia/scm/it/UserITCase.java index fae6de34ba..f537b3278b 100644 --- a/scm-webapp/src/test/java/sonia/scm/ic/UserITCase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/UserITCase.java @@ -31,7 +31,7 @@ -package sonia.scm.ic; +package sonia.scm.it; //~--- non-JDK imports -------------------------------------------------------- @@ -40,6 +40,7 @@ import org.junit.Before; import org.junit.Test; import sonia.scm.user.User; +import sonia.scm.user.UserTestData; import static org.junit.Assert.*; @@ -52,6 +53,8 @@ import com.sun.jersey.api.client.WebResource; import java.util.Collection; +import javax.ws.rs.core.MediaType; + /** * * @author Sebastian Sdorra @@ -59,6 +62,32 @@ import java.util.Collection; public class UserITCase extends AbstractITCaseBase { + /** + * Method description + * + */ + @Test + public void create() + { + User slarti = UserTestData.createSlarti(); + + slarti.setPassword("slarti123"); + createUser(slarti); + } + + /** + * Method description + * + */ + @Test + public void delete() + { + User dent = UserTestData.createDent(); + + createUser(dent); + deleteUser(dent); + } + /** * Method description * @@ -80,6 +109,32 @@ public class UserITCase extends AbstractITCaseBase logout(client); } + /** + * Method description + * + */ + @Test + public void modify() + { + User marvin = UserTestData.createMarvin(); + + createUser(marvin); + marvin = getUser(marvin.getName()); + marvin.setDisplayName("Paranoid Android"); + + WebResource wr = createResource(client, "users/".concat(marvin.getName())); + ClientResponse response = + wr.type(MediaType.APPLICATION_XML).put(ClientResponse.class, marvin); + + assertNotNull(response); + + // assertTrue( response.getStatus() == 204 ); + User other = getUser(marvin.getName()); + + assertEquals(marvin.getDisplayName(), other.getDisplayName()); + deleteUser(marvin); + } + //~--- get methods ---------------------------------------------------------- /** @@ -89,20 +144,14 @@ public class UserITCase extends AbstractITCaseBase @Test public void get() { - WebResource wr = createResource(client, "users/scmadmin"); - ClientResponse respone = wr.get(ClientResponse.class); + User scmadmin = getUser("scmadmin"); - assertNotNull(respone); - assertTrue(respone.getStatus() == 200); - - User user = respone.getEntity(User.class); - - testAdmin(user); + testAdmin(scmadmin); } /** * Method description - * + * */ @Test public void getAll() @@ -135,6 +184,45 @@ public class UserITCase extends AbstractITCaseBase //~--- methods -------------------------------------------------------------- + /** + * Method description + * + * + * @param user + */ + private void createUser(User user) + { + WebResource wr = createResource(client, "users"); + ClientResponse response = + wr.type(MediaType.APPLICATION_XML).post(ClientResponse.class, user); + + assertNotNull(response); + assertTrue(response.getStatus() == 201); + + User other = getUser(user.getName()); + + assertEquals(user.getName(), other.getName()); + assertEquals(user.getDisplayName(), other.getDisplayName()); + assertEquals(user.getMail(), other.getMail()); + assertNotNull(other.getType()); + assertNotNull(other.getCreationDate()); + } + + /** + * Method description + * + * + * @param user + */ + private void deleteUser(User user) + { + WebResource wr = createResource(client, "users/".concat(user.getName())); + ClientResponse respone = wr.delete(ClientResponse.class); + + assertNotNull(respone); + assertTrue(respone.getStatus() == 204); + } + /** * Method description * @@ -148,6 +236,31 @@ public class UserITCase extends AbstractITCaseBase assertTrue(user.isAdmin()); } + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param username + * + * @return + */ + private User getUser(String username) + { + WebResource wr = createResource(client, "users/".concat(username)); + ClientResponse respone = wr.get(ClientResponse.class); + + assertNotNull(respone); + assertTrue(respone.getStatus() == 200); + + User user = respone.getEntity(User.class); + + assertNotNull(user); + + return user; + } + //~--- fields --------------------------------------------------------------- /** Field description */