@Before public void setUp() { initMocks(this); when(notificationExtension.canHandlePlugin(PLUGIN_ID_1)).thenReturn(true); when(notificationExtension.canHandlePlugin(PLUGIN_ID_2)).thenReturn(true); when(notificationExtension.canHandlePlugin(PLUGIN_ID_3)).thenReturn(true); when(notificationExtension.canHandlePlugin(PLUGIN_ID_4)).thenReturn(false); when(notificationExtension.getNotificationsOfInterestFor(PLUGIN_ID_1)).thenReturn(asList(PIPELINE_STATUS, STAGE_STATUS, JOB_STATUS)); when(notificationExtension.getNotificationsOfInterestFor(PLUGIN_ID_2)).thenReturn(asList(PIPELINE_STATUS)); when(notificationExtension.getNotificationsOfInterestFor(PLUGIN_ID_3)).thenReturn(asList(STAGE_STATUS)); }
@Override public void pluginLoaded(GoPluginDescriptor pluginDescriptor) { if (notificationExtension.canHandlePlugin(pluginDescriptor.id())) { try { notificationPluginRegistry.registerPlugin(pluginDescriptor.id()); List<String> notificationsInterestedIn = notificationExtension.getNotificationsOfInterestFor(pluginDescriptor.id()); if (notificationsInterestedIn != null && !notificationsInterestedIn.isEmpty()) { checkNotificationTypes(pluginDescriptor, notificationsInterestedIn); notificationPluginRegistry.registerPluginInterests(pluginDescriptor.id(), notificationsInterestedIn); } } catch (Exception e) { LOGGER.warn("Error occurred during plugin notification interest registration.", e); } } }
@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); }