コード例 #1
0
  @Test
  public void shouldPopulateErrorsForCheckConnectionOnPlugin() throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = packageRepository(pluginId);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    PackageRepositoryService service =
        new PackageRepositoryService(
            pluginManager,
            packageAsRepositoryExtension,
            goConfigService,
            securityService,
            entityHashingService,
            localizer);

    ArgumentCaptor<RepositoryConfiguration> argumentCaptor =
        ArgumentCaptor.forClass(RepositoryConfiguration.class);

    when(packageAsRepositoryExtension.checkConnectionToRepository(
            eq(pluginId), argumentCaptor.capture()))
        .thenReturn(new Result().withErrorMessages("Repo invalid!!", "Could not connect"));
    service.checkConnection(packageRepository, result);

    RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
    PackageMaterialTestHelper.assertPackageConfiguration(
        packageConfigurations.list(), packageRepository.getConfiguration());
    assertThat(result.isSuccessful(), is(false));

    when(localizer.localize(
            "PACKAGE_REPOSITORY_CHECK_CONNECTION_FAILED", "Repo invalid!!\nCould not connect"))
        .thenReturn("error_msg");
    assertThat(result.message(localizer), is("error_msg"));
    verify(packageAsRepositoryExtension)
        .checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
  }
コード例 #2
0
  @Test
  public void shouldPerformCheckConnectionOnPluginAndCatchAnyExceptionsThrownByThePlugin()
      throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = packageRepository(pluginId);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();

    PackageRepositoryService service =
        new PackageRepositoryService(
            pluginManager,
            packageAsRepositoryExtension,
            goConfigService,
            securityService,
            entityHashingService,
            localizer);

    ArgumentCaptor<RepositoryConfiguration> argumentCaptor =
        ArgumentCaptor.forClass(RepositoryConfiguration.class);
    when(packageAsRepositoryExtension.checkConnectionToRepository(
            eq(pluginId), argumentCaptor.capture()))
        .thenThrow(new RuntimeException("Check Connection not implemented!!"));

    service.checkConnection(packageRepository, result);

    assertThat(result.isSuccessful(), is(false));
    when(localizer.localize(
            "PACKAGE_REPOSITORY_CHECK_CONNECTION_FAILED", "Check Connection not implemented!!"))
        .thenReturn("error_msg");
    assertThat(result.message(localizer), is("error_msg"));
    verify(packageAsRepositoryExtension)
        .checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
  }
コード例 #3
0
  @Test
  public void shouldPerformCheckConnectionOnPlugin() throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = packageRepository(pluginId);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();

    PackageRepositoryService service =
        new PackageRepositoryService(
            pluginManager,
            packageAsRepositoryExtension,
            goConfigService,
            securityService,
            entityHashingService,
            localizer);

    ArgumentCaptor<RepositoryConfiguration> argumentCaptor =
        ArgumentCaptor.forClass(RepositoryConfiguration.class);
    when(packageAsRepositoryExtension.checkConnectionToRepository(
            eq(pluginId), argumentCaptor.capture()))
        .thenReturn(new Result().withSuccessMessages("Accessed Repo File!!!"));

    service.checkConnection(packageRepository, result);

    RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
    PackageMaterialTestHelper.assertPackageConfiguration(
        packageConfigurations.list(), packageRepository.getConfiguration());
    assertThat(result.isSuccessful(), is(true));
    when(localizer.localize("CONNECTION_OK", "Accessed Repo File!!!")).thenReturn("success_msg");
    assertThat(result.message(localizer), is("success_msg"));
    verify(packageAsRepositoryExtension)
        .checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
  }
コード例 #4
0
 @Test
 public void shouldUpdatePluginVersionWhenValid() {
   String pluginId = "valid";
   RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
   when(pluginManager.getPluginDescriptorFor(pluginId))
       .thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
   when(packageAsRepositoryExtension.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(), is("1.0"));
 }
コード例 #5
0
  @Test
  public void shouldInvokePluginValidationsBeforeSavingPackageRepository() throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = new PackageRepository();
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
    packageRepository
        .getConfiguration()
        .add(ConfigurationPropertyMother.create("url", false, "junk-url"));

    ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor =
        ArgumentCaptor.forClass(RepositoryConfiguration.class);
    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));

    when(pluginManager.getPluginDescriptorFor(pluginId))
        .thenReturn(new GoPluginDescriptor("yum", "1.0", null, null, null, true));
    when(packageAsRepositoryExtension.isRepositoryConfigurationValid(
            eq(pluginId), packageConfigurationsArgumentCaptor.capture()))
        .thenReturn(expectedValidationResult);

    service =
        new PackageRepositoryService(
            pluginManager,
            packageAsRepositoryExtension,
            goConfigService,
            securityService,
            entityHashingService,
            mock(Localizer.class));
    service.performPluginValidationsFor(packageRepository);
    assertThat(
        packageRepository
            .getConfiguration()
            .get(0)
            .getConfigurationValue()
            .errors()
            .getAllOn("value"),
        is(Arrays.asList("url format incorrect")));
  }
コード例 #6
0
  @Test
  public void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository()
      throws Exception {
    // 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(packageAsRepositoryExtension.isRepositoryConfigurationValid(
            eq(pluginId), any(RepositoryConfiguration.class)))
        .thenReturn(new ValidationResult());
    when(pluginManager.getPluginDescriptorFor(pluginId))
        .thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
    when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("mandatory field");

    service.performPluginValidationsFor(packageRepository);

    assertThat(
        packageRepository
            .getConfiguration()
            .get(0)
            .getConfigurationValue()
            .errors()
            .getAllOn("value"),
        is(Arrays.asList("mandatory field")));
    assertThat(
        packageRepository
            .getConfiguration()
            .get(1)
            .getEncryptedConfigurationValue()
            .errors()
            .getAllOn("value"),
        is(Arrays.asList("mandatory field")));
  }