Search in sources :

Example 16 with Modifications

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"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) SCM(com.thoughtworks.go.domain.scm.SCM) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 17 with Modifications

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));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.dom4j.Element) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Modifications

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()));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) DefaultElement(org.dom4j.tree.DefaultElement) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Test(org.junit.Test)

Example 19 with Modifications

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"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.dom4j.Element) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Modifications

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);
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Aggregations

Modifications (com.thoughtworks.go.domain.materials.Modifications)35 Test (org.junit.Test)29 Modification (com.thoughtworks.go.domain.materials.Modification)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)15 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Date (java.util.Date)12 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)10 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)9 File (java.io.File)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5 SCM (com.thoughtworks.go.domain.scm.SCM)5 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4