diff --git a/src/main/java/org/gitlab4j/api/services/EmailOnPushService.java b/src/main/java/org/gitlab4j/api/services/EmailOnPushService.java index 247fbbdf46813547aa4536966b70c39a3f645749..4b3c3787308732559497052e892eaf7bb872bcbb 100644 --- a/src/main/java/org/gitlab4j/api/services/EmailOnPushService.java +++ b/src/main/java/org/gitlab4j/api/services/EmailOnPushService.java @@ -32,7 +32,7 @@ public class EmailOnPushService extends NotificationService { @JsonIgnore public String getRecipients() { - return ((String)getProperty(RECIPIENT_PROP)); + return (getProperty(RECIPIENT_PROP)); } public void setRecipients(String recipients) { setProperty(RECIPIENT_PROP, recipients); @@ -45,7 +45,7 @@ public class EmailOnPushService extends NotificationService { @JsonIgnore public Boolean getDisableDiffs() { - return Boolean.valueOf(getProperty(DISABLE_DIFFS_PROP,"false")); + return Boolean.valueOf(getProperty(DISABLE_DIFFS_PROP, false)); } public void setDisableDiffs(Boolean disableDiffs) { setProperty(DISABLE_DIFFS_PROP, disableDiffs); @@ -54,10 +54,10 @@ public class EmailOnPushService extends NotificationService { setDisableDiffs(disableDiffs); return this; } - + @JsonIgnore public Boolean getSendFromCommitterEmail() { - return Boolean.valueOf(getProperty(SEND_FROM_COMMITTER_EMAIL_PROP,"false")); + return Boolean.valueOf(getProperty(SEND_FROM_COMMITTER_EMAIL_PROP, false)); } public void setSendFromCommitterEmail(Boolean sendFromCommitterEmail) { setProperty(SEND_FROM_COMMITTER_EMAIL_PROP, sendFromCommitterEmail); @@ -68,16 +68,20 @@ public class EmailOnPushService extends NotificationService { } @JsonIgnore - public String getBranchesToBeNotified() { - return ((String)getProperty(BRANCHES_TO_BE_NOTIFIED_PROP)); + 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(String branchesToBeNotified) { - setProperty(BRANCHES_TO_BE_NOTIFIED_PROP, branchesToBeNotified); + public void setBranchesToBeNotified(BranchesToBeNotified branchesToBeNotified) { + setProperty(BRANCHES_TO_BE_NOTIFIED_PROP, branchesToBeNotified.toString()); } - public EmailOnPushService withBranchesToBeNotified(String branchesToBeNotified) { + public EmailOnPushService withBranchesToBeNotified(BranchesToBeNotified branchesToBeNotified) { setBranchesToBeNotified(branchesToBeNotified); return this; } - - } diff --git a/src/main/java/org/gitlab4j/api/services/NotificationService.java b/src/main/java/org/gitlab4j/api/services/NotificationService.java index 0ca5f10d29ecb38749c9ca4095bd2ec5e47b1e57..81968ccc90f2134c583fb27fcddafd5a35515d02 100644 --- a/src/main/java/org/gitlab4j/api/services/NotificationService.java +++ b/src/main/java/org/gitlab4j/api/services/NotificationService.java @@ -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 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()); + } + } + } diff --git a/src/test/java/org/gitlab4j/api/TestServicesApi.java b/src/test/java/org/gitlab4j/api/TestServicesApi.java index a4472b93ad8a55ad65ab62bba48de4d7f4eda131..537b38d836b15ef506e2fa4295300ed285d38638 100644 --- a/src/test/java/org/gitlab4j/api/TestServicesApi.java +++ b/src/test/java/org/gitlab4j/api/TestServicesApi.java @@ -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()); + } }