use of com.github.robozonky.api.notifications.InvestmentPurchasedEvent in project robozonky by RoboZonky.
the class Session method purchase.
public boolean purchase(final RecommendedParticipation recommendation) {
Events.fire(new PurchaseRequestedEvent(recommendation));
final Participation participation = recommendation.descriptor().item();
final Loan loan = recommendation.descriptor().related();
final boolean purchased = isDryRun || actualPurchase(participation);
if (purchased) {
final Investment i = Investment.fresh(participation, loan, recommendation.amount());
markSuccessfulPurchase(i);
Events.fire(new InvestmentPurchasedEvent(i, loan, portfolioOverview));
}
return purchased;
}
use of com.github.robozonky.api.notifications.InvestmentPurchasedEvent in project robozonky by RoboZonky.
the class EmailingListenerTest method listeners.
@TestFactory
Stream<DynamicNode> listeners() throws MalformedURLException {
// prepare data
final Loan loan = Loan.custom().setId(66666).setAmount(100_000).setInterestRate(BigDecimal.TEN).setDatePublished(OffsetDateTime.now().minusMonths(2)).setName("Úvěr").setRegion(Region.JIHOCESKY).setPurpose(Purpose.AUTO_MOTO).setMainIncomeType(MainIncomeType.EMPLOYMENT).setRemainingInvestment(2000).setRating(Rating.AAAAA).setTermInMonths(25).setUrl(new URL("http://www.robozonky.cz")).build();
final LoanDescriptor loanDescriptor = new LoanDescriptor(loan);
final RecommendedLoan recommendation = loanDescriptor.recommend(1200, false).get();
final Investment i = Investment.fresh((MarketplaceLoan) loan, 1000).build();
// create events for listeners
return Stream.of(forListener(SupportedListener.INVESTMENT_DELEGATED, new InvestmentDelegatedEvent(recommendation, "random")), forListener(SupportedListener.INVESTMENT_MADE, new InvestmentMadeEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.INVESTMENT_SOLD, new InvestmentSoldEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.INVESTMENT_SKIPPED, new InvestmentSkippedEvent(recommendation)), forListener(SupportedListener.INVESTMENT_REJECTED, new InvestmentRejectedEvent(recommendation, "random")), forListener(SupportedListener.LOAN_NO_LONGER_DELINQUENT, new LoanNoLongerDelinquentEvent(i, loan, LocalDate.now(), Collections.singletonList(mockCollectionNoEndDate()))), forListener(SupportedListener.LOAN_DEFAULTED, new LoanDefaultedEvent(i, loan, LocalDate.now(), Collections.singletonList(mockCollectionNoNote()))), forListener(SupportedListener.LOAN_NOW_DELINQUENT, new LoanNowDelinquentEvent(i, loan, LocalDate.now(), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_10_PLUS, new LoanDelinquent10DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(11), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_30_PLUS, new LoanDelinquent30DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(31), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_60_PLUS, new LoanDelinquent60DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(61), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_90_PLUS, new LoanDelinquent90DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(91), Collections.emptyList())), forListener(SupportedListener.LOAN_REPAID, new LoanRepaidEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.BALANCE_ON_TARGET, new ExecutionStartedEvent(Collections.emptyList(), MAX_PORTFOLIO)), forListener(SupportedListener.BALANCE_UNDER_MINIMUM, new ExecutionStartedEvent(Collections.emptyList(), mockPortfolio(0))), forListener(SupportedListener.CRASHED, new RoboZonkyCrashedEvent(ReturnCode.ERROR_UNEXPECTED, new RuntimeException())), forListener(SupportedListener.REMOTE_OPERATION_FAILED, new RemoteOperationFailedEvent(new RuntimeException())), forListener(SupportedListener.DAEMON_FAILED, new RoboZonkyDaemonFailedEvent(new RuntimeException())), forListener(SupportedListener.INITIALIZED, new RoboZonkyInitializedEvent()), forListener(SupportedListener.ENDING, new RoboZonkyEndingEvent()), forListener(SupportedListener.TESTING, new RoboZonkyTestingEvent()), forListener(SupportedListener.UPDATE_DETECTED, new RoboZonkyUpdateDetectedEvent("1.2.3")), forListener(SupportedListener.EXPERIMENTAL_UPDATE_DETECTED, new RoboZonkyExperimentalUpdateDetectedEvent("1.3.0-beta-1")), forListener(SupportedListener.INVESTMENT_PURCHASED, new InvestmentPurchasedEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.SALE_OFFERED, new SaleOfferedEvent(i, loan)));
}
use of com.github.robozonky.api.notifications.InvestmentPurchasedEvent in project robozonky by RoboZonky.
the class JmxListenerService method newListener.
private static <T extends Event> EventListener<T> newListener(final Class<T> eventType) {
if (Objects.equals(eventType, ExecutionStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((ExecutionStartedEvent) event));
} else if (Objects.equals(eventType, ExecutionCompletedEvent.class)) {
return (event, sessionInfo) -> {
final ExecutionCompletedEvent evt = (ExecutionCompletedEvent) event;
callOnRuntime(bean -> bean.handle(evt, sessionInfo));
callOnPortfolio(bean -> bean.handle(evt));
};
} else if (Objects.equals(eventType, SellingStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingStartedEvent) event));
} else if (Objects.equals(eventType, SellingCompletedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingCompletedEvent) event));
} else if (Objects.equals(eventType, PurchasingStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingStartedEvent) event));
} else if (Objects.equals(eventType, PurchasingCompletedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingCompletedEvent) event));
} else if (Objects.equals(eventType, InvestmentDelegatedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentDelegatedEvent) event));
} else if (Objects.equals(eventType, InvestmentRejectedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentRejectedEvent) event));
} else if (Objects.equals(eventType, InvestmentMadeEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentMadeEvent) event));
} else if (Objects.equals(eventType, SaleOfferedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((SaleOfferedEvent) event));
} else if (Objects.equals(eventType, InvestmentPurchasedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentPurchasedEvent) event));
} else {
return null;
}
}
use of com.github.robozonky.api.notifications.InvestmentPurchasedEvent 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);
}
Aggregations