@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));
  }
  @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));
  }
  @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));
  }