mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
improve user integration tests
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.ic;
|
package sonia.scm.it;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.ic;
|
package sonia.scm.it;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.ic;
|
package sonia.scm.it;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
@@ -40,6 +40,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
|
import sonia.scm.user.UserTestData;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ import com.sun.jersey.api.client.WebResource;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -59,6 +62,32 @@ import java.util.Collection;
|
|||||||
public class UserITCase extends AbstractITCaseBase
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -80,6 +109,32 @@ public class UserITCase extends AbstractITCaseBase
|
|||||||
logout(client);
|
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 ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,15 +144,9 @@ public class UserITCase extends AbstractITCaseBase
|
|||||||
@Test
|
@Test
|
||||||
public void get()
|
public void get()
|
||||||
{
|
{
|
||||||
WebResource wr = createResource(client, "users/scmadmin");
|
User scmadmin = getUser("scmadmin");
|
||||||
ClientResponse respone = wr.get(ClientResponse.class);
|
|
||||||
|
|
||||||
assertNotNull(respone);
|
testAdmin(scmadmin);
|
||||||
assertTrue(respone.getStatus() == 200);
|
|
||||||
|
|
||||||
User user = respone.getEntity(User.class);
|
|
||||||
|
|
||||||
testAdmin(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,6 +184,45 @@ public class UserITCase extends AbstractITCaseBase
|
|||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- 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
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -148,6 +236,31 @@ public class UserITCase extends AbstractITCaseBase
|
|||||||
assertTrue(user.isAdmin());
|
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 ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
Reference in New Issue
Block a user