Search in sources :

Example 76 with PipelineConfig

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

the class StageApprovalAuthorizationTest method shouldAuthorizeUserCruiseIfUserIsAuthorisedToOperateAutoStage.

@Test
public void shouldAuthorizeUserCruiseIfUserIsAuthorisedToOperateAutoStage() throws Exception {
    CONFIG_HELPER.addSecurityWithAdminConfig();
    CONFIG_HELPER.setOperatePermissionForStage(PIPELINE_NAME, STAGE_NAME, "cruise");
    StageConfig stage = StageConfigMother.custom("ft", new Approval(new AuthConfig(new AdminUser(new CaseInsensitiveString("cruise")))));
    PipelineConfig pipeline = CONFIG_HELPER.addStageToPipeline(PIPELINE_NAME, stage);
    assertThat(securityService.hasOperatePermissionForStage(CaseInsensitiveString.str(pipeline.name()), CaseInsensitiveString.str(stage.name()), "cruise"), is(true));
    assertThat(securityService.hasOperatePermissionForStage(PIPELINE_NAME, STAGE_NAME, "anyone"), is(false));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) AdminUser(com.thoughtworks.go.config.AdminUser) AuthConfig(com.thoughtworks.go.config.AuthConfig) Approval(com.thoughtworks.go.config.Approval) StageConfig(com.thoughtworks.go.config.StageConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 77 with PipelineConfig

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

the class PipelineRepositoryIntegrationTest method shouldReturnEarliestPMRFor1Material.

@Test
public void shouldReturnEarliestPMRFor1Material() throws Exception {
    HgMaterial hgmaterial = MaterialsMother.hgMaterial("first");
    PipelineConfig pipelineConfig = createPipelineConfig(PIPELINE_NAME, "stage", "job");
    pipelineConfig.setMaterialConfigs(new MaterialConfigs(hgmaterial.config()));
    DateTime date = new DateTime(1984, 12, 23, 0, 0, 0, 0);
    long firstId = createPipeline(hgmaterial, pipelineConfig, 1, oneModifiedFile("3", date.plusDays(2).toDate()), oneModifiedFile("2", date.plusDays(2).toDate()), oneModifiedFile("1", date.plusDays(3).toDate()));
    long secondId = createPipeline(hgmaterial, pipelineConfig, 2, oneModifiedFile("5", date.plusDays(1).toDate()), oneModifiedFile("4", date.toDate()));
    PipelineTimeline pipelineTimeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    ArrayList<PipelineTimelineEntry> entries = new ArrayList<>();
    pipelineRepository.updatePipelineTimeline(pipelineTimeline, entries);
    assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME).size(), is(2));
    assertThat(entries.size(), is(2));
    assertThat(entries, hasItem(expected(firstId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(2).toDate(), "123", hgmaterial.getFingerprint(), 10))), 1)));
    assertThat(entries, hasItem(expected(secondId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(1).toDate(), "12", hgmaterial.getFingerprint(), 8))), 2)));
    assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME), hasItem(expected(firstId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(2).toDate(), "123", hgmaterial.getFingerprint(), 10))), 1)));
    assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME), hasItem(expected(secondId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(1).toDate(), "12", hgmaterial.getFingerprint(), 8))), 2)));
    assertThat(pipelineTimeline.maximumId(), is(secondId));
    long thirdId = createPipeline(hgmaterial, pipelineConfig, 3, oneModifiedFile("30", date.plusDays(10).toDate()));
    pipelineRepository.updatePipelineTimeline(pipelineTimeline, new ArrayList<>());
    assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME).size(), is(3));
    assertThat(pipelineTimeline.getEntriesFor(PIPELINE_NAME), hasItem(expected(thirdId, Collections.singletonMap(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(10).toDate(), "1234", hgmaterial.getFingerprint(), 12))), 3)));
    assertThat(pipelineTimeline.maximumId(), is(thirdId));
    assertThat(pipelineSqlMapDao.pipelineByIdWithMods(firstId).getNaturalOrder(), is(1.0));
    assertThat(pipelineSqlMapDao.pipelineByIdWithMods(secondId).getNaturalOrder(), is(0.5));
    assertThat(pipelineSqlMapDao.pipelineByIdWithMods(thirdId).getNaturalOrder(), is(2.0));
    PipelineTimeline pipelineTimeline2 = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    pipelineRepository.updatePipelineTimeline(pipelineTimeline2, new ArrayList<>());
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfigMother.createPipelineConfig(com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) PipelineTimeline(com.thoughtworks.go.server.domain.PipelineTimeline) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 78 with PipelineConfig

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

the class PipelineRepositoryIntegrationTest method shouldAddExistingPipelinesToTimelineForNewTimeline.

