public AnalyticsPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) { Capabilities capabilities = capabilities(descriptor.id()); PluggableInstanceSettings pluginSettingsAndView = getPluginSettingsAndView(descriptor, extension); Image image = image(descriptor.id()); return new AnalyticsPluginInfo(descriptor, image, capabilities, pluginSettingsAndView); }
@Test public void shouldHandleUpdateAssetsPath() throws Exception { PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class); AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo(pluginDescriptor, null, null, null); when(pluginDescriptor.id()).thenReturn("plugin_id"); store.setPluginInfo(pluginInfo); store.updateAssetsPath("plugin_id", "static_assets_path"); assertThat(pluginInfo.getStaticAssetsPath(), is("static_assets_path")); } }
@Test public void onPluginLoaded_shouldAddPluginInfoToMetadataStore() throws Exception { GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false); AnalyticsMetadataLoader metadataLoader = new AnalyticsMetadataLoader(pluginManager, metadataStore, infoBuilder, extension); AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo(descriptor, null, null, null); when(extension.canHandlePlugin(descriptor.id())).thenReturn(true); when(infoBuilder.pluginInfoFor(descriptor)).thenReturn(pluginInfo); metadataLoader.pluginLoaded(descriptor); verify(metadataStore).setPluginInfo(pluginInfo); }
@Test public void onPluginLoad_shouldNotifyPluginMetadataLoadListeners() throws Exception { GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false); AnalyticsMetadataLoader metadataLoader = new AnalyticsMetadataLoader(pluginManager, metadataStore, infoBuilder, extension); PluginMetadataChangeListener pluginMetadataChangeListener = mock(PluginMetadataChangeListener.class); AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo(descriptor, null, null, null); when(extension.canHandlePlugin(descriptor.id())).thenReturn(true); when(infoBuilder.pluginInfoFor(descriptor)).thenReturn(pluginInfo); metadataLoader.registerListeners(pluginMetadataChangeListener); metadataLoader.pluginLoaded(descriptor); InOrder inOrder = inOrder(metadataStore, pluginMetadataChangeListener); inOrder.verify(metadataStore).setPluginInfo(pluginInfo); inOrder.verify(pluginMetadataChangeListener).onPluginMetadataCreate(descriptor.id()); }
@Test public void onPluginUnLoaded_shouldNotifyPluginMetadataLoadListeners() throws Exception { GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false); AnalyticsMetadataLoader metadataLoader = new AnalyticsMetadataLoader(pluginManager, metadataStore, infoBuilder, extension); AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo(descriptor, null, null, null); PluginMetadataChangeListener pluginMetadataChangeListener = mock(PluginMetadataChangeListener.class); when(extension.canHandlePlugin(descriptor.id())).thenReturn(true); metadataStore.setPluginInfo(pluginInfo); metadataLoader.registerListeners(pluginMetadataChangeListener); metadataLoader.pluginUnLoaded(descriptor); InOrder inOrder = inOrder(metadataStore, pluginMetadataChangeListener); inOrder.verify(metadataStore).remove(descriptor.id()); inOrder.verify(pluginMetadataChangeListener).onPluginMetadataRemove(descriptor.id()); } }
@Test public void shouldGetAnalytics() throws Exception { String responseBody = "{ \"view_path\": \"path/to/view\", \"data\": \"{}\" }"; AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo( new GoPluginDescriptor(PLUGIN_ID, null, null, null, null, false), null, null, null); pluginInfo.setStaticAssetsPath("/assets/root"); metadataStore.setPluginInfo(pluginInfo); when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ANALYTICS_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody)); AnalyticsData pipelineAnalytics = analyticsExtension.getAnalytics(PLUGIN_ID, "pipeline", "pipeline_with_highest_wait_time", Collections.singletonMap("pipeline_name", "test_pipeline")); String expectedRequestBody = "{" + "\"type\": \"pipeline\"," + "\"id\": \"pipeline_with_highest_wait_time\"," + " \"params\": {\"pipeline_name\": \"test_pipeline\"}}"; assertRequest(requestArgumentCaptor.getValue(), PluginConstants.ANALYTICS_EXTENSION, "1.0", REQUEST_GET_ANALYTICS, expectedRequestBody); assertThat(pipelineAnalytics.getData(), is("{}")); assertThat(pipelineAnalytics.getViewPath(), is("path/to/view")); assertThat(pipelineAnalytics.getFullViewPath(), is("/assets/root/path/to/view")); }
@Test public void onPluginUnloaded_shouldRemoveTheCorrespondingPluginInfoFromStore() throws Exception { GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false); AnalyticsMetadataLoader metadataLoader = new AnalyticsMetadataLoader(pluginManager, metadataStore, infoBuilder, extension); AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo(descriptor, null, null, null); metadataStore.setPluginInfo(pluginInfo); metadataLoader.pluginUnLoaded(descriptor); verify(metadataStore).remove(descriptor.id()); }
@Test public void shouldFindFirstExtensionWithImageIfPluginImplementsAtleastOneExtensionWithImage() throws Exception { Image image1 = new Image("c1", "d1", "hash1"); Image image2 = new Image("c2", "d2", "hash2"); Image image3 = new Image("c3", "d3", "hash3"); ElasticAgentPluginInfo elasticAgentPluginInfo = new ElasticAgentPluginInfo(null, null, image1, null, null); AuthorizationPluginInfo authorizationPluginInfo = new AuthorizationPluginInfo(null, null, null, image2, null); AnalyticsPluginInfo analyticsPluginInfo = new AnalyticsPluginInfo(null, image3, null, null); assertThat(new CombinedPluginInfo(elasticAgentPluginInfo).getImage(), is(image1)); assertThat(new CombinedPluginInfo(authorizationPluginInfo).getImage(), is(image2)); assertThat(new CombinedPluginInfo(analyticsPluginInfo).getImage(), is(image3)); assertThat(new CombinedPluginInfo(asList(elasticAgentPluginInfo, authorizationPluginInfo)).getImage(), anyOf(is(image1), is(image2))); assertThat(new CombinedPluginInfo(asList(analyticsPluginInfo, authorizationPluginInfo)).getImage(), anyOf(is(image2), is(image3))); }