use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method packageRepository.
private PackageRepository packageRepository(String pluginId) {
PackageRepository packageRepository = new PackageRepository();
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("p1", false, "v1"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("p2", true, "v2"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("p3", true, "v3"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("p4", false, "v4"));
return packageRepository;
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldSetResultAsUnprocessableEntityIfRulesViolationForCheckConnection.
@Test
void shouldSetResultAsUnprocessableEntityIfRulesViolationForCheckConnection() {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
doThrow(new RulesViolationException("some rule violation message")).when(secretParamResolver).resolve(any(PackageRepository.class));
service.checkConnection(packageRepository("some-plugin"), result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.httpCode()).isEqualTo(HttpStatus.SC_UNPROCESSABLE_ENTITY);
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): some rule violation message");
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPerformCheckConnectionOnPluginAndCatchAnyExceptionsThrownByThePlugin.
@Test
void shouldPerformCheckConnectionOnPluginAndCatchAnyExceptionsThrownByThePlugin() {
String pluginId = "yum";
PackageRepository packageRepository = packageRepository(pluginId);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), argumentCaptor.capture())).thenThrow(new RuntimeException("Check Connection not implemented!!"));
service.checkConnection(packageRepository, result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Check Connection not implemented!!");
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldInvokePluginValidationsBeforeSavingPackageRepository.
@Test
void shouldInvokePluginValidationsBeforeSavingPackageRepository() {
String pluginId = "yum";
PackageRepository packageRepository = new PackageRepository();
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("url", false, "junk-url"));
ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
ValidationResult expectedValidationResult = new ValidationResult();
expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));
when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(getPluginDescriptor("yum"));
when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), packageConfigurationsArgumentCaptor.capture())).thenReturn(expectedValidationResult);
service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
service.performPluginValidationsFor(packageRepository);
assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("url format incorrect"));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPerformCheckConnectionOnPlugin.
@Test
void shouldPerformCheckConnectionOnPlugin() {
String pluginId = "yum";
PackageRepository packageRepository = packageRepository(pluginId);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), argumentCaptor.capture())).thenReturn(new Result().withSuccessMessages("Accessed Repo File!!!"));
service.checkConnection(packageRepository, result);
RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
PackageMaterialTestHelper.assertPackageConfiguration(packageConfigurations.list(), packageRepository.getConfiguration());
assertThat(result.isSuccessful()).isTrue();
assertThat(result.message()).isEqualTo("Connection OK. Accessed Repo File!!!");
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
Aggregations