@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 shouldRegisterAsPluginFrameworkStartListener() throws Exception { metadataLoader = new SCMMetadataLoader(scmExtension, pluginManager); verify(pluginManager).addPluginChangeListener(metadataLoader); }
@Override public void pluginLoaded(GoPluginDescriptor pluginDescriptor) { if (scmExtension.canHandlePlugin(pluginDescriptor.id())) { fetchSCMMetaData(pluginDescriptor); } }
@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 shouldThrowExceptionWhenNullSCMConfigurationReturned() { when(scmExtension.getSCMConfiguration(pluginDescriptor.id())).thenReturn(null); try { metadataLoader.fetchSCMMetaData(pluginDescriptor); } catch (Exception e) { assertThat(e.getMessage(), is("Plugin[plugin-id] returned null SCM configuration")); } assertThat(SCMMetadataStore.getInstance().getConfigurationMetadata(pluginDescriptor.id()), 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)); }
@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 shouldThrowExceptionWhenNullSCMViewReturned() { when(scmExtension.getSCMConfiguration(pluginDescriptor.id())).thenReturn(new SCMPropertyConfiguration()); when(scmExtension.getSCMView(pluginDescriptor.id())).thenReturn(null); try { metadataLoader.fetchSCMMetaData(pluginDescriptor); } catch (Exception e) { assertThat(e.getMessage(), is("Plugin[plugin-id] returned null SCM view")); } assertThat(SCMMetadataStore.getInstance().getConfigurationMetadata(pluginDescriptor.id()), nullValue()); }
@Before public void setUp() throws Exception { pluginDescriptor = new GoPluginDescriptor("plugin-id", "1.0", null, null, null, true); pluginManager = mock(PluginManager.class); scmExtension = mock(SCMExtension.class); metadataLoader = new SCMMetadataLoader(scmExtension, pluginManager); SCMMetadataStore.getInstance().removeMetadata(pluginDescriptor.id()); }
@Test public void shouldFetchSCMMetadataForPluginsWhichImplementSCMExtensionPoint() { SCMPropertyConfiguration scmPropertyConfiguration = new SCMPropertyConfiguration(); scmPropertyConfiguration.add(new SCMProperty("k1").with(SCMProperty.REQUIRED, true).with(SCMProperty.PART_OF_IDENTITY, false)); when(scmExtension.getSCMConfiguration(pluginDescriptor.id())).thenReturn(scmPropertyConfiguration); when(scmExtension.getSCMView(pluginDescriptor.id())).thenReturn(createSCMView("display-value", "template")); metadataLoader.fetchSCMMetaData(pluginDescriptor); SCMConfigurations configurationMetadata = SCMMetadataStore.getInstance().getConfigurationMetadata(pluginDescriptor.id()); assertThat(configurationMetadata.size(), is(1)); SCMConfiguration scmConfiguration = configurationMetadata.get("k1"); assertThat(scmConfiguration.getKey(), is("k1")); assertThat(scmConfiguration.getOption(SCMProperty.REQUIRED), is(true)); assertThat(scmConfiguration.getOption(SCMProperty.PART_OF_IDENTITY), is(false)); SCMView viewMetadata = SCMMetadataStore.getInstance().getViewMetadata(pluginDescriptor.id()); assertThat(viewMetadata.displayValue(), is("display-value")); assertThat(viewMetadata.template(), is("template")); }