Search in sources :

Example 61 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldAllowPackageTypeMaterialForPipeline.

@Test
public void shouldAllowPackageTypeMaterialForPipeline() throws Exception {
    CruiseConfig configToSave = new BasicCruiseConfig();
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setId("id");
    packageRepository.setName("name");
    packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "version"));
    packageRepository.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go")));
    String packageId = "id";
    PackageDefinition expectedPackageDefinition = new PackageDefinition(packageId, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
    expectedPackageDefinition.setRepository(packageRepository);
    packageRepository.getPackages().add(expectedPackageDefinition);
    configToSave.getPackageRepositories().add(packageRepository);
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
    packageMaterialConfig.setPackageDefinition(expectedPackageDefinition);
    configToSave.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(new JobConfig("ls"))));
    xmlWriter.write(configToSave, output, false);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("test"));
    assertThat(pipelineConfig.materialConfigs().get(0) instanceof PackageMaterialConfig, is(true));
    assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageId(), is(packageId));
    PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
    assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageDefinition(), is(packageDefinition));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 62 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldWriteRepositoryConfigurationWithPackagesWhenNoRepoAndPkgIdIsProvided.

@Test
public void shouldWriteRepositoryConfigurationWithPackagesWhenNoRepoAndPkgIdIsProvided() throws Exception {
    CruiseConfig configToSave = new BasicCruiseConfig();
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setName("name");
    packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "version"));
    packageRepository.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go"), getConfigurationProperty("secure", true, "secure")));
    PackageDefinition packageDefinition = new PackageDefinition(null, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
    packageDefinition.setRepository(packageRepository);
    packageRepository.getPackages().add(packageDefinition);
    configToSave.getPackageRepositories().add(packageRepository);
    xmlWriter.write(configToSave, output, false);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
    PackageRepositories packageRepositories = goConfigHolder.config.getPackageRepositories();
    assertThat(packageRepositories.size(), is(configToSave.getPackageRepositories().size()));
    assertThat(packageRepositories.get(0).getId(), is(notNullValue()));
    assertThat(packageRepositories.get(0).getPackages().size(), is(1));
    assertThat(packageRepositories.get(0).getPackages().get(0).getId(), is(notNullValue()));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 63 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPackages.

@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPackages() throws Exception {
    String encryptedValue = new GoCipher().encrypt("secure-two");
    String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + "    <repository id='repo-id' name='name'>\n" + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>plain</key>\n" + "          <value>value</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>secure-one</key>\n" + "          <value>secure-value</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>secure-two</key>\n" + "          <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id' name='name'>\n" + "          <configuration>\n" + "              <property>\n" + "                <key>plain</key>\n" + "                <value>value</value>\n" + "              </property>\n" + "              <property>\n" + "                <key>secure-one</key>\n" + "                <value>secure-value</value>\n" + "              </property>\n" + "              <property>\n" + "                <key>secure-two</key>\n" + "                <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + "              </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "  </repositories>" + "<pipelines group=\"group_name\">\n" + "  <pipeline name=\"new_name\">\n" + "    <materials>\n" + "      <package ref='package-id' />\n" + "    </materials>\n" + "    <stage name=\"stage_name\">\n" + "      <jobs>\n" + "        <job name=\"job_name\" />\n" + "      </jobs>\n" + "    </stage>\n" + "  </pipeline>\n" + "</pipelines></cruise>";
    // meta data of package
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("plain"));
    packageConfigurations.addConfiguration(new PackageConfiguration("secure-one").with(PackageConfiguration.SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("secure-two").with(PackageConfiguration.SECURE, true));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PackageMaterialConfig packageMaterialConfig = (PackageMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(packageMaterialConfig.getPackageDefinition(), is(packageDefinition));
    Configuration repoConfig = packageMaterialConfig.getPackageDefinition().getRepository().getConfiguration();
    assertThat(repoConfig.get(0).getConfigurationValue().getValue(), is("value"));
    assertThat(repoConfig.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
    assertThat(repoConfig.get(2).getEncryptedValue(), is(encryptedValue));
    Configuration packageConfig = packageMaterialConfig.getPackageDefinition().getConfiguration();
    assertThat(packageConfig.get(0).getConfigurationValue().getValue(), is("value"));
    assertThat(packageConfig.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
    assertThat(packageConfig.get(2).getEncryptedValue(), is(encryptedValue));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 64 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldResolvePackageRepoReferenceElementForAPackageInConfig.

@Test
public void shouldResolvePackageRepoReferenceElementForAPackageInConfig() throws Exception {
    String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + "    <repository id='repo-id' name='name'>\n" + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>url</key>\n" + "          <value>http://go</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id' name='name'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>name</key>\n" + "              <value>go-agent</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "  </repositories></cruise>";
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    PackageRepository packageRepository = goConfigHolder.config.getPackageRepositories().first();
    PackageDefinition packageDefinition = packageRepository.getPackages().first();
    assertThat(packageDefinition.getRepository(), is(packageRepository));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 65 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MaterialsMother method packageMaterial.

public static PackageMaterial packageMaterial(String repoId, String repoName, String pkgId, String pkgName, final String pluginid, final String version, List<ConfigurationProperty> repoProperties, List<ConfigurationProperty> packageProperties) {
    PackageRepository repository = PackageRepositoryMother.create(repoId, repoName, pluginid, version, new Configuration((ConfigurationProperty[]) repoProperties.toArray()));
    PackageDefinition packageDefinition = PackageDefinitionMother.create(pkgId, pkgName, new Configuration((ConfigurationProperty[]) packageProperties.toArray()), repository);
    repository.getPackages().add(packageDefinition);
    PackageMaterial material = new PackageMaterial(pkgId);
    material.setId(1);
    material.setPackageDefinition(packageDefinition);
    return material;
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Aggregations

PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)69 Test (org.junit.Test)47 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)41 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)28 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)12 Configuration (com.thoughtworks.go.domain.config.Configuration)12 Packages (com.thoughtworks.go.domain.packagerepository.Packages)12 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)9 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)7 Serializable (java.io.Serializable)7 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)6 Before (org.junit.Before)6 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)4 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)3 SCM (com.thoughtworks.go.domain.scm.SCM)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Username (com.thoughtworks.go.server.domain.Username)3 Timestamp (java.sql.Timestamp)3