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
5934fd4d
Commit
5934fd4d
authored
Sep 10, 2019
by
Greg Messner
Browse files
Moved creation of external user to TestUserApi (#427).
parent
8367683b
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/IntegrationTestSuite.java
View file @
5934fd4d
...
@@ -4,9 +4,15 @@ import static org.junit.Assert.assertFalse;
...
@@ -4,9 +4,15 @@ import static org.junit.Assert.assertFalse;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
fail
;
import
java.util.*
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.gitlab4j.api.models.*
;
import
java.util.Optional
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.RepositoryFile
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.models.Visibility
;
import
org.gitlab4j.api.utils.AccessTokenUtils
;
import
org.gitlab4j.api.utils.AccessTokenUtils
;
import
org.gitlab4j.api.utils.AccessTokenUtils.Scope
;
import
org.gitlab4j.api.utils.AccessTokenUtils.Scope
;
import
org.junit.AfterClass
;
import
org.junit.AfterClass
;
...
@@ -38,8 +44,6 @@ public class IntegrationTestSuite implements PropertyConstants {
...
@@ -38,8 +44,6 @@ public class IntegrationTestSuite implements PropertyConstants {
private
static
final
String
TEST_GROUP
=
HelperUtils
.
getProperty
(
GROUP_KEY
);
private
static
final
String
TEST_GROUP
=
HelperUtils
.
getProperty
(
GROUP_KEY
);
private
static
final
String
TEST_GROUP_PROJECT_NAME
=
HelperUtils
.
getProperty
(
GROUP_PROJECT_KEY
);
private
static
final
String
TEST_GROUP_PROJECT_NAME
=
HelperUtils
.
getProperty
(
GROUP_PROJECT_KEY
);
private
static
final
String
TEST_SUB_GROUP
=
HelperUtils
.
getProperty
(
SUB_GROUP_KEY
);
private
static
final
String
TEST_SUB_GROUP
=
HelperUtils
.
getProperty
(
SUB_GROUP_KEY
);
private
static
final
String
TEST_EXTERNAL_PROVIDER
=
HelperUtils
.
getProperty
(
EXTERNAL_PROVIDER_KEY
);
private
static
final
String
TEST_EXTERNAL_UID
=
HelperUtils
.
getProperty
(
EXTERNAL_UID_KEY
);
protected
static
final
String
TEST_PRIVATE_TOKEN_NAME
=
"GitLab4J Test Private Token - "
+
HelperUtils
.
getRandomInt
(
1000
);
protected
static
final
String
TEST_PRIVATE_TOKEN_NAME
=
"GitLab4J Test Private Token - "
+
HelperUtils
.
getRandomInt
(
1000
);
protected
static
String
TEST_PRIVATE_TOKEN
=
HelperUtils
.
getProperty
(
PRIVATE_TOKEN_KEY
);
protected
static
String
TEST_PRIVATE_TOKEN
=
HelperUtils
.
getProperty
(
PRIVATE_TOKEN_KEY
);
...
@@ -164,18 +168,12 @@ public class IntegrationTestSuite implements PropertyConstants {
...
@@ -164,18 +168,12 @@ public class IntegrationTestSuite implements PropertyConstants {
// If the tester user doen't exists, create it
// If the tester user doen't exists, create it
Optional
<
User
>
optionalUser
=
gitLabApi
.
getUserApi
().
getOptionalUser
(
TEST_LOGIN_USERNAME
);
Optional
<
User
>
optionalUser
=
gitLabApi
.
getUserApi
().
getOptionalUser
(
TEST_LOGIN_USERNAME
);
if
(!
optionalUser
.
isPresent
())
{
if
(!
optionalUser
.
isPresent
())
{
Identity
identity
=
new
Identity
();
identity
.
setExternUid
(
TEST_EXTERNAL_UID
);
identity
.
setProvider
(
TEST_EXTERNAL_PROVIDER
);
User
userSettings
=
new
User
()
User
userSettings
=
new
User
()
.
withUsername
(
TEST_LOGIN_USERNAME
)
.
withUsername
(
TEST_LOGIN_USERNAME
)
.
withEmail
(
TEST_LOGIN_USERNAME
+
"@gitlab4j.org"
)
.
withEmail
(
TEST_LOGIN_USERNAME
+
"@gitlab4j.org"
)
.
withName
(
"GitLab4J Tester"
)
.
withName
(
"GitLab4J Tester"
)
.
withSkipConfirmation
(
true
)
.
withSkipConfirmation
(
true
)
.
withIsAdmin
(
true
)
.
withIsAdmin
(
true
);
.
withIdentities
(
Collections
.
singletonList
(
identity
));
gitLabApi
.
getUserApi
().
createUser
(
userSettings
,
TEST_LOGIN_PASSWORD
,
false
);
gitLabApi
.
getUserApi
().
createUser
(
userSettings
,
TEST_LOGIN_PASSWORD
,
false
);
System
.
out
.
format
(
"Created %s user (%s)%n"
,
userSettings
.
getName
(),
userSettings
.
getUsername
());
System
.
out
.
format
(
"Created %s user (%s)%n"
,
userSettings
.
getName
(),
userSettings
.
getUsername
());
}
}
...
...
src/test/java/org/gitlab4j/api/PropertyConstants.java
View file @
5934fd4d
...
@@ -30,4 +30,5 @@ public interface PropertyConstants {
...
@@ -30,4 +30,5 @@ public interface PropertyConstants {
public
static
final
String
XFER_NAMESPACE_KEY
=
"TEST_XFER_NAMESPACE"
;
public
static
final
String
XFER_NAMESPACE_KEY
=
"TEST_XFER_NAMESPACE"
;
public
static
final
String
EXTERNAL_PROVIDER_KEY
=
"TEST_EXTERNAL_PROVIDER"
;
public
static
final
String
EXTERNAL_PROVIDER_KEY
=
"TEST_EXTERNAL_PROVIDER"
;
public
static
final
String
EXTERNAL_UID_KEY
=
"TEST_EXTERNAL_UID"
;
public
static
final
String
EXTERNAL_UID_KEY
=
"TEST_EXTERNAL_UID"
;
public
static
final
String
EXTERNAL_USERNAME_KEY
=
"TEST_EXTERNAL_USERNAME"
;
}
}
src/test/java/org/gitlab4j/api/TestUserApi.java
View file @
5934fd4d
...
@@ -65,6 +65,7 @@ public class TestUserApi extends AbstractIntegrationTest {
...
@@ -65,6 +65,7 @@ public class TestUserApi extends AbstractIntegrationTest {
"tyXN2+OUVXcYAsuIIdGGB0wLvTDgiOOSZWnSE+sg6XX user@example.com"
;
"tyXN2+OUVXcYAsuIIdGGB0wLvTDgiOOSZWnSE+sg6XX user@example.com"
;
private
static
final
String
TEST_USER_EMAIL
=
"test-user-email123@gitlab4j.org"
;
private
static
final
String
TEST_USER_EMAIL
=
"test-user-email123@gitlab4j.org"
;
private
static
final
String
TEST_EXTERNAL_USERNAME
=
HelperUtils
.
getProperty
(
EXTERNAL_USERNAME_KEY
);
private
static
final
String
TEST_EXTERNAL_PROVIDER
=
HelperUtils
.
getProperty
(
EXTERNAL_PROVIDER_KEY
);
private
static
final
String
TEST_EXTERNAL_PROVIDER
=
HelperUtils
.
getProperty
(
EXTERNAL_PROVIDER_KEY
);
private
static
final
String
TEST_EXTERNAL_UID
=
HelperUtils
.
getProperty
(
EXTERNAL_UID_KEY
);
private
static
final
String
TEST_EXTERNAL_UID
=
HelperUtils
.
getProperty
(
EXTERNAL_UID_KEY
);
...
@@ -90,6 +91,15 @@ public class TestUserApi extends AbstractIntegrationTest {
...
@@ -90,6 +91,15 @@ public class TestUserApi extends AbstractIntegrationTest {
if
(
gitLabApi
!=
null
)
{
if
(
gitLabApi
!=
null
)
{
if
(
TEST_EXTERNAL_USERNAME
!=
null
)
{
Optional
<
User
>
optionalUser
=
gitLabApi
.
getUserApi
().
getOptionalUser
(
TEST_EXTERNAL_USERNAME
);
if
(
optionalUser
.
isPresent
())
{
try
{
gitLabApi
.
getUserApi
().
deleteUser
(
optionalUser
.
get
());
}
catch
(
Exception
ignore
)
{}
}
}
if
(
TEST_BLOCK_USERNAME
!=
null
)
{
if
(
TEST_BLOCK_USERNAME
!=
null
)
{
try
{
try
{
blockUser
=
gitLabApi
.
getUserApi
().
getUser
(
TEST_BLOCK_USERNAME
);
blockUser
=
gitLabApi
.
getUserApi
().
getUser
(
TEST_BLOCK_USERNAME
);
...
@@ -183,15 +193,42 @@ public class TestUserApi extends AbstractIntegrationTest {
...
@@ -183,15 +193,42 @@ public class TestUserApi extends AbstractIntegrationTest {
}
}
@Test
@Test
public
void
test
GetOptionalUserBy
ExternalUid
()
throws
GitLabApiException
{
public
void
testExternalUid
()
throws
GitLabApiException
{
Optional
<
User
>
optional
=
gitLabApi
.
getUserApi
().
getOptionalUserByExternalUid
(
TEST_EXTERNAL_PROVIDER
,
TEST_EXTERNAL_UID
);
assumeNotNull
(
TEST_EXTERNAL_USERNAME
);
ass
ert
NotNull
(
optional
);
ass
ume
NotNull
(
TEST_EXTERNAL_PROVIDER
);
ass
ertTrue
(
optional
.
isPresent
()
);
ass
umeNotNull
(
TEST_EXTERNAL_UID
);
optional
=
gitLabApi
.
getUserApi
().
getOptionalUserByExternalUid
(
"unknown-provider"
,
"unknown-uid"
);
User
externalUser
=
null
;
assertNotNull
(
optional
);
try
{
assertFalse
(
optional
.
isPresent
());
User
userSettings
=
new
User
()
.
withUsername
(
TEST_EXTERNAL_USERNAME
)
.
withEmail
(
TEST_EXTERNAL_USERNAME
+
"@gitlab4j.org"
)
.
withName
(
"GitLab4J External User"
)
.
withSkipConfirmation
(
true
)
.
withIsAdmin
(
false
)
.
withExternUid
(
TEST_EXTERNAL_UID
)
.
withProvider
(
TEST_EXTERNAL_PROVIDER
);
externalUser
=
gitLabApi
.
getUserApi
().
createUser
(
userSettings
,
TEST_LOGIN_PASSWORD
,
false
);
assertNotNull
(
externalUser
);
Optional
<
User
>
optionalUser
=
gitLabApi
.
getUserApi
().
getOptionalUserByExternalUid
(
TEST_EXTERNAL_PROVIDER
,
TEST_EXTERNAL_UID
);
assertNotNull
(
optionalUser
);
assertTrue
(
optionalUser
.
isPresent
());
assertEquals
(
externalUser
.
getId
(),
optionalUser
.
get
().
getId
());
optionalUser
=
gitLabApi
.
getUserApi
().
getOptionalUserByExternalUid
(
"unknown-provider"
,
"unknown-uid"
);
assertNotNull
(
optionalUser
);
assertFalse
(
optionalUser
.
isPresent
());
}
finally
{
if
(
externalUser
!=
null
)
{
try
{
gitLabApi
.
getUserApi
().
deleteUser
(
externalUser
);
}
catch
(
Exception
ignore
)
{}
}
}
}
}
@Test
@Test
...
...
src/test/resources/test-gitlab4j.properties
View file @
5934fd4d
...
@@ -29,11 +29,6 @@ TEST_LOGIN_PASSWORD=ChangeMeNow
...
@@ -29,11 +29,6 @@ TEST_LOGIN_PASSWORD=ChangeMeNow
TEST_PROJECT_NAME
=
test-project
TEST_PROJECT_NAME
=
test-project
TEST_USERNAME
=
gitlab4j
TEST_USERNAME
=
gitlab4j
# This specifies the default external provider to test against and the user served by this provider, change
# this if you'd like to test against a different project
TEST_EXTERNAL_PROVIDER
=
github
TEST_EXTERNAL_UID
=
2435223452345
# This is the user to test sudo, block, and project transfer. If the user does not exist
# This is the user to test sudo, block, and project transfer. If the user does not exist
# it will be created during integration testing
# it will be created during integration testing
...
@@ -54,3 +49,9 @@ TEST_PROXY_URI=
...
@@ -54,3 +49,9 @@ TEST_PROXY_URI=
TEST_PROXY_USERNAME
=
TEST_PROXY_USERNAME
=
TEST_PROXY_PASSWORD
=
TEST_PROXY_PASSWORD
=
# OPTIONAL: This specifies an external provider to test against and the user served by this provider.
# Copy to ~/test-gitlab4j.properties and change this if you'd like to test against a different project or user.
# TEST_EXTERNAL_USERNAME=externaluser
# TEST_EXTERNAL_PROVIDER=github
# TEST_EXTERNAL_UID=2435223452345
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