Search in sources :

Example 11 with PipelineScheduleOptions

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

the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorIfThePipelineBeingScheduledDoesnotExist.

@Test
public void shouldReturnErrorIfThePipelineBeingScheduledDoesnotExist() {
    String pipelineName = "does-not-exist";
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    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 : PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 12 with PipelineScheduleOptions

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

the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorIfTheFirstStageOfThePipelineBeingScheduledIsAlreadyRunning.

@Test
public void shouldReturnErrorIfTheFirstStageOfThePipelineBeingScheduledIsAlreadyRunning() {
    pipelineTriggerService.schedule(pipelineName, new PipelineScheduleOptions(), admin, result);
    assertThat(result.isSuccess(), is(true));
    pipelineTriggerService.schedule(pipelineName, new PipelineScheduleOptions(), admin, result);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.fullMessage(), is(String.format("Failed to trigger pipeline: %s { Pipeline already triggered }", pipelineName)));
    assertThat(result.getServerHealthState().getDescription(), is("Pipeline already triggered"));
    assertThat(result.httpCode(), is(409));
}
Also used : PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) Test(org.junit.Test)

Example 13 with PipelineScheduleOptions

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

the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedEncryptedEnvironmentVariable.

@Test
public void shouldScheduleAPipelineWithTheProvidedEncryptedEnvironmentVariable() 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 = new GoCipher().encrypt("overridden_value");
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", overriddenEncryptedValue));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(true));
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
    assertNotNull(buildCause);
    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(secureVariable.getValue(), is("overridden_value"));
    assertThat(secureVariable.isSecure(), is(true));
}
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) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) 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 14 with PipelineScheduleOptions

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

the class PipelineTriggerServiceIntegrationTest method shouldErrorOutIfSchedulingAPipelineWithBothValueAndEncryptedValueForAGiveVariable.

@Test
public void shouldErrorOutIfSchedulingAPipelineWithBothValueAndEncryptedValueForAGiveVariable() throws InvalidCipherTextException {
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    EnvironmentVariableConfig config = new EnvironmentVariableConfig(new GoCipher(), "SEC_VAR1", "PLAIN", true);
    config.deserialize("SEC_VAR1", "PLAIN", true, new GoCipher().encrypt("ENCRYPTED"));
    pipelineScheduleOptions.getAllEnvironmentVariables().add(config);
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, new Username("foo"), result);
    System.out.println(result.fullMessage());
    assertThat(result.isSuccess(), is(false));
    assertThat(result.httpCode(), is(422));
    assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline rejected { Variable 'SEC_VAR1' has not been configured for pipeline '%s' }", pipelineName)));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) GoCipher(com.thoughtworks.go.security.GoCipher) Username(com.thoughtworks.go.server.domain.Username) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) Test(org.junit.Test)

Example 15 with PipelineScheduleOptions

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

the class PipelineTriggerServiceIntegrationTest method shouldReturnErrorWhenSchedulingAPipelineWithUnconfiguredEnvironmentVariables.

@Test
public void shouldReturnErrorWhenSchedulingAPipelineWithUnconfiguredEnvironmentVariables() throws IOException {
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "value", false));
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "value", true));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(false));
    assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline rejected { Variable 'ENV_VAR1' has not been configured for pipeline '%s' }", pipelineName)));
    assertThat(result.httpCode(), is(422));
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) 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