Search in sources :

Example 16 with ApiProvider

use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.

the class Checker method getOneLoanFromMarketplace.

static Optional<RawLoan> getOneLoanFromMarketplace(final Supplier<ApiProvider> apiProviderSupplier) {
    try {
        final ApiProvider p = apiProviderSupplier.get();
        final Collection<RawLoan> loans = p.marketplace();
        /*
             * find a loan that is likely to stay on the marketplace for so long that the notification will
             * successfully come through.
             */
        return loans.stream().sorted(Checker.COMPARATOR).findFirst();
    } catch (final Exception t) {
        Checker.LOGGER.warn("Failed obtaining a loan.", t);
        return Optional.empty();
    }
}
Also used : ApiProvider(com.github.robozonky.common.remote.ApiProvider) RawLoan(com.github.robozonky.api.remote.entities.RawLoan)

Example 17 with ApiProvider

use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.

the class ZonkySettingsValidatorTest method properLogin.

@Test
void properLogin() {
    // mock data
    final ZonkyApiToken token = mock(ZonkyApiToken.class);
    final OAuth oauth = mock(OAuth.class);
    when(oauth.login(any(), any())).thenReturn(token);
    final Zonky zonky = mock(Zonky.class);
    final ApiProvider provider = mockApiProvider(oauth, token, zonky);
    // execute SUT
    final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
    final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
    final DataValidator.Status result = validator.validateData(d);
    // test
    assertThat(result).isEqualTo(DataValidator.Status.OK);
    verify(oauth).login(eq(ZonkySettingsValidatorTest.USERNAME), eq(ZonkySettingsValidatorTest.PASSWORD.toCharArray()));
    verify(zonky).logout();
}
Also used : InstallData(com.izforge.izpack.api.data.InstallData) DataValidator(com.izforge.izpack.api.installer.DataValidator) ApiProvider(com.github.robozonky.common.remote.ApiProvider) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) OAuth(com.github.robozonky.common.remote.OAuth) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test)

Example 18 with ApiProvider

use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.

the class ZonkySettingsValidatorTest method error.

@Test
void error() {
    // mock data
    final OAuth oauth = mock(OAuth.class);
    when(oauth.login(any(), any())).thenThrow(new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR));
    final ApiProvider provider = mockApiProvider(oauth);
    final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
    // execute SUT
    final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
    final DataValidator.Status result = validator.validateData(d);
    // test
    assertThat(result).isEqualTo(DataValidator.Status.ERROR);
}
Also used : InstallData(com.izforge.izpack.api.data.InstallData) DataValidator(com.izforge.izpack.api.installer.DataValidator) ApiProvider(com.github.robozonky.common.remote.ApiProvider) ServerErrorException(javax.ws.rs.ServerErrorException) OAuth(com.github.robozonky.common.remote.OAuth) Test(org.junit.jupiter.api.Test)

Example 19 with ApiProvider

use of com.github.robozonky.common.remote.ApiProvider in project robozonky by RoboZonky.

the class CheckerTest method confirmationsMarketplaceFail.

@Test
void confirmationsMarketplaceFail() {
    final ApiProvider provider = mock(ApiProvider.class);
    doThrow(new IllegalStateException("Testing")).when(provider).marketplace();
    final boolean result = Checker.confirmations(mock(ConfirmationProvider.class), "", SECRET, () -> provider);
    assertThat(result).isFalse();
}
Also used : ConfirmationProvider(com.github.robozonky.api.confirmations.ConfirmationProvider) ApiProvider(com.github.robozonky.common.remote.ApiProvider) Test(org.junit.jupiter.api.Test)

Aggregations

ApiProvider (com.github.robozonky.common.remote.ApiProvider)19 Test (org.junit.jupiter.api.Test)13 OAuth (com.github.robozonky.common.remote.OAuth)12 ZonkyApiToken (com.github.robozonky.api.remote.entities.ZonkyApiToken)11 Zonky (com.github.robozonky.common.remote.Zonky)5 Optional (java.util.Optional)5 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)3 SecretProvider (com.github.robozonky.common.secrets.SecretProvider)3 InstallData (com.izforge.izpack.api.data.InstallData)3 DataValidator (com.izforge.izpack.api.installer.DataValidator)3 Collection (java.util.Collection)3 ConfirmationProvider (com.github.robozonky.api.confirmations.ConfirmationProvider)2 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)2 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)2 Function (java.util.function.Function)2 ServerErrorException (javax.ws.rs.ServerErrorException)2 Consumer (java.util.function.Consumer)1