Search in sources :

Example 21 with SCMRevision

use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.

the class MaterialServiceTest method shouldGetModificationSince_PluggableSCMMaterial.

@Test
public void shouldGetModificationSince_PluggableSCMMaterial() {
    PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = pluggableSCMMaterial.createMaterialInstance();
    when(materialRepository.findMaterialInstance(any(Material.class))).thenReturn(materialInstance);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, asList(new SCMRevision("new-revision-456", new Date(), "user", "comment", null, null)));
    when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(materialPollResult);
    PluggableSCMMaterialRevision previouslyKnownRevision = new PluggableSCMMaterialRevision("revision-124", new Date());
    List<Modification> modifications = materialService.modificationsSince(pluggableSCMMaterial, new File("/tmp/flyweight"), previouslyKnownRevision, null);
    assertThat(modifications.get(0).getRevision(), is("new-revision-456"));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) Date(java.util.Date) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 22 with SCMRevision

use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.

the class PluggableSCMMaterialPollerTest method shouldGetLatestModificationAlongWithAdditionalDataFromTheSCMRevision.

@Test
public void shouldGetLatestModificationAlongWithAdditionalDataFromTheSCMRevision() {
    Date timestamp = new Date();
    Map<String, String> data = new HashMap<>();
    String dataKey = "revision_data";
    String dataValue = "revision_value";
    data.put(dataKey, dataValue);
    List<ModifiedFile> modifiedFiles = new ArrayList<>(asList(new ModifiedFile("f1", ModifiedAction.added), new ModifiedFile("f2", ModifiedAction.modified), new ModifiedFile("f3", ModifiedAction.deleted)));
    SCMRevision scmRevision = new SCMRevision("revision-123", timestamp, "user", "comment", data, modifiedFiles);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, scmRevision);
    when(scmExtension.getLatestRevision(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath))).thenReturn(materialPollResult);
    List<Modification> modifications = poller.latestModification(material, new File(flyweightFolderPath), null);
    assertThat(modifications.get(0).getRevision(), is("revision-123"));
    assertThat(modifications.get(0).getModifiedTime(), is(timestamp));
    assertThat(modifications.get(0).getUserName(), is("user"));
    assertThat(modifications.get(0).getComment(), is("comment"));
    assertThat(modifications.get(0).getAdditionalData(), is(JsonHelper.toJsonString(data)));
    assertThat(modifications.get(0).getModifiedFiles().size(), is(3));
    com.thoughtworks.go.domain.materials.ModifiedFile f1 = new com.thoughtworks.go.domain.materials.ModifiedFile("f1", null, com.thoughtworks.go.domain.materials.ModifiedAction.added);
    com.thoughtworks.go.domain.materials.ModifiedFile f2 = new com.thoughtworks.go.domain.materials.ModifiedFile("f2", null, com.thoughtworks.go.domain.materials.ModifiedAction.modified);
    com.thoughtworks.go.domain.materials.ModifiedFile f3 = new com.thoughtworks.go.domain.materials.ModifiedFile("f3", null, com.thoughtworks.go.domain.materials.ModifiedAction.deleted);
    assertThat(new HashSet(modifications.get(0).getModifiedFiles()), is(new HashSet(asList(f1, f2, f3))));
    assertConfiguration(scmConfiguration.getValue(), material.getScmConfig().getConfiguration());
    assertThat(materialData.getValue().size(), is(1));
    assertThat(materialData.getValue().get("mk-1"), is("mv-1"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Aggregations

SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)22 Test (org.junit.Test)16 MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)15 File (java.io.File)10 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 ModifiedFile (com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile)7 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)6 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)5 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)5 Date (java.util.Date)4 Map (java.util.Map)4 Modifications (com.thoughtworks.go.domain.materials.Modifications)3 Result (com.thoughtworks.go.plugin.api.response.Result)3 SimpleDateFormat (java.text.SimpleDateFormat)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)2 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)2 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)2