Search in sources :

Example 16 with PackageRepository

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

the class PackageRepositoryServiceTest method shouldUpdatePluginVersionWhenValid.

@Test
void shouldUpdatePluginVersionWhenValid() {
    String pluginId = "valid";
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(getPluginDescriptor(pluginId));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, ""));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getPluginConfiguration().getVersion()).isEqualTo("1.0");
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.jupiter.api.Test)

Example 17 with PackageRepository

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

the class PackageRepositoryServiceTest method shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository.

@Test
void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository() {
    // metadata setup
    String pluginId = "yum";
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.add(new PackageConfiguration("required").with(PackageConfiguration.REQUIRED, true));
    repositoryConfiguration.add(new PackageConfiguration("required_secure").with(PackageConfiguration.REQUIRED, true).with(PackageConfiguration.SECURE, true));
    repositoryConfiguration.add(new PackageConfiguration("secure").with(PackageConfiguration.SECURE, true).with(PackageConfiguration.REQUIRED, false));
    repositoryConfiguration.add(new PackageConfiguration("not_required_not_secure"));
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfiguration);
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required", false, ""));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required_secure", true, ""));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("secure", true, ""));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(getPluginDescriptor(pluginId));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("This field is required"));
    assertThat(packageRepository.getConfiguration().get(1).getEncryptedConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("This field is required"));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.jupiter.api.Test)

Example 18 with PackageRepository

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

the class PackageRepositoryServiceTest method shouldSendResolvedValuesForCheckConnectionOnPlugin.

@Test
void shouldSendResolvedValuesForCheckConnectionOnPlugin() {
    String pluginId = "yum";
    PackageRepository packageRepository = packageRepository(pluginId);
    packageRepository.getConfiguration().get(0).setConfigurationValue(new ConfigurationValue("{{SECRET:[secret_config_id][username]}}"));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
    when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), any())).thenReturn(new Result().withErrorMessages("Repo invalid!!", "Could not connect"));
    doAnswer(invocation -> {
        PackageRepository config = invocation.getArgument(0);
        config.getSecretParams().get(0).setValue("resolved-value");
        return config;
    }).when(secretParamResolver).resolve(packageRepository);
    service.checkConnection(packageRepository, result);
    assertThat(result.isSuccessful()).isFalse();
    assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Repo invalid!!\nCould not connect");
    ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
    verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), argumentCaptor.capture());
    RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
    assertThat(packageConfigurations.list().get(0).getValue()).isEqualTo("resolved-value");
}
Also used : ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Result(com.thoughtworks.go.plugin.api.response.Result) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.jupiter.api.Test)

Example 19 with PackageRepository

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

the class PackageDefinitionServiceIntegrationTest method setup.

@BeforeEach
public void setup() throws Exception {
    cachedGoPartials.clear();
    configHelper = new GoConfigFileHelper();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
    user = new Username(new CaseInsensitiveString("current"));
    final PackageRepository npmRepo = new PackageRepository();
    PluginConfiguration pluginConfiguration = new PluginConfiguration();
    pluginConfiguration.setId("npm");
    pluginConfiguration.setVersion("1");
    npmRepo.setPluginConfiguration(pluginConfiguration);
    repoId = "repoId";
    npmRepo.setId(repoId);
    npmRepo.setName(repoId);
    Configuration configuration = new Configuration();
    configuration.add(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
    npmRepo.setConfiguration(configuration);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.setPackageRepositories(new PackageRepositories(npmRepo));
            return cruiseConfig;
        }
    });
    UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
    goConfigService.updateConfig(command);
}
Also used : ContextConfiguration(org.springframework.test.context.ContextConfiguration) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Username(com.thoughtworks.go.server.domain.Username) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with PackageRepository

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

the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository.

@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository() throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String repoId = "npm";
    PackageRepository npmRepo = new PackageRepository();
    npmRepo.setId(repoId);
    goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.forbidden(EntityType.PackageRepository.forbiddenToDelete("npm", "UnauthorizedUser"), forbidden());
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
    service.deleteRepository(new Username("UnauthorizedUser"), npmRepo, result);
    assertThat(result, is(expectedResult));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
    assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) 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