use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class PipelineConfigsServiceTest method shouldThrowUpWithDifferentMessageForPostMergeValidationExceptions.
@Test
public void shouldThrowUpWithDifferentMessageForPostMergeValidationExceptions() throws Exception {
String groupName = "renamed_group_name";
GoConfigService.XmlPartialSaver groupSaver = mock(GoConfigService.XmlPartialSaver.class);
when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenReturn(true);
when(goConfigService.configFileMd5()).thenReturn("old-md5");
when(goConfigService.groupSaver(groupName)).thenReturn(groupSaver);
when(groupSaver.saveXml(null, "md5")).thenReturn(GoConfigValidity.invalid("some error").mergePostValidationError());
GoConfigOperationalResponse<PipelineConfigs> actual = service.updateXml(groupName, null, "md5", validUser, result);
PipelineConfigs configElement = actual.getConfigElement();
GoConfigValidity validity = actual.getValidity();
assertThat(configElement, is(nullValue()));
assertThat(result.isSuccessful(), is(false));
assertThat(validity.isValid(), is(false));
assertThat(validity.isPostValidationError(), is(true));
LocalizedKeyValueMessage message = (LocalizedKeyValueMessage) ReflectionUtil.getField(result, "message");
String key = (String) ReflectionUtil.getField(message, "key");
assertThat(key, is("FLASH_MESSAGE_ON_CONFLICT"));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class PipelineConfigsServiceTest method shouldSetSuccessMessageOnSuccessfulMerge.
@Test
public void shouldSetSuccessMessageOnSuccessfulMerge() throws Exception {
String groupName = "renamed_group_name";
GoConfigService.XmlPartialSaver groupSaver = mock(GoConfigService.XmlPartialSaver.class);
when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenReturn(true);
when(goConfigService.configFileMd5()).thenReturn("old-md5");
when(goConfigService.groupSaver(groupName)).thenReturn(groupSaver);
when(groupSaver.saveXml(groupXml(), "md5")).thenReturn(GoConfigValidity.valid(ConfigSaveState.MERGED));
GoConfigOperationalResponse<PipelineConfigs> actual = service.updateXml(groupName, groupXml(), "md5", validUser, result);
GoConfigValidity validity = actual.getValidity();
assertThat(result.localizable(), is(LocalizedMessage.composite(LocalizedMessage.string("SAVED_CONFIGURATION_SUCCESSFULLY"), LocalizedMessage.string("CONFIG_MERGED"))));
assertThat(validity.isValid(), is(true));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class PipelineConfigsServiceTest method shouldThrowUpWithDifferentMessageForMergeExceptions.
@Test
public void shouldThrowUpWithDifferentMessageForMergeExceptions() throws Exception {
String groupName = "renamed_group_name";
GoConfigService.XmlPartialSaver groupSaver = mock(GoConfigService.XmlPartialSaver.class);
when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenReturn(true);
when(goConfigService.configFileMd5()).thenReturn("old-md5");
when(goConfigService.groupSaver(groupName)).thenReturn(groupSaver);
when(groupSaver.saveXml(null, "md5")).thenReturn(GoConfigValidity.invalid("some error").mergeConflict());
GoConfigOperationalResponse<PipelineConfigs> actual = service.updateXml(groupName, null, "md5", validUser, result);
PipelineConfigs configElement = actual.getConfigElement();
GoConfigValidity validity = actual.getValidity();
assertThat(configElement, is(nullValue()));
assertThat(result.isSuccessful(), is(false));
assertThat(validity.isValid(), is(false));
assertThat(validity.isMergeConflict(), is(true));
LocalizedKeyValueMessage message = (LocalizedKeyValueMessage) ReflectionUtil.getField(result, "message");
String key = (String) ReflectionUtil.getField(message, "key");
assertThat(key, is("FLASH_MESSAGE_ON_CONFLICT"));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class GoConfigMigrationIntegrationTest method migrateConfigAndLoadTheNewConfig.
private CruiseConfig migrateConfigAndLoadTheNewConfig(String content, int fromVersion) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
String migratedContent = migrateXmlString(content, fromVersion);
GoConfigService.XmlPartialSaver fileSaver = goConfigService.fileSaver(true);
GoConfigValidity configValidity = fileSaver.saveXml(migratedContent, goConfigService.configFileMd5());
assertThat(configValidity.errorMessage(), configValidity.isValid(), is(true));
return goConfigService.getCurrentConfig();
}
Aggregations