Search in sources :

Example 1 with MaterialUpdateSuccessfulMessage

use of com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage in project gocd by gocd.

the class BuildCauseProducerServiceTest method manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials.

@Test
public void manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials() {
    HgMaterial material1 = new HgMaterial("url", null);
    HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
    HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
    pipelineConfig.addMaterialConfig(materialConfig1);
    pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig2, "plug"), "revision1"));
    when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
    buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
    MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
    statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
    verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
    verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
}
Also used : MaterialUpdateStatusListener(com.thoughtworks.go.server.materials.MaterialUpdateStatusListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HashMap(java.util.HashMap) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) Test(org.junit.Test)

Example 2 with MaterialUpdateSuccessfulMessage

use of com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage 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 3 with MaterialUpdateSuccessfulMessage

use of com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage 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 4 with MaterialUpdateSuccessfulMessage

use of com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage 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 5 with MaterialUpdateSuccessfulMessage

use of com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedMaterialRevisions.

@Test
public void shouldScheduleAPipelineWithTheProvidedMaterialRevisions() throws IOException {
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    String peggedRevision = "s2";
    MaterialForScheduling material = new MaterialForScheduling(pipelineConfig.materialConfigs().first().getFingerprint(), peggedRevision);
    pipelineScheduleOptions.getMaterials().add(material);
    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("s2"));
    assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
    assertTrue(buildCause.getVariables().isEmpty());
}
Also used : MaterialForScheduling(com.thoughtworks.go.server.domain.MaterialForScheduling) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Aggregations

MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)5 Test (org.junit.Test)5 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 EnvironmentVariable (com.thoughtworks.go.domain.EnvironmentVariable)2 GoCipher (com.thoughtworks.go.security.GoCipher)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Predicate (org.apache.commons.collections.Predicate)2 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 MaterialForScheduling (com.thoughtworks.go.server.domain.MaterialForScheduling)1 MaterialUpdateStatusListener (com.thoughtworks.go.server.materials.MaterialUpdateStatusListener)1 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)1 HashMap (java.util.HashMap)1