Search in sources :

Example 6 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithLatestRevisionOfAssociatedMaterial.

@Test
public void shouldScheduleAPipelineWithLatestRevisionOfAssociatedMaterial() {
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
    assertThat(result.httpCode(), is(202));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
    assertNotNull(buildCause);
    assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
    assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3"));
    assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
    assertTrue(buildCause.getVariables().isEmpty());
}
Also used : PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 7 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldNotScheduleAPipelineWithTheJunkEncryptedEnvironmentVariable.

@Test
public void shouldNotScheduleAPipelineWithTheJunkEncryptedEnvironmentVariable() throws InvalidCipherTextException {
    pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
    pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    String overriddenEncryptedValue = "some_junk";
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", overriddenEncryptedValue));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.fullMessage(), is("Request to schedule pipeline rejected { Encrypted value for variable named 'SECURE_VAR1' is invalid. This usually happens when the cipher text is modified to have an invalid value. }"));
    assertThat(result.httpCode(), is(422));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 8 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorWhenAnUnauthorizedUserTriesToScheduleAPipeline.

@Test
public void shouldReturnErrorWhenAnUnauthorizedUserTriesToScheduleAPipeline() throws IOException {
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, new Username("foo"), result);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.fullMessage(), is(String.format("Failed to trigger pipeline [%s] { User foo does not have permission to schedule %s/%s }", pipelineName, pipelineName, stageName)));
    assertThat(result.getServerHealthState().getDescription(), is(String.format("User foo does not have permission to schedule %s/%s", pipelineName, pipelineConfig.first().name())));
    assertThat(result.httpCode(), is(401));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) Test(org.junit.Test)

Example 9 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedEnvironmentVariables.

@Test
public void shouldScheduleAPipelineWithTheProvidedEnvironmentVariables() throws IOException {
    pipelineConfig.addEnvironmentVariable("ENV_VAR1", "VAL1");
    pipelineConfig.addEnvironmentVariable("ENV_VAR2", "VAL2");
    pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
    pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR2", "SECURE_VAL2", true));
    pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
    Integer pipelineCounterBefore = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
    assertThat(result.httpCode(), is(202));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
    assertNotNull(buildCause);
    assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
    assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3"));
    assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
    assertThat(buildCause.getVariables().size(), is(2));
    EnvironmentVariable plainTextVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            EnvironmentVariable variable = (EnvironmentVariable) o;
            return variable.getName().equals("ENV_VAR1");
        }
    });
    EnvironmentVariable secureVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            EnvironmentVariable variable = (EnvironmentVariable) o;
            return variable.getName().equals("SECURE_VAR1");
        }
    });
    assertThat(plainTextVariable.getValue(), is("overridden_value"));
    assertThat(secureVariable.getValue(), is("overridden_secure_value"));
    assertThat(secureVariable.isSecure(), is(true));
    scheduleService.autoSchedulePipelinesFromRequestBuffer();
    Integer pipelineCounterAfter = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
    assertThat(pipelineCounterAfter, is(pipelineCounterBefore + 1));
    BuildCause buildCauseOfLatestRun = pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, pipelineCounterAfter);
    assertThat(buildCauseOfLatestRun, is(buildCause));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Predicate(org.apache.commons.collections.Predicate) Test(org.junit.Test)

Example 10 with PipelineScheduleOptions

use of com.thoughtworks.go.server.domain.PipelineScheduleOptions in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorIfThePipelineBeingScheduledDoesnotExistAndHasMaterialsSetInRequest.

@Test
public void shouldReturnErrorIfThePipelineBeingScheduledDoesnotExistAndHasMaterialsSetInRequest() {
    String pipelineName = "does-not-exist";
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    pipelineScheduleOptions.getMaterials().add(new MaterialForScheduling("non-existant-material", "r1"));
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.fullMessage(), is("Pipeline 'does-not-exist' not found."));
    assertThat(result.httpCode(), is(404));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)18 Test (org.junit.Test)14 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)9 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)6 GoCipher (com.thoughtworks.go.security.GoCipher)6 MaterialForScheduling (com.thoughtworks.go.server.domain.MaterialForScheduling)6 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 JsonReader (com.thoughtworks.go.api.representers.JsonReader)2 EnvironmentVariable (com.thoughtworks.go.domain.EnvironmentVariable)2 Username (com.thoughtworks.go.server.domain.Username)2 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)2 Predicate (org.apache.commons.collections.Predicate)2 GsonTransformer (com.thoughtworks.go.api.util.GsonTransformer)1 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)1 ScheduleOptionsBuilder (com.thoughtworks.go.server.service.builders.ScheduleOptionsBuilder)1 HealthStateType (com.thoughtworks.go.serverhealth.HealthStateType)1 ArrayList (java.util.ArrayList)1