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
48804220
Unverified
Commit
48804220
authored
Jul 05, 2021
by
Gautier de Saint Martin Lacaze
Committed by
GitHub
Jul 05, 2021
Browse files
Merge branch 'master' into master
parents
28c40be0
ebaf80e6
Changes
43
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/models/MembershipSourceType.java
0 → 100644
View file @
48804220
package
org.gitlab4j.api.models
;
import
org.gitlab4j.api.utils.JacksonJsonEnumHelper
;
import
com.fasterxml.jackson.annotation.JsonCreator
;
import
com.fasterxml.jackson.annotation.JsonValue
;
public
enum
MembershipSourceType
{
PROJECT
,
/** Representing a group */
NAMESPACE
;
private
static
JacksonJsonEnumHelper
<
MembershipSourceType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
MembershipSourceType
.
class
);
@JsonCreator
public
static
MembershipSourceType
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
src/main/java/org/gitlab4j/api/models/Namespace.java
View file @
48804220
...
...
@@ -9,6 +9,8 @@ public class Namespace {
private
String
path
;
private
String
kind
;
private
String
fullPath
;
private
String
avatarUrl
;
private
String
webUrl
;
public
Integer
getId
()
{
return
this
.
id
;
...
...
@@ -75,6 +77,22 @@ public class Namespace {
return
this
;
}
public
String
getAvatarUrl
()
{
return
avatarUrl
;
}
public
void
setAvatarUrl
(
String
avatarUrl
)
{
this
.
avatarUrl
=
avatarUrl
;
}
public
String
getWebUrl
()
{
return
webUrl
;
}
public
void
setWebUrl
(
String
webUrl
)
{
this
.
webUrl
=
webUrl
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/main/java/org/gitlab4j/api/models/PipelineStatus.java
View file @
48804220
...
...
@@ -11,9 +11,19 @@ import com.fasterxml.jackson.annotation.JsonValue;
*/
public
enum
PipelineStatus
{
RUNNING
,
PENDING
,
SUCCESS
,
FAILED
,
CANCELED
,
SKIPPED
,
MANUAL
;
private
static
Map
<
String
,
PipelineStatus
>
valuesMap
=
new
HashMap
<>(
6
);
CREATED
,
WAITING_FOR_RESOURCE
,
PREPARING
,
PENDING
,
RUNNING
,
SUCCESS
,
FAILED
,
CANCELED
,
SKIPPED
,
MANUAL
,
SCHEDULED
;
private
static
Map
<
String
,
PipelineStatus
>
valuesMap
=
new
HashMap
<>(
11
);
static
{
for
(
PipelineStatus
status
:
PipelineStatus
.
values
())
valuesMap
.
put
(
status
.
toValue
(),
status
);
...
...
src/main/java/org/gitlab4j/api/models/Project.java
View file @
48804220
...
...
@@ -4,7 +4,10 @@ package org.gitlab4j.api.models;
import
java.util.Date
;
import
java.util.List
;
import
org.gitlab4j.api.Constants.AutoDevopsDeployStrategy
;
import
org.gitlab4j.api.Constants.BuildGitStrategy
;
import
org.gitlab4j.api.ProjectLicense
;
import
org.gitlab4j.api.models.ImportStatus.Status
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.utils.JacksonJsonEnumHelper
;
...
...
@@ -12,8 +15,6 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import
com.fasterxml.jackson.annotation.JsonValue
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
org.gitlab4j.api.Constants.BuildGitStrategy
;
public
class
Project
{
// Enum for the merge_method of the Project instance.
...
...
@@ -94,6 +95,16 @@ public class Project {
private
List
<
CustomAttribute
>
customAttributes
;
private
String
buildCoverageRegex
;
private
BuildGitStrategy
buildGitStrategy
;
private
String
readmeUrl
;
private
Boolean
canCreateMergeRequestIn
;
private
Status
importStatus
;
private
Integer
ciDefaultGitDepth
;
private
Boolean
removeSourceBranchAfterMerge
;
private
Boolean
autoDevopsEnabled
;
private
AutoDevopsDeployStrategy
autoDevopsDeployStrategy
;
private
Boolean
autocloseReferencedIssues
;
private
Boolean
emailsDisabled
;
private
String
suggestionCommitMessage
;
@JsonSerialize
(
using
=
JacksonJson
.
DateOnlySerializer
.
class
)
private
Date
markedForDeletionOn
;
...
...
@@ -736,4 +747,99 @@ public class Project {
this
.
buildGitStrategy
=
buildGitStrategy
;
return
this
;
}
public
String
getReadmeUrl
()
{
return
readmeUrl
;
}
public
void
setReadmeUrl
(
String
readmeUrl
)
{
this
.
readmeUrl
=
readmeUrl
;
}
public
Boolean
getCanCreateMergeRequestIn
()
{
return
canCreateMergeRequestIn
;
}
public
void
setCanCreateMergeRequestIn
(
Boolean
canCreateMergeRequestIn
)
{
this
.
canCreateMergeRequestIn
=
canCreateMergeRequestIn
;
}
public
Status
getImportStatus
()
{
return
importStatus
;
}
public
void
setImportStatus
(
Status
importStatus
)
{
this
.
importStatus
=
importStatus
;
}
public
Integer
getCiDefaultGitDepth
()
{
return
ciDefaultGitDepth
;
}
public
void
setCiDefaultGitDepth
(
Integer
ciDefaultGitDepth
)
{
this
.
ciDefaultGitDepth
=
ciDefaultGitDepth
;
}
public
Boolean
getRemoveSourceBranchAfterMerge
()
{
return
removeSourceBranchAfterMerge
;
}
public
void
setRemoveSourceBranchAfterMerge
(
Boolean
removeSourceBranchAfterMerge
)
{
this
.
removeSourceBranchAfterMerge
=
removeSourceBranchAfterMerge
;
}
public
Project
withRemoveSourceBranchAfterMerge
(
Boolean
removeSourceBranchAfterMerge
)
{
this
.
removeSourceBranchAfterMerge
=
removeSourceBranchAfterMerge
;
return
this
;
}
public
Boolean
getAutoDevopsEnabled
()
{
return
autoDevopsEnabled
;
}
public
void
setAutoDevopsEnabled
(
Boolean
autoDevopsEnabled
)
{
this
.
autoDevopsEnabled
=
autoDevopsEnabled
;
}
public
AutoDevopsDeployStrategy
getAutoDevopsDeployStrategy
()
{
return
autoDevopsDeployStrategy
;
}
public
void
setAutoDevopsDeployStrategy
(
AutoDevopsDeployStrategy
autoDevopsDeployStrategy
)
{
this
.
autoDevopsDeployStrategy
=
autoDevopsDeployStrategy
;
}
public
Boolean
getAutocloseReferencedIssues
()
{
return
autocloseReferencedIssues
;
}
public
void
setAutocloseReferencedIssues
(
Boolean
autocloseReferencedIssues
)
{
this
.
autocloseReferencedIssues
=
autocloseReferencedIssues
;
}
public
Boolean
getEmailsDisabled
()
{
return
emailsDisabled
;
}
public
void
setEmailsDisabled
(
Boolean
emailsDisabled
)
{
this
.
emailsDisabled
=
emailsDisabled
;
}
public
Project
withEmailsDisabled
(
Boolean
emailsDisabled
)
{
this
.
emailsDisabled
=
emailsDisabled
;
return
this
;
}
public
String
getSuggestionCommitMessage
()
{
return
this
.
suggestionCommitMessage
;
}
public
Project
withSuggestionCommitMessage
(
String
suggestionCommitMessage
)
{
this
.
suggestionCommitMessage
=
suggestionCommitMessage
;
return
this
;
}
public
void
setSuggestionCommitMessage
(
String
suggestionCommitMessage
)
{
this
.
suggestionCommitMessage
=
suggestionCommitMessage
;
}
}
src/main/java/org/gitlab4j/api/models/ProjectSharedGroup.java
View file @
48804220
...
...
@@ -3,9 +3,10 @@ package org.gitlab4j.api.models;
import
org.gitlab4j.api.utils.JacksonJson
;
public
class
ProjectSharedGroup
{
private
Integer
groupId
;
private
String
groupName
;
private
String
groupFullPath
;
private
AccessLevel
groupAccessLevel
;
public
int
getGroupId
()
{
...
...
@@ -32,6 +33,14 @@ public class ProjectSharedGroup {
this
.
groupAccessLevel
=
accessLevel
;
}
public
String
getGroupFullPath
()
{
return
groupFullPath
;
}
public
void
setGroupFullPath
(
String
groupFullPath
)
{
this
.
groupFullPath
=
groupFullPath
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/main/java/org/gitlab4j/api/models/ProjectStatistics.java
View file @
48804220
...
...
@@ -16,6 +16,7 @@ public class ProjectStatistics {
long
wikiSize
;
long
lfsObjectsSize
;
long
jobArtifactsSize
;
long
packagesSize
;
public
long
getCommitCount
()
{
return
commitCount
;
...
...
@@ -65,6 +66,14 @@ public class ProjectStatistics {
this
.
jobArtifactsSize
=
jobArtifactsSize
;
}
public
long
getPackagesSize
()
{
return
packagesSize
;
}
public
void
setPackagesSize
(
long
packagesSize
)
{
this
.
packagesSize
=
packagesSize
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/main/java/org/gitlab4j/api/models/SystemHook.java
View file @
48804220
...
...
@@ -13,6 +13,7 @@ public class SystemHook {
private
Boolean
tagPushEvents
;
private
Boolean
enableSslVerification
;
private
Boolean
repositoryUpdateEvents
;
private
Boolean
mergeRequestsEvents
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -70,6 +71,14 @@ public class SystemHook {
return
repositoryUpdateEvents
;
}
public
void
setMergeRequestsEvents
(
Boolean
mergeRequestsEvents
)
{
this
.
mergeRequestsEvents
=
mergeRequestsEvents
;
}
public
Boolean
getMergeRequestsEvents
()
{
return
mergeRequestsEvents
;
}
public
SystemHook
withId
(
Integer
id
)
{
this
.
id
=
id
;
return
(
this
);
...
...
@@ -105,6 +114,11 @@ public class SystemHook {
return
(
this
);
}
public
SystemHook
withMergeRequestsEvents
(
Boolean
mergeRequestsEvents
)
{
this
.
mergeRequestsEvents
=
mergeRequestsEvents
;
return
(
this
);
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/main/java/org/gitlab4j/api/services/EmailOnPushService.java
0 → 100644
View file @
48804220
package
org.gitlab4j.api.services
;
import
org.gitlab4j.api.GitLabApiForm
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
public
class
EmailOnPushService
extends
NotificationService
{
public
static
final
String
RECIPIENT_PROP
=
"recipients"
;
public
static
final
String
DISABLE_DIFFS_PROP
=
"disable_diffs"
;
public
static
final
String
SEND_FROM_COMMITTER_EMAIL_PROP
=
"send_from_committer_email"
;
public
static
final
String
BRANCHES_TO_BE_NOTIFIED_PROP
=
"branches_to_be_notified"
;
@Override
public
GitLabApiForm
servicePropertiesForm
()
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
RECIPIENT_PROP
,
getRecipients
(),
true
)
.
withParam
(
DISABLE_DIFFS_PROP
,
getDisableDiffs
())
.
withParam
(
SEND_FROM_COMMITTER_EMAIL_PROP
,
getSendFromCommitterEmail
())
.
withParam
(
PUSH_EVENTS_PROP
,
getPushEvents
())
.
withParam
(
"tag_push_events"
,
getTagPushEvents
())
.
withParam
(
BRANCHES_TO_BE_NOTIFIED_PROP
,
getBranchesToBeNotified
());
return
formData
;
}
public
EmailOnPushService
withPushEvents
(
Boolean
pushEvents
)
{
return
withPushEvents
(
pushEvents
,
this
);
}
public
EmailOnPushService
withTagPushEvents
(
Boolean
pushEvents
)
{
return
withTagPushEvents
(
pushEvents
,
this
);
}
@JsonIgnore
public
String
getRecipients
()
{
return
(
getProperty
(
RECIPIENT_PROP
));
}
public
void
setRecipients
(
String
recipients
)
{
setProperty
(
RECIPIENT_PROP
,
recipients
);
}
public
EmailOnPushService
withRecipients
(
String
recipients
)
{
setRecipients
(
recipients
);
return
this
;
}
@JsonIgnore
public
Boolean
getDisableDiffs
()
{
return
Boolean
.
valueOf
(
getProperty
(
DISABLE_DIFFS_PROP
,
false
));
}
public
void
setDisableDiffs
(
Boolean
disableDiffs
)
{
setProperty
(
DISABLE_DIFFS_PROP
,
disableDiffs
);
}
public
EmailOnPushService
withDisableDiffs
(
Boolean
disableDiffs
)
{
setDisableDiffs
(
disableDiffs
);
return
this
;
}
@JsonIgnore
public
Boolean
getSendFromCommitterEmail
()
{
return
Boolean
.
valueOf
(
getProperty
(
SEND_FROM_COMMITTER_EMAIL_PROP
,
false
));
}
public
void
setSendFromCommitterEmail
(
Boolean
sendFromCommitterEmail
)
{
setProperty
(
SEND_FROM_COMMITTER_EMAIL_PROP
,
sendFromCommitterEmail
);
}
public
EmailOnPushService
withSendFromCommitterEmail
(
Boolean
sendFromCommitterEmail
)
{
setSendFromCommitterEmail
(
sendFromCommitterEmail
);
return
this
;
}
@JsonIgnore
public
BranchesToBeNotified
getBranchesToBeNotified
()
{
String
branchesToBeNotified
=
getProperty
(
BRANCHES_TO_BE_NOTIFIED_PROP
);
if
(
branchesToBeNotified
==
null
||
branchesToBeNotified
.
isEmpty
())
{
return
null
;
}
return
(
BranchesToBeNotified
.
valueOf
(
branchesToBeNotified
.
toUpperCase
()));
}
public
void
setBranchesToBeNotified
(
BranchesToBeNotified
branchesToBeNotified
)
{
setProperty
(
BRANCHES_TO_BE_NOTIFIED_PROP
,
branchesToBeNotified
.
toString
());
}
public
EmailOnPushService
withBranchesToBeNotified
(
BranchesToBeNotified
branchesToBeNotified
)
{
setBranchesToBeNotified
(
branchesToBeNotified
);
return
this
;
}
}
src/main/java/org/gitlab4j/api/services/NotificationService.java
View file @
48804220
...
...
@@ -34,10 +34,12 @@ public abstract class NotificationService {
private
Integer
id
;
private
String
title
;
private
String
slug
;
private
Date
createdAt
;
private
Date
updatedAt
;
private
Boolean
active
;
private
Boolean
commitEvents
;
private
Boolean
pushEvents
;
private
Boolean
issuesEvents
;
private
Boolean
confidentialIssuesEvents
;
...
...
@@ -61,6 +63,14 @@ public abstract class NotificationService {
this
.
id
=
id
;
}
public
String
getSlug
()
{
return
slug
;
}
public
void
setSlug
(
String
slug
)
{
this
.
slug
=
slug
;
}
public
String
getTitle
()
{
return
title
;
}
...
...
@@ -97,6 +107,19 @@ public abstract class NotificationService {
// The following methods can be used to configure the notification service
// *******************************************************************************
public
Boolean
getCommitEvents
()
{
return
commitEvents
;
}
public
void
setCommitEvents
(
Boolean
commitEvents
)
{
this
.
commitEvents
=
commitEvents
;
}
protected
<
T
>
T
withCommitEvents
(
Boolean
commitEvents
,
T
derivedInstance
)
{
this
.
commitEvents
=
commitEvents
;
return
(
derivedInstance
);
}
public
Boolean
getPushEvents
()
{
return
pushEvents
;
}
...
...
@@ -237,7 +260,7 @@ public abstract class NotificationService {
@JsonIgnore
protected
String
getProperty
(
String
prop
)
{
return
(
(
String
)
getProperty
(
prop
,
""
));
return
(
getProperty
(
prop
,
""
));
}
@JsonIgnore
...
...
@@ -270,4 +293,13 @@ public abstract class NotificationService {
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
public
enum
BranchesToBeNotified
{
ALL
,
DEFAULT
,
PROTECTED
,
DEFAULT_AND_PROTECTED
;
@Override
public
String
toString
()
{
return
(
name
().
toLowerCase
());
}
}
}
src/main/java/org/gitlab4j/api/webhook/NoteEvent.java
View file @
48804220
...
...
@@ -131,6 +131,8 @@ public class NoteEvent extends AbstractEvent {
private
Integer
id
;
private
String
note
;
private
String
discussionId
;
private
String
type
;
private
NoteableType
noteableType
;
private
Integer
authorId
;
private
Date
createdAt
;
...
...
@@ -160,6 +162,22 @@ public class NoteEvent extends AbstractEvent {
this
.
note
=
note
;
}
public
String
getDiscussionId
()
{
return
discussionId
;
}
public
void
setDiscussionId
(
String
discussionId
)
{
this
.
discussionId
=
discussionId
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
NoteableType
getNoteableType
()
{
return
noteableType
;
}
...
...
src/test/java/org/gitlab4j/api/PagerSpliteratorTest.java
View file @
48804220
...
...
@@ -46,6 +46,16 @@ public class PagerSpliteratorTest {
assertFalse
(
success
);
}
@Test
public
void
shouldReturnFalseIfNextPagerItemMissing
()
{
when
(
pager
.
hasNext
()).
thenReturn
(
true
);
when
(
pager
.
next
()).
thenReturn
(
Collections
.
emptyList
());
boolean
success
=
pagerSpliterator
.
tryAdvance
(
System
.
out
::
println
);
assertFalse
(
success
);
}
@Test
public
void
shouldThrowNullPointerExceptionWhenActionIsMissing
()
{
...
...
@@ -75,4 +85,4 @@ public class PagerSpliteratorTest {
assertArrayEquals
(
new
Integer
[]{
1
,
2
,
3
,
4
,
5
},
elements
);
}
}
\ No newline at end of file
}
src/test/java/org/gitlab4j/api/PropertyConstants.java
View file @
48804220
...
...
@@ -2,33 +2,32 @@ package org.gitlab4j.api;
public
interface
PropertyConstants
{
public
static
final
String
TEST_PROJECT_SUBDIRECTORY_PATH
=
"src/main/docs/test-project.txt"
;
public
static
final
String
TEST_PROPERTIES_FILENAME
=
"test-gitlab4j.properties"
;
String
TEST_PROJECT_SUBDIRECTORY_PATH
=
"src/main/docs/test-project.txt"
;
// The following are keys used to look up values in the test properti
u
es file
public
static
final
String
ADMIN_PASSWORD_KEY
=
"TEST_ADMIN_PASSWORD"
;
public
static
final
String
ADMIN_USERNAME_KEY
=
"TEST_ADMIN_USERNAME"
;
public
static
final
String
ACCESS_TOKEN_KEY
=
"TEST_ACCESS_TOKEN"
;
public
static
final
String
BLOCK_USERNAME_KEY
=
"TEST_BLOCK_USERNAME"
;
public
static
final
String
GROUP_KEY
=
"TEST_GROUP"
;
public
static
final
String
GROUP_MEMBER_USERNAME_KEY
=
"TEST_GROUP_MEMBER_USERNAME"
;
public
static
final
String
GROUP_PROJECT_KEY
=
"TEST_GROUP_PROJECT"
;
public
static
final
String
HEALTH_CHECK_TOKEN_KEY
=
"TEST_HEALTH_CHECK_TOKEN"
;
public
static
final
String
HOST_URL_KEY
=
"TEST_HOST_URL"
;
public
static
final
String
LOGIN_PASSWORD_KEY
=
"TEST_LOGIN_PASSWORD"
;
public
static
final
String
LOGIN_USERNAME_KEY
=
"TEST_LOGIN_USERNAME"
;
public
static
final
String
NAMESPACE_KEY
=
"TEST_NAMESPACE"
;
public
static
final
String
PRIVATE_TOKEN_KEY
=
"TEST_PRIVATE_TOKEN"
;
public
static
final
String
PROJECT_NAME_KEY
=
"TEST_PROJECT_NAME"
;
public
static
final
String
PROXY_PASSWORD_KEY
=
"TEST_PROXY_PASSWORD"
;
public
static
final
String
PROXY_URI_KEY
=
"TEST_PROXY_URI"
;
public
static
final
String
PROXY_USERNAME_KEY
=
"TEST_PROXY_USERNAME"
;
public
static
final
String
SUB_GROUP_KEY
=
"TEST_SUB_GROUP"
;
public
static
final
String
SUDO_AS_USERNAME_KEY
=
"TEST_SUDO_AS_USERNAME"
;
public
static
final
String
TEST_REQUEST_ACCESS_USERNAME_KEY
=
"TEST_REQUEST_ACCESS_USERNAME"
;
public
static
final
String
USERNAME_KEY
=
"TEST_USERNAME"
;
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_UID_KEY
=
"TEST_EXTERNAL_UID"
;
public
static
final
String
EXTERNAL_USERNAME_KEY
=
"TEST_EXTERNAL_USERNAME"
;
// The following are keys used to look up values in the test properties file
String
ADMIN_PASSWORD_KEY
=
"TEST_ADMIN_PASSWORD"
;
String
ADMIN_USERNAME_KEY
=
"TEST_ADMIN_USERNAME"
;
String
ACCESS_TOKEN_KEY
=
"TEST_ACCESS_TOKEN"
;
String
BLOCK_USERNAME_KEY
=
"TEST_BLOCK_USERNAME"
;
String
GROUP_KEY
=
"TEST_GROUP"
;
String
GROUP_MEMBER_USERNAME_KEY
=
"TEST_GROUP_MEMBER_USERNAME"
;
String
GROUP_PROJECT_KEY
=
"TEST_GROUP_PROJECT"
;
String
HEALTH_CHECK_TOKEN_KEY
=
"TEST_HEALTH_CHECK_TOKEN"
;
String
HOST_URL_KEY
=
"TEST_HOST_URL"
;
String
LOGIN_PASSWORD_KEY
=
"TEST_LOGIN_PASSWORD"
;
String
LOGIN_USERNAME_KEY
=
"TEST_LOGIN_USERNAME"
;
String
NAMESPACE_KEY
=
"TEST_NAMESPACE"
;
String
PRIVATE_TOKEN_KEY
=
"TEST_PRIVATE_TOKEN"
;
String
PROJECT_NAME_KEY
=
"TEST_PROJECT_NAME"
;
String
PROXY_PASSWORD_KEY
=
"TEST_PROXY_PASSWORD"
;
String
PROXY_URI_KEY
=
"TEST_PROXY_URI"
;
String
PROXY_USERNAME_KEY
=
"TEST_PROXY_USERNAME"
;
String
SUB_GROUP_KEY
=
"TEST_SUB_GROUP"
;
String
SUDO_AS_USERNAME_KEY
=
"TEST_SUDO_AS_USERNAME"
;
String
TEST_REQUEST_ACCESS_USERNAME_KEY
=
"TEST_REQUEST_ACCESS_USERNAME"
;
String
USERNAME_KEY
=
"TEST_USERNAME"
;
String
XFER_NAMESPACE_KEY
=
"TEST_XFER_NAMESPACE"
;
String
EXTERNAL_PROVIDER_KEY
=
"TEST_EXTERNAL_PROVIDER"
;
String
EXTERNAL_UID_KEY
=
"TEST_EXTERNAL_UID"
;
String
EXTERNAL_USERNAME_KEY
=
"TEST_EXTERNAL_USERNAME"
;
}
src/test/java/org/gitlab4j/api/TestDeploymentsApi.java
0 → 100644
View file @
48804220
package
org.gitlab4j.api
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
import
org.gitlab4j.api.Constants.DeploymentStatus
;
import
org.gitlab4j.api.models.Commit
;
import
org.gitlab4j.api.models.Deployment
;
import
org.gitlab4j.api.models.DeploymentFilter
;
import
org.gitlab4j.api.models.Project
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.experimental.categories.Category
;
/**
* In order for these tests to run you must set the following properties in
* test-gitlab4j.properties
*
* TEST_HOST_URL TEST_PRIVATE_TOKEN TEST_USERNAME
*
* If any of the above are NULL, all tests in this class will be skipped.
*
*/
@Category
(
IntegrationTest
.
class
)
public
class
TestDeploymentsApi
extends
AbstractIntegrationTest
{
// The following needs to be set to your test repository
private
static
final
String
TEST_USERNAME
=
HelperUtils
.
getProperty
(
USERNAME_KEY
);
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
public
TestDeploymentsApi
()
{
super
();
}
@BeforeClass
public
static
void
setup
()
{
// Must setup the connection to the GitLab test server
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
if
(
TEST_USERNAME
==
null
||
TEST_USERNAME
.
trim
().
isEmpty
())
{
System
.
err
.
println
(
"TEST_USER_NAME cannot be empty"
);
}
}
@Before
public
void
beforeMethod
()
{
assumeTrue
(
gitLabApi
!=
null
);
assumeTrue
(
testProject
!=
null
);
}
@Test
public
void
testCreateDeployment
()
throws
GitLabApiException
{
assertNotNull
(
testProject
);
String
environment
=
"environment-"
+
HelperUtils
.
getRandomInt
(
1000
);
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
testProject
);
assertTrue
(
"Commits list should not be empty."
,
commits
.
size
()
>
0
);
Deployment
deployment
=
gitLabApi
.
getDeploymentsApi
().
addDeployment
(
testProject
,
environment
,
commits
.
get
(
0
).
getId
(),
testProject
.
getDefaultBranch
(),
false
,
DeploymentStatus
.
RUNNING
);
assertNotNull
(
deployment
);
assertEquals
(
environment
,
deployment
.
getEnvironment
().
getName
());
assertEquals
(
commits
.
get
(
0
).
getId
(),
deployment
.
getSha
());
assertEquals
(
testProject
.
getDefaultBranch
(),
deployment
.
getRef
());
assertEquals
(
DeploymentStatus
.
RUNNING
,
deployment
.
getStatus
());
}
@Test
public
void
testUpdateDeployment
()
throws
GitLabApiException
{
assertNotNull
(
testProject
);
String
environment
=
"environment-"
+
HelperUtils
.
getRandomInt
(
1000
);
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
testProject
);
assertTrue
(
"Commits list should not be empty."
,
commits
.
size
()
>
0
);
Deployment
deployment
=
gitLabApi
.
getDeploymentsApi
().
addDeployment
(
testProject
,
environment
,
commits
.
get
(
0
).
getId
(),
testProject
.
getDefaultBranch
(),
false
,
DeploymentStatus
.
RUNNING
);
assertNotNull
(
deployment
);
assertEquals
(
environment
,
deployment
.
getEnvironment
().
getName
());
assertEquals
(
commits
.
get
(
0
).
getId
(),
deployment
.
getSha
());
assertEquals
(
testProject
.
getDefaultBranch
(),
deployment
.
getRef
());
assertEquals
(
DeploymentStatus
.
RUNNING
,
deployment
.
getStatus
());
Deployment
updatedDeployment
=
gitLabApi
.
getDeploymentsApi
().
updateDeployment
(
testProject
,
deployment
.
getId
(),
DeploymentStatus
.
SUCCESS
);
assertNotNull
(
updatedDeployment
);
assertEquals
(
environment
,
updatedDeployment
.
getEnvironment
().
getName
());
assertEquals
(
commits
.
get
(
0
).
getId
(),
updatedDeployment
.
getSha
());
assertEquals
(
testProject
.
getDefaultBranch
(),
updatedDeployment
.
getRef
());
assertEquals
(
DeploymentStatus
.
SUCCESS
,
updatedDeployment
.
getStatus
());
}
@Test
public
void
testGetDeployment
()
throws
GitLabApiException
{
assertNotNull
(
testProject
);
String
environment
=
"environment-"
+
HelperUtils
.
getRandomInt
(
1000
);
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
testProject
);
assertTrue
(
"Commits list should not be empty."
,
commits
.
size
()
>
0
);
Deployment
deployment
=
gitLabApi
.
getDeploymentsApi
().
addDeployment
(
testProject
,
environment
,
commits
.
get
(
0
).
getId
(),
testProject
.
getDefaultBranch
(),
false
,
DeploymentStatus
.
SUCCESS
);
assertNotNull
(
deployment
);
assertEquals
(
environment
,
deployment
.
getEnvironment
().
getName
());
assertEquals
(
commits
.
get
(
0
).
getId
(),
deployment
.
getSha
());
assertEquals
(
testProject
.
getDefaultBranch
(),
deployment
.
getRef
());
assertEquals
(
DeploymentStatus
.
SUCCESS
,
deployment
.
getStatus
());
Deployment
getDeployment
=
gitLabApi
.
getDeploymentsApi
().
getDeployment
(
testProject
,
deployment
.
getId
());
assertNotNull
(
getDeployment
);
assertEquals
(
environment
,
getDeployment
.
getEnvironment
().
getName
());
assertEquals
(
commits
.
get
(
0
).
getId
(),
getDeployment
.
getSha
());
assertEquals
(
testProject
.
getDefaultBranch
(),
getDeployment
.
getRef
());
assertEquals
(
DeploymentStatus
.
SUCCESS
,
getDeployment
.
getStatus
());
assertEquals
(
deployment
.
getCreatedAt
(),
getDeployment
.
getCreatedAt
());
Optional
<
Deployment
>
optionalDeployment
=
gitLabApi
.
getDeploymentsApi
().
getOptionalDeployment
(
testProject
,
getDeployment
.
getId
());
optionalDeployment
.
ifPresent
(
d
->
{
assertEquals
(
environment
,
d
.
getEnvironment
().
getName
());
assertEquals
(
commits
.
get
(
0
).
getId
(),
d
.
getSha
());
assertEquals
(
testProject
.
getDefaultBranch
(),
d
.
getRef
());
assertEquals
(
DeploymentStatus
.
SUCCESS
,
d
.
getStatus
());
assertEquals
(
deployment
.
getCreatedAt
(),
d
.
getCreatedAt
());
});
if
(!
optionalDeployment
.
isPresent
())
{
fail
(
"A deployment should be present."
);
}
}
@Test
public
void
testGetDeployments
()
throws
GitLabApiException
{
assertNotNull
(
testProject
);
String
environment
=
"environment-"
+
HelperUtils
.
getRandomInt
(
1000
);
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
testProject
);
assertTrue
(
"Commits list should not be empty."
,
commits
.
size
()
>
0
);
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
gitLabApi
.
getDeploymentsApi
().
addDeployment
(
testProject
,
environment
,
commits
.
get
(
0
).
getId
(),
testProject
.
getDefaultBranch
(),
false
,
DeploymentStatus
.
SUCCESS
);
}
Pager
<
Deployment
>
pager
=
gitLabApi
.
getDeploymentsApi
().
getProjectDeployments
(
testProject
,
2
);
while
(
pager
.
hasNext
())
{
pager
.
next
();
assertTrue
(
pager
.
current
().
size
()
==
1
||
pager
.
current
().
size
()
==
2
);
}
List
<
Deployment
>
deployments
=
gitLabApi
.
getDeploymentsApi
().
getProjectDeployments
(
testProject
);
int
unfilteredeploymentNb
=
deployments
.
size
();
assertTrue
(
unfilteredeploymentNb
>=
10
);
DeploymentFilter
deploymentFilter
=
new
DeploymentFilter
();
deploymentFilter
.
setEnvironment
(
environment
);
Pager
<
Deployment
>
filteredPager
=
gitLabApi
.
getDeploymentsApi
().
getProjectDeployments
(
testProject
,
deploymentFilter
);
while
(
filteredPager
.
hasNext
())
{
filteredPager
.
next
();
assertTrue
(
filteredPager
.
current
().
size
()
>
1
&&
filteredPager
.
current
().
size
()
<
unfilteredeploymentNb
);
}
deploymentFilter
.
setEnvironment
(
"none"
);
filteredPager
=
gitLabApi
.
getDeploymentsApi
().
getProjectDeployments
(
testProject
,
deploymentFilter
);
if
(
filteredPager
.
hasNext
())
{
filteredPager
.
next
();
assertTrue
(
"Should be no deployments for environment `none`"
,
filteredPager
.
current
().
size
()
==
0
);
}
Stream
<
Deployment
>
projectDeploymentsStream
=
gitLabApi
.
getDeploymentsApi
().
getProjectDeploymentsStream
(
testProject
);
assertTrue
(
projectDeploymentsStream
.
count
()
>=
10
);
projectDeploymentsStream
=
gitLabApi
.
getDeploymentsApi
().
getProjectDeploymentsStream
(
testProject
,
deploymentFilter
);
assertEquals
(
0L
,
projectDeploymentsStream
.
count
());
}
}
src/test/java/org/gitlab4j/api/TestProjectApi.java
View file @
48804220
...
...
@@ -235,7 +235,10 @@ public class TestProjectApi extends AbstractIntegrationTest {
.
withWikiEnabled
(
true
)
.
withSnippetsEnabled
(
true
)
.
withVisibility
(
Visibility
.
PUBLIC
)
.
withTagList
(
Arrays
.
asList
(
"tag1"
,
"tag2"
));
.
withTagList
(
Arrays
.
asList
(
"tag1"
,
"tag2"
))
.
withMergeMethod
(
Project
.
MergeMethod
.
MERGE
)
.
withSuggestionCommitMessage
(
"SuggestionCommitMessageOriginal"
)
.
withRemoveSourceBranchAfterMerge
(
false
);
Project
newProject
=
gitLabApi
.
getProjectApi
().
createProject
(
project
);
assertNotNull
(
newProject
);
...
...
@@ -247,6 +250,9 @@ public class TestProjectApi extends AbstractIntegrationTest {
assertEquals
(
project
.
getSnippetsEnabled
(),
newProject
.
getSnippetsEnabled
());
assertEquals
(
project
.
getTagList
(),
newProject
.
getTagList
());
assertTrue
(
Visibility
.
PUBLIC
==
newProject
.
getVisibility
()
||
Boolean
.
TRUE
==
newProject
.
getPublic
());
assertEquals
(
Project
.
MergeMethod
.
MERGE
,
newProject
.
getMergeMethod
());
assertEquals
(
project
.
getSuggestionCommitMessage
(),
newProject
.
getSuggestionCommitMessage
());
assertEquals
(
project
.
getRemoveSourceBranchAfterMerge
(),
newProject
.
getRemoveSourceBranchAfterMerge
());
project
=
new
Project
()
.
withId
(
newProject
.
getId
())
...
...
@@ -256,7 +262,10 @@ public class TestProjectApi extends AbstractIntegrationTest {
.
withMergeRequestsEnabled
(
false
)
.
withWikiEnabled
(
false
)
.
withSnippetsEnabled
(
false
)
.
withVisibility
(
Visibility
.
PRIVATE
);
.
withVisibility
(
Visibility
.
PRIVATE
)
.
withMergeMethod
(
Project
.
MergeMethod
.
REBASE_MERGE
)
.
withSuggestionCommitMessage
(
"SuggestionCommitMessageUpdated"
)
.
withRemoveSourceBranchAfterMerge
(
true
);
Project
updatedProject
=
gitLabApi
.
getProjectApi
().
updateProject
(
project
);
assertNotNull
(
updatedProject
);
...
...
@@ -267,6 +276,9 @@ public class TestProjectApi extends AbstractIntegrationTest {
assertEquals
(
project
.
getWikiEnabled
(),
updatedProject
.
getWikiEnabled
());
assertEquals
(
project
.
getSnippetsEnabled
(),
updatedProject
.
getSnippetsEnabled
());
assertTrue
(
Visibility
.
PRIVATE
==
updatedProject
.
getVisibility
()
||
Boolean
.
FALSE
==
updatedProject
.
getPublic
());
assertEquals
(
Project
.
MergeMethod
.
REBASE_MERGE
,
updatedProject
.
getMergeMethod
());
assertEquals
(
project
.
getSuggestionCommitMessage
(),
updatedProject
.
getSuggestionCommitMessage
());
assertEquals
(
true
,
updatedProject
.
getRemoveSourceBranchAfterMerge
());
}
@Test
...
...
src/test/java/org/gitlab4j/api/TestServicesApi.java
View file @
48804220
...
...
@@ -9,9 +9,11 @@ import static org.junit.Assume.assumeNotNull;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.services.BugzillaService
;
import
org.gitlab4j.api.services.CustomIssueTrackerService
;
import
org.gitlab4j.api.services.EmailOnPushService
;
import
org.gitlab4j.api.services.ExternalWikiService
;
import
org.gitlab4j.api.services.JiraService
;
import
org.gitlab4j.api.services.MattermostService
;
import
org.gitlab4j.api.services.NotificationService.BranchesToBeNotified
;
import
org.gitlab4j.api.services.SlackService
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
...
...
@@ -21,300 +23,378 @@ import org.junit.experimental.categories.Category;
import
org.junit.runners.MethodSorters
;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
*
* TEST_NAMESPACE
* TEST_PROJECT_NAME
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
*
* In order for these tests to run you must set the following properties in
* test-gitlab4j.properties
*
* TEST_NAMESPACE TEST_PROJECT_NAME TEST_HOST_URL TEST_PRIVATE_TOKEN
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
@Category
(
IntegrationTest
.
class
)
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
public
class
TestServicesApi
extends
AbstractIntegrationTest
{
private
static
final
String
TEST_ENDPOINT
=
"https://foobar.com/gitlab_service/webhooks/"
;
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
public
TestServicesApi
()
{
super
();
}
@BeforeClass
public
static
void
setup
()
{
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
if
(
testProject
!=
null
)
{
try
{
gitLabApi
.
getServicesApi
().
deleteJiraService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
try
{
gitLabApi
.
getServicesApi
().
deleteSlackService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Before
public
void
beforeMethod
()
{
assumeNotNull
(
testProject
);
}
@Test
public
void
testProjectIdOrPath
()
throws
GitLabApiException
{
Integer
projectId
=
testProject
.
getId
();
JiraService
jiraServiceById
=
gitLabApi
.
getServicesApi
().
getJiraService
(
projectId
);
assertNotNull
(
jiraServiceById
);
JiraService
jiraServiceByPath
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
.
getPathWithNamespace
());
assertNotNull
(
jiraServiceByPath
);
JiraService
jiraServiceByProject
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
);
assertNotNull
(
jiraServiceByProject
);
assertEquals
(
jiraServiceById
.
getTitle
(),
jiraServiceByPath
.
getTitle
());
assertEquals
(
jiraServiceById
.
getTitle
(),
jiraServiceByProject
.
getTitle
());
}
@Test
public
void
testGetJiraService
()
throws
GitLabApiException
{
JiraService
jiraService
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
);
assertNotNull
(
jiraService
);
// Make sure the jira_issue_transition_id is retrievable.
// This is testing that a class cast exception is not thrown.
Integer
jiraIssueTransitionId
=
jiraService
.
getJiraIssueTransitionId
();
assertTrue
(
jiraIssueTransitionId
==
null
||
jiraIssueTransitionId
!=
null
);
}
@Test
public
void
testUpdateJiraService
()
throws
GitLabApiException
{
try
{
JiraService
jiraService
=
new
JiraService
()
.
withCommitEvents
(
true
)
.
withMergeRequestsEvents
(
true
)
.
withUrl
(
"http://jira.example.com"
)
.
withUsername
(
"GitLab4J"
)
.
withPassword
(
"test"
)
.
withProjectKey
(
"GL4J"
);
JiraService
updatedJiraService
=
gitLabApi
.
getServicesApi
().
updateJiraService
(
testProject
,
jiraService
);
assertNotNull
(
updatedJiraService
);
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteJiraService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Test
public
void
testDeleteJiraService
()
throws
GitLabApiException
{
JiraService
jiraService
=
new
JiraService
()
.
withCommitEvents
(
true
)
.
withMergeRequestsEvents
(
true
)
.
withUrl
(
"http://jira.example.com"
)
.
withUsername
(
"GitLab4J"
)
.
withPassword
(
"test"
)
.
withProjectKey
(
"GL4J"
);
JiraService
updatedJiraService
=
gitLabApi
.
getServicesApi
().
updateJiraService
(
testProject
,
jiraService
);
assertNotNull
(
updatedJiraService
);
assertTrue
(
updatedJiraService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteJiraService
(
testProject
);
JiraService
deleteJiraService
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
);
assertNotNull
(
deleteJiraService
);
assertFalse
(
deleteJiraService
.
getActive
());
}
@Test
public
void
testGetSlackService
()
throws
GitLabApiException
{
SlackService
slackService
=
gitLabApi
.
getServicesApi
().
getSlackService
(
testProject
);
assertNotNull
(
slackService
);
}
@Test
public
void
testUpdateSlackService
()
throws
GitLabApiException
{
try
{
SlackService
slackService
=
new
SlackService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.slack.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
SlackService
updatedSlackService
=
gitLabApi
.
getServicesApi
().
updateSlackService
(
testProject
,
slackService
);
assertNotNull
(
updatedSlackService
);
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteSlackService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Test
public
void
testDeleteSlackService
()
throws
GitLabApiException
{
SlackService
slackService
=
new
SlackService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.slack.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
SlackService
updatedSlackService
=
gitLabApi
.
getServicesApi
().
updateSlackService
(
testProject
,
slackService
);
assertNotNull
(
updatedSlackService
);
assertTrue
(
updatedSlackService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteSlackService
(
testProject
);
SlackService
deleteSlackService
=
gitLabApi
.
getServicesApi
().
getSlackService
(
testProject
);
assertNotNull
(
deleteSlackService
);
assertFalse
(
deleteSlackService
.
getActive
());
}
@Test
public
void
testGetExternalWiki
()
throws
GitLabApiException
{
ExternalWikiService
wikiService
=
gitLabApi
.
getServicesApi
().
getExternalWikiService
(
testProject
);
assertNotNull
(
wikiService
);
}
@Test
public
void
testUpdateExternalWiki
()
throws
GitLabApiException
{
try
{
ExternalWikiService
wikiService
=
new
ExternalWikiService
()
.
withExternalWikiUrl
(
"http://wiki.io"
);
ExternalWikiService
updatedExternalWikiService
=
gitLabApi
.
getServicesApi
().
updateExternalWikiService
(
testProject
,
wikiService
);
assertNotNull
(
updatedExternalWikiService
);
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteExternalWikiService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Test
public
void
testDeleteExternalWikiService
()
throws
GitLabApiException
{
ExternalWikiService
wikiService
=
new
ExternalWikiService
()
.
withExternalWikiUrl
(
"http://wiki.io"
);
ExternalWikiService
updatedExternalWikiService
=
gitLabApi
.
getServicesApi
().
updateExternalWikiService
(
testProject
,
wikiService
);
assertNotNull
(
updatedExternalWikiService
);
assertTrue
(
updatedExternalWikiService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteExternalWikiService
(
testProject
);
ExternalWikiService
deleteExternalWikiService
=
gitLabApi
.
getServicesApi
().
getExternalWikiService
(
testProject
);
assertNotNull
(
deleteExternalWikiService
);
assertFalse
(
deleteExternalWikiService
.
getActive
());
}
@Test
public
void
testGetMattermostService
()
throws
GitLabApiException
{
MattermostService
service
=
gitLabApi
.
getServicesApi
().
getMattermostService
(
testProject
);
assertNotNull
(
service
);
}
@Test
public
void
testUpdateMattermostService
()
throws
GitLabApiException
{
try
{
MattermostService
service
=
new
MattermostService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.mattermost.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
MattermostService
updatedService
=
gitLabApi
.
getServicesApi
().
updateMattermostService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertEquals
(
service
.
getWebhook
(),
updatedService
.
getWebhook
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteMattermostService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Test
public
void
testDeleteMattermostService
()
throws
GitLabApiException
{
MattermostService
service
=
new
MattermostService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.mattermost.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
MattermostService
updatedService
=
gitLabApi
.
getServicesApi
().
updateMattermostService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertTrue
(
updatedService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteMattermostService
(
testProject
);
MattermostService
deleteMattermostService
=
gitLabApi
.
getServicesApi
().
getMattermostService
(
testProject
);
assertNotNull
(
deleteMattermostService
);
assertFalse
(
deleteMattermostService
.
getActive
());
}
@Test
public
void
testGetBugzillaService
()
throws
GitLabApiException
{
BugzillaService
service
=
gitLabApi
.
getServicesApi
().
getBugzillaService
(
testProject
);
assertNotNull
(
service
);
}
@Test
public
void
testUpdateBugzillaService
()
throws
GitLabApiException
{
try
{
BugzillaService
service
=
new
BugzillaService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
BugzillaService
updatedService
=
gitLabApi
.
getServicesApi
().
updateBugzillaService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertEquals
(
service
.
getIssuesUrl
(),
updatedService
.
getIssuesUrl
());
assertEquals
(
service
.
getNewIssueUrl
(),
updatedService
.
getNewIssueUrl
());
assertEquals
(
service
.
getProjectUrl
(),
updatedService
.
getProjectUrl
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteBugzillaService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Test
public
void
testDeleteBugzillaService
()
throws
GitLabApiException
{
BugzillaService
service
=
new
BugzillaService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
BugzillaService
updatedService
=
gitLabApi
.
getServicesApi
().
updateBugzillaService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertTrue
(
updatedService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteBugzillaService
(
testProject
);
BugzillaService
deletedService
=
gitLabApi
.
getServicesApi
().
getBugzillaService
(
testProject
);
assertNotNull
(
deletedService
);
assertFalse
(
deletedService
.
getActive
());
}
@Test
public
void
testGetCustomIssueTrackerService
()
throws
GitLabApiException
{
CustomIssueTrackerService
service
=
gitLabApi
.
getServicesApi
().
getCustomIssueTrackerService
(
testProject
);
assertNotNull
(
service
);
}
@Test
public
void
testUpdateCustomIssueTrackerService
()
throws
GitLabApiException
{
try
{
CustomIssueTrackerService
service
=
new
CustomIssueTrackerService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
CustomIssueTrackerService
updatedService
=
gitLabApi
.
getServicesApi
().
updateCustomIssueTrackerService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertEquals
(
service
.
getIssuesUrl
(),
updatedService
.
getIssuesUrl
());
assertEquals
(
service
.
getNewIssueUrl
(),
updatedService
.
getNewIssueUrl
());
assertEquals
(
service
.
getProjectUrl
(),
updatedService
.
getProjectUrl
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteCustomIssueTrackerService
(
testProject
);
}
catch
(
Exception
ignore
)
{}
}
}
@Test
public
void
testDeleteCustomIssueTrackerService
()
throws
GitLabApiException
{
CustomIssueTrackerService
service
=
new
CustomIssueTrackerService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
CustomIssueTrackerService
updatedService
=
gitLabApi
.
getServicesApi
().
updateCustomIssueTrackerService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertTrue
(
updatedService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteCustomIssueTrackerService
(
testProject
);
CustomIssueTrackerService
deletedService
=
gitLabApi
.
getServicesApi
().
getCustomIssueTrackerService
(
testProject
);
assertNotNull
(
deletedService
);
assertFalse
(
deletedService
.
getActive
());
}
private
static
final
String
TEST_ENDPOINT
=
"https://foobar.com/gitlab_service/webhooks/"
;
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
public
TestServicesApi
()
{
super
();
}
@BeforeClass
public
static
void
setup
()
{
// Must setup the connection to the GitLab test server and get the test Project
// instance
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
if
(
testProject
!=
null
)
{
try
{
gitLabApi
.
getServicesApi
().
deleteJiraService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
try
{
gitLabApi
.
getServicesApi
().
deleteSlackService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Before
public
void
beforeMethod
()
{
assumeNotNull
(
testProject
);
}
@Test
public
void
testProjectIdOrPath
()
throws
GitLabApiException
{
Integer
projectId
=
testProject
.
getId
();
JiraService
jiraServiceById
=
gitLabApi
.
getServicesApi
().
getJiraService
(
projectId
);
assertNotNull
(
jiraServiceById
);
JiraService
jiraServiceByPath
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
.
getPathWithNamespace
());
assertNotNull
(
jiraServiceByPath
);
JiraService
jiraServiceByProject
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
);
assertNotNull
(
jiraServiceByProject
);
assertEquals
(
jiraServiceById
.
getSlug
(),
jiraServiceByPath
.
getSlug
());
assertEquals
(
jiraServiceById
.
getSlug
(),
jiraServiceByProject
.
getSlug
());
}
@Test
public
void
testGetJiraService
()
throws
GitLabApiException
{
JiraService
jiraService
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
);
assertNotNull
(
jiraService
);
// Make sure the jira_issue_transition_id is retrievable.
// This is testing that a class cast exception is not thrown.
Integer
jiraIssueTransitionId
=
jiraService
.
getJiraIssueTransitionId
();
assertTrue
(
jiraIssueTransitionId
==
null
||
jiraIssueTransitionId
!=
null
);
}
@Test
public
void
testUpdateJiraService
()
throws
GitLabApiException
{
try
{
JiraService
jiraService
=
new
JiraService
()
.
withCommitEvents
(
true
)
.
withMergeRequestsEvents
(
true
)
.
withUrl
(
"http://jira.example.com"
)
.
withUsername
(
"GitLab4J"
)
.
withPassword
(
"test"
)
.
withProjectKey
(
"GL4J"
);
JiraService
updatedJiraService
=
gitLabApi
.
getServicesApi
().
updateJiraService
(
testProject
,
jiraService
);
assertNotNull
(
updatedJiraService
);
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteJiraService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteJiraService
()
throws
GitLabApiException
{
JiraService
jiraService
=
new
JiraService
()
.
withCommitEvents
(
true
)
.
withMergeRequestsEvents
(
true
)
.
withUrl
(
"http://jira.example.com"
)
.
withUsername
(
"GitLab4J"
)
.
withPassword
(
"test"
)
.
withProjectKey
(
"GL4J"
);
JiraService
updatedJiraService
=
gitLabApi
.
getServicesApi
().
updateJiraService
(
testProject
,
jiraService
);
assertNotNull
(
updatedJiraService
);
assertTrue
(
updatedJiraService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteJiraService
(
testProject
);
JiraService
deleteJiraService
=
gitLabApi
.
getServicesApi
().
getJiraService
(
testProject
);
assertNotNull
(
deleteJiraService
);
assertFalse
(
deleteJiraService
.
getActive
());
}
@Test
public
void
testGetSlackService
()
throws
GitLabApiException
{
SlackService
slackService
=
gitLabApi
.
getServicesApi
().
getSlackService
(
testProject
);
assertNotNull
(
slackService
);
}
@Test
public
void
testUpdateSlackService
()
throws
GitLabApiException
{
try
{
SlackService
slackService
=
new
SlackService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.slack.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
SlackService
updatedSlackService
=
gitLabApi
.
getServicesApi
().
updateSlackService
(
testProject
,
slackService
);
assertNotNull
(
updatedSlackService
);
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteSlackService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteSlackService
()
throws
GitLabApiException
{
SlackService
slackService
=
new
SlackService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.slack.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
SlackService
updatedSlackService
=
gitLabApi
.
getServicesApi
().
updateSlackService
(
testProject
,
slackService
);
assertNotNull
(
updatedSlackService
);
assertTrue
(
updatedSlackService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteSlackService
(
testProject
);
SlackService
deleteSlackService
=
gitLabApi
.
getServicesApi
().
getSlackService
(
testProject
);
assertNotNull
(
deleteSlackService
);
assertFalse
(
deleteSlackService
.
getActive
());
}
@Test
public
void
testGetExternalWiki
()
throws
GitLabApiException
{
ExternalWikiService
wikiService
=
gitLabApi
.
getServicesApi
().
getExternalWikiService
(
testProject
);
assertNotNull
(
wikiService
);
}
@Test
public
void
testUpdateExternalWiki
()
throws
GitLabApiException
{
try
{
ExternalWikiService
wikiService
=
new
ExternalWikiService
()
.
withExternalWikiUrl
(
"http://wiki.io"
);
ExternalWikiService
updatedExternalWikiService
=
gitLabApi
.
getServicesApi
()
.
updateExternalWikiService
(
testProject
,
wikiService
);
assertNotNull
(
updatedExternalWikiService
);
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteExternalWikiService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteExternalWikiService
()
throws
GitLabApiException
{
ExternalWikiService
wikiService
=
new
ExternalWikiService
()
.
withExternalWikiUrl
(
"http://wiki.io"
);
ExternalWikiService
updatedExternalWikiService
=
gitLabApi
.
getServicesApi
()
.
updateExternalWikiService
(
testProject
,
wikiService
);
assertNotNull
(
updatedExternalWikiService
);
assertTrue
(
updatedExternalWikiService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteExternalWikiService
(
testProject
);
ExternalWikiService
deleteExternalWikiService
=
gitLabApi
.
getServicesApi
().
getExternalWikiService
(
testProject
);
assertNotNull
(
deleteExternalWikiService
);
assertFalse
(
deleteExternalWikiService
.
getActive
());
}
@Test
public
void
testGetMattermostService
()
throws
GitLabApiException
{
MattermostService
service
=
gitLabApi
.
getServicesApi
().
getMattermostService
(
testProject
);
assertNotNull
(
service
);
}
@Test
public
void
testUpdateMattermostService
()
throws
GitLabApiException
{
try
{
MattermostService
service
=
new
MattermostService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.mattermost.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
MattermostService
updatedService
=
gitLabApi
.
getServicesApi
().
updateMattermostService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertEquals
(
service
.
getWebhook
(),
updatedService
.
getWebhook
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteMattermostService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteMattermostService
()
throws
GitLabApiException
{
MattermostService
service
=
new
MattermostService
()
.
withMergeRequestsEvents
(
true
)
.
withWebhook
(
"https://hooks.mattermost.com/services/ABCDEFGHI/KJLMNOPQR/wetrewq7897HKLH8998wfjjj"
)
.
withUsername
(
"GitLab4J"
);
MattermostService
updatedService
=
gitLabApi
.
getServicesApi
().
updateMattermostService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertTrue
(
updatedService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteMattermostService
(
testProject
);
MattermostService
deleteMattermostService
=
gitLabApi
.
getServicesApi
().
getMattermostService
(
testProject
);
assertNotNull
(
deleteMattermostService
);
assertFalse
(
deleteMattermostService
.
getActive
());
}
@Test
public
void
testGetBugzillaService
()
throws
GitLabApiException
{
BugzillaService
service
=
gitLabApi
.
getServicesApi
().
getBugzillaService
(
testProject
);
assertNotNull
(
service
);
}
@Test
public
void
testUpdateBugzillaService
()
throws
GitLabApiException
{
try
{
BugzillaService
service
=
new
BugzillaService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
BugzillaService
updatedService
=
gitLabApi
.
getServicesApi
().
updateBugzillaService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertEquals
(
service
.
getIssuesUrl
(),
updatedService
.
getIssuesUrl
());
assertEquals
(
service
.
getNewIssueUrl
(),
updatedService
.
getNewIssueUrl
());
assertEquals
(
service
.
getProjectUrl
(),
updatedService
.
getProjectUrl
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteBugzillaService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteBugzillaService
()
throws
GitLabApiException
{
BugzillaService
service
=
new
BugzillaService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
BugzillaService
updatedService
=
gitLabApi
.
getServicesApi
().
updateBugzillaService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertTrue
(
updatedService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteBugzillaService
(
testProject
);
BugzillaService
deletedService
=
gitLabApi
.
getServicesApi
().
getBugzillaService
(
testProject
);
assertNotNull
(
deletedService
);
assertFalse
(
deletedService
.
getActive
());
}
@Test
public
void
testGetCustomIssueTrackerService
()
throws
GitLabApiException
{
CustomIssueTrackerService
service
=
gitLabApi
.
getServicesApi
().
getCustomIssueTrackerService
(
testProject
);
assertNotNull
(
service
);
}
@Test
public
void
testUpdateCustomIssueTrackerService
()
throws
GitLabApiException
{
try
{
CustomIssueTrackerService
service
=
new
CustomIssueTrackerService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
CustomIssueTrackerService
updatedService
=
gitLabApi
.
getServicesApi
()
.
updateCustomIssueTrackerService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertEquals
(
service
.
getIssuesUrl
(),
updatedService
.
getIssuesUrl
());
assertEquals
(
service
.
getNewIssueUrl
(),
updatedService
.
getNewIssueUrl
());
assertEquals
(
service
.
getProjectUrl
(),
updatedService
.
getProjectUrl
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteCustomIssueTrackerService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteCustomIssueTrackerService
()
throws
GitLabApiException
{
CustomIssueTrackerService
service
=
new
CustomIssueTrackerService
()
.
withIssuesUrl
(
TEST_ENDPOINT
+
"issues"
)
.
withNewIssueUrl
(
TEST_ENDPOINT
+
"new_issue"
)
.
withProjectUrl
(
TEST_ENDPOINT
+
"project"
);
CustomIssueTrackerService
updatedService
=
gitLabApi
.
getServicesApi
()
.
updateCustomIssueTrackerService
(
testProject
,
service
);
assertNotNull
(
updatedService
);
assertTrue
(
updatedService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteCustomIssueTrackerService
(
testProject
);
CustomIssueTrackerService
deletedService
=
gitLabApi
.
getServicesApi
().
getCustomIssueTrackerService
(
testProject
);
assertNotNull
(
deletedService
);
assertFalse
(
deletedService
.
getActive
());
}
@Test
public
void
testGetEmailOnPushService
()
throws
GitLabApiException
{
EmailOnPushService
emailOnPushService
=
gitLabApi
.
getServicesApi
().
getEmailOnPushService
(
testProject
);
assertNotNull
(
emailOnPushService
);
// This is testing that a class cast exception is not thrown.
Boolean
commitEvents
=
emailOnPushService
.
getCommitEvents
();
assertTrue
(
commitEvents
||
!
commitEvents
);
}
@Test
public
void
testUpdateEmailOnPushService
()
throws
GitLabApiException
{
try
{
EmailOnPushService
emailOnPushService
=
new
EmailOnPushService
()
.
withRecipients
(
"email@gitlab4j.localhost"
)
.
withBranchesToBeNotified
(
BranchesToBeNotified
.
ALL
)
.
withDisableDiffs
(
false
)
.
withPushEvents
(
false
)
.
withSendFromCommitterEmail
(
true
)
.
withTagPushEvents
(
false
);
EmailOnPushService
updatedEmailOnPushService
=
gitLabApi
.
getServicesApi
()
.
updateEmailOnPushService
(
testProject
,
emailOnPushService
);
assertNotNull
(
updatedEmailOnPushService
);
assertTrue
(
updatedEmailOnPushService
.
getActive
());
}
finally
{
try
{
gitLabApi
.
getServicesApi
().
deleteEmailonPushService
(
testProject
);
}
catch
(
Exception
ignore
)
{
}
}
}
@Test
public
void
testDeleteEmailOnPushService
()
throws
GitLabApiException
{
EmailOnPushService
emailOnPushService
=
new
EmailOnPushService
()
.
withRecipients
(
"email@gitlab4j.localhost"
)
.
withPushEvents
(
false
);
EmailOnPushService
updatedEmailOnPushService
=
gitLabApi
.
getServicesApi
().
updateEmailOnPushService
(
testProject
,
emailOnPushService
);
assertNotNull
(
updatedEmailOnPushService
);
assertTrue
(
updatedEmailOnPushService
.
getActive
());
gitLabApi
.
getServicesApi
().
deleteEmailonPushService
(
testProject
);
EmailOnPushService
deleteEmailOnPushService
=
gitLabApi
.
getServicesApi
().
getEmailOnPushService
(
testProject
);
assertNotNull
(
deleteEmailOnPushService
);
assertFalse
(
deleteEmailOnPushService
.
getActive
());
}
}
src/test/java/org/gitlab4j/api/TestSystemHooksApi.java
View file @
48804220
...
...
@@ -63,13 +63,33 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
assertEquals
(
TEST_HOOK_URL
,
hook
.
getUrl
());
assertTrue
(
hook
.
getPushEvents
());
assertFalse
(
hook
.
getTagPushEvents
());
assertFalse
(
hook
.
getMergeRequestsEvents
());
assertFalse
(
hook
.
getRepositoryUpdateEvents
());
assertTrue
(
hook
.
getEnableSslVerification
());
gitLabApi
.
getSystemHooksApi
().
deleteSystemHook
(
hook
);
hook
.
withPushEvents
(
false
)
.
withTagPushEvents
(
true
)
.
withMergeRequestsEvents
(
true
)
.
withRepositoryUpdateEvents
(
true
)
.
withEnableSslVerification
(
false
);
SystemHook
updatedHook
=
gitLabApi
.
getSystemHooksApi
().
addSystemHook
(
TEST_HOOK_URL
,
TEST_SECRET_TOKEN
,
hook
);
assertNotNull
(
updatedHook
);
assertEquals
(
TEST_HOOK_URL
,
updatedHook
.
getUrl
());
assertFalse
(
hook
.
getPushEvents
());
assertTrue
(
hook
.
getTagPushEvents
());
assertTrue
(
hook
.
getMergeRequestsEvents
());
assertTrue
(
hook
.
getRepositoryUpdateEvents
());
assertFalse
(
hook
.
getEnableSslVerification
());
gitLabApi
.
getSystemHooksApi
().
deleteSystemHook
(
hook
);
}
@Test
public
void
testGe
r
SystemHooks
()
throws
GitLabApiException
{
public
void
testGe
t
SystemHooks
()
throws
GitLabApiException
{
SystemHook
hook
=
gitLabApi
.
getSystemHooksApi
().
addSystemHook
(
TEST_HOOK_URL
,
TEST_SECRET_TOKEN
,
true
,
false
,
true
);
assertNotNull
(
hook
);
...
...
@@ -77,7 +97,7 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
List
<
SystemHook
>
hooks
=
gitLabApi
.
getSystemHooksApi
().
getSystemHooks
();
assertNotNull
(
hooks
);
assertFalse
(
hooks
.
isEmpty
());
gitLabApi
.
getSystemHooksApi
().
deleteSystemHook
(
hook
);
}
}
src/test/java/org/gitlab4j/api/TestUserApi.java
View file @
48804220
...
...
@@ -18,10 +18,13 @@ import java.util.Optional;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.Email
;
import
org.gitlab4j.api.models.GpgKey
;
import
org.gitlab4j.api.models.ImpersonationToken
;
import
org.gitlab4j.api.models.ImpersonationToken.Scope
;
import
org.gitlab4j.api.models.Membership
;
import
org.gitlab4j.api.models.MembershipSourceType
;
import
org.gitlab4j.api.models.SshKey
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.models.Version
;
...
...
@@ -540,4 +543,32 @@ public class TestUserApi extends AbstractIntegrationTest {
found
=
keys
.
stream
().
filter
(
e
->
e
.
getKey
().
equals
(
TEST_GPG_KEY
)).
findAny
().
orElse
(
null
);
assertNull
(
found
);
}
public
void
testGetMemberships
()
throws
GitLabApiException
{
User
currentUser
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
assertNotNull
(
currentUser
);
List
<
Membership
>
memberships
=
gitLabApi
.
getUserApi
().
getMemberships
(
currentUser
.
getId
());
assertNotNull
(
memberships
);
assertEquals
(
3
,
memberships
.
size
());
Membership
membership1
=
memberships
.
get
(
0
);
assertMembershipEquals
(
membership1
,
1
,
"test-project"
,
MembershipSourceType
.
PROJECT
,
AccessLevel
.
MAINTAINER
);
Membership
membership2
=
memberships
.
get
(
1
);
assertMembershipEquals
(
membership2
,
4
,
"Test Group"
,
MembershipSourceType
.
NAMESPACE
,
AccessLevel
.
OWNER
);
Membership
membership3
=
memberships
.
get
(
2
);
assertMembershipEquals
(
membership3
,
5
,
"subgroup"
,
MembershipSourceType
.
NAMESPACE
,
AccessLevel
.
OWNER
);
}
private
void
assertMembershipEquals
(
Membership
actualMembership
,
int
expectedSourceId
,
String
expectedSourceName
,
MembershipSourceType
expectedSourceType
,
AccessLevel
expectedAccessLevel
)
{
assertEquals
(
expectedSourceId
,
actualMembership
.
getSourceId
().
intValue
());
assertEquals
(
expectedSourceName
,
actualMembership
.
getSourceName
());
assertEquals
(
expectedSourceType
,
actualMembership
.
getSourceType
());
assertEquals
(
expectedAccessLevel
,
actualMembership
.
getAccessLevel
());
}
}
src/test/resources/org/gitlab4j/api/branch.json
View file @
48804220
...
...
@@ -2,8 +2,11 @@
"name"
:
"master"
,
"merged"
:
false
,
"protected"
:
true
,
"default"
:
true
,
"developers_can_push"
:
false
,
"developers_can_merge"
:
false
,
"can_push"
:
true
,
"web_url"
:
"http://gitlab.example.com/my-group/my-project/-/tree/master"
,
"commit"
:
{
"author_email"
:
"john@example.com"
,
"author_name"
:
"John Smith"
,
...
...
@@ -12,6 +15,8 @@
"committer_email"
:
"john@example.com"
,
"committer_name"
:
"John Smith"
,
"id"
:
"7b5c3cc8be40ee161ae89a06bba6229da1032a0c"
,
"short_id"
:
"7b5c3cc"
,
"title"
:
"add projects API"
,
"message"
:
"add projects API"
,
"parent_ids"
:
[
"4ad91d3c1144c406e50c7b33bae684bd6837faf8"
...
...
src/test/resources/org/gitlab4j/api/note-commit-event.json
View file @
48804220
...
...
@@ -30,6 +30,8 @@
"object_attributes"
:
{
"id"
:
1243
,
"note"
:
"This is a commit comment. How does this work?"
,
"discussion_id"
:
"56e2b4210419aed077d47ca2dc00551c7c4ac882"
,
"type"
:
"DiscussionNote"
,
"noteable_type"
:
"Commit"
,
"author_id"
:
1
,
"created_at"
:
"2015-05-17T18:08:09Z"
,
...
...
src/test/resources/org/gitlab4j/api/note-issue-event.json
View file @
48804220
...
...
@@ -29,6 +29,8 @@
"object_attributes"
:
{
"id"
:
1241
,
"note"
:
"Hello world"
,
"discussion_id"
:
"56e2b4210419aed077d47ca2dc00551c7c4ac882"
,
"type"
:
"DiscussionNote"
,
"noteable_type"
:
"Issue"
,
"author_id"
:
1
,
"created_at"
:
"2015-05-17T17:06:40Z"
,
...
...
Prev
1
2
3
Next
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