Search in sources :

Example 21 with Event

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

the class SellingTest method noSaleDueToStrategyForbidding.

@Test
void noSaleDueToStrategyForbidding() {
    final Investment i = mockInvestment();
    final Zonky zonky = mockApi();
    final Portfolio portfolio = new Portfolio(Collections.singleton(i), mockBalance(zonky));
    new Selling(NONE_ACCEPTING, true).accept(portfolio, mockAuthentication(zonky));
    final List<Event> e = getNewEvents();
    assertThat(e).hasSize(2);
    assertSoftly(softly -> {
        softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(SellingCompletedEvent.class);
    });
    verify(zonky, never()).sell(eq(i));
}
Also used : SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 22 with Event

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

the class PurchasingTest method noItems.

@Test
void noItems() {
    final Zonky zonky = mockApi();
    final Purchasing exec = new Purchasing(ALL_ACCEPTING, mockAuthentication(zonky), true);
    final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
    assertThat(exec.apply(portfolio, Collections.emptyList())).isEmpty();
    final List<Event> e = this.getNewEvents();
    assertThat(e).isEmpty();
}
Also used : Portfolio(com.github.robozonky.app.portfolio.Portfolio) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) PurchaseRecommendedEvent(com.github.robozonky.api.notifications.PurchaseRecommendedEvent) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 23 with Event

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

the class SessionTest method underBalance.

@Test
void underBalance() {
    final Participation p = mock(Participation.class);
    when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
    final Loan l = Loan.custom().build();
    final PurchaseStrategy s = mock(PurchaseStrategy.class);
    when(s.recommend(any(), any(), any())).thenAnswer(i -> {
        final Collection<ParticipationDescriptor> participations = i.getArgument(0);
        return participations.stream().map(ParticipationDescriptor::recommend).flatMap(o -> o.map(Stream::of).orElse(Stream.empty()));
    });
    final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
    final Zonky z = mockZonky();
    final Authenticated auth = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
    assertSoftly(softly -> {
        softly.assertThat(i).isEmpty();
        softly.assertThat(this.getNewEvents()).has(new Condition<List<? extends Event>>() {

            @Override
            public boolean matches(final List<? extends Event> events) {
                return events.stream().noneMatch(e -> e instanceof PurchaseRequestedEvent);
            }
        });
    });
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Event(com.github.robozonky.api.notifications.Event) Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Authenticated(com.github.robozonky.app.authentication.Authenticated) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Condition(org.assertj.core.api.Condition) Rating(com.github.robozonky.api.remote.enums.Rating) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Participation(com.github.robozonky.api.remote.entities.Participation) Participation(com.github.robozonky.api.remote.entities.Participation) Authenticated(com.github.robozonky.app.authentication.Authenticated) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Event(com.github.robozonky.api.notifications.Event) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Stream(java.util.stream.Stream) List(java.util.List) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 24 with Event

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

the class SessionTest method investmentIgnoredWhenNoConfirmationProviderAndCaptcha.

@Test
void investmentIgnoredWhenNoConfirmationProviderAndCaptcha() {
    final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
    final RecommendedLoan r = ld.recommend(200).get();
    final Collection<LoanDescriptor> availableLoans = Collections.singletonList(ld);
    // setup APIs
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final Investor p = mock(Investor.class);
    doReturn(new ZonkyResponse(ZonkyResponseType.REJECTED)).when(p).invest(eq(r), anyBoolean());
    doReturn(Optional.empty()).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(InvestmentSkippedEvent.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 25 with Event

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

the class SessionTest method underBalance.

@Test
void underBalance() {
    // setup APIs
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK - 1);
    final Authenticated auth = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    // run test
    final Session it = new Session(portfolio, Collections.emptySet(), getInvestor(auth), auth);
    final Optional<RecommendedLoan> recommendation = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(BigDecimal.valueOf(Defaults.MINIMUM_INVESTMENT_IN_CZK));
    final boolean result = it.invest(recommendation.get());
    // 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