diff --git a/scm-webapp/src/test/java/sonia/scm/it/AbstractAdminITCaseBase.java b/scm-webapp/src/test/java/sonia/scm/it/AbstractAdminITCaseBase.java new file mode 100644 index 0000000000..ea2dd07cdf --- /dev/null +++ b/scm-webapp/src/test/java/sonia/scm/it/AbstractAdminITCaseBase.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.it; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.After; +import org.junit.Before; + +//~--- JDK imports ------------------------------------------------------------ + +import com.sun.jersey.api.client.Client; + +/** + * + * @author Sebastian Sdorra + */ +public class AbstractAdminITCaseBase extends AbstractITCaseBase +{ + + /** + * Method description + * + */ + @Before + public void login() + { + client = createClient(); + adminLogin(client); + } + + /** + * Method description + * + */ + @After + public void logout() + { + logout(client); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + protected Client client; +} diff --git a/scm-webapp/src/test/java/sonia/scm/it/GroupITCase.java b/scm-webapp/src/test/java/sonia/scm/it/GroupITCase.java new file mode 100644 index 0000000000..8532eb695a --- /dev/null +++ b/scm-webapp/src/test/java/sonia/scm/it/GroupITCase.java @@ -0,0 +1,236 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.it; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.junit.Test; + +import sonia.scm.group.Group; + +import static org.junit.Assert.*; + +//~--- JDK imports ------------------------------------------------------------ + +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.GenericType; +import com.sun.jersey.api.client.WebResource; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * + * @author Sebastian Sdorra + */ +public class GroupITCase extends AbstractAdminITCaseBase +{ + + /** + * Method description + * + */ + @Test + public void create() + { + Group group = new Group(); + + group.setName("group-a"); + group.setDescription("group a"); + + List members = new ArrayList(); + + members.add("slarti"); + members.add("marvin"); + members.add("dent"); + group.setMembers(members); + createGroup(group); + } + + /** + * Method description + * + */ + @Test + public void delete() + { + Group group = new Group(); + + group.setName("group-b"); + group.setDescription("group b"); + + List members = new ArrayList(); + + members.add("slarti"); + members.add("dent"); + group.setMembers(members); + createGroup(group); + deleteGroup(group.getName()); + } + + /** + * Method description + * + */ + @Test + public void modify() + { + Group group = new Group(); + + group.setName("group-d"); + group.setDescription("group d"); + createGroup(group); + group = getGroup(group.getName()); + group.setDescription("GROUP D"); + + WebResource wr = createResource(client, "groups/group-d"); + ClientResponse response = wr.put(ClientResponse.class, group); + + assertNotNull(response); + assertTrue(response.getStatus() == 204); + + Group other = getGroup("group-d"); + + assertEquals(group.getName(), other.getName()); + assertEquals(group.getDescription(), other.getDescription()); + assertNotNull(other.getLastModified()); + deleteGroup(other.getName()); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + */ + @Test + public void getAll() + { + Group group = new Group(); + + group.setName("group-c"); + createGroup(group); + + WebResource wr = createResource(client, "groups"); + ClientResponse response = wr.get(ClientResponse.class); + Collection groups = + response.getEntity(new GenericType>() {} + ); + + assertNotNull(groups); + assertFalse(groups.isEmpty()); + + Group groupC = null; + + for (Group g : groups) + { + if (g.getName().equals("group-c")) + { + groupC = g; + } + } + + assertNotNull(groupC); + assertNotNull(groupC.getCreationDate()); + assertNotNull(groupC.getType()); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param group + */ + private void createGroup(Group group) + { + WebResource wr = createResource(client, "groups"); + ClientResponse response = wr.post(ClientResponse.class, group); + + assertNotNull(response); + assertTrue(response.getStatus() == 201); + + Group other = getGroup(group.getName()); + + assertNotNull(other); + assertNotNull(other.getType()); + assertEquals(group.getName(), other.getName()); + assertEquals(group.getDescription(), other.getDescription()); + assertArrayEquals(group.getMembers().toArray(new String[0]), + other.getMembers().toArray(new String[0])); + assertNotNull(other.getCreationDate()); + } + + /** + * Method description + * + * + * @param name + */ + private void deleteGroup(String name) + { + WebResource wr = createResource(client, "groups/".concat(name)); + ClientResponse response = wr.delete(ClientResponse.class); + + assertNotNull(response); + assertTrue(response.getStatus() == 204); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param groupname + * + * @return + */ + private Group getGroup(String groupname) + { + WebResource wr = createResource(client, "groups/".concat(groupname)); + ClientResponse response = wr.get(ClientResponse.class); + + assertNotNull(response); + + Group group = response.getEntity(Group.class); + + assertNotNull(group); + assertEquals(group.getName(), groupname); + + return group; + } +} diff --git a/scm-webapp/src/test/java/sonia/scm/it/UserITCase.java b/scm-webapp/src/test/java/sonia/scm/it/UserITCase.java index f537b3278b..d392600174 100644 --- a/scm-webapp/src/test/java/sonia/scm/it/UserITCase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/UserITCase.java @@ -35,8 +35,6 @@ package sonia.scm.it; //~--- non-JDK imports -------------------------------------------------------- -import org.junit.After; -import org.junit.Before; import org.junit.Test; import sonia.scm.user.User; @@ -46,7 +44,6 @@ import static org.junit.Assert.*; //~--- JDK imports ------------------------------------------------------------ -import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.WebResource; @@ -59,7 +56,7 @@ import javax.ws.rs.core.MediaType; * * @author Sebastian Sdorra */ -public class UserITCase extends AbstractITCaseBase +public class UserITCase extends AbstractAdminITCaseBase { /** @@ -88,27 +85,6 @@ public class UserITCase extends AbstractITCaseBase deleteUser(dent); } - /** - * Method description - * - */ - @Before - public void login() - { - client = createClient(); - adminLogin(client); - } - - /** - * Method description - * - */ - @After - public void logout() - { - logout(client); - } - /** * Method description * @@ -127,11 +103,12 @@ public class UserITCase extends AbstractITCaseBase wr.type(MediaType.APPLICATION_XML).put(ClientResponse.class, marvin); assertNotNull(response); + assertTrue(response.getStatus() == 204); - // assertTrue( response.getStatus() == 204 ); User other = getUser(marvin.getName()); assertEquals(marvin.getDisplayName(), other.getDisplayName()); + assertNotNull(other.getLastModified()); deleteUser(marvin); } @@ -260,9 +237,4 @@ public class UserITCase extends AbstractITCaseBase return user; } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private Client client; }