diff --git a/src/main/resources/atlassian-plugin.xml b/src/main/resources/atlassian-plugin.xml
index 8e67e6c..e614663 100644
--- a/src/main/resources/atlassian-plugin.xml
+++ b/src/main/resources/atlassian-plugin.xml
@@ -31,4 +31,16 @@
/prnfs/admin
+
+
+
+ triggerManualNotification
+ ${project.groupId}-${project.artifactId}:pr-triggerbutton
+
+
+
+
+ com.atlassian.stash.stash-web-plugin:global
+ stash.page.pullRequest.view
+
diff --git a/src/main/resources/pr-triggerbutton.js b/src/main/resources/pr-triggerbutton.js
new file mode 100644
index 0000000..30b31e9
--- /dev/null
+++ b/src/main/resources/pr-triggerbutton.js
@@ -0,0 +1,44 @@
+define('plugin/prnfs/pr-triggerbutton', [
+ 'jquery',
+ 'aui',
+ 'model/page-state'
+], function($, AJS, pageState) {
+
+ var getResourceUrl = function() {
+ return AJS.contextPath() + '/rest/prnfs-admin/1.0/manual/?repositoryId=' + pageState.getRepository().getId() + '&pullRequestId=' + pageState.getPullRequest().getId();
+ };
+
+ var waiting = '
Wait';
+
+ var $buttonArea = $(".triggerManualNotification").parent();
+ var $buttonTemplate = $(".triggerManualNotification");
+ $buttonTemplate.empty().remove();
+
+ $.get(getResourceUrl(), function(settings) {
+ settings.forEach(function(item) {
+ var $button = $buttonTemplate.clone();
+ $button.html(item.title);
+ $button.click(function() {
+ var $this = $(this);
+ var text = $this.text();
+
+ $this.attr("disabled", "disabled").html(waiting + " " + text);
+
+ $.post(getResourceUrl()+'&formIdentifier='+item.formIdentifier, function() {
+ setTimeout(function() {
+ $this.removeAttr("disabled").text(text);
+ }, 500);
+ });
+
+ return false;
+ });
+
+ $buttonArea.append($button);
+ });
+ });
+
+});
+
+AJS.$(document).ready(function() {
+ require('plugin/prnfs/pr-triggerbutton');
+});
diff --git a/src/test/java/se/bjurr/prnfs/ManualResourceTest.java b/src/test/java/se/bjurr/prnfs/ManualResourceTest.java
new file mode 100644
index 0000000..239f715
--- /dev/null
+++ b/src/test/java/se/bjurr/prnfs/ManualResourceTest.java
@@ -0,0 +1,45 @@
+package se.bjurr.prnfs;
+
+import static java.lang.Boolean.FALSE;
+import static java.lang.Boolean.TRUE;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static se.bjurr.prnfs.ManualResource.canUseButton;
+import static se.bjurr.prnfs.admin.AdminFormValues.BUTTON_VISIBILITY.ADMIN;
+import static se.bjurr.prnfs.admin.AdminFormValues.BUTTON_VISIBILITY.EVERYONE;
+import static se.bjurr.prnfs.admin.AdminFormValues.BUTTON_VISIBILITY.NONE;
+import static se.bjurr.prnfs.admin.AdminFormValues.BUTTON_VISIBILITY.SYSTEM_ADMIN;
+
+import org.junit.Test;
+
+import se.bjurr.prnfs.settings.PrnfsButton;
+
+public class ManualResourceTest {
+
+ @Test
+ public void testThatButtonIsOnlyDisplayedForPrivilegedUsers() {
+ PrnfsButton everyone = new PrnfsButton("", EVERYONE, "");
+ PrnfsButton admin = new PrnfsButton("", ADMIN, "");
+ PrnfsButton systemAdmin = new PrnfsButton("", SYSTEM_ADMIN, "");
+ PrnfsButton none = new PrnfsButton("", NONE, "");
+
+ assertTrue(canUseButton(everyone, TRUE, TRUE));
+ assertTrue(canUseButton(everyone, TRUE, FALSE));
+ assertTrue(canUseButton(everyone, FALSE, TRUE));
+
+ assertTrue(canUseButton(admin, TRUE, TRUE));
+ assertFalse(canUseButton(admin, FALSE, TRUE));
+ assertTrue(canUseButton(admin, TRUE, FALSE));
+ assertFalse(canUseButton(admin, FALSE, FALSE));
+
+ assertTrue(canUseButton(systemAdmin, TRUE, TRUE));
+ assertTrue(canUseButton(systemAdmin, FALSE, TRUE));
+ assertTrue(canUseButton(systemAdmin, TRUE, FALSE));
+ assertFalse(canUseButton(systemAdmin, FALSE, FALSE));
+
+ assertFalse(canUseButton(none, FALSE, FALSE));
+ assertFalse(canUseButton(none, FALSE, TRUE));
+ assertFalse(canUseButton(none, TRUE, FALSE));
+ assertFalse(canUseButton(none, FALSE, FALSE));
+ }
+}
diff --git a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java
index c3ce568..2a59eb0 100644
--- a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java
+++ b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java
@@ -19,8 +19,10 @@
import static se.bjurr.prnfs.admin.utils.PullRequestEventBuilder.PREVIOUS_TO_HASH;
import static se.bjurr.prnfs.admin.utils.PullRequestEventBuilder.pullRequestEventBuilder;
import static se.bjurr.prnfs.admin.utils.PullRequestRefBuilder.pullRequestRefBuilder;
+import static se.bjurr.prnfs.listener.PrnfsPullRequestAction.BUTTON_TRIGGER;
import static se.bjurr.prnfs.listener.PrnfsPullRequestAction.RESCOPED_FROM;
import static se.bjurr.prnfs.listener.PrnfsPullRequestAction.RESCOPED_TO;
+import static se.bjurr.prnfs.listener.PrnfsRenderer.PrnfsVariable.BUTTON_TRIGGER_TITLE;
import java.io.IOException;
import java.net.URL;
@@ -30,6 +32,7 @@
import org.junit.Test;
import se.bjurr.prnfs.admin.AdminFormValues.FIELDS;
+import se.bjurr.prnfs.admin.utils.PrnfsTestBuilder;
import se.bjurr.prnfs.admin.utils.PullRequestEventBuilder;
import se.bjurr.prnfs.admin.utils.PullRequestRefBuilder;
import se.bjurr.prnfs.listener.PrnfsPullRequestAction;
@@ -104,30 +107,42 @@ public void testThatAUrlWithoutVariablesCanBeInvoked() {
}
@Test
- public void testThatAUrlWithVariablesFromCanBeInvoked() {
+ public void testThatAUrlWithVariablesFromAndToCanBeInvoked() throws Exception {
for (final PrnfsVariable prnfsVariable : PrnfsVariable.values()) {
if (!prnfsVariable.name().contains("_FROM_") && !prnfsVariable.name().contains("_TO_")) {
continue;
}
- PullRequestEventBuilder builder = prnfsTestBuilder()
+ PrnfsTestBuilder builder = prnfsTestBuilder()
.isLoggedInAsAdmin()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "The Button")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "The Button Text")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build())
.withNotification(
notificationBuilder()
- .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/${" + prnfsVariable.name() + "}")
- .withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()).build()).store()
- .triggerPullRequestEventBuilder();
+ .withFieldValue(AdminFormValues.FIELDS.url,
+ "http://bjurr.se/${" + prnfsVariable.name() + "}${" + PrnfsVariable.BUTTON_TRIGGER_TITLE.name() + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, OPENED.name())
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER).build()).store();
+ PullRequestEventBuilder eventBuilder = builder.triggerPullRequestEventBuilder();
PullRequestRefBuilder refBuilder;
if (prnfsVariable.name().contains("_FROM_")) {
- refBuilder = builder.withFromRefPullRequestRefBuilder();
+ refBuilder = eventBuilder.withFromRefPullRequestRefBuilder();
} else {
- refBuilder = builder.withToRefPullRequestRefBuilder();
+ refBuilder = eventBuilder.withToRefPullRequestRefBuilder();
}
- refBuilder.withHash("10").withId("10").withProjectId(10).withProjectKey("10").withRepositoryId(10)
- .withRepositoryName("10").withRepositorySlug("10").withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.http, "10")
- .withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.ssh, "10").withDisplayId("10").build().withId(10L)
- .withPullRequestAction(OPENED).triggerEvent().invokedUrl(0, "http://bjurr.se/10");
+ PullRequestEventBuilder pullRequestEventBuilder = refBuilder.withHash("10").withId("10").withProjectId(10)
+ .withProjectKey("10").withRepositoryId(10).withRepositoryName("10").withRepositorySlug("10")
+ .withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.http, "10").withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.ssh, "10")
+ .withDisplayId("10").build().withId(10L);
+ pullRequestEventBuilder.withPullRequestAction(OPENED).triggerEvent().invokedOnlyUrl("http://bjurr.se/10");
+
+ builder.withPullRequest(pullRequestEventBuilder.build().getPullRequest()).triggerButton("The Button")
+ .invokedUrl(1, "http://bjurr.se/10The%20Button%20Text");
}
}
@@ -814,6 +829,128 @@ public void testThatProxyDoesNotAuthenticateIfNoPassword() {
.usedNoProxyAuthentication(0);
}
+ @Test
+ public void testThatButtonCanBeUsedForTriggeringEvent() throws Exception {
+ prnfsTestBuilder()
+ .isLoggedInAsAdmin()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "Button Form")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "Trigger notification")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build()).store().triggerButton("Button Form").invokedOnlyUrl("http://bjurr.se/Trigger%20notification")
+ .hasButtonEnabled("Button Form");
+ }
+
+ @Test
+ public void testThatEventTriggeredByButtonCanBeFiltered() throws Exception {
+ prnfsTestBuilder()
+ .isLoggedInAsAdmin()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/?123=${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.filter_string, "${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.filter_regexp, "123")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "Button Form")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "button text 123")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build()).store().triggerButton("Button Form").invokedOnlyUrl("http://bjurr.se/?123=button%20text%20123");
+ }
+
+ @Test
+ public void testThatEventTriggeredByButtonCanBeIgnoredByFilterWhileAnotherIsNotIgnored() throws Exception {
+ prnfsTestBuilder()
+ .isLoggedInAsAdmin()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/?123=${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.filter_string, "${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.filter_regexp, "123")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/?456=${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.filter_string, "${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.filter_regexp, "456")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "Button Form")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "button text 123")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build()).store().triggerButton("Button Form").invokedOnlyUrl("http://bjurr.se/?123=button%20text%20123");
+ }
+
+ @Test
+ public void testThatEventTriggeredByButtonCanResultInSeveralNotifications() throws Exception {
+ prnfsTestBuilder()
+ .isLoggedInAsAdmin()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/?123=${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.filter_string, "${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.filter_regexp, "button")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/?456=${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.filter_string, "${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.filter_regexp, "button")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "Button Form")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "button text 123")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build()).store().triggerButton("Button Form").invokedUrl(0, "http://bjurr.se/?123=button%20text%20123")
+ .invokedUrl(1, "http://bjurr.se/?456=button%20text%20123");
+ }
+
+ @Test
+ public void testThatThereCanBeSeveralButtons() throws Exception {
+ prnfsTestBuilder()
+ .isLoggedInAsAdmin()
+ .withNotification(
+ notificationBuilder()
+ .withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/?${" + BUTTON_TRIGGER_TITLE + "}")
+ .withFieldValue(AdminFormValues.FIELDS.events, BUTTON_TRIGGER)
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.TRIGGER_CONFIG_FORM.name()).build())
+ .store()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "Button Form 1")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "button text 1")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build())
+ .store()
+ .withNotification(
+ notificationBuilder().withFieldValue(AdminFormValues.FIELDS.FORM_IDENTIFIER, "Button Form 2")
+ .withFieldValue(AdminFormValues.FIELDS.FORM_TYPE, AdminFormValues.FORM_TYPE.BUTTON_CONFIG_FORM.name())
+ .withFieldValue(AdminFormValues.FIELDS.button_title, "button text 2")
+ .withFieldValue(AdminFormValues.FIELDS.button_visibility, AdminFormValues.BUTTON_VISIBILITY.EVERYONE.name())
+ .build()).store().triggerButton("Button Form 1").invokedUrl(0, "http://bjurr.se/?button%20text%201")
+ .triggerButton("Button Form 2").invokedUrl(1, "http://bjurr.se/?button%20text%202");
+ }
+
@Test
public void testThatProxyMayNotBeUsedWhenInvokingUrl() {
prnfsTestBuilder()
diff --git a/src/test/java/se/bjurr/prnfs/admin/utils/PrnfsTestBuilder.java b/src/test/java/se/bjurr/prnfs/admin/utils/PrnfsTestBuilder.java
index 3a6290a..74783d3 100644
--- a/src/test/java/se/bjurr/prnfs/admin/utils/PrnfsTestBuilder.java
+++ b/src/test/java/se/bjurr/prnfs/admin/utils/PrnfsTestBuilder.java
@@ -1,6 +1,7 @@
package se.bjurr.prnfs.admin.utils;
import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.newArrayList;
@@ -20,6 +21,7 @@
import static se.bjurr.prnfs.listener.UrlInvoker.getHeaderValue;
import static se.bjurr.prnfs.settings.PrnfsPredicates.predicate;
import static se.bjurr.prnfs.settings.SettingsStorage.fakeRandom;
+import static se.bjurr.prnfs.settings.SettingsStorage.getPrnfsSettings;
import java.net.URI;
import java.util.List;
@@ -32,6 +34,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import se.bjurr.prnfs.ManualResource;
import se.bjurr.prnfs.admin.AdminFormError;
import se.bjurr.prnfs.admin.AdminFormValues;
import se.bjurr.prnfs.admin.ConfigResource;
@@ -40,6 +43,8 @@
import se.bjurr.prnfs.listener.PrnfsPullRequestEventListener.Invoker;
import se.bjurr.prnfs.listener.UrlInvoker;
import se.bjurr.prnfs.settings.Header;
+import se.bjurr.prnfs.settings.PrnfsButton;
+import se.bjurr.prnfs.settings.PrnfsSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
@@ -49,11 +54,21 @@
import com.atlassian.sal.api.user.UserManager;
import com.atlassian.sal.api.user.UserProfile;
import com.atlassian.stash.event.pull.PullRequestEvent;
+import com.atlassian.stash.pull.PullRequest;
+import com.atlassian.stash.pull.PullRequestService;
import com.atlassian.stash.repository.RepositoryService;
import com.atlassian.stash.server.ApplicationPropertiesService;
+import com.atlassian.stash.user.EscalatedSecurityContext;
+import com.atlassian.stash.user.Permission;
+import com.atlassian.stash.user.SecurityService;
+import com.atlassian.stash.user.UserService;
+import com.atlassian.stash.util.Operation;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
public class PrnfsTestBuilder {
public class FakeRandom extends Random {
@@ -80,6 +95,7 @@ public static PrnfsTestBuilder prnfsTestBuilder() {
private final ConfigResource configResource;
private PrnfsPullRequestEventListener listener;
+ private final ManualResource manualResouce;
private final PluginSettings pluginSettings;
@@ -103,6 +119,12 @@ public static PrnfsTestBuilder prnfsTestBuilder() {
private List
postResponses;
+ private EscalatedSecurityContext escalatedSecurityContext;
+
+ private PullRequestService pullRequestService;
+
+ private PullRequest pullRequest;
+
private PrnfsTestBuilder() {
fakeRandomCounter = 0L;
fakeRandom(new FakeRandom());
@@ -122,6 +144,15 @@ public T execute(TransactionCallback action) {
when(pluginSettingsFactory.createGlobalSettings()).thenReturn(pluginSettings);
configResource = new ConfigResource(userManager, pluginSettingsFactory, transactionTemplate);
listener = new PrnfsPullRequestEventListener(pluginSettingsFactory, repositoryService, propertiesService);
+ UserService userService = mock(UserService.class);
+ pullRequestService = mock(PullRequestService.class);
+ withPullRequest(pullRequestEventBuilder().build().getPullRequest());
+ SecurityService securityService = mock(SecurityService.class);
+ escalatedSecurityContext = mock(EscalatedSecurityContext.class);
+ when(securityService.withPermission(Matchers.any(Permission.class), Matchers.anyString())).thenReturn(
+ escalatedSecurityContext);
+ manualResouce = new ManualResource(userManager, userService, pluginSettingsFactory, pullRequestService, listener,
+ repositoryService, propertiesService, securityService);
}
public PrnfsTestBuilder delete(String id) {
@@ -277,6 +308,44 @@ public void invoke(UrlInvoker urlInvoker) {
return this;
}
+ public PrnfsTestBuilder withPullRequest(PullRequest pullRequest) {
+ this.pullRequest = pullRequest;
+ return this;
+ }
+
+ public PrnfsTestBuilder triggerButton(String formIdentifier) throws Exception {
+ when(pullRequestService.getById(Matchers.anyInt(), Matchers.anyLong())).thenReturn(pullRequest);
+ try {
+ PrnfsSettings prnfsSettings = getPrnfsSettings(pluginSettings);
+ when(escalatedSecurityContext.call(Matchers.any(Operation.class))).thenReturn(prnfsSettings);
+ } catch (Throwable e) {
+ propagate(e);
+ }
+ setInvoker(new Invoker() {
+ @Override
+ public void invoke(UrlInvoker urlInvoker) {
+ urlInvokers.add(urlInvoker);
+ }
+ });
+ Integer repositoryId = 0;
+ Long pullRequestId = 0L;
+ manualResouce.post(request, repositoryId, pullRequestId, formIdentifier);
+ return this;
+ }
+
+ public PrnfsTestBuilder hasButtonEnabled(final String formIdentifier) throws Exception {
+ List enabledButtons = new Gson().fromJson((String) manualResouce.get(request).getEntity(),
+ new TypeToken>() {
+ }.getType());
+ assertTrue(tryFind(enabledButtons, new Predicate() {
+ @Override
+ public boolean apply(PrnfsButton input) {
+ return input.getFormIdentifier().equals(formIdentifier);
+ }
+ }).isPresent());
+ return this;
+ }
+
public PullRequestEventBuilder triggerPullRequestEventBuilder() {
return pullRequestEventBuilder(this);
}
@@ -347,4 +416,5 @@ public PrnfsTestBuilder usedProxyPassword(int i, String password) {
public RepositoryService getRepositoryService() {
return repositoryService;
}
+
}