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
04a76980
Commit
04a76980
authored
Apr 17, 2019
by
Greg Messner
Browse files
Reorganized and added new system hook event tests (#332).
parent
26362d95
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
04a76980
...
@@ -82,10 +82,6 @@ import org.gitlab4j.api.models.User;
...
@@ -82,10 +82,6 @@ import org.gitlab4j.api.models.User;
import
org.gitlab4j.api.models.Variable
;
import
org.gitlab4j.api.models.Variable
;
import
org.gitlab4j.api.services.JiraService
;
import
org.gitlab4j.api.services.JiraService
;
import
org.gitlab4j.api.services.SlackService
;
import
org.gitlab4j.api.services.SlackService
;
import
org.gitlab4j.api.systemhooks.ProjectSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.PushSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.SystemHookEvent
;
import
org.gitlab4j.api.systemhooks.TeamMemberSystemHookEvent
;
import
org.junit.Test
;
import
org.junit.Test
;
public
class
TestGitLabApiBeans
{
public
class
TestGitLabApiBeans
{
...
@@ -442,56 +438,6 @@ public class TestGitLabApiBeans {
...
@@ -442,56 +438,6 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
token
,
"oauth-token.json"
));
assertTrue
(
compareJson
(
token
,
"oauth-token.json"
));
}
}
@Test
public
void
testProjectSystemHookEvent
()
throws
Exception
{
ProjectSystemHookEvent
event
=
unmarshalResource
(
ProjectSystemHookEvent
.
class
,
"project-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"project-system-hook-event.json"
));
}
@Test
public
void
testTeamMemberSystemHookEvent
()
throws
Exception
{
TeamMemberSystemHookEvent
event
=
unmarshalResource
(
TeamMemberSystemHookEvent
.
class
,
"team-member-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"team-member-system-hook-event.json"
));
}
@Test
public
void
testPushSystemHookEvent
()
throws
Exception
{
PushSystemHookEvent
event
=
unmarshalResource
(
PushSystemHookEvent
.
class
,
"push-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"push-system-hook-event.json"
));
}
@Test
public
void
testUserSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"user-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"user-system-hook-event.json"
));
}
@Test
public
void
testGroupSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"group-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"group-system-hook-event.json"
));
}
@Test
public
void
testGroupMemberSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"group-member-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"group-member-system-hook-event.json"
));
}
@Test
public
void
testTagPushSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"tag-push-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"tag-push-system-hook-event.json"
));
}
@Test
public
void
testRepositorySystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"repository-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"repository-system-hook-event.json"
));
}
@Test
@Test
public
void
testLabels
()
throws
Exception
{
public
void
testLabels
()
throws
Exception
{
List
<
Label
>
labels
=
unmarshalResourceList
(
Label
.
class
,
"labels.json"
);
List
<
Label
>
labels
=
unmarshalResourceList
(
Label
.
class
,
"labels.json"
);
...
...
src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java
View file @
04a76980
package
org.gitlab4j.api
;
package
org.gitlab4j.api
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.IOException
;
import
static
org
.
gitlab4j
.
api
.
JsonUtils
.
compareJson
;
import
java.io.InputStreamReader
;
import
static
org
.
gitlab4j
.
api
.
JsonUtils
.
unmarshalResource
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.gitlab4j.api.systemhooks.MergeRequestSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.MergeRequestSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.ProjectSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.PushSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.SystemHookEvent
;
import
org.gitlab4j.api.systemhooks.TeamMemberSystemHookEvent
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.utils.JacksonJson
;
import
org.gitlab4j.api.webhook.BuildEvent
;
import
org.gitlab4j.api.webhook.BuildEvent
;
import
org.gitlab4j.api.webhook.Event
;
import
org.gitlab4j.api.webhook.Event
;
...
@@ -19,11 +23,6 @@ import org.gitlab4j.api.webhook.WikiPageEvent;
...
@@ -19,11 +23,6 @@ import org.gitlab4j.api.webhook.WikiPageEvent;
import
org.junit.BeforeClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.Test
;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
public
class
TestGitLabApiEvents
{
public
class
TestGitLabApiEvents
{
...
@@ -43,149 +42,205 @@ public class TestGitLabApiEvents {
...
@@ -43,149 +42,205 @@ public class TestGitLabApiEvents {
@Test
@Test
public
void
testIssueEvent
()
throws
Exception
{
public
void
testIssueEvent
()
throws
Exception
{
Event
issueEvent
=
makeFakeApiCall
(
IssueEvent
.
class
,
"issue-event"
);
Event
issueEvent
=
unmarshalResource
(
IssueEvent
.
class
,
"issue-event
.json
"
);
assertTrue
(
compareJson
(
issueEvent
,
"issue-event"
));
assertTrue
(
compareJson
(
issueEvent
,
"issue-event
.json
"
));
}
}
@Test
@Test
public
void
testMergeRequestEvent
()
throws
Exception
{
public
void
testMergeRequestEvent
()
throws
Exception
{
Event
mergeRequestEvent
=
makeFakeApiCall
(
MergeRequestEvent
.
class
,
"merge-request-event"
);
Event
mergeRequestEvent
=
unmarshalResource
(
MergeRequestEvent
.
class
,
"merge-request-event.json"
);
assertTrue
(
compareJson
(
mergeRequestEvent
,
"merge-request-event"
));
assertTrue
(
compareJson
(
mergeRequestEvent
,
"merge-request-event.json"
));
}
@Test
public
void
testMergeRequestSystemHookEvent
()
throws
Exception
{
MergeRequestSystemHookEvent
mergeRequestEvent
=
makeFakeApiCall
(
MergeRequestSystemHookEvent
.
class
,
"merge-request-system-hook-event"
);
assertTrue
(
compareJson
(
mergeRequestEvent
,
"merge-request-system-hook-event"
));
}
}
@Test
@Test
public
void
testPipelineEvent
()
throws
Exception
{
public
void
testPipelineEvent
()
throws
Exception
{
Event
event
=
makeFakeApiCall
(
PipelineEvent
.
class
,
"pipeline-event"
);
Event
event
=
unmarshalResource
(
PipelineEvent
.
class
,
"pipeline-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"pipeline-event"
));
assertTrue
(
compareJson
(
event
,
"pipeline-event
.json
"
));
}
}
@Test
@Test
public
void
testPushEvent
()
throws
Exception
{
public
void
testPushEvent
()
throws
Exception
{
Event
pushEvent
=
makeFakeApiCall
(
PushEvent
.
class
,
"push-event"
);
Event
pushEvent
=
unmarshalResource
(
PushEvent
.
class
,
"push-event
.json
"
);
assertTrue
(
compareJson
(
pushEvent
,
"push-event"
));
assertTrue
(
compareJson
(
pushEvent
,
"push-event
.json
"
));
}
}
@Test
@Test
public
void
testTagPushEvent
()
throws
Exception
{
public
void
testTagPushEvent
()
throws
Exception
{
Event
pushEvent
=
makeFakeApiCall
(
TagPushEvent
.
class
,
"tag-push-event"
);
Event
pushEvent
=
unmarshalResource
(
TagPushEvent
.
class
,
"tag-push-event
.json
"
);
assertTrue
(
compareJson
(
pushEvent
,
"tag-push-event"
));
assertTrue
(
compareJson
(
pushEvent
,
"tag-push-event
.json
"
));
}
}
@Test
@Test
public
void
testNoteCommitEvent
()
throws
Exception
{
public
void
testNoteCommitEvent
()
throws
Exception
{
Event
noteEvent
=
makeFakeApiCall
(
NoteEvent
.
class
,
"note-commit-event"
);
Event
noteEvent
=
unmarshalResource
(
NoteEvent
.
class
,
"note-commit-event
.json
"
);
assertTrue
(
compareJson
(
noteEvent
,
"note-commit-event"
));
assertTrue
(
compareJson
(
noteEvent
,
"note-commit-event
.json
"
));
}
}
@Test
@Test
public
void
testNoteMergeRequestEvent
()
throws
Exception
{
public
void
testNoteMergeRequestEvent
()
throws
Exception
{
Event
noteEvent
=
makeFakeApiCall
(
NoteEvent
.
class
,
"note-merge-request-event"
);
Event
noteEvent
=
unmarshalResource
(
NoteEvent
.
class
,
"note-merge-request-event
.json
"
);
assertTrue
(
compareJson
(
noteEvent
,
"note-merge-request-event"
));
assertTrue
(
compareJson
(
noteEvent
,
"note-merge-request-event
.json
"
));
}
}
@Test
@Test
public
void
testNoteIssueEvent
()
throws
Exception
{
public
void
testNoteIssueEvent
()
throws
Exception
{
Event
noteEvent
=
makeFakeApiCall
(
NoteEvent
.
class
,
"note-issue-event"
);
Event
noteEvent
=
unmarshalResource
(
NoteEvent
.
class
,
"note-issue-event
.json
"
);
assertTrue
(
compareJson
(
noteEvent
,
"note-issue-event"
));
assertTrue
(
compareJson
(
noteEvent
,
"note-issue-event
.json
"
));
}
}
@Test
@Test
public
void
testNoteSnippetEvent
()
throws
Exception
{
public
void
testNoteSnippetEvent
()
throws
Exception
{
Event
noteEvent
=
makeFakeApiCall
(
NoteEvent
.
class
,
"note-snippet-event"
);
Event
noteEvent
=
unmarshalResource
(
NoteEvent
.
class
,
"note-snippet-event
.json
"
);
assertTrue
(
compareJson
(
noteEvent
,
"note-snippet-event"
));
assertTrue
(
compareJson
(
noteEvent
,
"note-snippet-event
.json
"
));
}
}
@Test
@Test
public
void
testBuildEvent
()
throws
Exception
{
public
void
testBuildEvent
()
throws
Exception
{
Event
event
=
makeFakeApiCall
(
BuildEvent
.
class
,
"build-event"
);
Event
event
=
unmarshalResource
(
BuildEvent
.
class
,
"build-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"build-event"
));
assertTrue
(
compareJson
(
event
,
"build-event
.json
"
));
}
}
@Test
@Test
public
void
testWikiPageEvent
()
throws
Exception
{
public
void
testWikiPageEvent
()
throws
Exception
{
Event
event
=
makeFakeApiCall
(
WikiPageEvent
.
class
,
"wiki-page-event"
);
Event
event
=
unmarshalResource
(
WikiPageEvent
.
class
,
"wiki-page-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"wiki-page-event"
));
assertTrue
(
compareJson
(
event
,
"wiki-page-event
.json
"
));
}
}
@Test
@Test
public
void
testPolymorphicEvent
()
throws
Exception
{
public
void
testPolymorphicEvent
()
throws
Exception
{
Event
event
=
makeFakeApiCall
(
Event
.
class
,
"build-event"
);
Event
event
=
unmarshalResource
(
Event
.
class
,
"build-event.json"
);
assertTrue
(
compareJson
(
event
,
"build-event"
));
assertTrue
(
compareJson
(
event
,
"build-event.json"
));
event
=
unmarshalResource
(
Event
.
class
,
"issue-event.json"
);
assertTrue
(
compareJson
(
event
,
"issue-event.json"
));
event
=
unmarshalResource
(
Event
.
class
,
"merge-request-event.json"
);
assertTrue
(
compareJson
(
event
,
"merge-request-event.json"
));
event
=
unmarshalResource
(
Event
.
class
,
"note-commit-event.json"
);
assertTrue
(
compareJson
(
event
,
"note-commit-event.json"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"issue-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"
note-
issue-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"issue-event"
));
assertTrue
(
compareJson
(
event
,
"
note-
issue-event
.json
"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"merge-request-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"
note-
merge-request-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"merge-request-event"
));
assertTrue
(
compareJson
(
event
,
"
note-
merge-request-event
.json
"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"note-
commi
t-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"note-
snippe
t-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"note-
commi
t-event"
));
assertTrue
(
compareJson
(
event
,
"note-
snippe
t-event
.json
"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"
note-issu
e-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"
pipelin
e-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"
note-issu
e-event"
));
assertTrue
(
compareJson
(
event
,
"
pipelin
e-event
.json
"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"note-merge-request
-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"push
-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"
note-merge-request
-event"
));
assertTrue
(
compareJson
(
event
,
"
push
-event
.json
"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"
note-snippet
-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"
tag-push
-event
.json
"
);
assertTrue
(
compareJson
(
event
,
"
note-snippet
-event"
));
assertTrue
(
compareJson
(
event
,
"
tag-push
-event
.json
"
));
event
=
makeFakeApiCall
(
Event
.
class
,
"pipeline-event"
);
event
=
unmarshalResource
(
Event
.
class
,
"wiki-page-event.json"
);
assertTrue
(
compareJson
(
event
,
"pipeline-event"
));
assertTrue
(
compareJson
(
event
,
"wiki-page-event.json"
));
}
@Test
public
void
testProjectSystemHookEvent
()
throws
Exception
{
ProjectSystemHookEvent
event
=
unmarshalResource
(
ProjectSystemHookEvent
.
class
,
"project-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"project-system-hook-event.json"
));
}
event
=
makeFakeApiCall
(
Event
.
class
,
"push-event"
);
@Test
assertTrue
(
compareJson
(
event
,
"push-event"
));
public
void
testTeamMemberSystemHookEvent
()
throws
Exception
{
TeamMemberSystemHookEvent
event
=
unmarshalResource
(
TeamMemberSystemHookEvent
.
class
,
"team-member-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"team-member-system-hook-event.json"
));
}
@Test
public
void
testPushSystemHookEvent
()
throws
Exception
{
PushSystemHookEvent
event
=
unmarshalResource
(
PushSystemHookEvent
.
class
,
"push-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"push-system-hook-event.json"
));
}
event
=
makeFakeApiCall
(
Event
.
class
,
"tag-push-event"
);
@Test
assertTrue
(
compareJson
(
event
,
"tag-push-event"
));
public
void
testUserSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"user-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"user-system-hook-event.json"
));
}
event
=
makeFakeApiCall
(
Event
.
class
,
"wiki-page-event"
);
@Test
assertTrue
(
compareJson
(
event
,
"wiki-page-event"
));
public
void
testGroupSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"group-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"group-system-hook-event.json"
));
}
}
private
<
T
>
T
makeFakeApiCall
(
Class
<
T
>
returnType
,
String
file
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
@Test
public
void
testGroupMemberSystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"group-member-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"group-member-system-hook-event.json"
));
}
InputStreamReader
reader
=
new
InputStreamReader
(
GitLabApi
.
class
.
getResourceAsStream
(
file
+
".json"
));
@Test
ObjectMapper
objectMapper
=
jacksonJson
.
getContext
(
returnType
);
public
void
testTagPushSystemHookEvent
()
throws
Exception
{
return
(
objectMapper
.
readValue
(
reader
,
returnType
));
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"tag-push-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"tag-push-system-hook-event.json"
));
}
}
private
<
T
>
boolean
compareJson
(
T
apiObject
,
String
file
)
throws
IOException
{
@Test
public
void
testRepositorySystemHookEvent
()
throws
Exception
{
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"repository-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"repository-system-hook-event.json"
));
}
InputStreamReader
reader
=
new
InputStreamReader
(
GitLabApi
.
class
.
getResourceAsStream
(
file
+
".json"
));
@Test
String
objectJson
=
jacksonJson
.
marshal
(
apiObject
);
public
void
testMergeRequestSystemHookEvent
()
throws
Exception
{
JsonNode
tree1
=
jacksonJson
.
getObjectMapper
().
readTree
(
objectJson
.
getBytes
()
);
MergeRequestSystemHookEvent
mergeRequestEvent
=
unmarshalResource
(
MergeRequestSystemHookEvent
.
class
,
"merge-request-system-hook-event.json"
);
JsonNode
tree2
=
jacksonJson
.
getObjectMapper
().
readTree
(
reader
);
assertTrue
(
compareJson
(
mergeRequestEvent
,
"merge-request-system-hook-event.json"
)
);
boolean
sameJson
=
tree1
.
equals
(
tree2
);
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"merge-request-system-hook-event.json"
);
if
(!
sameJson
)
{
assertTrue
(
compareJson
(
event
,
"merge-request-system-hook-event.json"
));
System
.
out
.
println
(
"JSON did not match:"
);
sortedDump
(
tree1
);
sortedDump
(
tree2
);
}
return
(
sameJson
);
}
}
private
void
sortedDump
(
final
JsonNode
node
)
throws
JsonProcessingException
{
@Test
final
Object
obj
=
jacksonJson
.
getObjectMapper
().
treeToValue
(
node
,
Object
.
class
);
public
void
testPolymorphicSystemHookEvent
()
throws
Exception
{
System
.
out
.
println
(
jacksonJson
.
getObjectMapper
().
writeValueAsString
(
obj
));
SystemHookEvent
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"project-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"project-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"team-member-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"team-member-system-hook-event.json"
));
event
=
unmarshalResource
(
PushSystemHookEvent
.
class
,
"push-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"push-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"user-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"user-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"group-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"group-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"group-member-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"group-member-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"tag-push-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"tag-push-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"repository-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"repository-system-hook-event.json"
));
event
=
unmarshalResource
(
SystemHookEvent
.
class
,
"merge-request-system-hook-event.json"
);
assertTrue
(
compareJson
(
event
,
"merge-request-system-hook-event.json"
));
}
}
}
}
src/test/resources/org/gitlab4j/api/merge-request-system-hook-event.json
View file @
04a76980
{
{
"object_kind"
:
"merge_request"
,
"object_kind"
:
"merge_request"
,
"event_name"
:
"merge_request"
,
"user"
:
{
"user"
:
{
"name"
:
"Administrator"
,
"name"
:
"Administrator"
,
"username"
:
"root"
,
"username"
:
"root"
,
...
...
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