Search in sources :

Example 1 with MaterialInstance

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

the class MaterialDatabaseGitUpdaterTest method shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist.

@Test
public void shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist() throws Exception {
    File flyweightDir = new File("pipelines", "flyweight");
    FileUtils.deleteQuietly(flyweightDir);
    material = new GitMaterial(testRepo.projectRepositoryUrl(), "bad-bad-branch");
    try {
        updater.updateMaterial(material);
        fail("material update should have failed as given branch does not exist in repository");
    } catch (Exception e) {
    //ignore
    }
    MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
    assertThat(materialInstance, is(nullValue()));
    //no flyweight dir left behind
    assertThat(FileUtil.listFiles(flyweightDir).length, is(0));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with MaterialInstance

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

the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenPluginIsUpgraded.

@Test
public void shouldUpdateMaterialInstanceWhenPluginIsUpgraded() throws Exception {
    final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    addMetadata(material, "fieldX", false);
    material.getScmConfig().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) {
            pluggableSCMMaterialUpdater.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) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Example 3 with MaterialInstance

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

the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince.

@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince() throws Exception {
    final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    Map<String, String> oldData = new HashMap<>();
    oldData.put("k1", "v1");
    materialInstance.setAdditionalData(new GsonBuilder().create().toJson(oldData));
    materialRepository.saveOrUpdate(materialInstance);
    Map<String, String> newData = new HashMap<>(oldData);
    newData.put("k2", "v2");
    when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(new MaterialPollResult(newData, 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(new Modification()));
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getAdditionalDataMap(), is(newData));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) 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 4 with MaterialInstance

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

the class DownstreamInstancePopulatorIntegrationTest method shouldPopulateInstancesBuiltFromCurrentMaterial.

@Test
public void shouldPopulateInstancesBuiltFromCurrentMaterial() {
    /*
			g1 -> P -> P2  -->  P4
			   |		\      /
			   |		 + P3 +
			   +-> Q
			   |
			   +-> R
		*/
    GitMaterial g1 = u.wf(new GitMaterial("g1"), "folder3");
    u.checkinInOrder(g1, "g_1", "g_2");
    ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("p", u.m(g1));
    ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(p));
    ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p2));
    ScheduleTestUtil.AddedPipeline p4 = u.saveConfigWith("p4", u.m(p2), u.m(p3));
    ScheduleTestUtil.AddedPipeline q = u.saveConfigWith("q", u.m(g1));
    ScheduleTestUtil.AddedPipeline r = u.saveConfigWith("r", u.m(g1));
    String p_1 = u.runAndPass(p, "g_1");
    String p2_1 = u.runAndPass(p2, p_1);
    String p3_1 = u.runAndPass(p3, p2_1);
    String p4_1 = u.runAndPass(p4, p2_1, p3_1);
    String q_1 = u.runAndPass(q, "g_1");
    String q_2 = u.runAndPass(q, "g_1");
    MaterialInstance g1Instance = materialRepository.findMaterialInstance(g1);
    Modification g1Modification = materialRepository.findModificationWithRevision(g1, "g_1");
    ValueStreamMap valueStreamMap = new ValueStreamMap(g1, g1Instance, g1Modification);
    Node gitNode = valueStreamMap.getCurrentMaterial();
    Node nodep1 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p", "p"), gitNode.getId());
    Node nodep2 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p2", "p2"), "p");
    Node nodep3 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p3", "p3"), "p2");
    Node nodep4 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p3");
    valueStreamMap.addDownstreamNode(new PipelineDependencyNode("p4", "p4"), "p2");
    Node nodep5 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("q", "q"), gitNode.getId());
    Node nodep6 = valueStreamMap.addDownstreamNode(new PipelineDependencyNode("r", "r"), gitNode.getId());
    downstreamInstancePopulator.apply(valueStreamMap);
    assertInstances(nodep1, "p", 1);
    assertInstances(nodep2, "p2", 1);
    assertInstances(nodep3, "p3", 1);
    assertInstances(nodep4, "p4", 1);
    assertInstances(nodep5, "q", 1, 2);
    assertThat(nodep6.revisions().size(), is(0));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ValueStreamMap(com.thoughtworks.go.domain.valuestreammap.ValueStreamMap) PipelineDependencyNode(com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) PipelineDependencyNode(com.thoughtworks.go.domain.valuestreammap.PipelineDependencyNode) SCMDependencyNode(com.thoughtworks.go.domain.valuestreammap.SCMDependencyNode) Node(com.thoughtworks.go.domain.valuestreammap.Node) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) Test(org.junit.Test)

Example 5 with MaterialInstance

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

the class TransactionCacheInterceptorTest method savedHg.

private MaterialInstance savedHg() {
    MaterialInstance materialInstance = hgInstance();
    hibernateDaoSupport.getHibernateTemplate().save(materialInstance);
    return materialInstance;
}
Also used : MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

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