Search in sources :

Example 6 with PackageMaterial

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

Example 7 with PackageMaterial

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));
}
Also used : PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 8 with PackageMaterial

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));
}
Also used : PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) Test(org.junit.Test)

Example 9 with PackageMaterial

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));
}
Also used : PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Test(org.junit.Test)

Example 10 with PackageMaterial

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));
}
Also used : PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageMaterialAgent(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialAgent) PluggableSCMMaterialAgent(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent) PackageMaterialAgent(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialAgent) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) File(java.io.File) Test(org.junit.Test)

Aggregations

PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)25 Test (org.junit.Test)18 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 File (java.io.File)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)4 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)4 Configuration (com.thoughtworks.go.domain.config.Configuration)4 Modification (com.thoughtworks.go.domain.materials.Modification)4 PackageRevision (com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision)4 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)3 Modifications (com.thoughtworks.go.domain.materials.Modifications)3 SCM (com.thoughtworks.go.domain.scm.SCM)3 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3 Materials (com.thoughtworks.go.config.materials.Materials)2 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)2