use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageDefinitionServiceTest method shouldPerformCheckConnectionForPackageAndReportFailure.
@Test
void shouldPerformCheckConnectionForPackageAndReportFailure() throws Exception {
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("required", false, ""));
configuration.add(ConfigurationPropertyMother.create("required_secure", true, ""));
configuration.add(ConfigurationPropertyMother.create("secure", true, ""));
configuration.add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
configuration.add(ConfigurationPropertyMother.create("spec", false, "xyz?"));
PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", configuration, packageRepository);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageDefinitionService service = new PackageDefinitionService(packageRepositoryExtension, entityHashingService, goConfigService, secretParamResolver);
ArgumentCaptor<com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration> packageConfigurationsCaptor = ArgumentCaptor.forClass(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class);
ArgumentCaptor<RepositoryConfiguration> packageRepositoryConfigurationsCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToPackage(eq(packageRepository.getPluginConfiguration().getId()), packageConfigurationsCaptor.capture(), packageRepositoryConfigurationsCaptor.capture())).thenReturn(new Result().withErrorMessages("Package not available", "Repo not available"));
service.checkConnection(packageDefinition, result);
assertPackageConfiguration(packageConfigurationsCaptor.getValue().list(), packageDefinition.getConfiguration());
assertPackageConfiguration(packageRepositoryConfigurationsCaptor.getValue().list(), packageRepository.getConfiguration());
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Package check Failed. Reason(s): Package not available\nRepo not available");
verify(packageRepositoryExtension).checkConnectionToPackage(anyString(), any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageDefinitionServiceTest method shouldPerformCheckConnectionForPackageAndCatchException.
@Test
void shouldPerformCheckConnectionForPackageAndCatchException() throws Exception {
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("required", false, ""));
configuration.add(ConfigurationPropertyMother.create("required_secure", true, ""));
configuration.add(ConfigurationPropertyMother.create("secure", true, ""));
configuration.add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
configuration.add(ConfigurationPropertyMother.create("spec", false, "xyz?"));
PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", configuration, packageRepository);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageDefinitionService service = new PackageDefinitionService(packageRepositoryExtension, entityHashingService, goConfigService, secretParamResolver);
ArgumentCaptor<com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration> packageConfigurationsCaptor = ArgumentCaptor.forClass(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class);
ArgumentCaptor<RepositoryConfiguration> packageRepositoryConfigurationsCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToPackage(eq(packageRepository.getPluginConfiguration().getId()), packageConfigurationsCaptor.capture(), packageRepositoryConfigurationsCaptor.capture())).thenThrow(new RuntimeException("Check connection for package not implemented!!"));
service.checkConnection(packageDefinition, result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Package check Failed. Reason(s): Check connection for package not implemented!!");
verify(packageRepositoryExtension).checkConnectionToPackage(anyString(), any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageMaterialPluginInfoBuilder method pluginInfoFor.
@Override
public PackageMaterialPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) {
RepositoryConfiguration repositoryConfiguration = extension.getRepositoryConfiguration(descriptor.id());
com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = extension.getPackageConfiguration(descriptor.id());
if (repositoryConfiguration == null) {
throw new RuntimeException(format("Plugin[%s] returned null repository configuration", descriptor.id()));
}
if (packageConfiguration == null) {
throw new RuntimeException(format("Plugin[%s] returned null package configuration", descriptor.id()));
}
PluggableInstanceSettings pluginSettingsAndView = getPluginSettingsAndView(descriptor, extension);
return new PackageMaterialPluginInfo(descriptor, new PluggableInstanceSettings(packageRepoConfigurations(repositoryConfiguration)), new PluggableInstanceSettings(packageRepoConfigurations(packageConfiguration)), pluginSettingsAndView);
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryExtensionTest method setUp.
@BeforeEach
public void setUp() throws Exception {
extension = new PackageRepositoryExtension(pluginManager, extensionsRegistry);
pluginSettingsConfiguration = new PluginSettingsConfiguration();
repositoryConfiguration = new RepositoryConfiguration();
repositoryConfiguration.add(new PackageMaterialProperty("key-one", "value-one"));
repositoryConfiguration.add(new PackageMaterialProperty("key-two", "value-two"));
packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
packageConfiguration.add(new PackageMaterialProperty("key-three", "value-three"));
packageConfiguration.add(new PackageMaterialProperty("key-four", "value-four"));
requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class);
when(pluginManager.resolveExtensionVersion(PLUGIN_ID, PACKAGE_MATERIAL_EXTENSION, asList("1.0"))).thenReturn("1.0");
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryExtensionTest method shouldTalkToPluginToGetRepositoryConfiguration.
@Test
public void shouldTalkToPluginToGetRepositoryConfiguration() throws Exception {
String expectedRequestBody = null;
String expectedResponseBody = "{" + "\"key-one\":{}," + "\"key-two\":{\"default-value\":\"two\",\"part-of-identity\":true,\"secure\":true,\"required\":true,\"display-name\":\"display-two\",\"display-order\":\"1\"}," + "\"key-three\":{\"default-value\":\"three\",\"part-of-identity\":false,\"secure\":false,\"required\":false,\"display-name\":\"display-three\",\"display-order\":\"2\"}" + "}";
when(pluginManager.isPluginOfType(PACKAGE_MATERIAL_EXTENSION, PLUGIN_ID)).thenReturn(true);
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(PACKAGE_MATERIAL_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(expectedResponseBody));
RepositoryConfiguration repositoryConfiguration = extension.getRepositoryConfiguration(PLUGIN_ID);
assertRequest(requestArgumentCaptor.getValue(), PACKAGE_MATERIAL_EXTENSION, "1.0", PackageRepositoryExtension.REQUEST_REPOSITORY_CONFIGURATION, expectedRequestBody);
assertPropertyConfiguration((PackageMaterialProperty) repositoryConfiguration.get("key-one"), "key-one", "", true, true, false, "", 0);
assertPropertyConfiguration((PackageMaterialProperty) repositoryConfiguration.get("key-two"), "key-two", "two", true, true, true, "display-two", 1);
assertPropertyConfiguration((PackageMaterialProperty) repositoryConfiguration.get("key-three"), "key-three", "three", false, false, false, "display-three", 2);
}
Aggregations