Search in sources :

Example 16 with StageConfig

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

the class PipelineTemplateConfigViewModelTest method shouldSetConfigAttributesBasedOnExistingPipeline.

@Test
public void shouldSetConfigAttributesBasedOnExistingPipeline() {
    StageConfig stage1 = StageConfigMother.custom("stage_foo", "foo1", "foo2");
    StageConfig stage2 = StageConfigMother.custom("stage_bar", "bar1", "bar2");
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfig("pipeline", stage1, stage2);
    PipelineTemplateConfigViewModel viewModel = new PipelineTemplateConfigViewModel(new PipelineTemplateConfig(), "", Arrays.asList(PipelineConfigMother.pipelineConfig("foo_bar"), pipeline));
    Map m = m("template", m(PipelineTemplateConfig.NAME, "template_name"), PipelineTemplateConfigViewModel.USE_EXISTING_PIPELINE, "1", PipelineTemplateConfigViewModel.SELECTED_PIPELINE_NAME, pipeline.name().toString());
    viewModel.setConfigAttributes(m);
    assertThat(viewModel.useExistingPipeline(), is(true));
    assertThat(viewModel.selectedPipelineName(), is(pipeline.name().toString()));
    PipelineTemplateConfig template = viewModel.templateConfig();
    assertThat(template.name(), is(new CaseInsensitiveString("template_name")));
    assertThat(template.size(), is(2));
    assertThat(template.get(0), is(stage1));
    assertThat(template.get(1), is(stage2));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) PipelineTemplateConfig(com.thoughtworks.go.config.PipelineTemplateConfig) Map(java.util.Map) StageConfig(com.thoughtworks.go.config.StageConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 17 with StageConfig

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

the class BuildRepositoryServiceIntegrationTest method shouldCancelAllJobs.

@Test
public void shouldCancelAllJobs() throws Exception {
    mingle = PipelineMother.twoBuildPlansWithResourcesAndSvnMaterialsAtUrl(PIPELINE_NAME, DEV_STAGE, svnTestRepo.projectRepositoryUrl());
    StageConfig devStage = mingle.get(0);
    schedulePipeline(mingle);
    final Stage stage = stageDao.mostRecentWithBuilds(CaseInsensitiveString.str(mingle.name()), devStage);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        public void doInTransactionWithoutResult(TransactionStatus status) {
            stageService.cancelStage(stage);
        }
    });
    final Stage cancelled = stageService.stageById(stage.getId());
    assertThat(cancelled.stageState(), is(StageState.Cancelled));
    final JobInstances builds = cancelled.getJobInstances();
    for (JobInstance job : builds) {
        assertThat(job.currentStatus(), is(JobState.Completed));
        assertThat(job.getResult(), is(JobResult.Cancelled));
        assertThat(job.displayStatusWithResult(), is("cancelled"));
    }
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) StageConfig(com.thoughtworks.go.config.StageConfig) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 18 with StageConfig

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

the class StageApprovalAuthorizationTest method shouldAuthorizeIfRoleIsInApprovalList.

@Test
public void shouldAuthorizeIfRoleIsInApprovalList() throws Exception {
    CONFIG_HELPER.addSecurityWithAdminConfig();
    CONFIG_HELPER.addRole(new RoleConfig(new CaseInsensitiveString("adminRole"), new RoleUser(new CaseInsensitiveString("tester"))));
    StageConfig stage = StageConfigMother.custom("test", authConfigWithAdminRole);
    PipelineConfig pipeline = CONFIG_HELPER.addStageToPipeline(PIPELINE_NAME, stage);
    assertThat("User tester should have permission on test stage", securityService.hasOperatePermissionForStage(CaseInsensitiveString.str(pipeline.name()), CaseInsensitiveString.str(stage.name()), "tester"), is(true));
}
Also used : RoleConfig(com.thoughtworks.go.config.RoleConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) RoleUser(com.thoughtworks.go.config.RoleUser) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageConfig(com.thoughtworks.go.config.StageConfig) Test(org.junit.Test)

Example 19 with StageConfig

use of com.thoughtworks.go.config.StageConfig 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 20 with StageConfig

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

the class PipelineSchedulerIntegrationTest method shouldThrowExceptionIfOtherStageIsRunningInTheSamePipeline.

@Test
public void shouldThrowExceptionIfOtherStageIsRunningInTheSamePipeline() throws Exception {
    Pipeline pipeline = makeCompletedPipeline();
    StageConfig ftStage = goConfigService.stageConfigNamed(PIPELINE_MINGLE, FT_STAGE);
    scheduleService.rerunStage(PIPELINE_MINGLE, pipeline.getCounter().toString(), FT_STAGE);
    try {
        scheduleService.rerunStage(PIPELINE_MINGLE, pipeline.getCounter().toString(), FT_STAGE);
        Assert.fail("Should throw exception if fails to re-run stage");
    } catch (Exception ignored) {
        assertThat(ignored.getMessage(), matches("Cannot schedule: Pipeline.+is still in progress"));
    }
}
Also used : StageConfig(com.thoughtworks.go.config.StageConfig) IOException(java.io.IOException)

Aggregations

StageConfig (com.thoughtworks.go.config.StageConfig)31 Test (org.junit.Test)12 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 TimeProvider (com.thoughtworks.go.util.TimeProvider)4 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)3 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 Agents (com.thoughtworks.go.config.Agents)2 JobConfigs (com.thoughtworks.go.config.JobConfigs)2 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)2 NullStage (com.thoughtworks.go.domain.NullStage)2 Stage (com.thoughtworks.go.domain.Stage)2 InstanceFactory (com.thoughtworks.go.server.service.InstanceFactory)2 Map (java.util.Map)2 Gson (com.google.gson.Gson)1 AdminUser (com.thoughtworks.go.config.AdminUser)1 Approval (com.thoughtworks.go.config.Approval)1 AuthConfig (com.thoughtworks.go.config.AuthConfig)1