Search in sources :

Example 11 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class DelinquentsTest method oldDelinquency.

@Test
void oldDelinquency() {
    final PortfolioOverview po = mock(PortfolioOverview.class);
    final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
    final Function<Investment, Loan> f = (id) -> l;
    // make sure new delinquencies are reported and stored
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    assertSoftly(softly -> {
        softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
        // all 5 delinquency events
        softly.assertThat(this.getNewEvents()).hasSize(5);
    });
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 12 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class PortfolioTest method newSale.

@Test
void newSale() {
    final Loan l = Loan.custom().setId(1).setAmount(1000).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200);
    final BlockedAmount ba = new BlockedAmount(l.getId(), BigDecimal.valueOf(l.getAmount()), TransactionCategory.SMP_SALE_FEE);
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(l.getId()))).thenReturn(l);
    final Authenticated auth = mockAuthentication(z);
    final Portfolio portfolio = new Portfolio(Collections.singletonList(i), mockBalance(z));
    assertThat(portfolio.wasOnceSold(l)).isFalse();
    Investment.putOnSmp(i);
    assertThat(portfolio.wasOnceSold(l)).isTrue();
    portfolio.newBlockedAmount(auth, ba);
    assertSoftly(softly -> {
        softly.assertThat(i.isOnSmp()).isFalse();
        softly.assertThat(i.getStatus()).isEqualTo(InvestmentStatus.SOLD);
    });
    final List<Event> events = this.getNewEvents();
    assertThat(events).first().isInstanceOf(InvestmentSoldEvent.class);
    // doing the same thing again shouldn't do anything
    this.readPreexistingEvents();
    portfolio.newBlockedAmount(auth, ba);
    assertSoftly(softly -> {
        softly.assertThat(i.isOnSmp()).isFalse();
        softly.assertThat(i.getStatus()).isEqualTo(InvestmentStatus.SOLD);
        softly.assertThat(portfolio.wasOnceSold(l)).isTrue();
    });
    final List<Event> newEvents = this.getNewEvents();
    assertThat(newEvents).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Event(com.github.robozonky.api.notifications.Event) InvestmentSoldEvent(com.github.robozonky.api.notifications.InvestmentSoldEvent) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) 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 13 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class InvestingTest method noneAccepted.

@Test
void noneAccepted() {
    // new ID every time to avoid caches
    final int loanId = (int) (Math.random() * 1000);
    final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Investor.Builder builder = new Investor.Builder().asDryRun();
    final Zonky z = harmlessZonky(9000);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    when(z.getLoan(eq(loanId))).thenReturn(loan);
    final Authenticated auth = mockAuthentication(z);
    final Investing exec = new Investing(builder, NONE_ACCEPTING, auth);
    assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 14 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class InvestingTest method noStrategy.

@Test
void noStrategy() {
    // new ID every time to avoid caches
    final int loanId = (int) (Math.random() * 1000);
    final Loan loan = Loan.custom().setId(loanId).setAmount(2).build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Investing exec = new Investing(null, Optional::empty, null);
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(1000);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    assertThat(exec.apply(portfolio, Collections.singletonList(ld))).isEmpty();
    // check events
    final List<Event> events = this.getNewEvents();
    assertThat(events).isEmpty();
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Event(com.github.robozonky.api.notifications.Event) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 15 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class InvestingTest method someAccepted.

@Test
void someAccepted() {
    // new ID every time to avoid caches
    final int loanId = (int) (Math.random() * 1000);
    final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setRemainingInvestment(20_000).setDatePublished(OffsetDateTime.now()).build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Investor.Builder builder = new Investor.Builder().asDryRun();
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(loanId))).thenReturn(loan);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Authenticated auth = mockAuthentication(z);
    final Investing exec = new Investing(builder, ALL_ACCEPTING, auth);
    final Collection<Investment> result = exec.apply(portfolio, Collections.singleton(ld));
    // dry run
    verify(z, never()).invest(any());
    assertThat(result).extracting(Investment::getLoanId).isEqualTo(Collections.singletonList(loanId));
    // re-check; no balance changed, no marketplace changed, nothing should happen
    assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)53 Test (org.junit.jupiter.api.Test)46 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)25 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)20 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)19 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)14 Zonky (com.github.robozonky.common.remote.Zonky)14 SoftAssertions (org.assertj.core.api.SoftAssertions)14 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Assertions (org.assertj.core.api.Assertions)13 Mockito (org.mockito.Mockito)13 Event (com.github.robozonky.api.notifications.Event)12 Portfolio (com.github.robozonky.app.portfolio.Portfolio)12 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 Stream (java.util.stream.Stream)10 Optional (java.util.Optional)9 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)8 Participation (com.github.robozonky.api.remote.entities.Participation)8