Search in sources :

Example 31 with GoConfigValidity

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"));
}
Also used : LocalizedKeyValueMessage(com.thoughtworks.go.i18n.LocalizedKeyValueMessage) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 32 with GoConfigValidity

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));
}
Also used : GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 33 with GoConfigValidity

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"));
}
Also used : LocalizedKeyValueMessage(com.thoughtworks.go.i18n.LocalizedKeyValueMessage) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 34 with GoConfigValidity

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();
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity)

Aggregations

GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)34 Test (org.junit.Test)28 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)4 Localizer (com.thoughtworks.go.i18n.Localizer)3 LocalizedKeyValueMessage (com.thoughtworks.go.i18n.LocalizedKeyValueMessage)2 Cloner (com.rits.cloning.Cloner)1 PipelineGroupNotFoundException (com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)1 Localizable (com.thoughtworks.go.i18n.Localizable)1 Username (com.thoughtworks.go.server.domain.Username)1 GoConfigOperationalResponse (com.thoughtworks.go.server.service.responses.GoConfigOperationalResponse)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 File (java.io.File)1