Search in sources :

Example 1 with GoConfigService

use of com.thoughtworks.go.server.service.GoConfigService in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldScheduleAfterAllMaterialsAreUpdated.

@Test
public void shouldScheduleAfterAllMaterialsAreUpdated() throws Exception {
    HgMaterial hgMaterial = new HgMaterial("url", null);
    HgMaterialConfig hgMaterialConfig = new HgMaterialConfig("url", null);
    SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig("url", null, null, false);
    pipelineConfig.addMaterialConfig(hgMaterialConfig);
    pipelineConfig.addMaterialConfig(svnMaterialConfig);
    GoConfigService service = mock(GoConfigService.class);
    when(service.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
    when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
    when(materialConfigConverter.toMaterial(svnMaterialConfig)).thenReturn(svnMaterial);
    MaterialUpdateStatusNotifier notifier = new MaterialUpdateStatusNotifier(mock(MaterialUpdateCompletedTopic.class));
    buildCauseProducerService = spy(createBuildCauseProducerService(notifier));
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), new ServerHealthStateOperationResult());
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    doReturn(ServerHealthState.success(healthStateType)).when(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), new ScheduleOptions(eq(EMPTY_REVISIONS), stringStringHashMap, new HashMap<>()), any(ServerHealthStateOperationResult.class), eq(12345L));
    assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
    notifier.onMessage(new MaterialUpdateSuccessfulMessage(hgMaterial, 1111L));
    assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
    notifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 2222L));
    assertThat(notifier.hasListenerFor(pipelineConfig), is(false));
    verify(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), eq(new ScheduleOptions()), any(ServerHealthStateOperationResult.class), eq(2222L));
}
Also used : HashMap(java.util.HashMap) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ManualBuild(com.thoughtworks.go.server.service.ManualBuild) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialUpdateStatusNotifier(com.thoughtworks.go.server.materials.MaterialUpdateStatusNotifier) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) MaterialUpdateCompletedTopic(com.thoughtworks.go.server.materials.MaterialUpdateCompletedTopic) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Example 2 with GoConfigService

use of com.thoughtworks.go.server.service.GoConfigService in project gocd by gocd.

the class SecurityAuthConfigUpdateCommandTest method setUp.

@Before
public void setUp() throws Exception {
    currentUser = new Username("bob");
    goConfigService = mock(GoConfigService.class);
    cruiseConfig = GoConfigMother.defaultCruiseConfig();
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Example 3 with GoConfigService

use of com.thoughtworks.go.server.service.GoConfigService in project gocd by gocd.

the class SCMMaterialSourceTest method setUp.

@Before
public void setUp() throws Exception {
    goConfigService = mock(GoConfigService.class);
    systemEnvironment = new SystemEnvironment();
    serverHealthService = mock(ServerHealthService.class);
    materialConfigConverter = mock(MaterialConfigConverter.class);
    materialUpdateService = mock(MaterialUpdateService.class);
    source = new SCMMaterialSource(goConfigService, systemEnvironment, materialConfigConverter, materialUpdateService);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Example 4 with GoConfigService

use of com.thoughtworks.go.server.service.GoConfigService in project gocd by gocd.

the class IsSecurityEnabledVoterTest method shouldNotVoteAccessGrantedIfSecurityIsEnabledButAnonymousIsNot.

@Test
public void shouldNotVoteAccessGrantedIfSecurityIsEnabledButAnonymousIsNot() {
    configHelper.addSecurityWithBogusLdapConfig(false);
    GoConfigService configService = new GoConfigService(goConfigDao, null, new SystemTimeClock(), mock(GoConfigMigration.class), null, null, ConfigElementImplementationRegistryMother.withNoPlugins(), new InstanceFactory(), mock(CachedGoPartials.class), null);
    IsSecurityEnabledVoter voter = new IsSecurityEnabledVoter(configService);
    int accessStatus = voter.vote(null, null, null);
    assertThat(accessStatus, Is.is(AccessDecisionVoter.ACCESS_ABSTAIN));
}
Also used : CachedGoPartials(com.thoughtworks.go.config.CachedGoPartials) InstanceFactory(com.thoughtworks.go.server.service.InstanceFactory) SystemTimeClock(com.thoughtworks.go.util.SystemTimeClock) GoConfigMigration(com.thoughtworks.go.config.GoConfigMigration) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 5 with GoConfigService

use of com.thoughtworks.go.server.service.GoConfigService 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)

Aggregations

GoConfigService (com.thoughtworks.go.server.service.GoConfigService)16 Before (org.junit.Before)13 Username (com.thoughtworks.go.server.domain.Username)8 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)3 Test (org.junit.Test)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)2 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)2 AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)2 MaterialConfigConverter (com.thoughtworks.go.server.service.MaterialConfigConverter)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 CachedGoPartials (com.thoughtworks.go.config.CachedGoPartials)1 GoConfigMigration (com.thoughtworks.go.config.GoConfigMigration)1 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1