Search in sources :

Example 46 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleCaseWhenExceptionWithoutMessageIsRaised.

@Test
public void shouldHandleCaseWhenExceptionWithoutMessageIsRaised() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
    when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1")))).thenThrow(new NullPointerException());
    ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
    verify(mockServerHealthService).update(argThat(hasErrorHealthState("Error while scheduling pipeline: pipeline", "Details not available, please check server logs.")));
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 47 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class BuildCauseProducerServiceTest method manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo.

@Test
public void manualTrigger_shouldRequestUpdateOfNewMaterials_WhenPipelineConfigInConfigRepo() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterial material2 = new HgMaterial("url2", null);
    HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
    HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig1, "plug"), "revision1"));
    when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
    when(materialConfigConverter.toMaterial(materialConfig2)).thenReturn(material2);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
    // updated pipeline config
    PipelineConfig updatedPipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs());
    updatedPipelineConfig.addMaterialConfig(materialConfig1);
    updatedPipelineConfig.addMaterialConfig(materialConfig2);
    when(goConfigService.pipelineConfigNamed(pipelineConfig.name())).thenReturn(updatedPipelineConfig);
    when(goConfigService.hasPipelineNamed(pipelineConfig.name())).thenReturn(true);
    Materials materials = new Materials(material1, material2);
    when(materialConfigConverter.toMaterials(updatedPipelineConfig.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(updatedPipelineConfig.materialConfigs())).thenReturn(updatedPipelineConfig.materialConfigs());
    when(pipelineScheduleQueue.mostRecentScheduled(updatedPipelineConfig.name().toString())).thenReturn(BuildCause.createNeverRun());
    when(materialChecker.findLatestRevisions(any(), eq(materials))).thenReturn(new MaterialRevisions());
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
    verify(goConfigService, times(2)).pipelineConfigNamed(pipelineConfig.name());
    verify(mockMaterialUpdateService, times(1)).updateMaterial(material1);
    verify(mockMaterialUpdateService, times(1)).updateMaterial(material2);
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material2, 0));
    verify(mockMaterialUpdateStatusNotifier).removeListenerFor(updatedPipelineConfig);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 48 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleCaseWhereSpecifiedRevisionDoesNotExist.

@Test
public void shouldHandleCaseWhereSpecifiedRevisionDoesNotExist() throws Exception {
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
    when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1")))).thenThrow(new RuntimeException("Invalid specified revision"));
    ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
    final HashMap<String, String> stringStringHashMap = new HashMap<>();
    buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/200/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
    verify(mockServerHealthService).update(argThat(hasErrorHealthState("Error while scheduling pipeline: pipeline", "Invalid specified revision")));
}
Also used : DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 49 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.

@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
    String pipelineName = "pipeline";
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
    Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
    DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
    config.materialConfigs().clear();
    config.addMaterialConfig(svnMaterial.config());
    config.addMaterialConfig(dependencyMaterial.config());
    when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
    when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
    Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
    when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
    when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
    when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
    when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
    MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
    Materials materials = new Materials(svnMaterial, dependencyMaterial);
    when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
    when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
    when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
    AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null);
    ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
    assertThat(serverHealthState.isSuccess(), is(true));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) PipelineConfigDependencyGraph(com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Test(org.junit.Test)

Example 50 with CaseInsensitiveString

use of com.thoughtworks.go.config.CaseInsensitiveString in project gocd by gocd.

the class AuthorityGranterTest method shouldGrantTemplateViewUserRoleToTemplateViewUsers.

@Test
public void shouldGrantTemplateViewUserRoleToTemplateViewUsers() {
    String templateViewUser = "templateViewUser";
    when(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString(templateViewUser)))).thenReturn(false);
    when(securityService.isAuthorizedToViewTemplates(new Username(templateViewUser))).thenReturn(true);
    GrantedAuthority[] authorities = authorityGranter.authorities(templateViewUser);
    assertThat(authorities, hasItemInArray(GoAuthority.ROLE_TEMPLATE_VIEW_USER.asAuthority()));
    assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_TEMPLATE_SUPERVISOR.asAuthority())));
    assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority())));
    assertThat(authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)392 Test (org.junit.Test)277 Username (com.thoughtworks.go.server.domain.Username)80 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)65 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)65 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)57 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)56 Date (java.util.Date)50 Modification (com.thoughtworks.go.domain.materials.Modification)44 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)30 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)28 Before (org.junit.Before)28 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)27 HashMap (java.util.HashMap)26 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)24 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)24 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)19 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)19 ArrayList (java.util.ArrayList)19 Pipeline (com.thoughtworks.go.domain.Pipeline)18