TestGitLabApiEvents.java 14.40 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.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.util.logging.Level;
import jakarta.servlet.ServletInputStream;
import jakarta.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.ChangeContainer;
import org.gitlab4j.api.webhook.Event;
import org.gitlab4j.api.webhook.IssueEvent;
import org.gitlab4j.api.webhook.JobEvent;
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.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.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();
    @BeforeAll
    public static void setup() throws Exception {
        jacksonJson = new JacksonJson();
        jacksonJson.getObjectMapper().configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
        savedLevel = GitLabApi.getLogger().getLevel();
    @AfterAll
    public static void teardown() {
        GitLabApi.getLogger().setLevel(savedLevel);
    @Test
    public void testIssueEvent() throws Exception {
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
IssueEvent issueEvent = unmarshalResource(IssueEvent.class, "issue-event.json"); assertTrue(compareJson(issueEvent, "issue-event.json")); ChangeContainer<Integer> idChange = issueEvent.getChanges().get("id"); assertNotNull(idChange); assertEquals(123, (int)idChange.getPrevious()); assertEquals(456, (int)idChange.getCurrent()); } @Test public void testIssueChanges() throws Exception { IssueEvent issueEvent = unmarshalResource(IssueEvent.class, "issue-event.json"); assertNotNull(issueEvent); ChangeContainer<Integer> idChange = issueEvent.getChanges().get("id"); assertNotNull(idChange); assertEquals(123, (int)idChange.getPrevious()); assertEquals(456, (int)idChange.getCurrent()); ChangeContainer<Boolean> confidentialChange = issueEvent.getChanges().getConfidential(); assertNotNull(confidentialChange); assertFalse(confidentialChange.getPrevious()); assertTrue(confidentialChange.getCurrent()); } @Test public void testMergeRequestEvent() throws Exception { MergeRequestEvent mergeRequestEvent = unmarshalResource(MergeRequestEvent.class, "merge-request-event.json"); assertTrue(compareJson(mergeRequestEvent, "merge-request-event.json")); } @Test public void testMergeRequestEventChanges() throws Exception { MergeRequestEvent mergeRequestEvent = unmarshalResource(MergeRequestEvent.class, "merge-request-event.json"); assertNotNull(mergeRequestEvent); ChangeContainer<Integer> iidChange = mergeRequestEvent.getChanges().get("iid"); assertNotNull(iidChange); assertEquals(12, (int)iidChange.getPrevious()); assertEquals(34, (int)iidChange.getCurrent()); ChangeContainer<String> mergeStatusChangeChange = mergeRequestEvent.getChanges().getMergeStatus(); assertNotNull(mergeStatusChangeChange); assertNull(mergeStatusChangeChange.getPrevious()); assertEquals("unchecked", mergeStatusChangeChange.getCurrent()); } @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")); }