Search in sources :

Example 26 with P4MaterialConfig

use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.

the class PipelineConfigValidationTest method shouldNotAllowAnEmptyView.

@Test
public void shouldNotAllowAnEmptyView() throws Exception {
    CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
    P4MaterialConfig materialConfig = new P4MaterialConfig("localhost:1666", "");
    PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
    pipelineConfig.addMaterialConfig(materialConfig);
    materialConfig.validate(validationContext);
    assertThat(materialConfig.errors().on("view"), is("P4 view cannot be empty."));
}
Also used : P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) Test(org.junit.Test)

Example 27 with P4MaterialConfig

use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.

the class GoConfigMaterialsTest method pipelineWithManyMaterials.

private PipelineConfig pipelineWithManyMaterials(boolean autoUpdate) {
    SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig();
    svnMaterialConfig.setAutoUpdate(autoUpdate);
    MaterialConfig gitMaterialConfig = MaterialConfigsMother.gitMaterialConfig("/foo/bar.git");
    HgMaterialConfig hgMaterialConfig = MaterialConfigsMother.hgMaterialConfig();
    P4MaterialConfig p4MaterialConfig = MaterialConfigsMother.p4MaterialConfig();
    return new PipelineConfig(new CaseInsensitiveString("pipeline1"), new MaterialConfigs(svnMaterialConfig, hgMaterialConfig, gitMaterialConfig, p4MaterialConfig));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)

Example 28 with P4MaterialConfig

use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldMigrateEncryptedMaterialPasswordWithNewlineAndSpaces_XslMigrationFrom88To90.

