added group integration tests

This commit is contained in:
Sebastian Sdorra
2011-02-16 21:13:54 +01:00
parent 4e7227ab26
commit 7fc326da97
3 changed files with 316 additions and 31 deletions

View File

@@ -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;
}

View File

@@ -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<String> members = new ArrayList<String>();
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<String> members = new ArrayList<String>();
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<Group> groups =
response.getEntity(new GenericType<Collection<Group>>() {}
);
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;
}
}

View File

@@ -35,8 +35,6 @@ package sonia.scm.it;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import sonia.scm.user.User; import sonia.scm.user.User;
@@ -46,7 +44,6 @@ import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
@@ -59,7 +56,7 @@ import javax.ws.rs.core.MediaType;
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class UserITCase extends AbstractITCaseBase public class UserITCase extends AbstractAdminITCaseBase
{ {
/** /**
@@ -88,27 +85,6 @@ public class UserITCase extends AbstractITCaseBase
deleteUser(dent); deleteUser(dent);
} }
/**
* Method description
*
*/
@Before
public void login()
{
client = createClient();
adminLogin(client);
}
/**
* Method description
*
*/
@After
public void logout()
{
logout(client);
}
/** /**
* Method description * Method description
* *
@@ -127,11 +103,12 @@ public class UserITCase extends AbstractITCaseBase
wr.type(MediaType.APPLICATION_XML).put(ClientResponse.class, marvin); wr.type(MediaType.APPLICATION_XML).put(ClientResponse.class, marvin);
assertNotNull(response); assertNotNull(response);
assertTrue(response.getStatus() == 204);
// assertTrue( response.getStatus() == 204 );
User other = getUser(marvin.getName()); User other = getUser(marvin.getName());
assertEquals(marvin.getDisplayName(), other.getDisplayName()); assertEquals(marvin.getDisplayName(), other.getDisplayName());
assertNotNull(other.getLastModified());
deleteUser(marvin); deleteUser(marvin);
} }
@@ -260,9 +237,4 @@ public class UserITCase extends AbstractITCaseBase
return user; return user;
} }
//~--- fields ---------------------------------------------------------------
/** Field description */
private Client client;
} }