Search in sources :

Example 66 with PackageRepository

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

the class GoConfigGraphWalkerTest method shouldNotWalkFieldsWhichAreTaggedWithIgnoreTraversal.

@Test
public void shouldNotWalkFieldsWhichAreTaggedWithIgnoreTraversal() {
    PackageRepository repository = mock(PackageRepository.class);
    PackageDefinition packageDefinition = new PackageDefinition();
    packageDefinition.setRepository(repository);
    new GoConfigGraphWalker(packageDefinition).walk(new GoConfigGraphWalker.Handler() {

        @Override
        public void handle(Validatable validatable, ValidationContext ctx) {
            validatable.validate(ctx);
        }
    });
    verify(repository, never()).validate(any(ValidationContext.class));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 67 with PackageRepository

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

the class MagicalGoConfigXmlLoaderTest method shouldResolvePackageRepoReferenceElementForAPackageInConfig.

@Test
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()).isEqualTo(packageRepository);
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 68 with PackageRepository

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

the class MagicalGoConfigXmlWriterTest method shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage.

@Test
public void shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage() throws Exception {
    String packageId = "does-not-exist";
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
    PackageRepository repository = com.thoughtworks.go.domain.packagerepository.PackageRepositoryMother.create("repo-id", "repo-name", "pluginid", "version", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k1", false, "v1")));
    packageMaterialConfig.setPackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinitionMother.create("does-not-exist", "package-name", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k2", false, "v2")), repository));
    JobConfig jobConfig = new JobConfig("ls");
    jobConfig.addTask(new AntTask());
    cruiseConfig.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(jobConfig)));
    try {
        xmlWriter.write(cruiseConfig, output, false);
        fail("should not allow this");
    } catch (XsdValidationException exception) {
        assertThat(exception.getMessage(), is("Key 'packageIdReferredByMaterial' with value 'does-not-exist' not found for identity constraint of element 'cruise'."));
    }
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) XsdValidationException(com.thoughtworks.go.util.XsdValidationException) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 69 with PackageRepository

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

the class MagicalGoConfigXmlWriterTest method shouldNotWriteToFileWithDefaultValueOfTrueForPackageDefinitionAutoUpdateWhenTrue.

@Test
public void shouldNotWriteToFileWithDefaultValueOfTrueForPackageDefinitionAutoUpdateWhenTrue() throws Exception {
    Configuration configuration = new Configuration(getConfigurationProperty("url", false, "http://go"));
    Packages packages = new Packages();
    PackageRepository repository = createPackageRepository("plugin-id", "version", "id", "name", configuration, packages);
    PackageDefinition aPackage = new PackageDefinition("package-id", "package-name", configuration);
    aPackage.setAutoUpdate(true);
    packages.add(aPackage);
    aPackage.setRepository(repository);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    xmlWriter.write(cruiseConfig, output, false);
    assertThat(output.toString().contains("autoUpdate=\"true\""), is(false));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 70 with PackageRepository

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

the class MagicalGoConfigXmlWriterTest method shouldWriteRepositoryConfigurationWithPackages.

@Test
public void shouldWriteRepositoryConfigurationWithPackages() throws Exception {
    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"), getConfigurationProperty("secure", true, "secure")));
    PackageDefinition packageDefinition = new PackageDefinition("id", "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
    packageDefinition.setRepository(packageRepository);
    packageRepository.getPackages().add(packageDefinition);
    cruiseConfig.getPackageRepositories().add(packageRepository);
    xmlWriter.write(cruiseConfig, output, false);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
    PackageRepositories packageRepositories = goConfigHolder.config.getPackageRepositories();
    assertThat(packageRepositories, is(cruiseConfig.getPackageRepositories()));
    assertThat(packageRepositories.get(0).getConfiguration().first().getConfigurationValue().getValue(), is("http://go"));
    assertThat(packageRepositories.get(0).getConfiguration().first().getEncryptedConfigurationValue(), is(nullValue()));
    assertThat(packageRepositories.get(0).getConfiguration().last().getEncryptedValue(), is(new GoCipher().encrypt("secure")));
    assertThat(packageRepositories.get(0).getConfiguration().last().getConfigurationValue(), is(nullValue()));
    assertThat(packageRepositories.get(0).getPackages().get(0), is(packageDefinition));
    assertThat(packageRepositories.get(0).getPackages().get(0).getConfiguration().first().getConfigurationValue().getValue(), is("go-agent"));
    assertThat(packageRepositories.get(0).getPackages().get(0).getConfiguration().first().getEncryptedConfigurationValue(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Aggregations

PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)89 Test (org.junit.jupiter.api.Test)46 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)40 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)39 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)23 Packages (com.thoughtworks.go.domain.packagerepository.Packages)13 Username (com.thoughtworks.go.server.domain.Username)13 Test (org.junit.Test)13 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)9 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)5 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)5 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)5 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)5 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4