Search in sources :

Example 1 with PackageMaterialInstance

use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance in project gocd by gocd.

the class MaterialRepositoryIntegrationTest method shouldSavePackageMaterialInstance.

@Test
public void shouldSavePackageMaterialInstance() {
    PackageMaterial material = new PackageMaterial();
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1")));
    material.setPackageDefinition(PackageDefinitionMother.create("p-id", "name", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2")), repository));
    PackageMaterialInstance savedMaterialInstance = (PackageMaterialInstance) repo.findOrCreateFrom(material);
    assertThat(savedMaterialInstance.getId() > 0, is(true));
    assertThat(savedMaterialInstance.getFingerprint(), is(material.getFingerprint()));
    assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PackageMaterial.class).getPackageDefinition().getConfiguration(), is(material.getPackageDefinition().getConfiguration()));
    assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PackageMaterial.class).getPackageDefinition().getRepository().getPluginConfiguration().getId(), is(material.getPackageDefinition().getRepository().getPluginConfiguration().getId()));
    assertThat(JsonHelper.fromJson(savedMaterialInstance.getConfiguration(), PackageMaterial.class).getPackageDefinition().getRepository().getConfiguration(), is(material.getPackageDefinition().getRepository().getConfiguration()));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) Test(org.junit.jupiter.api.Test)

Example 2 with PackageMaterialInstance

use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance in project gocd by gocd.

the class PackageMaterialTest method shouldCreatePackageMaterialInstance.

@Test
void shouldCreatePackageMaterialInstance() {
    PackageMaterial material = MaterialsMother.packageMaterial();
    PackageMaterialInstance materialInstance = (PackageMaterialInstance) material.createMaterialInstance();
    assertThat(materialInstance).isNotNull();
    assertThat(materialInstance.getFlyweightName()).isNotNull();
    assertThat(materialInstance.getConfiguration()).isEqualTo(JsonHelper.toJsonString(material));
}
Also used : PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) Test(org.junit.jupiter.api.Test)

Example 3 with PackageMaterialInstance

use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance in project gocd by gocd.

the class PackageMaterialUpdater method insertLatestOrNewModifications.

@Override
public void insertLatestOrNewModifications(final Material material, MaterialInstance materialInstance, File folder, Modifications list) {
    final PackageMaterialInstance packageMaterialInstance = (PackageMaterialInstance) materialInstance;
    if (packageMaterialInstance.shouldUpgradeTo((PackageMaterialInstance) material.createMaterialInstance())) {
        transactionTemplate.execute((TransactionCallback) transactionStatus -> {
            PackageMaterialInstance materialInstance1 = (PackageMaterialInstance) materialRepository.find(packageMaterialInstance.getId());
            materialInstance1.upgradeTo((PackageMaterialInstance) material.createMaterialInstance());
            materialRepository.saveOrUpdate(materialInstance1);
            return materialInstance1;
        });
    }
    scmMaterialUpdater.insertLatestOrNewModifications(material, packageMaterialInstance, 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) File(java.io.File) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance) PackageMaterialInstance(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance)

Aggregations

PackageMaterialInstance (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialInstance)3 Test (org.junit.jupiter.api.Test)2 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)1 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 Material (com.thoughtworks.go.domain.materials.Material)1 Modifications (com.thoughtworks.go.domain.materials.Modifications)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)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