use of com.thoughtworks.go.config.commands.EntityConfigUpdateCommand in project gocd by gocd.
the class GoConfigDaoTestBase method shouldUpdateValidEntity.
@Test
public void shouldUpdateValidEntity() {
CachedGoConfig cachedConfigService = mock(CachedGoConfig.class);
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
when(cachedConfigService.currentConfig()).thenReturn(cruiseConfig);
EntityConfigUpdateCommand saveCommand = mock(EntityConfigUpdateCommand.class);
when(saveCommand.isValid(cruiseConfig)).thenReturn(true);
when(saveCommand.canContinue(cruiseConfig)).thenReturn(true);
goConfigDao = new GoConfigDao(cachedConfigService);
Username currentUser = new Username(new CaseInsensitiveString("user"));
goConfigDao.updateConfig(saveCommand, currentUser);
verify(cachedConfigService).writeEntityWithLock(saveCommand, currentUser);
}
use of com.thoughtworks.go.config.commands.EntityConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigTest method shouldNotifyConcernedListenersWhenEntityChanges.
@Test
public void shouldNotifyConcernedListenersWhenEntityChanges() {
final boolean[] pipelineConfigChangeListenerCalled = { false };
final boolean[] agentConfigChangeListenerCalled = { false };
final boolean[] cruiseConfigChangeListenerCalled = { false };
EntityConfigChangedListener<PipelineConfig> pipelineConfigChangeListener = new EntityConfigChangedListener<PipelineConfig>() {
@Override
public void onEntityConfigChange(PipelineConfig entity) {
pipelineConfigChangeListenerCalled[0] = true;
}
};
EntityConfigChangedListener<AgentConfig> agentConfigChangeListener = new EntityConfigChangedListener<AgentConfig>() {
@Override
public void onEntityConfigChange(AgentConfig entity) {
agentConfigChangeListenerCalled[0] = true;
}
};
EntityConfigChangedListener<CruiseConfig> cruiseConfigChangeListener = new EntityConfigChangedListener<CruiseConfig>() {
@Override
public void onEntityConfigChange(CruiseConfig entity) {
cruiseConfigChangeListenerCalled[0] = true;
}
};
cachedGoConfig.registerListener(pipelineConfigChangeListener);
cachedGoConfig.registerListener(agentConfigChangeListener);
cachedGoConfig.registerListener(cruiseConfigChangeListener);
EntityConfigUpdateCommand configCommand = mock(EntityConfigUpdateCommand.class);
when(configCommand.isValid(any(CruiseConfig.class))).thenReturn(true);
when(configCommand.getPreprocessedEntityConfig()).thenReturn(mock(PipelineConfig.class));
EntityConfigSaveResult entityConfigSaveResult = mock(EntityConfigSaveResult.class);
when(entityConfigSaveResult.getConfigHolder()).thenReturn(configHolder);
when(entityConfigSaveResult.getEntityConfig()).thenReturn(new PipelineConfig());
Username user = new Username(new CaseInsensitiveString("user"));
when(dataSource.writeEntityWithLock(configCommand, configHolder, user)).thenReturn(entityConfigSaveResult);
cachedGoConfig.loadConfigIfNull();
cachedGoConfig.writeEntityWithLock(configCommand, user);
assertThat(pipelineConfigChangeListenerCalled[0], is(true));
assertThat(agentConfigChangeListenerCalled[0], is(false));
assertThat(cruiseConfigChangeListenerCalled[0], is(false));
}
use of com.thoughtworks.go.config.commands.EntityConfigUpdateCommand in project gocd by gocd.
the class CachedGoConfigTest method shouldDelegateWriteEntityConfigCallToDataSource.
@Test
public void shouldDelegateWriteEntityConfigCallToDataSource() {
EntityConfigUpdateCommand saveCommand = mock(EntityConfigUpdateCommand.class);
GoConfigHolder savedConfig = new GoConfigHolder(new BasicCruiseConfig(), new BasicCruiseConfig());
GoConfigHolder holderBeforeUpdate = cachedGoConfig.loadConfigHolder();
Username user = new Username(new CaseInsensitiveString("user"));
EntityConfigSaveResult entityConfigSaveResult = mock(EntityConfigSaveResult.class);
when(entityConfigSaveResult.getConfigHolder()).thenReturn(savedConfig);
when(entityConfigSaveResult.getEntityConfig()).thenReturn(new PipelineConfig());
when(dataSource.writeEntityWithLock(saveCommand, holderBeforeUpdate, user)).thenReturn(entityConfigSaveResult);
cachedGoConfig.writeEntityWithLock(saveCommand, user);
assertThat(cachedGoConfig.loadConfigHolder(), is(savedConfig));
assertThat(cachedGoConfig.currentConfig(), is(savedConfig.config));
assertThat(cachedGoConfig.loadForEditing(), is(savedConfig.configForEdit));
verify(dataSource).writeEntityWithLock(saveCommand, holderBeforeUpdate, user);
}
use of com.thoughtworks.go.config.commands.EntityConfigUpdateCommand 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