Search in sources :

Example 41 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class InvestmentDaemonTest method standard.

@Test
void standard() {
    final int loanId = 1;
    final MarketplaceLoan ml = MarketplaceLoan.custom().setId(loanId).setRating(Rating.A).build();
    final Loan l = Loan.custom().setId(loanId).setRating(Rating.A).build();
    final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK);
    when(z.getAvailableLoans((Select) notNull())).thenReturn(Stream.of(ml));
    when(z.getLoan(eq(loanId))).thenReturn(l);
    final Authenticated a = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final InvestmentStrategy is = mock(InvestmentStrategy.class);
    final Supplier<Optional<InvestmentStrategy>> s = () -> Optional.of(is);
    final InvestingDaemon d = new InvestingDaemon(t -> {
    }, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
    d.run();
    verify(z).getAvailableLoans((Select) notNull());
    verify(z).getLoan(ml.getId());
    verify(is).recommend(any(), any(), any());
    assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) Investor(com.github.robozonky.app.investing.Investor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 42 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class PortfolioUpdaterTest method backoffFailed.

@Test
void backoffFailed() {
    final Zonky z = harmlessZonky(10_000);
    // will always fail
    doThrow(IllegalStateException.class).when(z).getInvestments();
    final Authenticated a = mockAuthentication(z);
    final Consumer<Throwable> t = mock(Consumer.class);
    final PortfolioUpdater instance = new PortfolioUpdater(t, a, mockBalance(z), Duration.ofSeconds(2));
    instance.run();
    assertSoftly(softly -> {
        softly.assertThat(instance.get()).isEmpty();
        softly.assertThat(instance.isUpdating()).isTrue();
    });
    verify(t).accept(notNull());
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 43 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class PortfolioUpdaterTest method updatingDependants.

@Test
void updatingDependants() {
    final Zonky z = harmlessZonky(10_000);
    final Authenticated a = mockAuthentication(z);
    final PortfolioDependant dependant = mock(PortfolioDependant.class);
    final PortfolioUpdater instance = new PortfolioUpdater((t) -> {
    }, a, mockBalance(z));
    instance.registerDependant(dependant);
    instance.run();
    // this is the call to update Portfolio
    verify(a, times(2)).call(any());
    final Optional<Portfolio> result = instance.get();
    // make sure that the dependants were called with the proper value of Portfolio
    verify(dependant).accept(eq(result.get()), eq(a));
    // it's false when update finished
    assertThat(instance.isUpdating()).isFalse();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) PortfolioDependant(com.github.robozonky.app.portfolio.PortfolioDependant) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 44 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class AbstractZonkyLeveragingTest method mockAuthentication.

protected static Authenticated mockAuthentication(final Zonky zonky) {
    final Authenticated auth = mock(Authenticated.class);
    when(auth.getSecretProvider()).thenReturn(SecretProvider.fallback("someone", "password".toCharArray()));
    when(auth.getRestrictions()).thenReturn(new Restrictions());
    doAnswer(invocation -> {
        final Function<Zonky, Object> operation = invocation.getArgument(0);
        return operation.apply(zonky);
    }).when(auth).call(any());
    doAnswer(invocation -> {
        final Consumer<Zonky> operation = invocation.getArgument(0);
        operation.accept(zonky);
        return null;
    }).when(auth).run(any());
    return auth;
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Zonky(com.github.robozonky.common.remote.Zonky)

Aggregations

Authenticated (com.github.robozonky.app.authentication.Authenticated)44 Test (org.junit.jupiter.api.Test)37 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)32 Zonky (com.github.robozonky.common.remote.Zonky)31 Portfolio (com.github.robozonky.app.portfolio.Portfolio)28 Event (com.github.robozonky.api.notifications.Event)13 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)11 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)10 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)9 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)9 Optional (java.util.Optional)9 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)8 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 InvestmentRequestedEvent (com.github.robozonky.api.notifications.InvestmentRequestedEvent)8 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)8 LoanRecommendedEvent (com.github.robozonky.api.notifications.LoanRecommendedEvent)8 Collection (java.util.Collection)8