@Override public void pluginLoaded(GoPluginDescriptor pluginDescriptor) { if (scmExtension.canHandlePlugin(pluginDescriptor.id())) { fetchSCMMetaData(pluginDescriptor); } }
@Override public void pluginUnLoaded(GoPluginDescriptor pluginDescriptor) { if (scmExtension.canHandlePlugin(pluginDescriptor.id())) { scmMetadataStore.removeMetadata(pluginDescriptor.id()); } } }
@Test public void shouldNotTryToFetchMetadataOnPluginLoadedCallback() throws Exception { SCMMetadataLoader spy = spy(metadataLoader); when(scmExtension.canHandlePlugin(pluginDescriptor.id())).thenReturn(false); spy.pluginLoaded(pluginDescriptor); verify(spy, never()).fetchSCMMetaData(pluginDescriptor); }
@Test public void shouldFetchMetadataOnPluginLoadedCallback() throws Exception { SCMMetadataLoader spy = spy(metadataLoader); doNothing().when(spy).fetchSCMMetaData(pluginDescriptor); when(scmExtension.canHandlePlugin(pluginDescriptor.id())).thenReturn(true); spy.pluginLoaded(pluginDescriptor); verify(spy).fetchSCMMetaData(pluginDescriptor); }
@Test public void shouldNotFailWhenAPluginWithMultipleExtensionsHasMoreThanOneExtensionRespondingWithSettings_BUT_OneIsValidAndOtherThrowsException() throws Exception { PluginSettingsConfiguration configuration = new PluginSettingsConfiguration(); configuration.add(new PluginSettingsProperty("k1").with(Property.REQUIRED, true).with(Property.SECURE, false)); String pluginID = "plugin-id"; GoPluginDescriptor pluginDescriptor = new GoPluginDescriptor(pluginID, "1.0", null, null, null, true); setupSettingsResponses(notificationExtension, pluginID, configuration, "view"); when(packageRepositoryExtension.canHandlePlugin(pluginID)).thenReturn(false); when(scmExtension.canHandlePlugin(pluginID)).thenReturn(true); when(scmExtension.getPluginSettingsConfiguration(pluginID)).thenThrow(new RuntimeException("Ouch!")); when(scmExtension.getPluginSettingsView(pluginID)).thenReturn("view"); metadataLoader.fetchPluginSettingsMetaData(pluginDescriptor); assertThat(PluginSettingsMetadataStore.getInstance().hasPlugin(pluginID), is(true)); verify(packageRepositoryExtension, never()).getPluginSettingsConfiguration(pluginID); verify(packageRepositoryExtension, never()).getPluginSettingsView(pluginID); }
@Test public void shouldRemoveMetadataOnPluginUnLoadedCallback() throws Exception { SCMMetadataStore.getInstance().addMetadataFor(pluginDescriptor.id(), new SCMConfigurations(), createSCMView(null, null)); when(scmExtension.canHandlePlugin(pluginDescriptor.id())).thenReturn(true); metadataLoader.pluginUnLoaded(pluginDescriptor); assertThat(SCMMetadataStore.getInstance().getConfigurationMetadata(pluginDescriptor.id()), is(nullValue())); assertThat(SCMMetadataStore.getInstance().getViewMetadata(pluginDescriptor.id()), is(nullValue())); }
@Test public void shouldNotTryRemoveMetadataOnPluginUnLoadedCallback() throws Exception { SCMConfigurations scmConfigurations = new SCMConfigurations(); SCMView scmView = createSCMView(null, null); SCMMetadataStore.getInstance().addMetadataFor(pluginDescriptor.id(), scmConfigurations, scmView); when(scmExtension.canHandlePlugin(pluginDescriptor.id())).thenReturn(false); metadataLoader.pluginUnLoaded(pluginDescriptor); assertThat(SCMMetadataStore.getInstance().getConfigurationMetadata(pluginDescriptor.id()), is(scmConfigurations)); assertThat(SCMMetadataStore.getInstance().getViewMetadata(pluginDescriptor.id()), is(scmView)); }