private List<ModuleBean> getLifecycleWebhooks(LifecycleBean lifecycle) { List<ModuleBean> webhooks = new ArrayList<>(); if (!Strings.isNullOrEmpty(lifecycle.getEnabled())) { webhooks.add(newWebHookBean().withEvent(ConnectWebhookEvent.ADD_ON_ENABLED.getId()).withUrl(lifecycle.getEnabled()).build()); } if (!Strings.isNullOrEmpty(lifecycle.getDisabled())) { webhooks.add(newWebHookBean().withEvent(ConnectWebhookEvent.ADD_ON_DISABLED.getId()).withUrl(lifecycle.getDisabled()).build()); } if (!Strings.isNullOrEmpty(lifecycle.getUninstalled())) { webhooks.add(newWebHookBean().withEvent(ConnectWebhookEvent.ADD_ON_UNINSTALLED.getId()).withUrl(lifecycle.getUninstalled()).build()); } return webhooks; }
private static String createWebhookExample() { final WebHookModuleBean bean = WebHookModuleBean.newWebHookBean() .withEvent("jira:issue_created") .withUrl("/issue-created") .build(); return JsonExamplesUtils.createModuleArrayAsString("webhooks", bean); }
public static void runInRunner(String baseUrl, String eventId, String pluginKey, WebHookTester tester) throws Exception { final String webHookPath = "/webhook"; final WebHookTestServlet servlet = new WebHookTestServlet(); ConnectRunner runner = new ConnectRunner(baseUrl, pluginKey) .addModule("webhooks", newWebHookBean() .withUrl(webHookPath) .withEvent(eventId) .build()) .addRoute(webHookPath, servlet) .addScope(ScopeName.READ) .addJWT(new WebHookTestServlet()) // different servlet for installed callback so that tests can inspect only the webhooks .start(); try { tester.test(servlet::waitForHook); } finally { runner.stopAndUninstall(); } }
public static void runInJsonRunner(String baseUrl, String addonKey, String eventId, WebHookTester tester) throws Exception { final String path = "/webhook"; final WebHookTestServlet servlet = new WebHookTestServlet(); ConnectRunner runner = new ConnectRunner(baseUrl, addonKey) .setAuthenticationToNone() .addModule("webhooks", newWebHookBean().withEvent(eventId).withUrl(path).build()) .addRoute(path, servlet) .addModule("webItems", randomWebItemBean()) .addScope(ScopeName.READ) // for receiving web hooks .start(); try { tester.test(servlet::waitForHook); } finally { runner.stopAndUninstall(); } }