@Test
public void shouldAddExistingPipelinesToTimelineForNewTimeline() {
    HgMaterial hgmaterial = MaterialsMother.hgMaterial(UUID.randomUUID().toString());
    PipelineConfig pipelineConfig = createPipelineConfig(PIPELINE_NAME, "stage", "job");
    pipelineConfig.setMaterialConfigs(new MaterialConfigs(hgmaterial.config()));
    DateTime date = new DateTime(1984, 12, 23, 0, 0, 0, 0);
    long firstId = createPipeline(hgmaterial, pipelineConfig, 1, oneModifiedFile("3", date.plusDays(2).toDate()), oneModifiedFile("2", date.plusDays(2).toDate()), oneModifiedFile("1", date.plusDays(3).toDate()));
    long secondId = createPipeline(hgmaterial, pipelineConfig, 2, oneModifiedFile("5", date.plusDays(1).toDate()), oneModifiedFile("4", date.toDate()));
    PipelineTimeline mods = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    mods.update();
    assertThat(pipelineSqlMapDao.pipelineByIdWithMods(firstId).getNaturalOrder(), is(1.0));
    assertThat(pipelineSqlMapDao.pipelineByIdWithMods(secondId).getNaturalOrder(), is(0.5));
    PipelineTimeline modsAfterReboot = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    modsAfterReboot.update();
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfigMother.createPipelineConfig(com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) PipelineTimeline(com.thoughtworks.go.server.domain.PipelineTimeline) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 79 with PipelineConfig

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

the class PipelineRepositoryIntegrationTest method shouldReturnEarliestPMRForMultipleMaterial.

@Test
public void shouldReturnEarliestPMRForMultipleMaterial() throws Exception {
    final HgMaterial hgmaterial = MaterialsMother.hgMaterial("first");
    final SvnMaterial svnMaterial = MaterialsMother.svnMaterial();
    PipelineConfig pipelineConfig = createPipelineConfig(PIPELINE_NAME, "stage", "job");
    pipelineConfig.setMaterialConfigs(new MaterialConfigs(hgmaterial.config(), svnMaterial.config()));
    final DateTime date = new DateTime(1984, 12, 23, 0, 0, 0, 0);
    long first = save(pipelineConfig, 1, 1.0, new MaterialRevision(hgmaterial, oneModifiedFile("13", date.plusDays(2).toDate()), oneModifiedFile("12", date.plusDays(2).toDate()), oneModifiedFile("11", date.plusDays(3).toDate())), new MaterialRevision(svnMaterial, oneModifiedFile("23", date.plusDays(6).toDate()), oneModifiedFile("22", date.plusDays(2).toDate()), oneModifiedFile("21", date.plusDays(2).toDate())));
    long second = save(pipelineConfig, 2, 0.0, new MaterialRevision(hgmaterial, oneModifiedFile("15", date.plusDays(3).toDate()), oneModifiedFile("14", date.plusDays(2).toDate())), new MaterialRevision(svnMaterial, oneModifiedFile("25", date.plusDays(5).toDate())));
    PipelineTimeline pipelineTimeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    pipelineRepository.updatePipelineTimeline(pipelineTimeline, new ArrayList<>());
    Collection<PipelineTimelineEntry> modifications = pipelineTimeline.getEntriesFor(PIPELINE_NAME);
    assertThat(modifications.size(), is(2));
    assertThat(modifications, hasItem(expected(first, new HashMap<String, List<PipelineTimelineEntry.Revision>>() {

        {
            put(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(2).toDate(), "123", hgmaterial.getFingerprint(), 8)));
            put(svnMaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(6).toDate(), "456", svnMaterial.getFingerprint(), 12)));
        }
    }, 1)));
    assertThat(modifications, hasItem(expected(second, new HashMap<String, List<PipelineTimelineEntry.Revision>>() {

        {
            put(hgmaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(3).toDate(), "234", hgmaterial.getFingerprint(), 9)));
            put(svnMaterial.getFingerprint(), a(new PipelineTimelineEntry.Revision(date.plusDays(5).toDate(), "345", svnMaterial.getFingerprint(), 10)));
        }
    }, 2)));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfigMother.createPipelineConfig(com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PipelineTimeline(com.thoughtworks.go.server.domain.PipelineTimeline) DateTime(org.joda.time.DateTime) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Test(org.junit.Test)

Example 80 with PipelineConfig

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

the class ResourceRepositoryIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    dbHelper.onSetUp();
    PipelineConfig pipelineConfig = PipelineMother.withSingleStageWithMaterials(PIPELINE_NAME, STAGE_NAME, BuildPlanMother.withBuildPlans(JOB_NAME, OTHER_JOB_NAME));
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext(DEFAULT_APPROVED_BY);
    Pipeline savedPipeline = instanceFactory.createPipelineInstance(pipelineConfig, modifySomeFiles(pipelineConfig), schedulingContext, "md5-test", new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(savedPipeline);
    Stage savedStage = savedPipeline.getFirstStage();
    stageId = savedStage.getId();
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) Before(org.junit.Before)

Aggregations

PipelineConfig (com.thoughtworks.go.config.PipelineConfig)186 Test (org.junit.Test)129 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)76 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)32 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)19 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)17 TimeProvider (com.thoughtworks.go.util.TimeProvider)16 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)13 Pipeline (com.thoughtworks.go.domain.Pipeline)13 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)13 Date (java.util.Date)13 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)12 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)12 StageConfig (com.thoughtworks.go.config.StageConfig)11 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)11 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)11 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)11 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)9 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)9