void fetchSCMMetaData(GoPluginDescriptor pluginDescriptor) { try { SCMPropertyConfiguration scmConfiguration = scmExtension.getSCMConfiguration(pluginDescriptor.id()); if (scmConfiguration == null) { throw new RuntimeException(format("Plugin[%s] returned null SCM configuration", pluginDescriptor.id())); } SCMView scmView = scmExtension.getSCMView(pluginDescriptor.id()); if (scmView == null) { throw new RuntimeException(format("Plugin[%s] returned null SCM view", pluginDescriptor.id())); } scmMetadataStore.addMetadataFor(pluginDescriptor.id(), new SCMConfigurations(scmConfiguration), scmView); } catch (GoPluginFrameworkException e) { LOGGER.error("Failed to fetch SCM metadata for plugin : {}", pluginDescriptor.id(), e); } }
public SCMPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) { SCMPropertyConfiguration scmConfiguration = extension.getSCMConfiguration(descriptor.id()); SCMView scmView = extension.getSCMView(descriptor.id()); PluggableInstanceSettings pluginSettingsAndView = getPluginSettingsAndView(descriptor, extension); if (scmConfiguration == null) { throw new RuntimeException(format("Plugin[%s] returned null scm configuration", descriptor.id())); } if (scmView == null) { throw new RuntimeException(format("Plugin[%s] returned null scm view", descriptor.id())); } PluggableInstanceSettings scmSettings = new PluggableInstanceSettings(scmPluginConfigurations(scmConfiguration), new PluginView(scmView.template())); return new SCMPluginInfo(descriptor, scmView.displayValue(), scmSettings, pluginSettingsAndView); }
@Test public void shouldTalkToPluginToGetSCMConfiguration() throws Exception { SCMPropertyConfiguration deserializedResponse = new SCMPropertyConfiguration(); when(jsonMessageHandler.responseMessageForSCMConfiguration(responseBody)).thenReturn(deserializedResponse); SCMPropertyConfiguration response = scmExtension.getSCMConfiguration(PLUGIN_ID); assertRequest(requestArgumentCaptor.getValue(), SCM_EXTENSION, "1.0", SCMExtension.REQUEST_SCM_CONFIGURATION, null); verify(jsonMessageHandler).responseMessageForSCMConfiguration(responseBody); assertSame(response, deserializedResponse); }
@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 shouldThrowAnExceptionIfScmConfigReturnedByPluginIsNull() { GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin1", null, null, null, null, false); when(extension.getSCMConfiguration("plugin1")).thenReturn(null); thrown.expectMessage("Plugin[plugin1] returned null scm configuration"); new SCMPluginInfoBuilder(extension).pluginInfoFor(descriptor); }
@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 { extension = mock(SCMExtension.class); SCMPropertyConfiguration value = new SCMPropertyConfiguration(); value.add(new SCMProperty("username", null).with(Property.REQUIRED, true).with(Property.SECURE, false).with(Property.PART_OF_IDENTITY, true).with(Property.DISPLAY_ORDER, 1)); value.add(new SCMProperty("password", null).with(Property.REQUIRED, true).with(Property.SECURE, true).with(Property.PART_OF_IDENTITY, false).with(Property.DISPLAY_ORDER, 2)); when(extension.getSCMConfiguration("plugin1")).thenReturn(value); when(extension.getSCMView("plugin1")).thenReturn(new SCMView() { @Override public String displayValue() { return "some scm plugin"; } @Override public String template() { return "some html"; } }); PluginSettingsConfiguration pluginSettingsConfiguration = new PluginSettingsConfiguration(); pluginSettingsConfiguration.add(new PluginSettingsProperty("k1", null).with(Property.REQUIRED, true).with(Property.SECURE, false).with(Property.DISPLAY_ORDER, 3)); when(extension.getPluginSettingsConfiguration("plugin1")).thenReturn(pluginSettingsConfiguration); when(extension.getPluginSettingsView("plugin1")).thenReturn("settings view"); }
@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")); }