use of com.thoughtworks.go.config.update.ConfigUpdateResponse 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.config.update.ConfigUpdateResponse in project gocd by gocd.
the class GoConfigServiceTest method badConfigShouldContainOldMD5_WhenConfigUpdateFailed.
@Test
public void badConfigShouldContainOldMD5_WhenConfigUpdateFailed() {
when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenThrow(new RuntimeException(getGoConfigInvalidException()));
ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "old-md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
assertThat(configUpdateResponse.wasMerged(), is(false));
assertThat(configUpdateResponse.getCruiseConfig().getMd5(), is("old-md5"));
}
use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnNotMergedInConfigUpdateResponse_WhenConfigIsUpdated.
@Test
public void shouldReturnNotMergedInConfigUpdateResponse_WhenConfigIsUpdated() {
when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenReturn(ConfigSaveState.UPDATED);
ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
assertThat(configUpdateResponse.wasMerged(), is(false));
}
use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.
the class GoConfigServiceIntegrationTest method shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict.
@Test
public void shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict() {
configHelper.addPipeline("pipeline", "stage");
String md5 = goConfigService.getConfigForEditing().getMd5();
goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("secondStage"), md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("thirdStage"), md5, Username.ANONYMOUS, result);
assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
CruiseConfig expectedConfig = goConfigService.getConfigForEditing();
CruiseConfig modifiedConfig = new Cloner().deepClone(expectedConfig);
ReflectionUtil.setField(modifiedConfig, "md5", expectedConfig.getMd5());
PipelineConfig expected = modifiedConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline"));
expected.addStageWithoutValidityAssertion(StageConfigMother.custom("thirdStage", "job"));
PipelineConfig actual = (PipelineConfig) response.getNode();
assertThat(response.configAfterUpdate(), is(expectedConfig));
assertThat(response.getCruiseConfig(), is(modifiedConfig));
assertThat(actual, is(expected));
assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
}
use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.
the class TimeReportingTest method write.
private ConfigUpdateResponse write(int numberOfNewPipelines, String oldMd5) throws InterruptedException {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Date a = new Date();
ConfigUpdateResponse res = goConfigService.updateConfigFromUI(new ReplaceConfigCommand(numberOfNewPipelines), oldMd5, null, result);
Date b = new Date();
assertThat(result.isSuccessful(), is(true));
// System.out.println("WRITE = " + (b.getTime() - a.getTime()) / 1000.0 + "s");
return res;
}
Aggregations