use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.
the class PluggableSCMMaterialAgent method prepare.
@Override
public void prepare() {
PluggableSCMMaterial material = (PluggableSCMMaterial) revision.getMaterial();
Modification latestModification = revision.getLatestModification();
SCMRevision scmRevision = new SCMRevision(latestModification.getRevision(), latestModification.getModifiedTime(), null, null, latestModification.getAdditionalDataMap(), null);
File destinationFolder = material.workingDirectory(workingDirectory);
Result result = scmExtension.checkout(material.getScmConfig().getPluginConfiguration().getId(), buildSCMPropertyConfigurations(material.getScmConfig()), destinationFolder.getAbsolutePath(), scmRevision);
if (!result.isSuccessful()) {
// handle
}
// handle messages
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.
the class PluggableSCMMaterialAgentTest method shouldTalkToPluginCheckoutForPrepare.
@Test
public void shouldTalkToPluginCheckoutForPrepare() {
PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
pluggableSCMMaterial.setFolder("destination-folder");
Modification modification = ModificationsMother.oneModifiedFile("r1");
Map<String, String> additionalData = new HashMap<>();
additionalData.put("a1", "v1");
additionalData.put("a2", "v2");
modification.setAdditionalData(new Gson().toJson(additionalData));
MaterialRevision revision = new MaterialRevision(pluggableSCMMaterial, modification);
String pipelineFolder = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
String destinationFolder = new File(pipelineFolder, "destination-folder").getAbsolutePath();
PluggableSCMMaterialAgent pluggableSCMMaterialAgent = new PluggableSCMMaterialAgent(scmExtension, revision, new File(pipelineFolder));
when(scmExtension.checkout(eq("pluginid"), scmConfiguration.capture(), eq(destinationFolder), scmRevision.capture())).thenReturn(new Result());
pluggableSCMMaterialAgent.prepare();
verify(scmExtension).checkout(any(String.class), any(SCMPropertyConfiguration.class), any(String.class), any(SCMRevision.class));
assertThat(scmConfiguration.getValue().size(), is(2));
assertThat(scmConfiguration.getValue().get("k1").getValue(), is("v1"));
assertThat(scmConfiguration.getValue().get("k2").getValue(), is("v2"));
assertThat(scmRevision.getValue().getRevision(), is("r1"));
assertThat(scmRevision.getValue().getTimestamp(), is(modification.getModifiedTime()));
assertThat(scmRevision.getValue().getData().size(), is(2));
assertThat(scmRevision.getValue().getDataFor("a1"), is("v1"));
assertThat(scmRevision.getValue().getDataFor("a2"), is("v2"));
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.
the class PluggableSCMMaterialInstanceTest method shouldCorrectlyCopyConfigurationValue.
@Test
public void shouldCorrectlyCopyConfigurationValue() {
PluggableSCMMaterialInstance materialInstance = (PluggableSCMMaterialInstance) MaterialsMother.pluggableSCMMaterial().createMaterialInstance();
materialInstance.setId(10L);
PluggableSCMMaterial latestMaterial = MaterialsMother.pluggableSCMMaterial("scm-id", "scm-name", ConfigurationPropertyMother.create("key1", false, "value1"));
PluggableSCMMaterialInstance newPluggableSCMMaterialInstance = (PluggableSCMMaterialInstance) latestMaterial.createMaterialInstance();
materialInstance.upgradeTo(newPluggableSCMMaterialInstance);
assertThat(materialInstance.getId(), is(10L));
assertThat(materialInstance.getConfiguration(), is(newPluggableSCMMaterialInstance.getConfiguration()));
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.
the class PluggableSCMMaterialInstanceTest method shouldConvertMaterialInstanceToMaterial.
@Test
public void shouldConvertMaterialInstanceToMaterial() {
PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
SCM scmConfig = material.getScmConfig();
PluggableSCMMaterialInstance materialInstance = new PluggableSCMMaterialInstance(JsonHelper.toJsonString(material), "flyweight");
materialInstance.setId(1L);
PluggableSCMMaterial constructedMaterial = (PluggableSCMMaterial) materialInstance.toOldMaterial(null, null, null);
assertThat(constructedMaterial.getId(), is(1L));
assertThat(constructedMaterial.getScmConfig().getPluginConfiguration().getId(), is(scmConfig.getPluginConfiguration().getId()));
assertThat(constructedMaterial.getScmConfig().getConfiguration(), is(scmConfig.getConfiguration()));
}
use of com.thoughtworks.go.config.materials.PluggableSCMMaterial in project gocd by gocd.
the class PluggableSCMMaterialInstanceTest method shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial.
@Test
public void shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial() {
String fingerprint = "fingerprint";
PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
PluggableSCMMaterialInstance materialInstance = new PluggableSCMMaterialInstance(JsonHelper.toJsonString(material), "flyweight");
ReflectionUtil.setField(materialInstance, "fingerprint", fingerprint);
materialInstance.setId(1L);
PluggableSCMMaterial constructedMaterial = (PluggableSCMMaterial) materialInstance.toOldMaterial(null, null, null);
assertThat(constructedMaterial.getFingerprint(), is(fingerprint));
}
Aggregations