use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class AdminRoleTest method shouldAddValidationErrorIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext.
@Test
public void shouldAddValidationErrorIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext() throws Exception {
AdminRole role = new AdminRole(new CaseInsensitiveString("role2"));
PipelineConfig pipelineConfig = new PipelineConfig();
PipelineConfigs pipelinesConfig = new BasicPipelineConfigs(new Authorization(new ViewConfig(role)), pipelineConfig);
CruiseConfig config = new BasicCruiseConfig(pipelinesConfig);
role.validate(PipelineConfigSaveValidationContext.forChain(true, "group", config, pipelineConfig));
ConfigErrors errors = role.errors();
assertThat(errors.isEmpty(), is(false));
assertThat(errors.on(AdminRole.NAME), is("Role \"role2\" does not exist."));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class GoConfigInvalidMergeException method allErrorsToString.
private static String allErrorsToString(List<ConfigErrors> allErrors, String summary) {
if (allErrors == null || allErrors.size() == 0)
// should never be
return "Error list empty";
StringBuilder b = new StringBuilder();
b.append(allErrors.size()).append("+ errors :: ");
for (ConfigErrors e : allErrors) {
b.append(e.firstError()).append(";; ");
}
return b.toString();
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class MergeCruiseConfigTest method shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned.
@Test
public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned() {
// we need this case because cloning has proven to be problematic with complex object graph in merged config
BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2");
partialConfig.setOrigin(new RepoConfigOrigin());
CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
Cloner CLONER = new Cloner();
CruiseConfig cloned = CLONER.deepClone(config);
List<ConfigErrors> allErrors = cloned.validateAfterPreprocess();
assertThat(allErrors.size(), is(2));
assertThat(allErrors.get(0).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
}
use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.
the class EnvironmentAgentValidator method validate.
public void validate(CruiseConfig cruiseConfig) throws Exception {
List<ConfigErrors> errors = validateConfig(cruiseConfig);
List<String> errorMessages = new ArrayList<>();
for (ConfigErrors error : errors) {
errorMessages.addAll(error.getAll());
}
if (!errors.isEmpty())
throw new RuntimeException(StringUtils.join(errorMessages, ", "));
}
use of com.thoughtworks.go.domain.ConfigErrors 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));
}
}
Aggregations