use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldFailAndReturnReturnFailureResponse.
@Test
public void shouldFailAndReturnReturnFailureResponse() throws Exception {
service = spy(service);
Username username = new Username(new CaseInsensitiveString("user"));
final PackageRepository packageRepository = new PackageRepository();
packageRepository.errors().add("name", "Name is invalid");
final CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("sample");
cruiseConfig.errors().add("global", "error");
final UpdateConfigFromUI updateConfigFromUI = mock(UpdateConfigFromUI.class);
final ConfigAwareUpdate configAwareUpdate = mock(ConfigAwareUpdate.class);
doNothing().when(service).performPluginValidationsFor(packageRepository);
doReturn(updateConfigFromUI).when(service).getPackageRepositoryUpdateCommand(packageRepository, username);
when(configAwareUpdate.configAfter()).thenReturn(cruiseConfig);
when(goConfigService.updateConfigFromUI(eq(updateConfigFromUI), eq("md5"), eq(username), any(LocalizedOperationResult.class))).then(new Answer<ConfigUpdateResponse>() {
@Override
public ConfigUpdateResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
LocalizedOperationResult result = (LocalizedOperationResult) invocationOnMock.getArguments()[3];
result.badRequest(LocalizedMessage.string("BAD_REQUEST"));
return new ConfigUpdateResponse(cruiseConfig, cruiseConfig, packageRepository, configAwareUpdate, ConfigSaveState.UPDATED);
}
});
when(localizer.localize("BAD_REQUEST", new Object[] {})).thenReturn("Save Failed");
ConfigUpdateAjaxResponse response = service.savePackageRepositoryToConfig(packageRepository, "md5", username);
assertThat(response.isSuccessful(), is(false));
assertThat(response.getMessage(), is("Save Failed"));
assertThat(response.getFieldErrors().size(), is(1));
assertThat(response.getFieldErrors().get("package_repository[name]"), is(asList("Name is invalid")));
assertThat(response.getGlobalErrors().size(), is(1));
assertThat(response.getGlobalErrors().contains("error"), is(true));
assertThat(response.getStatusCode(), is(HttpStatus.SC_BAD_REQUEST));
verify(service).performPluginValidationsFor(packageRepository);
verify(service).getPackageRepositoryUpdateCommand(packageRepository, username);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class GoConfigGraphWalkerTest method shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial.
@Test
public void shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial() {
PackageDefinition packageDefinition = mock(PackageDefinition.class);
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig("package-id");
setField(packageMaterialConfig, "packageDefinition", packageDefinition);
BasicCruiseConfig config = new BasicCruiseConfig();
PackageRepository packageRepository = mock(PackageRepository.class);
when(packageRepository.getPackages()).thenReturn(new Packages(packageDefinition));
when(packageDefinition.getRepository()).thenReturn(packageRepository);
when(packageRepository.doesPluginExist()).thenReturn(true);
when(packageDefinition.getId()).thenReturn("package-id");
config.getPackageRepositories().add(packageRepository);
final ConfigSaveValidationContext context = new ConfigSaveValidationContext(config);
new GoConfigGraphWalker(packageMaterialConfig).walk(new GoConfigGraphWalker.Handler() {
@Override
public void handle(Validatable validatable, ValidationContext ctx) {
validatable.validate(context);
}
});
verify(packageDefinition, never()).validate(any(ValidationContext.class));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class UpdatePackageRepositoryCommand method isRequestFresh.
private boolean isRequestFresh() {
PackageRepository oldRepo = goConfigService.getPackageRepository(newRepo.getRepoId());
boolean freshRequest = entityHashingService.hashForEntity(oldRepo).equals(digest);
if (!freshRequest) {
result.stale(EntityType.PackageRepository.staleConfig(newRepo.getRepoId()));
}
return freshRequest;
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class UpdatePackageRepositoryCommand method update.
@Override
public void update(CruiseConfig modifiedConfig) {
PackageRepository oldRepo = modifiedConfig.getPackageRepositories().find(newRepo.getRepoId());
this.newRepo.setPackages(oldRepo.getPackages());
PackageRepositories repositories = modifiedConfig.getPackageRepositories();
repositories.replace(oldRepo, newRepo);
modifiedConfig.setPackageRepositories(repositories);
updatePackageRepositoryConfigurationOnAssociatedPipelines(modifiedConfig);
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPopulateErrorsForCheckConnectionOnPlugin.
@Test
void shouldPopulateErrorsForCheckConnectionOnPlugin() {
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().withErrorMessages("Repo invalid!!", "Could not connect"));
service.checkConnection(packageRepository, result);
RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
PackageMaterialTestHelper.assertPackageConfiguration(packageConfigurations.list(), packageRepository.getConfiguration());
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Repo invalid!!\nCould not connect");
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
Aggregations