Search in sources :

Example 1 with PluggableSCMMaterialInstance

use of com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method shouldSavePluggableSCMMaterialInstance.

@Test
public void shouldSavePluggableSCMMaterialInstance() {
    PluggableSCMMaterial material = new PluggableSCMMaterial();
    ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
    ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", true, "v2");
    material.setSCMConfig(SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(k1, k2)));
    PluggableSCMMaterialInstance savedMaterialInstance = (PluggableSCMMaterialInstance) repo.findOrCreateFrom(material);
    assertThat(savedMaterialInstance.getId() > 0, is(true));
    assertThat(savedMaterialInstance.getFingerprint(), is(material.getFingerprint()));
    assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PluggableSCMMaterial.class).getScmConfig().getConfiguration(), is(material.getScmConfig().getConfiguration()));
    assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PluggableSCMMaterial.class).getScmConfig().getPluginConfiguration().getId(), is(material.getScmConfig().getPluginConfiguration().getId()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) Configuration(com.thoughtworks.go.domain.config.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) Test(org.junit.jupiter.api.Test)

Example 2 with PluggableSCMMaterialInstance

use of com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance in project gocd by gocd.

the class PluggableSCMMaterialUpdater method insertLatestOrNewModifications.

@Override
public void insertLatestOrNewModifications(final Material material, MaterialInstance materialInstance, File folder, Modifications list) {
    final PluggableSCMMaterialInstance currentMaterialInstance = (PluggableSCMMaterialInstance) materialInstance;
    final PluggableSCMMaterialInstance latestMaterialInstance = (PluggableSCMMaterialInstance) material.createMaterialInstance();
    if (currentMaterialInstance.shouldUpgradeTo(latestMaterialInstance)) {
        transactionTemplate.execute((TransactionCallback) transactionStatus -> {
            PluggableSCMMaterialInstance materialInstance1 = (PluggableSCMMaterialInstance) materialRepository.find(currentMaterialInstance.getId());
            materialInstance1.upgradeTo(latestMaterialInstance);
            materialRepository.saveOrUpdate(materialInstance1);
            return materialInstance1;
        });
    }
    scmMaterialUpdater.insertLatestOrNewModifications(material, currentMaterialInstance, folder, list);
}
Also used : MaterialRepository(com.thoughtworks.go.server.persistence.MaterialRepository) Component(org.springframework.stereotype.Component) Material(com.thoughtworks.go.domain.materials.Material) Autowired(org.springframework.beans.factory.annotation.Autowired) TransactionCallback(org.springframework.transaction.support.TransactionCallback) TransactionTemplate(com.thoughtworks.go.server.transaction.TransactionTemplate) Modifications(com.thoughtworks.go.domain.materials.Modifications) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) File(java.io.File) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance)

Example 3 with PluggableSCMMaterialInstance

use of com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance in project gocd by gocd.

the class PluggableSCMMaterialTest method shouldCreatePluggableSCMMaterialInstance.

@Test
void shouldCreatePluggableSCMMaterialInstance() {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    PluggableSCMMaterialInstance materialInstance = (PluggableSCMMaterialInstance) material.createMaterialInstance();
    assertThat(materialInstance).isNotNull();
    assertThat(materialInstance.getFlyweightName()).isNotNull();
    assertThat(materialInstance.getConfiguration()).isEqualTo(JsonHelper.toJsonString(material));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) PluggableSCMMaterialInstance(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance) Test(org.junit.jupiter.api.Test)

Aggregations

PluggableSCMMaterialInstance (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialInstance)3 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)2 Test (org.junit.jupiter.api.Test)2 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1 Material (com.thoughtworks.go.domain.materials.Material)1 Modifications (com.thoughtworks.go.domain.materials.Modifications)1 MaterialRepository (com.thoughtworks.go.server.persistence.MaterialRepository)1 TransactionTemplate (com.thoughtworks.go.server.transaction.TransactionTemplate)1 File (java.io.File)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1 ContextConfiguration (org.springframework.test.context.ContextConfiguration)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1