use of com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException in project gocd by gocd.
the class GoConfigDao method updateConfig.
public ConfigSaveState updateConfig(UpdateConfigCommand command) {
ConfigSaveState configSaveState = null;
LOGGER.info("Config update request by {} is in queue - {}", UserHelper.getUserName().getUsername(), command);
synchronized (GoConfigWriteLock.class) {
try {
LOGGER.info("Config update request {} by {} is being processed", command, UserHelper.getUserName().getUsername());
if (command instanceof CheckedUpdateCommand) {
CheckedUpdateCommand checkedCommand = (CheckedUpdateCommand) command;
if (!checkedCommand.canContinue(cachedConfigService.currentConfig())) {
throw new ConfigUpdateCheckFailedException();
}
}
configSaveState = cachedConfigService.writeWithLock(command);
} finally {
if (command instanceof ConfigAwareUpdate) {
((ConfigAwareUpdate) command).afterUpdate(clonedConfig());
}
LOGGER.info("Config update request by {} is completed", UserHelper.getUserName().getUsername());
}
}
return configSaveState;
}
use of com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException in project gocd by gocd.
the class GoConfigDaoTestBase method shouldNotUpdatePipelineConfigIfUserDoesNotHaveRequiredPermissionsToDoSo.
@Test
public void shouldNotUpdatePipelineConfigIfUserDoesNotHaveRequiredPermissionsToDoSo() {
CachedGoConfig cachedConfigService = mock(CachedGoConfig.class);
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
when(cachedConfigService.currentConfig()).thenReturn(cruiseConfig);
goConfigDao = new GoConfigDao(cachedConfigService);
EntityConfigUpdateCommand command = mock(EntityConfigUpdateCommand.class);
when(command.canContinue(cruiseConfig)).thenReturn(false);
try {
goConfigDao.updateConfig(command, new Username(new CaseInsensitiveString("user")));
fail("Expected to throw exception of type:" + ConfigUpdateCheckFailedException.class.getName());
} catch (Exception e) {
assertTrue(e instanceof ConfigUpdateCheckFailedException);
}
verify(cachedConfigService).currentConfig();
verifyNoMoreInteractions(cachedConfigService);
}
Aggregations