use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.
the class PluggableSCMMaterialTest method shouldPopulateEnvironmentContext.
@Test
public void shouldPopulateEnvironmentContext() {
ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
ConfigurationProperty k2 = ConfigurationPropertyMother.create("scm-secure", true, "value");
SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1, k2));
PluggableSCMMaterial material = new PluggableSCMMaterial();
material.setSCMConfig(scmConfig);
material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
Modifications modifications = new Modifications(new Modification(null, null, null, new Date(), "revision-123"));
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_SCM_SECURE"), is("value"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_SCM_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
}
use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.
the class PackageXmlViewModelTest method shouldPopulateModificationDetailsForPackageMaterial.
@Test
public void shouldPopulateModificationDetailsForPackageMaterial() {
String userName = "user";
String comment = "comments";
Date checkinDate = new Date(System.currentTimeMillis());
String revision = "package-1.0.0.rpm";
Element modificationsTag = DocumentHelper.createDocument().addElement("modifications");
Modifications modifications = new Modifications(new Modification(userName, comment, null, checkinDate, revision));
XmlWriterContext writerContext = mock(XmlWriterContext.class);
when(writerContext.getBaseUrl()).thenReturn("http://someurl:8153/go");
new PipelineXmlViewModel.PackageXmlViewModel(MaterialsMother.packageMaterial()).populateXmlForModifications(modifications, writerContext, modificationsTag);
Element changeSet = modificationsTag.element("changeset");
assertThat(changeSet, is(not(IsNull.nullValue())));
assertThat(changeSet.attributeValue("changesetUri"), is("http://someurl:8153/go/api/materials/1/changeset/package-1.0.0.rpm.xml"));
assertThat(changeSet.element("user").getText(), is(userName));
assertThat(changeSet.element("revision").getText(), is(revision));
assertThat(changeSet.element("checkinTime").getText(), is(DateUtils.formatISO8601(checkinDate)));
assertThat(changeSet.element("message").getText(), is(comment));
}
use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.
the class PipelineXmlViewModelTest method shouldReturnProperXMLWhenTherAreNullAttributesOnAMaterial.
@Test
public void shouldReturnProperXMLWhenTherAreNullAttributesOnAMaterial() {
PipelineXmlViewModel.ScmXmlViewModel model = new PipelineXmlViewModel.ScmXmlViewModel(MaterialsMother.svnMaterial("url", "folder", null, null, false, null));
DefaultElement materials = new DefaultElement("materials");
model.populateXml(materials, new Modifications(), mock(XmlWriterContext.class));
assertThat(materials.selectSingleNode("./material/@username"), is(nullValue()));
}
use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.
the class SCMXmlViewModelTest method shouldPopulateModificationDetailsForPluggableSCMMaterial.
@Test
public void shouldPopulateModificationDetailsForPluggableSCMMaterial() {
String userName = "user";
String comment = "comment-1";
Date checkinDate = new Date(System.currentTimeMillis());
String revision = "revision-1";
Modification modification = new Modification(userName, comment, null, checkinDate, revision);
modification.setModifiedFiles(new ArrayList<>(asList(new ModifiedFile("f1", null, ModifiedAction.added), new ModifiedFile("f2", null, ModifiedAction.deleted))));
Modifications modifications = new Modifications(modification);
XmlWriterContext writerContext = mock(XmlWriterContext.class);
when(writerContext.getBaseUrl()).thenReturn("http://someurl:8153/go");
Element modificationsTag = DocumentHelper.createDocument().addElement("modifications");
new PipelineXmlViewModel.ScmXmlViewModel(MaterialsMother.pluggableSCMMaterial()).populateXmlForModifications(modifications, writerContext, modificationsTag);
Element changeSet = modificationsTag.element("changeset");
assertThat(changeSet, is(not(IsNull.nullValue())));
assertThat(changeSet.attributeValue("changesetUri"), is("http://someurl:8153/go/api/materials/1/changeset/revision-1.xml"));
assertThat(changeSet.element("user").getText(), is(userName));
assertThat(changeSet.element("revision").getText(), is(revision));
assertThat(changeSet.element("checkinTime").getText(), is(DateUtils.formatISO8601(checkinDate)));
assertThat(changeSet.element("message").getText(), is(comment));
Element file1 = (Element) changeSet.elements("file").get(0);
assertThat(file1.attributeValue("name"), is("f1"));
assertThat(file1.attributeValue("action"), is("added"));
Element file2 = (Element) changeSet.elements("file").get(1);
assertThat(file2.attributeValue("name"), is("f2"));
assertThat(file2.attributeValue("action"), is("deleted"));
}
use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.
the class PluggableSCMMaterialUpdaterTest method shouldUpdateToNewMaterialInstanceWhenConfigHas_Changed.
@Test
public void shouldUpdateToNewMaterialInstanceWhenConfigHas_Changed() throws Exception {
PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
MaterialInstance materialInstance = material.createMaterialInstance();
materialInstance.setId(1);
material.getScmConfig().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2"));
MaterialInstance newMaterialInstance = material.createMaterialInstance();
newMaterialInstance.setId(1);
File file = new File("random");
Modifications modifications = new Modifications();
when(materialRepository.find(anyLong())).thenReturn(materialInstance);
materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);
verify(materialRepository).saveOrUpdate(newMaterialInstance);
verify(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, file, modifications);
}
Aggregations