use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForInvestmentPurchased.
private DynamicTest getParametersForInvestmentPurchased() {
final Loan l = mockLoan();
final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
final Event evt = new InvestmentPurchasedEvent(i, l, PortfolioOverview.calculate(BigDecimal.valueOf(2000), Stream::empty));
final Consumer<SoftAssertions> before = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getPurchasedInvestments()).isEmpty();
};
final Consumer<SoftAssertions> after = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getPurchasedInvestments()).containsOnlyKeys(i.getLoanId());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class DelinquentsTest method newDelinquence.
@Test
void newDelinquence() {
final PortfolioOverview po = mock(PortfolioOverview.class);
final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setAmount(200).setMyInvestment(mockMyInvestment()).build();
final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.now().minusDays(1)).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);
softly.assertThat(this.getNewEvents()).hasSize(1);
});
assertThat(this.getNewEvents().get(0)).isInstanceOf(LoanNowDelinquentEvent.class);
// make sure delinquencies are persisted even when there are none present
Delinquents.update(Collections.emptyList(), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertSoftly(softly -> {
softly.assertThat(Delinquents.getDelinquents()).hasSize(1);
softly.assertThat(this.getNewEvents()).hasSize(2);
});
assertThat(this.getNewEvents().get(1)).isInstanceOf(LoanNoLongerDelinquentEvent.class);
// and when they are no longer active, they're gone for good
Delinquents.update(Collections.emptyList(), Collections.singleton(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
assertThat(Delinquents.getDelinquents()).hasSize(0);
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan 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);
}
});
});
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class SessionTest method properDryRun.
@Test
void properDryRun() {
final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setRemainingInvestment(200).setMyInvestment(mockMyInvestment()).build();
final Participation p = mock(Participation.class);
when(p.getLoanId()).thenReturn(l.getId());
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
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 Zonky z = mockZonky(BigDecimal.valueOf(100_000));
when(z.getLoan(eq(l.getId()))).thenReturn(l);
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
assertThat(i).hasSize(1);
assertThat(this.getNewEvents()).hasSize(5);
verify(z, never()).purchase(eq(p));
verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.
the class InvestmentDaemonTest method standard.
@Test
void standard() {
final int loanId = 1;
final MarketplaceLoan ml = MarketplaceLoan.custom().setId(loanId).setRating(Rating.A).build();
final Loan l = Loan.custom().setId(loanId).setRating(Rating.A).build();
final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK);
when(z.getAvailableLoans((Select) notNull())).thenReturn(Stream.of(ml));
when(z.getLoan(eq(loanId))).thenReturn(l);
final Authenticated a = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final InvestmentStrategy is = mock(InvestmentStrategy.class);
final Supplier<Optional<InvestmentStrategy>> s = () -> Optional.of(is);
final InvestingDaemon d = new InvestingDaemon(t -> {
}, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
d.run();
verify(z).getAvailableLoans((Select) notNull());
verify(z).getLoan(ml.getId());
verify(is).recommend(any(), any(), any());
assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
Aggregations