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."));
}
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));
}
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"));
}
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));
}
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."));
}
Aggregations