use of com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan 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.MarketplaceLoan 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));
}
use of com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan in project robozonky by RoboZonky.
the class ParsedStrategyTest method sellOffStarted.
@Test
void sellOffStarted() {
final DefaultPortfolio portfolio = DefaultPortfolio.EMPTY;
final DefaultValues values = new DefaultValues(portfolio);
// activate default sell-off 3 months before the given date, which is already in the past
values.setExitProperties(new ExitProperties(LocalDate.now().plusMonths(2)));
final ParsedStrategy strategy = new ParsedStrategy(values, Collections.emptyList());
// no loan or participation should be bought; every investment should be sold
final Loan l = mockLoan(1000);
final LoanDescriptor ld = new LoanDescriptor(l);
final ParticipationDescriptor pd = mockParticipationDescriptor(l);
final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
final InvestmentDescriptor id = new InvestmentDescriptor(i, l);
assertSoftly(softly -> {
softly.assertThat(strategy.getApplicableLoans(Collections.singleton(ld))).isEmpty();
softly.assertThat(strategy.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
softly.assertThat(strategy.getApplicableInvestments(Collections.singleton(id))).containsOnly(id);
});
}
use of com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan in project robozonky by RoboZonky.
the class WrapperTest method fromInvestment.
@Test
void fromInvestment() {
final Loan loan = Loan.custom().setId(1).setAmount(100_000).build();
final int invested = 200;
final Investment investment = Investment.fresh((MarketplaceLoan) loan, invested).build();
final Wrapper w = new Wrapper(investment, loan);
assertSoftly(softly -> {
softly.assertThat(w.getLoanId()).isEqualTo(loan.getId());
softly.assertThat(w.getStory()).isEqualTo(loan.getStory());
softly.assertThat(w.getRegion()).isEqualTo(loan.getRegion());
softly.assertThat(w.getRating()).isEqualTo(loan.getRating());
softly.assertThat(w.getOriginalAmount()).isEqualTo(loan.getAmount());
softly.assertThat(w.getInterestRate()).isEqualTo(loan.getInterestRate());
softly.assertThat(w.getRemainingTermInMonths()).isEqualTo(investment.getRemainingMonths());
softly.assertThat(w.getRemainingAmount()).isEqualTo(BigDecimal.valueOf(invested));
softly.assertThat(w.getIdentifier()).isNotNull();
});
}
Aggregations