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));
}
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);
}
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);
}
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));
}
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));
}
Aggregations