use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class MissingPluggableTaskViewModelTest method shouldReturnPluginIdAsDisplayValue.
@Test
public void shouldReturnPluginIdAsDisplayValue() throws Exception {
PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-1", "1.0");
PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, new Configuration());
MissingPluggableTaskViewModel viewModel = new MissingPluggableTaskViewModel(pluggableTask, null);
assertThat(viewModel.getParameters().get("template"), is(String.format("Associated plugin '%s' not found. Please contact the Go admin to install the plugin.", pluginConfiguration.getId())));
assertThat(viewModel.getTypeForDisplay(), is(pluginConfiguration.getId()));
}
use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method shouldPassValidationIfAllRequiredFieldsHaveValuesForSCM.
@Test
public void shouldPassValidationIfAllRequiredFieldsHaveValuesForSCM() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
configuration.getProperty("KEY1").setConfigurationValue(new ConfigurationValue("junk"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
assertTrue(validationResult.getErrors().isEmpty());
}
use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method shouldSendResolvedValueToPluginDuringIsValidCall.
@Test
public void shouldSendResolvedValueToPluginDuringIsValidCall() {
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("url", false, "url"));
configuration.add(ConfigurationPropertyMother.create("username", false, "{{SECRET:[secret_config_id][username]}}"));
SCM scmConfig = mock(SCM.class);
when(scmConfig.doesPluginExist()).thenReturn(true);
when(scmConfig.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(scmConfig.getConfiguration()).thenReturn(configuration);
when(scmExtension.isSCMConfigurationValid(any(String.class), any(SCMPropertyConfiguration.class))).thenReturn(new ValidationResult());
doAnswer(invocation -> {
configuration.get(1).getSecretParams().get(0).setValue("resolved-value");
return scmConfig;
}).when(secretParamResolver).resolve(any(SCM.class));
assertTrue(pluggableScmService.isValid(scmConfig));
ArgumentCaptor<SCMPropertyConfiguration> captor = ArgumentCaptor.forClass(SCMPropertyConfiguration.class);
verify(scmExtension).isSCMConfigurationValid(anyString(), captor.capture());
assertThat(captor.getValue().list().get(1).getValue(), is("resolved-value"));
}
use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method shouldValidateSCM.
@Test
public void shouldValidateSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, false));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("KEY1", "error message"));
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
assertFalse(modifiedSCM.getConfiguration().getProperty("KEY1").errors().isEmpty());
assertThat(modifiedSCM.getConfiguration().getProperty("KEY1").errors().firstError(), is("error message"));
verify(scmExtension).isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class));
}
use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method shouldValidateMandatoryAndSecureFieldsForSCM.
@Test
public void shouldValidateMandatoryAndSecureFieldsForSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, true).with(Property.SECURE, true));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("KEY2", true, ""));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertFalse(validationErrors.isEmpty());
final ValidationError validationErrorForKey1 = getValidationErrorFor(validationErrors, "KEY1");
assertNotNull(validationErrorForKey1);
assertThat(validationErrorForKey1.getMessage(), is("This field is required"));
final ValidationError validationErrorForKey2 = getValidationErrorFor(validationErrors, "KEY2");
assertNotNull(validationErrorForKey2);
assertThat(validationErrorForKey2.getMessage(), is("This field is required"));
}
Aggregations