Search in sources :

Example 1 with EntityConfigUpdateCommand

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);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) Test(org.junit.Test)

Example 2 with EntityConfigUpdateCommand

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.Test)

Example 3 with EntityConfigUpdateCommand

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);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) Test(org.junit.Test)

Example 4 with EntityConfigUpdateCommand

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);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) ConfigUpdateCheckFailedException(com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) ConfigUpdateCheckFailedException(com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException) Test(org.junit.Test)

Aggregations

EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)4 Username (com.thoughtworks.go.server.domain.Username)4 Test (org.junit.Test)4 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigUpdateCheckFailedException (com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException)1 EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)1