TestGitLabApiEvents.java 11.69 KiB
package org.gitlab4j.api;
import static org.gitlab4j.api.JsonUtils.compareJson;
import static org.gitlab4j.api.JsonUtils.readTreeFromResource;
import static org.gitlab4j.api.JsonUtils.unmarshalResource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.util.logging.Level;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
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.SystemHookListener;
import org.gitlab4j.api.systemhooks.SystemHookManager;
import org.gitlab4j.api.systemhooks.TeamMemberSystemHookEvent;
import org.gitlab4j.api.utils.JacksonJson;
import org.gitlab4j.api.webhook.BuildEvent;
import org.gitlab4j.api.webhook.Event;
import org.gitlab4j.api.webhook.IssueEvent;
import org.gitlab4j.api.webhook.MergeRequestEvent;
import org.gitlab4j.api.webhook.NoteEvent;
import org.gitlab4j.api.webhook.PipelineEvent;
import org.gitlab4j.api.webhook.PushEvent;
import org.gitlab4j.api.webhook.TagPushEvent;
import org.gitlab4j.api.webhook.WikiPageEvent;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class TestGitLabApiEvents {
    private static JacksonJson jacksonJson;
    private static Level savedLevel;
    public TestGitLabApiEvents() {
        super();
    @BeforeClass
    public static void setup() throws Exception {
        jacksonJson = new JacksonJson();
        jacksonJson.getObjectMapper().configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
        savedLevel = GitLabApi.getLogger().getLevel();
    @AfterClass
    public static void teardown() {
        GitLabApi.getLogger().setLevel(savedLevel);
    @Test
    public void testIssueEvent() throws Exception {
        Event issueEvent = unmarshalResource(IssueEvent.class, "issue-event.json");
        assertTrue(compareJson(issueEvent, "issue-event.json"));
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
@Test public void testMergeRequestEvent() throws Exception { Event mergeRequestEvent = unmarshalResource(MergeRequestEvent.class, "merge-request-event.json"); assertTrue(compareJson(mergeRequestEvent, "merge-request-event.json")); } @Test public void testPipelineEvent() throws Exception { Event event = unmarshalResource(PipelineEvent.class, "pipeline-event.json"); assertTrue(compareJson(event, "pipeline-event.json")); } @Test public void testPushEvent() throws Exception { Event pushEvent = unmarshalResource(PushEvent.class, "push-event.json"); assertTrue(compareJson(pushEvent, "push-event.json")); } @Test public void testTagPushEvent() throws Exception { Event pushEvent = unmarshalResource(TagPushEvent.class, "tag-push-event.json"); assertTrue(compareJson(pushEvent, "tag-push-event.json")); } @Test public void testNoteCommitEvent() throws Exception { Event noteEvent = unmarshalResource(NoteEvent.class, "note-commit-event.json"); assertTrue(compareJson(noteEvent, "note-commit-event.json")); } @Test public void testNoteMergeRequestEvent() throws Exception { Event noteEvent = unmarshalResource(NoteEvent.class, "note-merge-request-event.json"); assertTrue(compareJson(noteEvent, "note-merge-request-event.json")); } @Test public void testNoteIssueEvent() throws Exception { Event noteEvent = unmarshalResource(NoteEvent.class, "note-issue-event.json"); assertTrue(compareJson(noteEvent, "note-issue-event.json")); } @Test public void testNoteSnippetEvent() throws Exception { Event noteEvent = unmarshalResource(NoteEvent.class, "note-snippet-event.json"); assertTrue(compareJson(noteEvent, "note-snippet-event.json")); } @Test public void testBuildEvent() throws Exception { Event event = unmarshalResource(BuildEvent.class, "build-event.json"); assertTrue(compareJson(event, "build-event.json")); } @Test public void testWikiPageEvent() throws Exception { Event event = unmarshalResource(WikiPageEvent.class, "wiki-page-event.json"); assertTrue(compareJson(event, "wiki-page-event.json")); }