Commit a851e3ac authored by Greg Messner's avatar Greg Messner
Browse files

Mods related to blockUser() and unblockUser() fixes (#169).

parent 94b37c53
...@@ -24,9 +24,12 @@ TEST_GROUP_MEMBER_USERNAME= ...@@ -24,9 +24,12 @@ TEST_GROUP_MEMBER_USERNAME=
TEST_LOGIN_USERNAME= TEST_LOGIN_USERNAME=
TEST_LOGIN_PASSWORD= TEST_LOGIN_PASSWORD=
# OPTIONAL: To test sudo capability provide a username to sudo as # OPTIONAL: To test sudo capability, provide a username to sudo as
TEST_SUDO_AS_USERNAME= TEST_SUDO_AS_USERNAME=
# OPTIONAL: To test block/unblock capability, provide a username to block/unblock
TEST_BLOCK_USERNAME=
# OPTIONAL: To test using GitLab4J-API with a proxy, set the following properties # OPTIONAL: To test using GitLab4J-API with a proxy, set the following properties
TEST_PROXY_URI= TEST_PROXY_URI=
TEST_PROXY_USERNAME= TEST_PROXY_USERNAME=
......
...@@ -119,17 +119,15 @@ public class UserApi extends AbstractApi { ...@@ -119,17 +119,15 @@ public class UserApi extends AbstractApi {
* POST /users/:id/block * POST /users/:id/block
* *
* @param userId the ID of the user to block * @param userId the ID of the user to block
* @return the User instance for the blocked user
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public User blockUser(Integer userId) throws GitLabApiException { public void blockUser(Integer userId) throws GitLabApiException {
if (userId == null) { if (userId == null) {
throw new RuntimeException("userId cannot be null"); throw new RuntimeException("userId cannot be null");
} }
Response response = post(Response.Status.CREATED, (Form) null, "users", userId, "block"); post(Response.Status.CREATED, (Form) null, "users", userId, "block");
return (response.readEntity(User.class));
} }
/** /**
...@@ -138,17 +136,15 @@ public class UserApi extends AbstractApi { ...@@ -138,17 +136,15 @@ public class UserApi extends AbstractApi {
* POST /users/:id/unblock * POST /users/:id/unblock
* *
* @param userId the ID of the user to unblock * @param userId the ID of the user to unblock
* @return the User instance for the unblocked user
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public User unblockUser(Integer userId) throws GitLabApiException { public void unblockUser(Integer userId) throws GitLabApiException {
if (userId == null) { if (userId == null) {
throw new RuntimeException("userId cannot be null"); throw new RuntimeException("userId cannot be null");
} }
Response response = post(Response.Status.CREATED, (Form) null, "users", userId, "unblock"); post(Response.Status.CREATED, (Form) null, "users", userId, "unblock");
return (response.readEntity(User.class));
} }
/** /**
......
...@@ -2,9 +2,11 @@ package org.gitlab4j.api; ...@@ -2,9 +2,11 @@ package org.gitlab4j.api;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import java.text.ParseException; import java.text.ParseException;
...@@ -49,12 +51,14 @@ public class TestUserApi { ...@@ -49,12 +51,14 @@ public class TestUserApi {
private static final String TEST_HOST_URL; private static final String TEST_HOST_URL;
private static final String TEST_PRIVATE_TOKEN; private static final String TEST_PRIVATE_TOKEN;
private static final String TEST_USERNAME; private static final String TEST_USERNAME;
private static final String TEST_BLOCK_USERNAME;
private static final String TEST_SUDO_AS_USERNAME; private static final String TEST_SUDO_AS_USERNAME;
private static final String TEST_SSH_KEY; private static final String TEST_SSH_KEY;
static { static {
TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL"); TEST_HOST_URL = TestUtils.getProperty("TEST_HOST_URL");
TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN"); TEST_PRIVATE_TOKEN = TestUtils.getProperty("TEST_PRIVATE_TOKEN");
TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME"); TEST_USERNAME = TestUtils.getProperty("TEST_USERNAME");
TEST_BLOCK_USERNAME = TestUtils.getProperty("TEST_BLOCK_USERNAME");
TEST_SUDO_AS_USERNAME = TestUtils.getProperty("TEST_SUDO_AS_USERNAME"); TEST_SUDO_AS_USERNAME = TestUtils.getProperty("TEST_SUDO_AS_USERNAME");
TEST_SSH_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j" + TEST_SSH_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j" +
"BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/" + "BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/" +
...@@ -66,6 +70,7 @@ public class TestUserApi { ...@@ -66,6 +70,7 @@ public class TestUserApi {
private static final String TEST_IMPERSONATION_TOKEN_NAME = "token1"; private static final String TEST_IMPERSONATION_TOKEN_NAME = "token1";
private static GitLabApi gitLabApi; private static GitLabApi gitLabApi;
private static User blockUser;
public TestUserApi() { public TestUserApi() {
super(); super();
...@@ -90,6 +95,15 @@ public class TestUserApi { ...@@ -90,6 +95,15 @@ public class TestUserApi {
if (problems.isEmpty()) { if (problems.isEmpty()) {
gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN); gitLabApi = new GitLabApi(ApiVersion.V4, TEST_HOST_URL, TEST_PRIVATE_TOKEN);
if (TEST_BLOCK_USERNAME != null) {
try {
blockUser = gitLabApi.getUserApi().getUser(TEST_BLOCK_USERNAME);
if (blockUser != null) {
gitLabApi.getUserApi().unblockUser(blockUser.getId());
}
} catch (Exception ignore) {}
}
if (TEST_SSH_KEY != null) { if (TEST_SSH_KEY != null) {
try { try {
List<SshKey> sshKeys = gitLabApi.getUserApi().getSshKeys(); List<SshKey> sshKeys = gitLabApi.getUserApi().getSshKeys();
...@@ -136,6 +150,20 @@ public class TestUserApi { ...@@ -136,6 +150,20 @@ public class TestUserApi {
assertEquals(TEST_USERNAME, user.getUsername()); assertEquals(TEST_USERNAME, user.getUsername());
} }
@Test
public void testBlockUnblockUser() throws GitLabApiException {
assumeNotNull(blockUser);
assertNotEquals("blocked", blockUser.getState());
gitLabApi.getUserApi().blockUser(blockUser.getId());
User user = gitLabApi.getUserApi().getUser(blockUser.getId());
assertEquals("blocked", user.getState());
gitLabApi.getUserApi().unblockUser(blockUser.getId());
user = gitLabApi.getUserApi().getUser(blockUser.getId());
assertNotEquals("blocked", user.getState());
}
@Test @Test
public void testGetOptionalUser() throws GitLabApiException { public void testGetOptionalUser() throws GitLabApiException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment