Search in sources :

Example 26 with Event

use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.

the class SessionTest method investmentSuccessful.

@Test
void investmentSuccessful() {
    final int oldBalance = 10_000;
    final int amountToInvest = 200;
    final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(amountToInvest).get();
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(oldBalance);
    when(z.getLoan(eq(r.descriptor().item().getId()))).thenReturn(r.descriptor().item());
    final Authenticated auth = mockAuthentication(z);
    final Investor p = mock(Investor.class);
    doReturn(new ZonkyResponse(amountToInvest)).when(p).invest(eq(r), anyBoolean());
    doReturn(Optional.of("something")).when(p).getConfirmationProviderId();
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
    final boolean result = t.invest(r);
    assertThat(result).isTrue();
    final List<Investment> investments = t.getResult();
    assertThat(investments).hasSize(1);
    assertThat(investments.get(0).getOriginalPrincipal().intValue()).isEqualTo(amountToInvest);
    // validate event sequence
    final List<Event> newEvents = this.getNewEvents();
    assertThat(newEvents).hasSize(2);
    assertSoftly(softly -> {
        softly.assertThat(newEvents.get(0)).isInstanceOf(InvestmentRequestedEvent.class);
        softly.assertThat(newEvents.get(1)).isInstanceOf(InvestmentMadeEvent.class);
    });
    // validate event contents
    final InvestmentMadeEvent e = (InvestmentMadeEvent) newEvents.get(1);
    assertThat(e.getPortfolioOverview().getCzkAvailable()).isEqualTo(oldBalance - amountToInvest);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) Event(com.github.robozonky.api.notifications.Event) InvestmentRequestedEvent(com.github.robozonky.api.notifications.InvestmentRequestedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) InvestmentSkippedEvent(com.github.robozonky.api.notifications.InvestmentSkippedEvent) LoanRecommendedEvent(com.github.robozonky.api.notifications.LoanRecommendedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Aggregations

Event (com.github.robozonky.api.notifications.Event)26 Test (org.junit.jupiter.api.Test)23 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)18 Zonky (com.github.robozonky.common.remote.Zonky)17 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)15 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)15 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)15 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)15 Portfolio (com.github.robozonky.app.portfolio.Portfolio)15 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)14 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)13 Authenticated (com.github.robozonky.app.authentication.Authenticated)12 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)11 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)11 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)10 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)10 PurchasingCompletedEvent (com.github.robozonky.api.notifications.PurchasingCompletedEvent)10 PurchasingStartedEvent (com.github.robozonky.api.notifications.PurchasingStartedEvent)10 Collections (java.util.Collections)10 Optional (java.util.Optional)10