use of com.github.robozonky.api.remote.entities.sanitized.Investment in project robozonky by RoboZonky.
the class DelinquentsTest method defaulted.
@Test
void defaulted() {
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).setPaymentStatus(PaymentStatus.PAID_OFF).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
final Function<Investment, Loan> f = (id) -> l;
// register delinquency
Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
// ignore events just emitted
this.readPreexistingEvents();
// the investment is defaulted
Delinquents.update(Collections.emptyList(), Collections.singletonList(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanDefaultedEvent.class);
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment 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);
});
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment 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();
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment 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();
}
use of com.github.robozonky.api.remote.entities.sanitized.Investment 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));
}
Aggregations