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()));
}
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));
}
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);
}
Aggregations