Search in sources :

Example 6 with Event

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

the class SessionTest method investmentDelegatedButExpectedConfirmed.

@Test
void investmentDelegatedButExpectedConfirmed() {
    final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
    final RecommendedLoan r = ld.recommend(200, true).get();
    final Collection<LoanDescriptor> availableLoans = Collections.singletonList(ld);
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final Investor p = mock(Investor.class);
    doReturn(new ZonkyResponse(ZonkyResponseType.DELEGATED)).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, new LinkedHashSet<>(availableLoans), p, auth);
    final boolean result = t.invest(r);
    assertThat(result).isFalse();
    // validate event
    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(InvestmentDelegatedEvent.class);
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) 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) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 7 with Event

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

the class SessionTest method makeInvestment.

@Test
void makeInvestment() {
    // setup APIs
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(200);
    // run test
    final int amount = 200;
    final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptorWithoutCaptcha();
    final int loanId = ld.item().getId();
    when(z.getLoan(eq(loanId))).thenReturn(ld.item());
    final Authenticated auth = mockAuthentication(z);
    final Collection<LoanDescriptor> lds = Arrays.asList(ld, AbstractZonkyLeveragingTest.mockLoanDescriptor());
    final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
    final Collection<Investment> i = Session.invest(portfolio, getInvestor(auth), auth, lds, mockStrategy(loanId, amount));
    // check that one investment was made
    assertThat(i).hasSize(1);
    final List<Event> newEvents = this.getNewEvents();
    assertThat(newEvents).hasSize(5);
    assertSoftly(softly -> {
        softly.assertThat(newEvents.get(0)).isInstanceOf(ExecutionStartedEvent.class);
        softly.assertThat(newEvents.get(1)).isInstanceOf(LoanRecommendedEvent.class);
        softly.assertThat(newEvents.get(2)).isInstanceOf(InvestmentRequestedEvent.class);
        softly.assertThat(newEvents.get(3)).isInstanceOf(InvestmentMadeEvent.class);
        softly.assertThat(newEvents.get(4)).isInstanceOf(ExecutionCompletedEvent.class);
    });
    verify(portfolio).newBlockedAmount(eq(auth), argThat(a -> a.getLoanId() == loanId));
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Arrays(java.util.Arrays) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) TransactionCategory(com.github.robozonky.api.remote.enums.TransactionCategory) SoftAssertions(org.assertj.core.api.SoftAssertions) Zonky(com.github.robozonky.common.remote.Zonky) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) BigDecimal(java.math.BigDecimal) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) Authenticated(com.github.robozonky.app.authentication.Authenticated) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) LinkedHashSet(java.util.LinkedHashSet) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Collection(java.util.Collection) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) Event(com.github.robozonky.api.notifications.Event) Test(org.junit.jupiter.api.Test) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Mockito(org.mockito.Mockito) List(java.util.List) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) InvestmentRequestedEvent(com.github.robozonky.api.notifications.InvestmentRequestedEvent) Stream(java.util.stream.Stream) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Optional(java.util.Optional) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) InvestmentSkippedEvent(com.github.robozonky.api.notifications.InvestmentSkippedEvent) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Collections(java.util.Collections) LoanRecommendedEvent(com.github.robozonky.api.notifications.LoanRecommendedEvent) Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) 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) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 8 with Event

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

the class SessionTest method investmentRejected.

@Test
void investmentRejected() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
    final Investor p = mock(Investor.class);
    doReturn(new ZonkyResponse(ZonkyResponseType.REJECTED)).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).isFalse();
    // validate event
    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(InvestmentRejectedEvent.class);
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) 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) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 9 with Event

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

the class SessionTest method investmentDelegated.

@Test
void investmentDelegated() {
    final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
    final RecommendedLoan r = ld.recommend(200).get();
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final Investor p = mock(Investor.class);
    doReturn(new ZonkyResponse(ZonkyResponseType.DELEGATED)).when(p).invest(eq(r), anyBoolean());
    doReturn(Optional.of("something")).when(p).getConfirmationProviderId();
    final Collection<LoanDescriptor> availableLoans = Collections.singletonList(ld);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, new LinkedHashSet<>(availableLoans), p, auth);
    final boolean result = t.invest(r);
    assertThat(result).isFalse();
    // validate event
    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(InvestmentDelegatedEvent.class);
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) 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) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 10 with Event

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

the class SessionTest method underAmount.

@Test
void underAmount() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(0);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan recommendation = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(Defaults.MINIMUM_INVESTMENT_IN_CZK).get();
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.singleton(recommendation.descriptor()), getInvestor(auth), auth);
    final boolean result = t.invest(recommendation);
    // verify result
    assertThat(result).isFalse();
    final List<Event> newEvents = this.getNewEvents();
    assertThat(newEvents).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) 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) Zonky(com.github.robozonky.common.remote.Zonky) 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