Search in sources :

Example 1 with EntityConfigChangedListener

use of com.thoughtworks.go.listener.EntityConfigChangedListener 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 2 with EntityConfigChangedListener

use of com.thoughtworks.go.listener.EntityConfigChangedListener in project gocd by gocd.

the class DependencyMaterialUpdateNotifierTest method shouldListenToConfigChange.

@Test
public void shouldListenToConfigChange() {
    EntityConfigChangedListener entityConfigChangedListener = mock(EntityConfigChangedListener.class);
    notifier = new DependencyMaterialUpdateNotifier(goConfigService, materialConfigConverter, materialUpdateService, serverHealthService);
    notifier = spy(notifier);
    stub(notifier.pipelineConfigChangedListener()).toReturn(entityConfigChangedListener);
    notifier.initialize();
    verify(goConfigService).register(notifier);
    verify(goConfigService).register(entityConfigChangedListener);
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.Test)

Example 3 with EntityConfigChangedListener

use of com.thoughtworks.go.listener.EntityConfigChangedListener in project gocd by gocd.

the class SCMMaterialSourceTest method shouldListenToConfigChange.

@Test
public void shouldListenToConfigChange() {
    EntityConfigChangedListener entityConfigChangedListener = mock(EntityConfigChangedListener.class);
    source = spy(source);
    stub(source.pipelineConfigChangedListener()).toReturn(entityConfigChangedListener);
    source.initialize();
    verify(goConfigService).register(source);
    verify(goConfigService).register(entityConfigChangedListener);
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.Test)

Example 4 with EntityConfigChangedListener

use of com.thoughtworks.go.listener.EntityConfigChangedListener in project gocd by gocd.

the class InvalidConfigMessageRemoverTest method shouldRemoveServerHealthServiceMessageAboutStartedWithInvalidConfigurationOnPipelineConfigSave.

@Test
public void shouldRemoveServerHealthServiceMessageAboutStartedWithInvalidConfigurationOnPipelineConfigSave() {
    GoConfigService goConfigService = mock(GoConfigService.class);
    ServerHealthService serverHealthService = mock(ServerHealthService.class);
    ArgumentCaptor<ConfigChangedListener> configChangedListenerArgumentCaptor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    doNothing().when(goConfigService).register(configChangedListenerArgumentCaptor.capture());
    InvalidConfigMessageRemover invalidConfigMessageRemover = new InvalidConfigMessageRemover(goConfigService, serverHealthService);
    invalidConfigMessageRemover.initialize();
    invalidConfigMessageRemover.onConfigChange(null);
    List<ConfigChangedListener> listeners = configChangedListenerArgumentCaptor.getAllValues();
    assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
    EntityConfigChangedListener listener = (EntityConfigChangedListener) listeners.get(1);
    assertThat(listener.shouldCareAbout(mock(PipelineConfig.class)), is(true));
    invalidConfigMessageRemover.pipelineConfigChangedListener().onEntityConfigChange(mock(PipelineConfig.class));
    ArgumentCaptor<HealthStateScope> captor = ArgumentCaptor.forClass(HealthStateScope.class);
    verify(serverHealthService).removeByScope(captor.capture());
    assertThat(captor.getValue().compareTo(HealthStateScope.forInvalidConfig()), is(0));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 5 with EntityConfigChangedListener

use of com.thoughtworks.go.listener.EntityConfigChangedListener in project gocd by gocd.

the class PipelineConfigServiceIntegrationTest method shouldNotifyListenersWithPreprocessedConfigUponSuccessfulUpdate.

@Test
public void shouldNotifyListenersWithPreprocessedConfigUponSuccessfulUpdate() {
    final String pipelineName = UUID.randomUUID().toString();
    final String templateName = UUID.randomUUID().toString();
    final boolean[] listenerInvoked = { false };
    setupPipelineWithTemplate(pipelineName, templateName);
    PipelineConfig pipelineConfig1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
    String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig1);
    String md5 = CachedDigestUtils.md5Hex(xml);
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener = new EntityConfigChangedListener<PipelineConfig>() {

        @Override
        public void onConfigChange(CruiseConfig newCruiseConfig) {
        }

        @Override
        public void onEntityConfigChange(PipelineConfig pipelineConfig) {
            listenerInvoked[0] = true;
            assertThat(pipelineConfig.first(), is(goConfigService.cruiseConfig().getTemplateByName(new CaseInsensitiveString(templateName)).first()));
        }
    };
    goConfigService.register(pipelineConfigChangedListener);
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfigWithTemplate(pipelineName, templateName);
    pipeline.setVariables(new EnvironmentVariablesConfig());
    pipelineConfigService.updatePipelineConfig(user, pipeline, md5, new DefaultLocalizedOperationResult());
    assertThat(listenerInvoked[0], is(true));
}
Also used : DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener)

Aggregations

EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)11 Test (org.junit.Test)7 ConfigChangedListener (com.thoughtworks.go.listener.ConfigChangedListener)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)3 DefaultLocalizedOperationResult (com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult)2 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)1 Username (com.thoughtworks.go.server.domain.Username)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Closure (org.apache.commons.collections.Closure)1