use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldNotRetryConfigSaveWhenConfigRepoIsNotSetup.
@Test
public void shouldNotRetryConfigSaveWhenConfigRepoIsNotSetup() throws Exception {
MagicalGoConfigXmlLoader loader = mock(MagicalGoConfigXmlLoader.class);
MagicalGoConfigXmlWriter writer = mock(MagicalGoConfigXmlWriter.class);
GoConfigMigration migration = mock(GoConfigMigration.class);
ServerHealthService serverHealthService = mock(ServerHealthService.class);
CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
ConfigRepository configRepository = mock(ConfigRepository.class);
dataSource = new GoFileConfigDataSource(migration, configRepository, systemEnvironment, timeProvider, mock(ServerVersion.class), loader, writer, serverHealthService, cachedGoPartials, null, null, null, null);
final String pipelineName = UUID.randomUUID().toString();
BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines(pipelineName);
ConfigErrors configErrors = new ConfigErrors();
configErrors.add("key", "some error");
when(loader.loadConfigHolder(Matchers.any(String.class))).thenThrow(new GoConfigInvalidException(cruiseConfig, configErrors.firstError()));
try {
dataSource.writeWithLock(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName)).clear();
return cruiseConfig;
}
}, new GoConfigHolder(cruiseConfig, cruiseConfig));
fail("expected the test to fail");
} catch (Exception e) {
verifyZeroInteractions(configRepository);
verifyZeroInteractions(serverHealthService);
verify(loader, times(1)).loadConfigHolder(Matchers.any(String.class), Matchers.any(MagicalGoConfigXmlLoader.Callback.class));
}
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class GoFileConfigDataSourceTest method shouldNotRetryConfigUpdateIfLastKnownAndValidPartialsAreSame_OnWriteFullConfigWithLock.
@Test(expected = RuntimeException.class)
public void shouldNotRetryConfigUpdateIfLastKnownAndValidPartialsAreSame_OnWriteFullConfigWithLock() throws Exception {
PartialConfig partialConfig1 = PartialConfigMother.withPipeline("p1", new RepoConfigOrigin(new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig(), "plugin"), "git_r1"));
List<PartialConfig> known = asList(partialConfig1);
List<PartialConfig> valid = asList(partialConfig1);
BasicCruiseConfig configForEdit = new BasicCruiseConfig();
MagicalGoConfigXmlLoader.setMd5(configForEdit, "md5");
FullConfigUpdateCommand updatingCommand = new FullConfigUpdateCommand(new BasicCruiseConfig(), "md5");
GoConfigHolder configHolder = new GoConfigHolder(new BasicCruiseConfig(), configForEdit);
CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
GoFileConfigDataSource source = new GoFileConfigDataSource(null, null, systemEnvironment, null, null, null, null, null, cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow);
stub(cachedGoPartials.lastKnownPartials()).toReturn(known);
stub(cachedGoPartials.lastValidPartials()).toReturn(valid);
when(fullConfigSaveNormalFlow.execute(updatingCommand, known, "loser_boozer")).thenThrow(new GoConfigInvalidException(configForEdit, "error"));
source.writeFullConfigWithLock(updatingCommand, configHolder);
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class TemplateConfigServiceTest method shouldPopulateErrorInResultOnFailure.
@Test
public void shouldPopulateErrorInResultOnFailure() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Username user = new Username(new CaseInsensitiveString("user"));
String templateName = "template-name";
PipelineTemplateConfig pipelineTemplateConfig = new PipelineTemplateConfig(new CaseInsensitiveString(templateName), StageConfigMother.oneBuildPlanWithResourcesAndMaterials("stage", "job"));
String errorMessage = "invalid template";
doThrow(new GoConfigInvalidException(new GoConfigMother().defaultCruiseConfig(), errorMessage)).when(goConfigService).updateConfig(any(CreateTemplateConfigCommand.class), any(Username.class));
service.createTemplateConfig(user, pipelineTemplateConfig, result);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.unprocessableEntity(LocalizedMessage.string("ENTITY_CONFIG_VALIDATION_FAILED", "template", templateName, errorMessage));
assertThat(result.toString(), is(expectedResult.toString()));
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class MagicalGoConfigXmlLoader method validateCruiseConfig.
private CruiseConfig validateCruiseConfig(CruiseConfig config) throws Exception {
LOGGER.debug("[Config Save] In validateCruiseConfig: Starting.");
List<ConfigErrors> allErrors = validate(config);
if (!allErrors.isEmpty()) {
if (config.isLocal())
throw new GoConfigInvalidException(config, allErrors.get(0).asString());
else
throw new GoConfigInvalidMergeException("Merged validation failed", config, config.getMergedPartials(), allErrors);
}
LOGGER.debug("[Config Save] In validateCruiseConfig: Running validate.");
for (GoConfigValidator validator : VALIDATORS) {
validator.validate(config);
}
LOGGER.debug("[Config Save] In validateCruiseConfig: Done.");
return config;
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldThrowInvalidConfigWhenAttemptedToSaveMergedConfig.
@Test
public void shouldThrowInvalidConfigWhenAttemptedToSaveMergedConfig() throws Exception {
String xml = ConfigFileFixture.TWO_PIPELINES;
CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(IOUtils.toInputStream(xml)).config;
PartialConfig remotePart = PartialConfigMother.withPipeline("some-pipe");
remotePart.setOrigin(new RepoConfigOrigin());
BasicCruiseConfig merged = new BasicCruiseConfig((BasicCruiseConfig) cruiseConfig, remotePart);
try {
xmlWriter.write(merged, output, true);
} catch (GoConfigInvalidException ex) {
// ok
assertThat(ex.getMessage(), is("Attempted to save merged configuration with patials"));
return;
}
fail("should have thrown when saving merged configuration");
}
Aggregations