Search in sources :

Example 1 with GoConfigValidity

use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnInvalidWhenPipelineGroupPartialXmlIsInvalid.

@Test
public void shouldReturnInvalidWhenPipelineGroupPartialXmlIsInvalid() throws Exception {
    String groupName = "group_name";
    String md5 = "md5";
    cruiseConfig = new BasicCruiseConfig();
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
    GoConfigValidity validity = goConfigService.groupSaver(groupName).saveXml("<foobar>", "md5");
    assertThat(validity.isValid(), Matchers.is(false));
    assertThat(validity.errorMessage(), containsString("XML document structures must start and end within the same entity"));
    verify(goConfigDao, never()).updateConfig(any(UpdateConfigCommand.class));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 2 with GoConfigValidity

use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.

the class GoConfigServiceTest method shouldUpdateXmlUsingNewFlowIfEnabled.

@Test
public void shouldUpdateXmlUsingNewFlowIfEnabled() throws Exception {
    String groupName = "group_name";
    String md5 = "md5";
    cruiseConfig = new BasicCruiseConfig();
    ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
    when(systemEnvironment.optimizeFullConfigSave()).thenReturn(true);
    when(goConfigDao.updateFullConfig(commandArgumentCaptor.capture())).thenReturn(null);
    GoConfigService.XmlPartialSaver partialSaver = goConfigService.groupSaver(groupName);
    String renamedGroupName = "renamed_group_name";
    GoConfigValidity validity = partialSaver.saveXml(groupXml(renamedGroupName), md5);
    assertThat(validity.isValid(), Matchers.is(true));
    assertThat(validity.errorMessage(), Matchers.is(""));
    CruiseConfig updatedConfig = commandArgumentCaptor.getValue().configForEdit();
    PipelineConfigs group = updatedConfig.findGroup(renamedGroupName);
    PipelineConfig pipeline = group.findBy(new CaseInsensitiveString("new_name"));
    assertThat(pipeline.name(), is(new CaseInsensitiveString("new_name")));
    assertThat(pipeline.getLabelTemplate(), is("${COUNT}-#{foo}"));
    assertThat(pipeline.materialConfigs().first(), is(IsInstanceOf.instanceOf(SvnMaterialConfig.class)));
    assertThat(pipeline.materialConfigs().first().getUriForDisplay(), is("file:///tmp/foo"));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 3 with GoConfigValidity

use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnInvalidWhenWholeConfigIsInvalid.

@Test
public void shouldReturnInvalidWhenWholeConfigIsInvalid() throws Exception {
    CruiseConfig config = configWithPipeline();
    when(goConfigDao.loadForEditing()).thenReturn(config);
    String configContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<cruise xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"cruise-config.xsd\" schemaVersion=\"" + GoConstants.CONFIG_SCHEMA_VERSION + "\">\n" + "<server artifactsdir='artifactsDir'/><unknown/></cruise>";
    GoConfigValidity validity = goConfigService.fileSaver(false).saveXml(configContent, "md5");
    assertThat(validity.errorMessage(), containsString("Invalid content was found starting with element 'unknown'"));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 4 with GoConfigValidity

use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.

the class GoConfigServiceTest method shouldNotHaveErrorMessageWhenConfigFileValid.

@Test
public void shouldNotHaveErrorMessageWhenConfigFileValid() throws Exception {
    when(goConfigDao.checkConfigFileValid()).thenReturn(GoConfigValidity.valid());
    GoConfigValidity configValidity = goConfigService.checkConfigFileValid();
    assertThat(configValidity.isValid(), is(true));
    assertThat(configValidity.errorMessage(), is(""));
}
Also used : GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 5 with GoConfigValidity

use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.

the class GoConfigServiceTest method shouldNotThrowExceptionWhenUpgradeFailsForConfigFileUpdate.

@Test
public void shouldNotThrowExceptionWhenUpgradeFailsForConfigFileUpdate() throws Exception {
    expectLoadForEditing(configWith(createPipelineConfig("pipeline", "stage", "build")));
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(true);
    GoConfigValidity validity = saver.saveXml("some_junk", "junk_md5");
    assertThat(validity.isValid(), is(false));
    assertThat(validity.errorMessage(), is("Error on line 1: Content is not allowed in prolog."));
}
Also used : GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

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