Search in sources :

Example 1 with PackageRepositories

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

the class UpdatePackageConfigCommandTest method shouldValidateDuplicateIdentity.

@Test
public void shouldValidateDuplicateIdentity() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
    PackageDefinition pkg = new PackageDefinition("Id", "name", configuration);
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, newPackageDefinition, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(newPackageDefinition.errors().size(), is(1));
    assertThat(newPackageDefinition.errors().firstError(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'repoName', Package Name: 'name'], [Repo Name: 'repoName', Package Name: 'prettyjson']"));
}
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 2 with PackageRepositories

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

the class PackageMaterialAddWithNewPackageDefinitionCommandTest method shouldPerformValidationsBeforeDeleteEmptyConfigurationsHappensDuringAddingPackageIntoConfig.

@Test
public void shouldPerformValidationsBeforeDeleteEmptyConfigurationsHappensDuringAddingPackageIntoConfig() throws Exception {
    String repoId = "repoId";
    HashMap repositoryIdMap = new HashMap();
    repositoryIdMap.put("repositoryId", repoId);
    Map params = new HashMap();
    params.put("package_definition", repositoryIdMap);
    CruiseConfig config = mock(BasicCruiseConfig.class);
    PackageRepositories packageRepositories = mock(PackageRepositories.class);
    when(packageRepositories.find(repoId)).thenReturn(mock(PackageRepository.class));
    when(config.getPackageRepositories()).thenReturn(packageRepositories);
    PackageMaterialAddWithNewPackageDefinitionCommand command = spy(new PackageMaterialAddWithNewPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, new PackageMaterialConfig(), admin, params));
    command.createNewPackageDefinition(config);
    InOrder inOrder = inOrder(command, config);
    inOrder.verify(config).savePackageDefinition(any(PackageDefinition.class));
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HashMap(java.util.HashMap) Map(java.util.Map) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.Test)

Example 3 with PackageRepositories

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

the class GoConfigMigrationIntegrationTest method shouldValidatePackageRepositoriesConfiguration.

@Test
public void shouldValidatePackageRepositoriesConfiguration() throws Exception {
    String configString = "<cruise schemaVersion='66'>" + "<repositories>" + "<repository id='go-repo' name='go-repo'>" + "		<pluginConfiguration id='plugin-id' version='1.0'/>" + "		<configuration>" + "			<property><key>url</key><value>http://fake-yum-repo</value></property>" + "			<property><key>username</key><value>godev</value></property>" + "			<property><key>password</key><value>password</value></property>" + "		</configuration>" + "		<packages>" + "			<package id='go-server' name='go-server'>" + "				<configuration>" + "					<property><key>name</key><value>go-server-13.2.0-1-i386</value></property>" + "				</configuration>" + "			</package>" + "		</packages>" + "</repository>" + "</repositories>" + "</cruise>";
    CruiseConfig cruiseConfig = migrateConfigAndLoadTheNewConfig(configString, 66);
    PackageRepositories packageRepositories = cruiseConfig.getPackageRepositories();
    assertThat(packageRepositories.size(), is(1));
    assertThat(packageRepositories.get(0).getId(), is("go-repo"));
    assertThat(packageRepositories.get(0).getName(), is("go-repo"));
    assertThat(packageRepositories.get(0).getPluginConfiguration().getId(), is("plugin-id"));
    assertThat(packageRepositories.get(0).getPluginConfiguration().getVersion(), is("1.0"));
    assertThat(packageRepositories.get(0).getConfiguration(), is(notNullValue()));
    assertThat(packageRepositories.get(0).getPackages().size(), is(1));
    assertConfiguration(packageRepositories.get(0).getConfiguration(), asList(new List[] { asList("url", Boolean.FALSE, "http://fake-yum-repo"), asList("username", Boolean.FALSE, "godev"), asList("password", Boolean.FALSE, "password") }));
    assertThat(packageRepositories.get(0).getPackages().get(0).getId(), is("go-server"));
    assertThat(packageRepositories.get(0).getPackages().get(0).getName(), is("go-server"));
    assertConfiguration(packageRepositories.get(0).getPackages().get(0).getConfiguration(), asList(new List[] { asList("name", Boolean.FALSE, "go-server-13.2.0-1-i386") }));
}
Also used : PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 4 with PackageRepositories

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

the class GoConfigMigrationIntegrationTest method shouldAllowOnlyRepositoryConfiguration.

@Test
public void shouldAllowOnlyRepositoryConfiguration() throws Exception {
    String configString = "<cruise schemaVersion='66'>" + "<repositories>" + "<repository id='go-repo' name='go-repo'>" + "		<pluginConfiguration id='plugin-id' version='1.0'/>" + "		<configuration>" + "			<property><key>url</key><value>http://fake-yum-repo</value></property>" + "			<property><key>username</key><value>godev</value></property>" + "			<property><key>password</key><value>password</value></property>" + "		</configuration>" + "</repository>" + "</repositories>" + "</cruise>";
    CruiseConfig cruiseConfig = loadConfigFileWithContent(configString);
    PackageRepositories packageRepositories = cruiseConfig.getPackageRepositories();
    assertThat(packageRepositories.size(), is(1));
    assertThat(packageRepositories.get(0).getId(), is("go-repo"));
    assertThat(packageRepositories.get(0).getName(), is("go-repo"));
    assertThat(packageRepositories.get(0).getPluginConfiguration().getId(), is("plugin-id"));
    assertThat(packageRepositories.get(0).getPluginConfiguration().getVersion(), is("1.0"));
    assertThat(packageRepositories.get(0).getConfiguration(), is(notNullValue()));
    assertThat(packageRepositories.get(0).getPackages().size(), is(0));
    assertConfiguration(packageRepositories.get(0).getConfiguration(), asList(new List[] { asList("url", Boolean.FALSE, "http://fake-yum-repo"), asList("username", Boolean.FALSE, "godev"), asList("password", Boolean.FALSE, "password") }));
}
Also used : PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 5 with PackageRepositories

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

the class UpdatePackageConfigCommand method update.

@Override
public void update(CruiseConfig modifiedConfig) {
    PackageRepositories packageRepositories = modifiedConfig.getPackageRepositories();
    PackageRepository repository = packageRepositories.findPackageRepositoryHaving(oldPackageId);
    int index = packageRepositories.indexOf(repository);
    newPackage.setRepository(repository);
    repository.removePackage(oldPackageId);
    repository.addPackage(this.newPackage);
    packageRepositories.replace(index, repository);
    modifiedConfig.setPackageRepositories(packageRepositories);
    updatePackageConfigurationOnAssociatedPipelines(modifiedConfig);
}
Also used : PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Aggregations

PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)52 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)40 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)29 Test (org.junit.jupiter.api.Test)29 Packages (com.thoughtworks.go.domain.packagerepository.Packages)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 Test (org.junit.Test)8 Username (com.thoughtworks.go.server.domain.Username)7 BeforeEach (org.junit.jupiter.api.BeforeEach)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)4 ArrayList (java.util.ArrayList)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 GoCipher (com.thoughtworks.go.security.GoCipher)2