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
a62fa83b
Commit
a62fa83b
authored
May 01, 2019
by
Greg Messner
Browse files
Now only creates personal access tokens if not in properties file (#311).
parent
03651d35
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/IntegrationTestSuite.java
View file @
a62fa83b
...
@@ -28,11 +28,13 @@ public class IntegrationTestSuite implements PropertyConstants {
...
@@ -28,11 +28,13 @@ public class IntegrationTestSuite implements PropertyConstants {
protected
static
final
String
TEST_NAMESPACE
=
HelperUtils
.
getProperty
(
NAMESPACE_KEY
);
protected
static
final
String
TEST_NAMESPACE
=
HelperUtils
.
getProperty
(
NAMESPACE_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
;
protected
static
String
TEST_PRIVATE_TOKEN
=
HelperUtils
.
getProperty
(
PRIVATE_TOKEN_KEY
)
;
protected
static
final
String
TEST_ACCESS_TOKEN_NAME
=
"GitLab4J Test Access Token - "
+
HelperUtils
.
getRandomInt
(
1000
);
protected
static
final
String
TEST_ACCESS_TOKEN_NAME
=
"GitLab4J Test Access Token - "
+
HelperUtils
.
getRandomInt
(
1000
);
protected
static
String
TEST_ACCESS_TOKEN
;
protected
static
String
TEST_ACCESS_TOKEN
=
HelperUtils
.
getProperty
(
ACCESS_TOKEN_KEY
)
;
private
static
boolean
createdPrivateToken
=
false
;
private
static
boolean
createdAccessToken
=
false
;
private
static
String
problems
=
""
;
private
static
String
problems
=
""
;
@BeforeClass
@BeforeClass
...
@@ -58,22 +60,31 @@ public class IntegrationTestSuite implements PropertyConstants {
...
@@ -58,22 +60,31 @@ public class IntegrationTestSuite implements PropertyConstants {
fail
(
problems
);
fail
(
problems
);
}
}
// Create a new personal access token for both the private and access tokens
// If the private token is not in the properties, create it
TEST_PRIVATE_TOKEN
=
AccessTokenUtils
.
createPersonalAccessToken
(
if
(
TEST_PRIVATE_TOKEN
==
null
||
TEST_PRIVATE_TOKEN
.
trim
().
isEmpty
())
{
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
TEST_PRIVATE_TOKEN_NAME
,
Arrays
.
asList
(
"api"
,
"sudo"
));
TEST_PRIVATE_TOKEN
=
AccessTokenUtils
.
createPersonalAccessToken
(
System
.
out
.
println
(
"Created private token: "
+
TEST_PRIVATE_TOKEN
);
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
assertNotNull
(
TEST_PRIVATE_TOKEN
);
TEST_PRIVATE_TOKEN_NAME
,
Arrays
.
asList
(
"api"
,
"sudo"
));
assertFalse
(
TEST_PRIVATE_TOKEN
.
trim
().
isEmpty
());
System
.
out
.
println
(
"Created private token: "
+
TEST_PRIVATE_TOKEN
);
HelperUtils
.
setProperty
(
PRIVATE_TOKEN_KEY
,
TEST_PRIVATE_TOKEN
);
assertNotNull
(
TEST_PRIVATE_TOKEN
);
assertFalse
(
TEST_PRIVATE_TOKEN
.
trim
().
isEmpty
());
TEST_ACCESS_TOKEN
=
AccessTokenUtils
.
createPersonalAccessToken
(
HelperUtils
.
setProperty
(
PRIVATE_TOKEN_KEY
,
TEST_PRIVATE_TOKEN
);
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
createdPrivateToken
=
true
;
TEST_ACCESS_TOKEN_NAME
,
Arrays
.
asList
(
"api"
,
"sudo"
));
}
System
.
out
.
println
(
"Created access token: "
+
TEST_ACCESS_TOKEN
);
assertNotNull
(
TEST_ACCESS_TOKEN
);
// If the access token is not in the properties, create it t
assertFalse
(
TEST_ACCESS_TOKEN
.
trim
().
isEmpty
());
if
(
TEST_ACCESS_TOKEN
==
null
||
TEST_ACCESS_TOKEN
.
trim
().
isEmpty
())
{
HelperUtils
.
setProperty
(
ACCESS_TOKEN_KEY
,
TEST_ACCESS_TOKEN
);
TEST_ACCESS_TOKEN
=
AccessTokenUtils
.
createPersonalAccessToken
(
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
TEST_ACCESS_TOKEN_NAME
,
Arrays
.
asList
(
"api"
,
"sudo"
));
System
.
out
.
println
(
"Created access token: "
+
TEST_ACCESS_TOKEN
);
assertNotNull
(
TEST_ACCESS_TOKEN
);
assertFalse
(
TEST_ACCESS_TOKEN
.
trim
().
isEmpty
());
HelperUtils
.
setProperty
(
ACCESS_TOKEN_KEY
,
TEST_ACCESS_TOKEN
);
createdAccessToken
=
true
;
}
}
}
@AfterClass
@AfterClass
...
@@ -83,7 +94,7 @@ public class IntegrationTestSuite implements PropertyConstants {
...
@@ -83,7 +94,7 @@ public class IntegrationTestSuite implements PropertyConstants {
System
.
out
.
println
(
"* Test Suite Teardown *"
);
System
.
out
.
println
(
"* Test Suite Teardown *"
);
System
.
out
.
println
(
"********************************************************"
);
System
.
out
.
println
(
"********************************************************"
);
if
(
TEST_PRIVATE_TOKEN
!=
null
)
{
if
(
createdPrivateToken
&&
TEST_PRIVATE_TOKEN
!=
null
)
{
try
{
try
{
AccessTokenUtils
.
revokePersonalAccessToken
(
AccessTokenUtils
.
revokePersonalAccessToken
(
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
...
@@ -92,7 +103,7 @@ public class IntegrationTestSuite implements PropertyConstants {
...
@@ -92,7 +103,7 @@ public class IntegrationTestSuite implements PropertyConstants {
}
catch
(
Exception
ignore
)
{}
}
catch
(
Exception
ignore
)
{}
}
}
if
(
TEST_ACCESS_TOKEN
!=
null
)
{
if
(
createdAccessToken
&&
TEST_ACCESS_TOKEN
!=
null
)
{
try
{
try
{
AccessTokenUtils
.
revokePersonalAccessToken
(
AccessTokenUtils
.
revokePersonalAccessToken
(
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
TEST_HOST_URL
,
TEST_LOGIN_USERNAME
,
TEST_LOGIN_PASSWORD
,
...
...
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