@Test
public void shouldMigrateEncryptedMaterialPasswordWithNewlineAndSpaces_XslMigrationFrom88To90() throws Exception {
    String plainText = "something";
    String encryptedValue = new GoCipher().encrypt(plainText);
    String encryptedValueWithWhitespaceAndNewline = new StringBuilder(encryptedValue).insert(2, "\r\n" + "                        ").toString();
    String content = configWithPipeline("<pipeline name='some_pipeline'>" + "    <materials>" + "      <svn url='asdsa' username='user' encryptedPassword='" + encryptedValueWithWhitespaceAndNewline + "' dest='svn'>" + "<filter>\n" + "            <ignore pattern='**/*' />\n" + "          </filter>" + "</svn>" + "<tfs url='tfsurl' username='user' domain='domain' encryptedPassword='" + encryptedValueWithWhitespaceAndNewline + "' projectPath='path' dest='tfs' />" + "<p4 port='host:9999' username='user' encryptedPassword='" + encryptedValueWithWhitespaceAndNewline + "' dest='perforce'>\n" + "          <view><![CDATA[view]]></view>\n" + "        </p4>" + "    </materials>" + "  <stage name='some_stage'>" + "    <jobs>" + "      <job name='some_job'>" + "      </job>" + "    </jobs>" + "  </stage>" + "</pipeline>", 88);
    CruiseConfig config = ConfigMigrator.loadWithMigration(content).config;
    MaterialConfigs materialConfigs = config.allPipelines().get(0).materialConfigs();
    SvnMaterialConfig svnMaterialConfig = (SvnMaterialConfig) materialConfigs.get(0);
    assertThat(svnMaterialConfig.getPassword(), is(plainText));
    assertThat(svnMaterialConfig.getEncryptedPassword(), is(encryptedValue));
    assertThat(svnMaterialConfig.getFilterAsString(), is("**/*"));
    TfsMaterialConfig tfs = (TfsMaterialConfig) materialConfigs.get(1);
    assertThat(tfs.getPassword(), is(plainText));
    assertThat(tfs.getEncryptedPassword(), is(encryptedValue));
    assertThat(tfs.getUrl(), is("tfsurl"));
    P4MaterialConfig p4 = (P4MaterialConfig) materialConfigs.get(2);
    assertThat(p4.getPassword(), is(plainText));
    assertThat(p4.getEncryptedPassword(), is(encryptedValue));
    assertThat(p4.getServerAndPort(), is("host:9999"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Example 29 with P4MaterialConfig

use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldLoadPipelineWithP4MaterialFromXmlPartial.

@Test
public void shouldLoadPipelineWithP4MaterialFromXmlPartial() throws Exception {
    String pipelineWithP4MaterialXmlPartial = "<pipeline name=\"pipeline\">\n" + "  <materials>\n" + "    <p4 port=\"10.18.3.241:9999\" username=\"cruise\" password=\"password\" " + "        useTickets=\"true\">\n" + "          <view><![CDATA[//depot/dev/... //lumberjack/...]]></view>\n" + "    </p4>" + "  </materials>\n" + "  <stage name=\"mingle\">\n" + "    <jobs>\n" + "      <job name=\"functional\">\n" + "        <artifacts>\n" + "          <log src=\"artifact1.xml\" dest=\"cruise-output\" />\n" + "        </artifacts>\n" + "      </job>\n" + "    </jobs>\n" + "  </stage>\n" + "</pipeline>\n";
    PipelineConfig pipeline = xmlLoader.fromXmlPartial(toInputStream(pipelineWithP4MaterialXmlPartial), PipelineConfig.class);
    assertThat(pipeline.name(), is(new CaseInsensitiveString("pipeline")));
    MaterialConfig material = pipeline.materialConfigs().first();
    assertThat(material, is(instanceOf(P4MaterialConfig.class)));
    assertThat(((P4MaterialConfig) material).getUseTickets(), is(true));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) Test(org.junit.Test)

Example 30 with P4MaterialConfig

use of com.thoughtworks.go.config.materials.perforce.P4MaterialConfig in project gocd by gocd.

the class ScheduledPipelineLoaderIntegrationTest method shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound.

@Test
public void shouldSetAServerHealthMessageWhenMaterialForPipelineWithBuildCauseIsNotFound() throws IllegalArtifactLocationException, IOException {
    PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("last", new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    pipelineConfig.materialConfigs().clear();
    SvnMaterialConfig onDirOne = MaterialConfigsMother.svnMaterialConfig("google.com", "dirOne", "loser", "boozer", false, "**/*.html");
    final P4MaterialConfig onDirTwo = MaterialConfigsMother.p4MaterialConfig("host:987654321", "zoozer", "secret", "through-the-window", true);
    onDirTwo.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "dirTwo"));
    pipelineConfig.addMaterialConfig(onDirOne);
    pipelineConfig.addMaterialConfig(onDirTwo);
    configHelper.addPipeline(pipelineConfig);
    Pipeline building = PipelineMother.building(pipelineConfig);
    final Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);
    CruiseConfig cruiseConfig = configHelper.currentConfig();
    PipelineConfig cfg = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("last"));
    cfg.removeMaterialConfig(cfg.materialConfigs().get(1));
    configHelper.writeConfigFile(cruiseConfig);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPipeline("last")).size(), is(0));
    final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();
    Date currentTime = new Date(System.currentTimeMillis() - 1);
    Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            Pipeline loadedPipeline = null;
            try {
                loadedPipeline = loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
                fail("should not have loaded pipeline with build-cause as one of the necessary materials was not found");
            } catch (Exception e) {
                assertThat(e, is(instanceOf(StaleMaterialsOnBuildCause.class)));
                assertThat(e.getMessage(), is("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config."));
            }
            return loadedPipeline;
        }
    });
    assertThat(loadedPipeline, is(nullValue()));
    JobInstance reloadedJobInstance = jobInstanceService.buildById(jobId);
    assertThat(reloadedJobInstance.getState(), is(JobState.Completed));
    assertThat(reloadedJobInstance.getResult(), is(JobResult.Failed));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forJob("last", "stage", "job-one")).size(), is(1));
    ServerHealthState error = serverHealthService.filterByScope(HealthStateScope.forJob("last", "stage", "job-one")).get(0);
    assertThat(error, is(ServerHealthState.error("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config.", "Job for pipeline 'last/" + pipeline.getCounter() + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed.", HealthStateType.general(HealthStateScope.forJob("last", "stage", "job-one")))));
    DateTime expiryTime = (DateTime) ReflectionUtil.getField(error, "expiryTime");
    assertThat(expiryTime.toDate().after(currentTime), is(true));
    assertThat(expiryTime.toDate().before(new Date(System.currentTimeMillis() + 5 * 60 * 1000 + 1)), is(true));
    String logText = FileUtils.readFileToString(consoleService.consoleLogArtifact(reloadedJobInstance.getIdentifier()), UTF_8);
    assertThat(logText, containsString("Cannot load job 'last/" + pipeline.getCounter() + "/stage/1/job-one' because material " + onDirTwo + " was not found in config."));
    assertThat(logText, containsString("Job for pipeline 'last/" + pipeline.getCounter() + "/stage/1/job-one' has been failed as one or more material configurations were either changed or removed."));
}
Also used : StaleMaterialsOnBuildCause(com.thoughtworks.go.server.materials.StaleMaterialsOnBuildCause) TransactionStatus(org.springframework.transaction.TransactionStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) Date(java.util.Date) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) TransactionCallback(org.springframework.transaction.support.TransactionCallback) P4MaterialConfig(com.thoughtworks.go.config.materials.perforce.P4MaterialConfig) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Aggregations

P4MaterialConfig (com.thoughtworks.go.config.materials.perforce.P4MaterialConfig)30 Test (org.junit.Test)22 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)13 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)8 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)8 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)7 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)4 GoCipher (com.thoughtworks.go.security.GoCipher)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)3 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)2 MaterialConfigsMother.filteredHgMaterialConfig (com.thoughtworks.go.helper.MaterialConfigsMother.filteredHgMaterialConfig)2 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)2 Date (java.util.Date)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Filter (com.thoughtworks.go.config.materials.Filter)1