Search in sources :

Example 11 with Event

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

the class SellingTest method noSaleDueToNoData.

@Test
void noSaleDueToNoData() {
    // no data is inserted into portfolio, therefore nothing happens
    final Zonky zonky = mockApi();
    final Portfolio portfolio = new Portfolio(mockBalance(zonky));
    new Selling(ALL_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(any());
}
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) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 12 with Event

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

the class PurchasingTest method noneAccepted.

@Test
void noneAccepted() {
    final Zonky zonky = mockApi();
    final Participation mock = mock(Participation.class);
    when(mock.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(250));
    final Purchasing exec = new Purchasing(NONE_ACCEPTING, mockAuthentication(zonky), true);
    final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
    final List<Event> e = this.getNewEvents();
    assertThat(e).hasSize(2);
    assertSoftly(softly -> {
        softly.assertThat(e).first().isInstanceOf(PurchasingStartedEvent.class);
        softly.assertThat(e).last().isInstanceOf(PurchasingCompletedEvent.class);
    });
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) 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 13 with Event

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

the class PurchasingTest method noStrategy.

@Test
void noStrategy() {
    final Participation mock = mock(Participation.class);
    final Purchasing exec = new Purchasing(Optional::empty, null, true);
    final Portfolio portfolio = mock(Portfolio.class);
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
    // check events
    final List<Event> events = this.getNewEvents();
    assertThat(events).isEmpty();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Optional(java.util.Optional) 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) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 14 with Event

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

the class PurchasingTest method someAccepted.

@Test
void someAccepted() {
    final int loanId = 1;
    final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setRemainingInvestment(1000).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
    final Zonky zonky = mockApi();
    when(zonky.getLoan(eq(loanId))).thenReturn(loan);
    final Participation mock = mock(Participation.class);
    when(mock.getId()).thenReturn(1);
    when(mock.getLoanId()).thenReturn(loan.getId());
    when(mock.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(250));
    when(mock.getRating()).thenReturn(loan.getRating());
    final Purchasing exec = new Purchasing(ALL_ACCEPTING, mockAuthentication(zonky), true);
    final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isNotEmpty();
    // purchase as balance changed
    verify(zonky, never()).purchase(eq(mock));
    final List<Event> e = this.getNewEvents();
    assertThat(e).hasSize(5);
    assertSoftly(softly -> {
        softly.assertThat(e).first().isInstanceOf(PurchasingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(PurchaseRecommendedEvent.class);
        softly.assertThat(e.get(2)).isInstanceOf(PurchaseRequestedEvent.class);
        softly.assertThat(e.get(3)).isInstanceOf(InvestmentPurchasedEvent.class);
        softly.assertThat(e).last().isInstanceOf(PurchasingCompletedEvent.class);
    });
    // purchase as marketplace first initialized
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isNotEmpty();
    // no balance change, no marketplace change => don't purchase
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
    // nothing changed, so no more purchase
    verify(zonky, never()).purchase(eq(mock));
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) 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 15 with Event

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

the class Repayments method accept.

@Override
public void accept(final Portfolio portfolio, final Authenticated authenticated) {
    final PortfolioOverview portfolioOverview = portfolio.calculateOverview();
    final Collection<Integer> active = getActiveLastTime();
    // detect and process loans that have been fully repaid, comparing to the last time active loans were checked
    final Stream<Investment> repaid = portfolio.getActiveWithPaymentStatus(PaymentStatuses.of(PaymentStatus.PAID));
    repaid.filter(i -> active.contains(i.getLoanId())).peek(i -> {
        final Loan l = authenticated.call(zonky -> LoanCache.INSTANCE.getLoan(i, zonky));
        final Event e = new LoanRepaidEvent(i, l, portfolioOverview);
        Events.fire(e);
    }).forEach(i -> active.remove(i.getLoanId()));
    // add all active loans to date
    portfolio.getActiveWithPaymentStatus(PaymentStatus.getActive()).forEach(i -> active.add(i.getLoanId()));
    // store for future reference
    setActive(active);
}
Also used : Collection(java.util.Collection) Set(java.util.Set) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Collectors(java.util.stream.Collectors) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) Event(com.github.robozonky.api.notifications.Event) Stream(java.util.stream.Stream) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanCache(com.github.robozonky.app.util.LoanCache) Events(com.github.robozonky.app.Events) Authenticated(com.github.robozonky.app.authentication.Authenticated) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) State(com.github.robozonky.internal.api.State) PaymentStatuses(com.github.robozonky.api.remote.enums.PaymentStatuses) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) Event(com.github.robozonky.api.notifications.Event) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

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