use of com.thoughtworks.go.config.materials.PackageMaterial 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.config.materials.PackageMaterial in project gocd by gocd.
the class FaninDependencyResolutionTest method shouldResolveDiamondDependencyWithPackageMaterial.
@Test
public void shouldResolveDiamondDependencyWithPackageMaterial() {
/*
+---> P1 ---+
| v
pkg1 P3
| ^
+--> P2 ----+
*/
int i = 1;
PackageMaterial pkg1 = MaterialsMother.packageMaterial();
u.addPackageDefinition((PackageMaterialConfig) pkg1.config());
String[] pkg_revs = { "pkg1-1", "pkg1-2" };
u.checkinInOrder(pkg1, u.d(i++), pkg_revs);
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", u.m(pkg1));
ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(pkg1));
ScheduleTestUtil.AddedPipeline p3 = u.saveConfigWith("p3", u.m(p1), u.m(p2));
String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "pkg1-1");
String p2_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "pkg1-1");
String p2_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "pkg1-2");
MaterialRevisions given = u.mrs(u.mr(p1, true, p1_1), u.mr(p2, true, p2_2));
MaterialRevisions expected = u.mrs(u.mr(p1, true, p1_1), u.mr(p2, true, p2_1));
assertThat(getRevisionsBasedOnDependencies(p3, goConfigDao.load(), given), is(expected));
}
use of com.thoughtworks.go.config.materials.PackageMaterial in project gocd by gocd.
the class PackageMaterialInstanceTest method shouldCorrectlyCheckIfUpgradeIsNecessary.
@Test
public void shouldCorrectlyCheckIfUpgradeIsNecessary() {
PackageMaterial material = MaterialsMother.packageMaterial("repo-id", "repo-name", "pkg-id", "pkg-name", ConfigurationPropertyMother.create("key1", false, "value1"));
PackageMaterialInstance materialInstance = (PackageMaterialInstance) material.createMaterialInstance();
materialInstance.setId(10L);
PackageMaterialInstance materialInstanceCopy = (PackageMaterialInstance) material.createMaterialInstance();
material.getPackageDefinition().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2"));
PackageMaterialInstance newMaterialInstance = (PackageMaterialInstance) material.createMaterialInstance();
assertThat(materialInstance.shouldUpgradeTo(materialInstanceCopy), is(false));
assertThat(materialInstance.shouldUpgradeTo(newMaterialInstance), is(true));
}
use of com.thoughtworks.go.config.materials.PackageMaterial in project gocd by gocd.
the class PackageMaterialInstanceTest method shouldConvertMaterialInstanceToMaterial.
@Test
public void shouldConvertMaterialInstanceToMaterial() {
PackageMaterial material = MaterialsMother.packageMaterial();
PackageDefinition packageDefinition = material.getPackageDefinition();
PackageMaterialInstance materialInstance = new PackageMaterialInstance(JsonHelper.toJsonString(material), "flyweight");
materialInstance.setId(1L);
PackageMaterial constructedMaterial = (PackageMaterial) materialInstance.toOldMaterial(null, null, null);
assertThat(constructedMaterial.getPackageDefinition().getConfiguration(), Is.is(packageDefinition.getConfiguration()));
assertThat(constructedMaterial.getPackageDefinition().getRepository().getPluginConfiguration().getId(), Is.is(packageDefinition.getRepository().getPluginConfiguration().getId()));
assertThat(constructedMaterial.getPackageDefinition().getRepository().getConfiguration(), Is.is(packageDefinition.getRepository().getConfiguration()));
assertThat(constructedMaterial.getId(), Is.is(1L));
}
use of com.thoughtworks.go.config.materials.PackageMaterial in project gocd by gocd.
the class MaterialAgentFactoryTest method shouldGetPackageMaterialAgent.
@Test
public void shouldGetPackageMaterialAgent() {
File workingDirectory = new File("/tmp/workingDirectory");
MaterialRevision revision = new MaterialRevision(new PackageMaterial(), new Modifications());
MaterialAgentFactory factory = new MaterialAgentFactory(null, workingDirectory, null, packageRepositoryExtension, scmExtension);
MaterialAgent agent = factory.createAgent(revision);
assertThat(agent instanceof PackageMaterialAgent, is(true));
assertThat(ReflectionUtil.getField(agent, "packageRepositoryExtension"), is(packageRepositoryExtension));
assertThat(ReflectionUtil.getField(agent, "revision"), is(revision));
assertThat(ReflectionUtil.getField(agent, "workingDirectory"), is(workingDirectory));
}
Aggregations