use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.
the class GoConfigServiceIntegrationTest method shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError.
@Test
public void shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError() throws Exception {
String oldMd5 = goConfigService.getConfigForEditing().getMd5();
CruiseConfig user1SeeingConfig = configHelper.load();
// Setup a pipeline group in the config
new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
ByteArrayOutputStream os = new ByteArrayOutputStream();
configHelper.getXml(user1SeeingConfig, os);
GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
saver.saveXml(os.toString(), oldMd5);
CruiseConfig configBeforePipelineGroupWasAddedAtBeginning = configHelper.load();
String md5BeforeAddingGroupAtBeginning = configBeforePipelineGroupWasAddedAtBeginning.getMd5();
// User 1 edits config XML and adds a pipeline group before the first group in config
String configXMLWithGroupAddedAtBeginning = os.toString().replace("</pipelines>", "</pipelines><pipelines group=\"first_group\"/>");
saver.saveXml(configXMLWithGroupAddedAtBeginning, md5BeforeAddingGroupAtBeginning);
// User 2 adds another pipeline group, with the same name, through UI, but using the older MD5.
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new UpdateConfigFromUI() {
public void checkPermission(CruiseConfig cruiseConfig, LocalizedOperationResult result) {
}
public Validatable node(CruiseConfig cruiseConfig) {
return cruiseConfig;
}
public Validatable updatedNode(CruiseConfig cruiseConfig) {
return node(cruiseConfig);
}
public void update(Validatable config) {
CruiseConfig cruiseConfig = (CruiseConfig) config;
MaterialConfigs materials = new MaterialConfigs(MaterialConfigsMother.mockMaterialConfigs("file:///tmp/foo"));
new GoConfigMother().addPipelineWithGroup(cruiseConfig, "first_group", "up_pipeline", materials, "down_stage", "down_job");
}
public Validatable subject(Validatable node) {
return node;
}
public Validatable updatedSubject(Validatable updatedNode) {
return subject(updatedNode);
}
}, md5BeforeAddingGroupAtBeginning, new Username(new CaseInsensitiveString("admin")), result);
CruiseConfig config = response.getCruiseConfig();
assertThat(config.getMd5(), is(md5BeforeAddingGroupAtBeginning));
assertThat(result.isSuccessful(), is(false));
assertThat(result.httpCode(), is(SC_CONFLICT));
assertThat(result.message(localizer), is("Save failed. Duplicate unique value [first_group] declared for identity constraint of element \"cruise\"."));
}
use of com.thoughtworks.go.config.materials.MaterialConfigs 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.materials.MaterialConfigs in project gocd by gocd.
the class MaterialExpansionServiceCachingTest method shouldCacheSvnMaterialCheckExternalCommand.
@Test
public void shouldCacheSvnMaterialCheckExternalCommand() {
SvnMaterialConfig svnMaterialConfig = svnMaterialConfig(svnRepo.projectRepositoryUrl(), "mainRepo");
MaterialConfigs materialConfigs = new MaterialConfigs();
String cacheKey = (MaterialExpansionService.class + "_cacheKeyForSvnMaterialCheckExternalCommand_" + svnMaterialConfig.getFingerprint()).intern();
Subversion svn = (SvnCommand) goCache.get(cacheKey);
assertNull(svn);
materialExpansionService.expandForScheduling(svnMaterialConfig, materialConfigs);
svn = (SvnCommand) goCache.get(cacheKey);
assertNotNull(svn);
assertThat(svn.getUrl().forCommandline(), is(svnMaterialConfig.getUrl()));
}
use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.
the class PipelineConfigServiceIntegrationTest method shouldUpdatePipelineConfigWithDependencyMaterialWhenUpstreamPipelineHasTemplateDefinedANDUpstreamPipelineIsCreatedUsingCreatePipelineFlow.
@Test
public void shouldUpdatePipelineConfigWithDependencyMaterialWhenUpstreamPipelineHasTemplateDefinedANDUpstreamPipelineIsCreatedUsingCreatePipelineFlow() throws Exception {
CaseInsensitiveString templateName = new CaseInsensitiveString("template_with_param");
saveTemplateWithParamToConfig(templateName);
MaterialConfigs materialConfigs = new MaterialConfigs();
materialConfigs.add(new DependencyMaterialConfig(pipelineConfig.name(), new CaseInsensitiveString("stage")));
PipelineConfig upstream = new PipelineConfig(new CaseInsensitiveString("upstream"), materialConfigs);
upstream.setTemplateName(templateName);
upstream.addParam(new ParamConfig("SOME_PARAM", "SOME_VALUE"));
pipelineConfigService.createPipelineConfig(user, upstream, result, groupName);
PipelineConfig downstream = GoConfigMother.createPipelineConfigWithMaterialConfig("downstream", new DependencyMaterialConfig(upstream.name(), new CaseInsensitiveString("stage")));
pipelineConfigService.createPipelineConfig(user, downstream, result, groupName);
assertThat(result.toString(), result.isSuccessful(), is(true));
assertTrue(downstream.materialConfigs().first().errors().isEmpty());
}
use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.
the class PipelineConfigServicePerformanceTest method performanceTestForCreatePipeline.
@Test
public void performanceTestForCreatePipeline() throws Exception {
setupPipelines(0);
final ConcurrentHashMap<String, Boolean> results = new ConcurrentHashMap<>();
run(new Runnable() {
@Override
public void run() {
JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("job"));
StageConfig stageConfig = new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(jobConfig));
PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString(Thread.currentThread().getName()), new MaterialConfigs(new GitMaterialConfig("FOO")), stageConfig);
PerfTimer updateTimer = PerfTimer.start("Saving pipelineConfig : " + pipelineConfig.name());
pipelineConfigService.createPipelineConfig(user, pipelineConfig, result, "jumbo");
updateTimer.stop();
results.put(Thread.currentThread().getName(), result.isSuccessful());
if (!result.isSuccessful()) {
LOGGER.error(result.toString());
LOGGER.error("Errors on pipeline" + Thread.currentThread().getName() + " are : " + StringUtils.join(getAllErrors(pipelineConfig), ", "));
}
}
}, numberOfRequests, results);
}
Aggregations