Search in sources :

Example 31 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class PackageMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenPluginIsUpgraded.

@Test
public void shouldUpdateMaterialInstanceWhenPluginIsUpgraded() throws Exception {
    final PackageMaterial material = MaterialsMother.packageMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    addMetadata(material, "fieldX", false);
    material.getPackageDefinition().getConfiguration().addNewConfiguration("fieldX", true);
    final List<Modification> modifications = ModificationsMother.multipleModificationList();
    doNothing().when(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            packageMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getConfiguration(), is(material.createMaterialInstance().getConfiguration()));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) TransactionCallback(org.springframework.transaction.support.TransactionCallback) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Example 32 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance 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 33 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class TestFailureSetup method setupPipelineInstnace.

private SavedStage setupPipelineInstnace(final boolean failStage, final String overriddenLabel, final List<Modification> modifications, final TestResultsStubbing test, final Date latestTransitionDate) {
    return (SavedStage) transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            MaterialInstance materialInstance = materialRepository.findOrCreateFrom(hgMaterial);
            for (Modification mod : modifications) {
                mod.setMaterialInstance(materialInstance);
            }
            MaterialRevision rev = new MaterialRevision(hgMaterial, modifications);
            materialRepository.saveMaterialRevision(rev);
            Pipeline pipeline = PipelineMother.schedule(pipelineConfig, BuildCause.createManualForced(new MaterialRevisions(rev), new Username(new CaseInsensitiveString("loser"))));
            if (overriddenLabel != null) {
                pipeline.setLabel(overriddenLabel);
            }
            for (JobInstance instance : pipeline.getStages().get(0).getJobInstances()) {
                for (JobStateTransition jobStateTransition : instance.getTransitions()) {
                    jobStateTransition.setStateChangeTime(latestTransitionDate);
                }
            }
            dbHelper.save(pipeline);
            Stage barStage = pipeline.getFirstStage();
            if (failStage) {
                dbHelper.failStage(barStage, latestTransitionDate);
            }
            test.stub(barStage);
            pipelineTimeline.update();
            return new SavedStage(pipeline);
        }
    });
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) JobInstance(com.thoughtworks.go.domain.JobInstance) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) TransactionStatus(org.springframework.transaction.TransactionStatus) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) JobStateTransition(com.thoughtworks.go.domain.JobStateTransition) TransactionCallback(org.springframework.transaction.support.TransactionCallback) Username(com.thoughtworks.go.server.domain.Username) Stage(com.thoughtworks.go.domain.Stage) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision)

Example 34 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class ModificationIntegrationTest method shouldPersistAdditionalDataIntoModificationsTable.

@Test
public void shouldPersistAdditionalDataIntoModificationsTable() throws Exception {
    String revision = "revision";
    HashMap<String, String> additionalDataMap = new HashMap<>();
    additionalDataMap.put("key", "value");
    String additionalData = JsonHelper.toJsonString(additionalDataMap);
    final Modification modification = new Modification("user", "comment", "foo@bar.fooadsf", new Date(), revision, additionalData);
    final GitMaterial git = new GitMaterial("url", "branch");
    transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus status) throws Exception {
            MaterialInstance gitInstance = materialRepository.findOrCreateFrom(git);
            materialRepository.saveModification(gitInstance, modification);
            return null;
        }
    });
    Modification actual = materialRepository.findModificationWithRevision(git, revision);
    /*
            Checking if time are the same, because actual has SQLTime whereas we send in java.util.Date. No idea how we were testing this ever
            because Modification#equals fails instance check (ShilpaG & Sachin)
         */
    assertThat(actual.getModifiedTime().getTime(), is(modification.getModifiedTime().getTime()));
    assertThat(actual.getAdditionalData(), is(additionalData));
    assertThat(actual.getAdditionalDataMap(), is(additionalDataMap));
}
Also used : TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Date(java.util.Date) Test(org.junit.Test)

Example 35 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class TfsMaterialPersistenceTest method shouldBeAbleToConvertAMaterialInstanceObjectToTfsMaterialObject.

@Test
public void shouldBeAbleToConvertAMaterialInstanceObjectToTfsMaterialObject() {
    TfsMaterial tfsCfg = new TfsMaterial(new GoCipher(), new UrlArgument("url"), "loser", "CORPORATE", "password", "/dev/null");
    tfsCfg.setFolder("folder");
    tfsCfg.setName(new CaseInsensitiveString("materialName"));
    MaterialInstance tfsInstance = materialRepository.findOrCreateFrom(tfsCfg);
    Material material = tfsInstance.toOldMaterial("materialName", "folder", "password");
    assertThat(material, is(tfsCfg));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) GoCipher(com.thoughtworks.go.security.GoCipher) Material(com.thoughtworks.go.domain.materials.Material) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)39 Test (org.junit.Test)28 File (java.io.File)13 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 Modification (com.thoughtworks.go.domain.materials.Modification)9 Modifications (com.thoughtworks.go.domain.materials.Modifications)9 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)7 MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)7 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)6 Date (java.util.Date)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)5 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 TfsMaterial (com.thoughtworks.go.config.materials.tfs.TfsMaterial)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)4 Material (com.thoughtworks.go.domain.materials.Material)4 HashMap (java.util.HashMap)4