Search in sources :

Example 6 with GoConfigInvalidException

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));
    }
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 7 with GoConfigInvalidException

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);
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 8 with GoConfigInvalidException

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()));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) CreateTemplateConfigCommand(com.thoughtworks.go.config.update.CreateTemplateConfigCommand) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 9 with GoConfigInvalidException

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;
}
Also used : GoConfigInvalidMergeException(com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 10 with GoConfigInvalidException

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");
}
Also used : PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Aggregations

GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)17 Test (org.junit.Test)13 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)4 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 Packages (com.thoughtworks.go.domain.packagerepository.Packages)4 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)3 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 SCM (com.thoughtworks.go.domain.scm.SCM)2 SCMs (com.thoughtworks.go.domain.scm.SCMs)2 IOException (java.io.IOException)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1