use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnWasMergedInConfigUpdateResponse_WhenConfigIsMerged.
@Test
public void shouldReturnWasMergedInConfigUpdateResponse_WhenConfigIsMerged() {
when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenReturn(ConfigSaveState.MERGED);
ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
assertThat(configUpdateResponse.wasMerged(), is(true));
}
use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.
the class GoConfigServiceTest method configShouldContainOldMD5_WhenConfigMergeFailed.
@Test
public void configShouldContainOldMD5_WhenConfigMergeFailed() {
when(goConfigDao.loadForEditing()).thenReturn(new BasicCruiseConfig());
when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenThrow(new ConfigFileHasChangedException());
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 PackageRepositoryServiceTest method shouldSavePackageRepositoryAndReturnSuccess.
@Test
public void shouldSavePackageRepositoryAndReturnSuccess() throws Exception {
service = spy(service);
PackageRepository packageRepository = new PackageRepository();
packageRepository.setId("repoid");
Username username = new Username(new CaseInsensitiveString("user"));
UpdateConfigFromUI updateConfigFromUI = mock(UpdateConfigFromUI.class);
doNothing().when(service).performPluginValidationsFor(packageRepository);
doReturn(updateConfigFromUI).when(service).getPackageRepositoryUpdateCommand(packageRepository, username);
when(goConfigService.updateConfigFromUI(eq(updateConfigFromUI), eq("md5"), eq(username), any(LocalizedOperationResult.class))).then(new Answer<ConfigUpdateResponse>() {
@Override
public ConfigUpdateResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
return new ConfigUpdateResponse(null, null, null, mock(ConfigAwareUpdate.class), ConfigSaveState.UPDATED);
}
});
when(localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY")).thenReturn("SAVED_CONFIGURATION_SUCCESSFULLY");
ConfigUpdateAjaxResponse response = service.savePackageRepositoryToConfig(packageRepository, "md5", username);
assertThat(response.isSuccessful(), is(true));
assertThat(response.getMessage(), is("SAVED_CONFIGURATION_SUCCESSFULLY"));
assertThat(response.getSubjectIdentifier(), is("repoid"));
assertThat(response.getStatusCode(), is(HttpStatus.SC_OK));
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 shouldReturnNotMergedInConfigUpdateResponse_WhenConfigUpdateFailed.
@Test
public void shouldReturnNotMergedInConfigUpdateResponse_WhenConfigUpdateFailed() throws Exception {
when(goConfigDao.updateConfig(org.mockito.Matchers.<UpdateConfigCommand>any())).thenThrow(new ConfigFileHasChangedException());
expectLoadForEditing(cruiseConfig);
ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(mock(UpdateConfigFromUI.class), "md5", new Username(new CaseInsensitiveString("user")), new HttpLocalizedOperationResult());
assertThat(configUpdateResponse.wasMerged(), is(false));
}
Aggregations