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));
}
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"));
}
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'"));
}
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(""));
}
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."));
}
Aggregations