SCMProperty scmProperty = new SCMProperty(key); if (!isEmpty(defaultValue)) { scmProperty.withDefault(defaultValue); scmProperty.with(Property.PART_OF_IDENTITY, partOfIdentity); scmProperty.with(Property.SECURE, isSecure); scmProperty.with(Property.REQUIRED, required); scmProperty.with(Property.DISPLAY_NAME, displayName); scmProperty.with(Property.DISPLAY_ORDER, displayOrder);
@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"); }
private void populateConfiguration(Configuration configuration, com.thoughtworks.go.plugin.api.config.Configuration pluginConfiguration) { for (ConfigurationProperty configurationProperty : configuration) { pluginConfiguration.add(new SCMProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } } }
@Test public void validateSCMPropertyDefaults() throws Exception { SCMProperty scmProperty = new SCMProperty("Test-Property"); assertThat(scmProperty.getOptions().size(), is(5)); assertThat(scmProperty.getOption(Property.REQUIRED), is(true)); assertThat(scmProperty.getOption(Property.PART_OF_IDENTITY), is(true)); assertThat(scmProperty.getOption(Property.SECURE), is(false)); assertThat(scmProperty.getOption(Property.DISPLAY_NAME), is("")); assertThat(scmProperty.getOption(Property.DISPLAY_ORDER), is(0)); scmProperty = new SCMProperty("Test-Property", "Dummy Value"); assertThat(scmProperty.getOptions().size(), is(5)); assertThat(scmProperty.getOption(Property.REQUIRED), is(true)); assertThat(scmProperty.getOption(Property.PART_OF_IDENTITY), is(true)); assertThat(scmProperty.getOption(Property.SECURE), is(false)); assertThat(scmProperty.getOption(Property.DISPLAY_NAME), is("")); assertThat(scmProperty.getOption(Property.DISPLAY_ORDER), is(0)); } }
private void assertPropertyConfiguration(SCMProperty property, String key, String value, boolean partOfIdentity, boolean required, boolean secure, String displayName, int displayOrder) { assertThat(property.getKey(), is(key)); assertThat(property.getValue(), is(value)); assertThat(property.getOption(Property.PART_OF_IDENTITY), is(partOfIdentity)); assertThat(property.getOption(Property.REQUIRED), is(required)); assertThat(property.getOption(Property.SECURE), is(secure)); assertThat(property.getOption(Property.DISPLAY_NAME), is(displayName)); assertThat(property.getOption(Property.DISPLAY_ORDER), is(displayOrder)); }
@Test public void shouldConstructSCMConfiguration() throws Exception { SCMPropertyConfiguration scmPropertyConfiguration = new SCMPropertyConfiguration(); scmPropertyConfiguration.add(new SCMProperty("k1", "v1").with(Property.SECURE, Boolean.TRUE)); SCMConfigurations scmConfigurations = new SCMConfigurations(scmPropertyConfiguration); assertThat(scmConfigurations.list().size(), is(1)); SCMConfiguration scmConfiguration = scmConfigurations.list().get(0); assertThat(scmConfiguration.getKey(), is("k1")); assertThat(scmConfiguration.getValue(), is("v1")); assertThat(scmConfiguration.getOption(SCMConfiguration.REQUIRED), is(true)); assertThat(scmConfiguration.getOption(SCMConfiguration.PART_OF_IDENTITY), is(true)); assertThat(scmConfiguration.getOption(SCMConfiguration.SECURE), is(true)); assertThat(scmConfiguration.getOption(SCMConfiguration.DISPLAY_NAME), is("")); assertThat(scmConfiguration.getOption(SCMConfiguration.DISPLAY_ORDER), is(0)); } }
private void populateConfiguration(Configuration configuration, com.thoughtworks.go.plugin.api.config.Configuration pluginConfiguration) { for (ConfigurationProperty configurationProperty : configuration) { pluginConfiguration.add(new SCMProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } }
@Test public void shouldFailValidationIfSCMWithDuplicateFingerprintExists() throws Exception { SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration(); scmConfiguration.add(new SCMProperty("SCM-KEY1")); scmConfiguration.add(new SCMProperty("SCM-KEY2").with(REQUIRED, false).with(PART_OF_IDENTITY, false)); scmConfiguration.add(new SCMProperty("SCM-KEY3").with(REQUIRED, false).with(PART_OF_IDENTITY, false).with(SECURE, true)); SCMMetadataStore.getInstance().addMetadataFor("plugin-1", new SCMConfigurations(scmConfiguration), null);
@Before public void setUp() throws Exception { messageHandler = new JsonMessageHandler1_0(); scmPropertyConfiguration = new SCMPropertyConfiguration(); scmPropertyConfiguration.add(new SCMProperty("key-one", "value-one")); scmPropertyConfiguration.add(new SCMProperty("key-two", "value-two")); materialData = new HashMap<>(); materialData.put("key-one", "value-one"); }
@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")); }
private SCMPropertyConfiguration getScmPropertyConfiguration(SCM scmConfig) { final SCMPropertyConfiguration configuration = new SCMPropertyConfiguration(); for (ConfigurationProperty configurationProperty : scmConfig.getConfiguration()) { configuration.add(new SCMProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue())); } return configuration; } }
String pluginId = "plugin-id"; SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration(); scmConfiguration.add(new SCMProperty("k1")); scmConfiguration.add(new SCMProperty("k2").with(REQUIRED, false).with(PART_OF_IDENTITY, false)); SCMMetadataStore.getInstance().addMetadataFor(pluginId, new SCMConfigurations(scmConfiguration), null);
scmConfiguration.add(new SCMProperty("plain")); scmConfiguration.add(new SCMProperty("secure-one").with(SCMConfiguration.SECURE, true)); scmConfiguration.add(new SCMProperty("secure-two").with(SCMConfiguration.SECURE, true)); SCMMetadataStore.getInstance().addMetadataFor("plugin-id", new SCMConfigurations(scmConfiguration), null);