use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.
the class Repayments method accept.
@Override
public void accept(final Portfolio portfolio, final Authenticated authenticated) {
final PortfolioOverview portfolioOverview = portfolio.calculateOverview();
final Collection<Integer> active = getActiveLastTime();
// detect and process loans that have been fully repaid, comparing to the last time active loans were checked
final Stream<Investment> repaid = portfolio.getActiveWithPaymentStatus(PaymentStatuses.of(PaymentStatus.PAID));
repaid.filter(i -> active.contains(i.getLoanId())).peek(i -> {
final Loan l = authenticated.call(zonky -> LoanCache.INSTANCE.getLoan(i, zonky));
final Event e = new LoanRepaidEvent(i, l, portfolioOverview);
Events.fire(e);
}).forEach(i -> active.remove(i.getLoanId()));
// add all active loans to date
portfolio.getActiveWithPaymentStatus(PaymentStatus.getActive()).forEach(i -> active.add(i.getLoanId()));
// store for future reference
setActive(active);
}
use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForInvestmentRejected.
private DynamicTest getParametersForInvestmentRejected() {
final Loan l = mockLoan();
final LoanDescriptor ld = new LoanDescriptor(l);
final RecommendedLoan r = ld.recommend(200).get();
final Event evt = new InvestmentRejectedEvent(r, "");
final Consumer<SoftAssertions> before = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getRejectedInvestments()).isEmpty();
};
final Consumer<SoftAssertions> after = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getRejectedInvestments()).containsOnlyKeys(l.getId());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForSaleOffered.
private DynamicTest getParametersForSaleOffered() {
final Loan l = mockLoan();
final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
final Event evt = new SaleOfferedEvent(i, l);
final Consumer<SoftAssertions> before = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getOfferedInvestments()).isEmpty();
};
final Consumer<SoftAssertions> after = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getOfferedInvestments()).containsOnlyKeys(i.getLoanId());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.notifications.Event in project robozonky by RoboZonky.
the class JmxListenerServiceTest method getParametersForInvestmentDelegated.
private DynamicTest getParametersForInvestmentDelegated() {
final Loan l = mockLoan();
final LoanDescriptor ld = new LoanDescriptor(l);
final RecommendedLoan r = ld.recommend(200).get();
final Event evt = new InvestmentDelegatedEvent(r, "");
final Consumer<SoftAssertions> before = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getDelegatedInvestments()).isEmpty();
};
final Consumer<SoftAssertions> after = (softly) -> {
final OperationsMBean mbean = getOperationsMBean();
softly.assertThat(mbean.getDelegatedInvestments()).containsOnlyKeys(l.getId());
softly.assertThat(mbean.getLatestUpdatedDateTime()).isEqualTo(evt.getCreatedOn());
};
return getParameters(evt, before, after);
}
use of com.github.robozonky.api.notifications.Event 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();
}
Aggregations