Search in sources :

Example 36 with MaterialInstance

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

the class TransactionCacheInterceptorTest method shouldOptOutOfCacheServing_forUpdate.

@Test
public void shouldOptOutOfCacheServing_forUpdate() {
    final MaterialInstance materialInstance = savedHg();
    ReflectionUtil.setField(materialInstance, "url", "loser-name");
    assertionUtil.assertCacheBehaviourInTxn(new TransactionCacheAssertionUtil.DoInTxn() {

        public void invoke() {
            hibernateDaoSupport.getHibernateTemplate().update(materialInstance);
            hibernateDaoSupport.getHibernateTemplate().flush();
        }
    });
    assertThat(ReflectionUtil.getField(hibernateDaoSupport.getHibernateTemplate().load(MaterialInstance.class, materialInstance.getId()), "url"), is("loser-name"));
}
Also used : MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Test(org.junit.Test)

Example 37 with MaterialInstance

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

the class MaterialServiceTest method shouldGetLatestModification_PluggableSCMMaterial.

@Test
public void shouldGetLatestModification_PluggableSCMMaterial() {
    PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = pluggableSCMMaterial.createMaterialInstance();
    when(materialRepository.findMaterialInstance(any(Material.class))).thenReturn(materialInstance);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, new SCMRevision("blah-123", new Date(), "user", "comment", null, null));
    when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(materialPollResult);
    List<Modification> modifications = materialService.latestModification(pluggableSCMMaterial, new File("/tmp/flyweight"), null);
    assertThat(modifications.get(0).getRevision(), is("blah-123"));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) 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) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Map(java.util.Map) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 38 with MaterialInstance

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

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

the class PluggableSCMMaterialPollerTest method setup.

@Before
public void setup() {
    initMocks(this);
    ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
    ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", true, "v2");
    SCM scmConfig = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(k1, k2));
    material = new PluggableSCMMaterial();
    material.setSCMConfig(scmConfig);
    MaterialInstance materialInstance = material.createMaterialInstance();
    Map<String, String> data = new HashMap<>();
    data.put("mk-1", "mv-1");
    materialInstance.setAdditionalData(JsonHelper.toJsonString(data));
    when(materialRepository.findMaterialInstance(material)).thenReturn(materialInstance);
    poller = new PluggableSCMMaterialPoller(materialRepository, scmExtension, transactionTemplate);
    scmConfiguration = ArgumentCaptor.forClass(SCMPropertyConfiguration.class);
    materialData = ArgumentCaptor.forClass(Map.class);
    flyweightFolderPath = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCM(com.thoughtworks.go.domain.scm.SCM) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Before(org.junit.Before)

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