Search in sources :

Example 16 with Zonky

use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.

the class RepaymentsTest method registerNewRepayments.

@Test
void registerNewRepayments() {
    final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setRemainingInvestment(0).build();
    final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.OK).build();
    // first, portfolio contains one active investment; no repaid
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(l.getId()))).thenReturn(l);
    final Portfolio p = new Portfolio(Collections.singletonList(i), mockBalance(z));
    final Authenticated a = mockAuthentication(z);
    final Repayments r = new Repayments();
    r.accept(p, a);
    assertThat(getNewEvents()).isEmpty();
    // now, portfolio has the same investment marked as paid; event will be triggered
    Investment.markAsPaid(i);
    r.accept(p, a);
    assertThat(getNewEvents()).first().isInstanceOf(LoanRepaidEvent.class);
    // make sure the loan was retrieved from Zonky
    verify(z).getLoan(eq(l.getId()));
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) 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 17 with Zonky

use of com.github.robozonky.common.remote.Zonky 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 18 with Zonky

use of com.github.robozonky.common.remote.Zonky 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 19 with Zonky

use of com.github.robozonky.common.remote.Zonky 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 20 with Zonky

use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.

the class PurchasingTest method mockApi.

private static Zonky mockApi() {
    final Zonky zonky = mock(Zonky.class);
    when(zonky.getLoan(anyInt())).thenAnswer(invocation -> {
        final int id = invocation.getArgument(0);
        return Loan.custom().setId(id).setAmount(200).build();
    });
    when(zonky.getWallet()).thenReturn(new Wallet(BigDecimal.valueOf(10000), BigDecimal.valueOf(9000)));
    return zonky;
}
Also used : Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky)

Aggregations

Zonky (com.github.robozonky.common.remote.Zonky)55 Test (org.junit.jupiter.api.Test)47 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)46 Authenticated (com.github.robozonky.app.authentication.Authenticated)30 Portfolio (com.github.robozonky.app.portfolio.Portfolio)30 Event (com.github.robozonky.api.notifications.Event)19 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)15 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)13 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)12 Wallet (com.github.robozonky.api.remote.entities.Wallet)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)9 BigDecimal (java.math.BigDecimal)9 Collection (java.util.Collection)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