use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class GoConfigServiceIntegrationTest method shouldThrowUpOnConfigSavePostValidationError_ViaMergeFlow.
@Test
public void shouldThrowUpOnConfigSavePostValidationError_ViaMergeFlow() throws Exception {
// User 1 adds a pipeline
configHelper.addPipelineWithGroup("defaultGroup", "up_pipeline", "up_stage", "up_job");
configHelper.addPipelineWithGroup("anotherGroup", "random_pipeline", "random_stage", "random_job");
CruiseConfig user1SeeingConfig = configHelper.load();
String user1SeeingMd5 = user1SeeingConfig.getMd5();
// User 2 edits config
configHelper.removePipeline("up_pipeline");
// User 1 edits old config
MaterialConfigs materialConfigs = new MaterialConfigs();
materialConfigs.add(MaterialConfigsMother.dependencyMaterialConfig("up_pipeline", "up_stage"));
new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "anotherGroup", "down_pipeline", materialConfigs, "down_stage", "down_job");
ByteArrayOutputStream os = new ByteArrayOutputStream();
configHelper.getXml(user1SeeingConfig, os);
// User 1 saves edited config
String xml = os.toString();
GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
GoConfigValidity validity = saver.saveXml(xml, user1SeeingMd5);
assertThat(validity.isValid(), is(false));
assertThat(validity.toString(), validity.isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR), is(true));
assertThat(validity.errorMessage(), is("Pipeline \"up_pipeline\" does not exist. It is used from pipeline \"down_pipeline\"."));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class GoConfigServiceTest method shouldProvideDetailsWhenXmlConfigDomIsInvalid.
@Test
public void shouldProvideDetailsWhenXmlConfigDomIsInvalid() throws Exception {
expectLoadForEditing(configWith(createPipelineConfig("pipeline", "stage", "build")));
GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
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></cruise>";
GoConfigValidity validity = saver.saveXml(configContent, "junk_md5");
assertThat(validity.isValid(), is(false));
assertThat(validity.errorMessage(), is("Invalid Configuration - Error on line 3: The value of attribute \"artifactsdir\" associated with an element type \"server\" must not contain the '<' character."));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnInvalidWhenWholeConfigIsInvalidAndShouldUpgrade.
@Test
public void shouldReturnInvalidWhenWholeConfigIsInvalidAndShouldUpgrade() 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=\"14\">\n" + "<server artifactsdir='artifactsDir'/><unknown/></cruise>";
GoConfigValidity validity = goConfigService.fileSaver(true).saveXml(configContent, "md5");
assertThat(validity.errorMessage(), is("Cruise config file with version 14 is invalid. Unable to upgrade."));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class GoConfigServiceTest method shouldReturnInvalidWhenPipelineGroupPartialHasInvalidAttributeValue.
@Test
public void shouldReturnInvalidWhenPipelineGroupPartialHasInvalidAttributeValue() 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);
String pipelineGroupContent = groupXmlWithInvalidAttributeValue(groupName);
GoConfigValidity validity = goConfigService.groupSaver(groupName).saveXml(pipelineGroupContent, "md5");
assertThat(validity.isValid(), Matchers.is(false));
assertThat(validity.errorMessage(), containsString("Name is invalid. \"pipeline@$^\""));
verify(goConfigDao, never()).updateConfig(any(UpdateConfigCommand.class));
}
use of com.thoughtworks.go.config.validation.GoConfigValidity in project gocd by gocd.
the class AdminServiceTest method shouldReturnInvalidIfConfigIsNotSaved.
@Test
public void shouldReturnInvalidIfConfigIsNotSaved() throws Exception {
HashMap attributes = new HashMap();
String content = "invalid_config_xml";
attributes.put("content", content);
String md5 = "config_md5";
attributes.put("md5", md5);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
GoConfigService.XmlPartialSaver fileSaver = mock(GoConfigService.XmlPartialSaver.class);
GoConfigValidity validity = GoConfigValidity.invalid("Wrong config xml");
when(fileSaver.saveXml(content, md5)).thenReturn(validity);
when(goConfigService.fileSaver(false)).thenReturn(fileSaver);
GoConfigValidity actual = adminService.updateConfig(attributes, result);
assertThat(result.isSuccessful(), is(false));
assertThat(actual.isValid(), is(false));
assertThat(actual.errorMessage(), is("Wrong config xml"));
verify(fileSaver).saveXml(content, md5);
verify(goConfigService).fileSaver(false);
}
Aggregations