Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
a851e3ac
Commit
a851e3ac
authored
Apr 04, 2018
by
Greg Messner
Browse files
Mods related to blockUser() and unblockUser() fixes (#169).
parent
94b37c53
Changes
3
Hide whitespace changes
Inline
Side-by-side
example-test-gitlab4j.properties
View file @
a851e3ac
...
...
@@ -24,9 +24,12 @@ TEST_GROUP_MEMBER_USERNAME=
TEST_LOGIN_USERNAME
=
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
=
# 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
TEST_PROXY_URI
=
TEST_PROXY_USERNAME
=
...
...
src/main/java/org/gitlab4j/api/UserApi.java
View file @
a851e3ac
...
...
@@ -119,17 +119,15 @@ public class UserApi extends AbstractApi {
* POST /users/:id/block
*
* @param userId the ID of the user to block
* @return the User instance for the blocked user
* @throws GitLabApiException if any exception occurs
*/
public
User
blockUser
(
Integer
userId
)
throws
GitLabApiException
{
public
void
blockUser
(
Integer
userId
)
throws
GitLabApiException
{
if
(
userId
==
null
)
{
throw
new
RuntimeException
(
"userId cannot be null"
);
}
Response
response
=
post
(
Response
.
Status
.
CREATED
,
(
Form
)
null
,
"users"
,
userId
,
"block"
);
return
(
response
.
readEntity
(
User
.
class
));
post
(
Response
.
Status
.
CREATED
,
(
Form
)
null
,
"users"
,
userId
,
"block"
);
}
/**
...
...
@@ -138,17 +136,15 @@ public class UserApi extends AbstractApi {
* POST /users/:id/unblock
*
* @param userId the ID of the user to unblock
* @return the User instance for the unblocked user
* @throws GitLabApiException if any exception occurs
*/
public
User
unblockUser
(
Integer
userId
)
throws
GitLabApiException
{
public
void
unblockUser
(
Integer
userId
)
throws
GitLabApiException
{
if
(
userId
==
null
)
{
throw
new
RuntimeException
(
"userId cannot be null"
);
}
Response
response
=
post
(
Response
.
Status
.
CREATED
,
(
Form
)
null
,
"users"
,
userId
,
"unblock"
);
return
(
response
.
readEntity
(
User
.
class
));
post
(
Response
.
Status
.
CREATED
,
(
Form
)
null
,
"users"
,
userId
,
"unblock"
);
}
/**
...
...
src/test/java/org/gitlab4j/api/TestUserApi.java
View file @
a851e3ac
...
...
@@ -2,9 +2,11 @@ package org.gitlab4j.api;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assume
.
assumeNotNull
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
java.text.ParseException
;
...
...
@@ -49,12 +51,14 @@ public class TestUserApi {
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
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_SSH_KEY
;
static
{
TEST_HOST_URL
=
TestUtils
.
getProperty
(
"TEST_HOST_URL"
);
TEST_PRIVATE_TOKEN
=
TestUtils
.
getProperty
(
"TEST_PRIVATE_TOKEN"
);
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_SSH_KEY
=
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j"
+
"BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/"
+
...
...
@@ -66,6 +70,7 @@ public class TestUserApi {
private
static
final
String
TEST_IMPERSONATION_TOKEN_NAME
=
"token1"
;
private
static
GitLabApi
gitLabApi
;
private
static
User
blockUser
;
public
TestUserApi
()
{
super
();
...
...
@@ -90,6 +95,15 @@ public class TestUserApi {
if
(
problems
.
isEmpty
())
{
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
)
{
try
{
List
<
SshKey
>
sshKeys
=
gitLabApi
.
getUserApi
().
getSshKeys
();
...
...
@@ -136,6 +150,20 @@ public class TestUserApi {
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
public
void
testGetOptionalUser
()
throws
GitLabApiException
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment