@Test public void shouldTalkToPluginToGetPluginSettingsView() throws Exception { String deserializedResponse = ""; when(pluginSettingsJSONMessageHandler().responseMessageForPluginSettingsView(RESPONSE_BODY)).thenReturn(deserializedResponse); String response = notificationExtension.getPluginSettingsView(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, apiVersion(), PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_VIEW, null); verify(pluginSettingsJSONMessageHandler()).responseMessageForPluginSettingsView(RESPONSE_BODY); assertSame(response, deserializedResponse); }
@Test public void shouldTalkToPluginToGetNotificationsInterestedIn() throws Exception { List<String> response = asList("pipeline-status", "stage-status"); when(jsonMessageHandler().responseMessageForNotificationsInterestedIn(RESPONSE_BODY)).thenReturn(response); List<String> deserializedResponse = notificationExtension.getNotificationsOfInterestFor(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, apiVersion(), NotificationExtension.REQUEST_NOTIFICATIONS_INTERESTED_IN, null); verify(jsonMessageHandler()).responseMessageForNotificationsInterestedIn(RESPONSE_BODY); assertSame(response, deserializedResponse); }
@Before public void setUp() throws Exception { initMocks(this); notificationExtension = new NotificationExtension(pluginManager); notificationExtension.getPluginSettingsMessageHandlerMap().put(apiVersion(), pluginSettingsJSONMessageHandler()); notificationExtension.getMessageHandlerMap().put(apiVersion(), jsonMessageHandler()); pluginSettingsConfiguration = new PluginSettingsConfiguration(); requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class); when(pluginManager.resolveExtensionVersion(PLUGIN_ID, NOTIFICATION_EXTENSION, NotificationExtension.goSupportedVersions)).thenReturn(apiVersion()); when(pluginManager.isPluginOfType(NOTIFICATION_EXTENSION, PLUGIN_ID)).thenReturn(true); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(NOTIFICATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(RESPONSE_BODY)); }
@Test public void shouldTalkToPluginToValidatePluginSettings() throws Exception { String requestBody = "expected-request"; when(pluginSettingsJSONMessageHandler().requestMessageForPluginSettingsValidation(pluginSettingsConfiguration)).thenReturn(requestBody); ValidationResult deserializedResponse = new ValidationResult(); when(pluginSettingsJSONMessageHandler().responseMessageForPluginSettingsValidation(RESPONSE_BODY)).thenReturn(deserializedResponse); ValidationResult response = notificationExtension.validatePluginSettings(PLUGIN_ID, pluginSettingsConfiguration); assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, apiVersion(), PluginSettingsConstants.REQUEST_VALIDATE_PLUGIN_SETTINGS, requestBody); verify(pluginSettingsJSONMessageHandler()).responseMessageForPluginSettingsValidation(RESPONSE_BODY); assertSame(response, deserializedResponse); }
@Test public void shouldTalkToPluginToNotify() throws Exception { Result response = new Result(); String notificationName = "notification-name"; String jsonResponse = "json-response"; StageNotificationData stageNotificationData = new StageNotificationData(new Stage(), BuildCause.createWithEmptyModifications(), "group"); when(jsonMessageHandler().requestMessageForNotify(stageNotificationData)).thenReturn(jsonResponse); when(jsonMessageHandler().responseMessageForNotify(RESPONSE_BODY)).thenReturn(response); Result deserializedResponse = notificationExtension.notify(PLUGIN_ID, notificationName, stageNotificationData); assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, apiVersion(), notificationName, jsonResponse); verify(jsonMessageHandler()).responseMessageForNotify(RESPONSE_BODY); assertSame(response, deserializedResponse); }
@Test public void shouldTalkToPluginToGetPluginSettingsConfiguration() throws Exception { PluginSettingsConfiguration deserializedResponse = new PluginSettingsConfiguration(); when(pluginSettingsJSONMessageHandler().responseMessageForPluginSettingsConfiguration(RESPONSE_BODY)).thenReturn(deserializedResponse); PluginSettingsConfiguration response = notificationExtension.getPluginSettingsConfiguration(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, apiVersion(), PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_CONFIGURATION, null); verify(pluginSettingsJSONMessageHandler()).responseMessageForPluginSettingsConfiguration(RESPONSE_BODY); assertSame(response, deserializedResponse); }