Search in sources :

Example 11 with SCMRevision

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

the class PluggableSCMMaterialPollerTest method shouldTalkToPlugInToGetLatestModifications.

@Test
public void shouldTalkToPlugInToGetLatestModifications() {
    Date timestamp = new Date();
    SCMRevision scmRevision = new SCMRevision("revision-123", timestamp, "user", "comment", null, null);
    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"));
    assertConfiguration(scmConfiguration.getValue(), "k1", "v1");
    assertConfiguration(scmConfiguration.getValue(), "k2", "v2");
    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) 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)

Example 12 with SCMRevision

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

the class JsonMessageHandler1_0 method toSCMRevisions.

List<SCMRevision> toSCMRevisions(Map map) {
    try {
        List<SCMRevision> scmRevisions = new ArrayList<>();
        if (map == null || map.get("revisions") == null) {
            return scmRevisions;
        }
        List revisionMaps = null;
        try {
            revisionMaps = (List) map.get("revisions");
        } catch (Exception e) {
            throw new RuntimeException("'revisions' should be of type list of map");
        }
        if (revisionMaps != null && !revisionMaps.isEmpty()) {
            for (Object revision : revisionMaps) {
                if (!(revision instanceof Map)) {
                    throw new RuntimeException("SCM revision should be of type map");
                }
            }
            for (Object revisionObj : revisionMaps) {
                Map revisionMap = (Map) revisionObj;
                SCMRevision scmRevision = getScmRevisionFromMap(revisionMap);
                scmRevisions.add(scmRevision);
            }
        }
        return scmRevisions;
    } catch (Exception e) {
        throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage()));
    }
}
Also used : SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)

Example 13 with SCMRevision

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

the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification.

@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification() throws Exception {
    final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    Map<String, String> data = new HashMap<>();
    data.put("k1", "v1");
    when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(new MaterialPollResult(data, new SCMRevision()));
    mockSCMExtensionInPoller();
    scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, materialService);
    pluggableSCMMaterialUpdater = new PluggableSCMMaterialUpdater(materialRepository, scmMaterialUpdater, transactionTemplate);
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications());
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getAdditionalDataMap(), is(data));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) TransactionStatus(org.springframework.transaction.TransactionStatus) Modifications(com.thoughtworks.go.domain.materials.Modifications) TransactionCallback(org.springframework.transaction.support.TransactionCallback) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 14 with SCMRevision

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

the class SCMRevisionTest method shouldThrowExceptionIfDataKeyContainsCharactersOtherThanAlphaNumericAndUnderScoreCharacters.

@Test
public void shouldThrowExceptionIfDataKeyContainsCharactersOtherThanAlphaNumericAndUnderScoreCharacters() throws Exception {
    SCMRevision scmRevision = new SCMRevision("rev123", new Date(), "loser", null, null, null);
    try {
        scmRevision.addData("HEL-LO-WORLD", "value");
        fail("should have thrown exception");
    } catch (InvalidSCMRevisionDataException e) {
        assertThat(e.getMessage(), is("Key 'HEL-LO-WORLD' is invalid. Key names should consists of only alphanumeric characters and/or underscores."));
    }
}
Also used : InvalidSCMRevisionDataException(com.thoughtworks.go.plugin.access.scm.exceptions.InvalidSCMRevisionDataException) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) Date(java.util.Date) Test(org.junit.Test)

Example 15 with SCMRevision

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

the class SCMExtensionTest method shouldTalkToPluginToCheckout.

@Test
public void shouldTalkToPluginToCheckout() throws Exception {
    String destination = "destination";
    SCMRevision revision = new SCMRevision();
    when(jsonMessageHandler.requestMessageForCheckout(scmPropertyConfiguration, destination, revision)).thenReturn(requestBody);
    Result deserializedResponse = new Result();
    when(jsonMessageHandler.responseMessageForCheckout(responseBody)).thenReturn(deserializedResponse);
    Result response = scmExtension.checkout(PLUGIN_ID, scmPropertyConfiguration, destination, revision);
    assertRequest(requestArgumentCaptor.getValue(), SCMExtension.EXTENSION_NAME, "1.0", SCMExtension.REQUEST_CHECKOUT, requestBody);
    verify(jsonMessageHandler).requestMessageForCheckout(scmPropertyConfiguration, destination, revision);
    verify(jsonMessageHandler).responseMessageForCheckout(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) Result(com.thoughtworks.go.plugin.api.response.Result) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) 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