Search in sources :

Example 1 with RoboZonkyTestingEvent

use of com.github.robozonky.api.notifications.RoboZonkyTestingEvent 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)));
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentSoldEvent(com.github.robozonky.api.notifications.InvestmentSoldEvent) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) URL(java.net.URL) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) RemoteOperationFailedEvent(com.github.robozonky.api.notifications.RemoteOperationFailedEvent) LoanDelinquent10DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent10DaysOrMoreEvent) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) RoboZonkyDaemonFailedEvent(com.github.robozonky.api.notifications.RoboZonkyDaemonFailedEvent) InvestmentSkippedEvent(com.github.robozonky.api.notifications.InvestmentSkippedEvent) RoboZonkyInitializedEvent(com.github.robozonky.api.notifications.RoboZonkyInitializedEvent) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) LoanDelinquent30DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent30DaysOrMoreEvent) LoanDelinquent60DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent60DaysOrMoreEvent) RoboZonkyUpdateDetectedEvent(com.github.robozonky.api.notifications.RoboZonkyUpdateDetectedEvent) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) LoanDelinquent90DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent90DaysOrMoreEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RoboZonkyCrashedEvent(com.github.robozonky.api.notifications.RoboZonkyCrashedEvent) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) RoboZonkyExperimentalUpdateDetectedEvent(com.github.robozonky.api.notifications.RoboZonkyExperimentalUpdateDetectedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) TestFactory(org.junit.jupiter.api.TestFactory)

Example 2 with RoboZonkyTestingEvent

use of com.github.robozonky.api.notifications.RoboZonkyTestingEvent in project robozonky by RoboZonky.

the class EmailingListenerTest method spamProtectionAvailable.

@Test
void spamProtectionAvailable() throws IOException {
    // for some reason, JUnit 5 doesn't invoke this from the abstract parent
    this.deleteState();
    final Properties props = new Properties();
    props.load(NotificationPropertiesTest.class.getResourceAsStream("notifications-enabled.cfg"));
    // spam protection
    props.setProperty("hourlyMaxEmails", String.valueOf(1));
    final ListenerSpecificNotificationProperties p = new ListenerSpecificNotificationProperties(SupportedListener.TESTING, new NotificationProperties(props));
    final Consumer<RoboZonkyTestingEvent> c = mock(Consumer.class);
    final TestingEmailingListener l = new TestingEmailingListener(p);
    l.registerFinisher(c);
    // both spam protection and custom finisher available
    assertThat(l.countFinishers()).isEqualTo(2);
    l.handle(EVENT, SESSION_INFO);
    assertThat(EMAIL.getReceivedMessages()).hasSize(1);
    l.handle(EVENT, SESSION_INFO);
    // e-mail not re-sent, finisher not called again
    verify(c, times(1)).accept(any());
    assertThat(EMAIL.getReceivedMessages()).hasSize(1);
}
Also used : Properties(java.util.Properties) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 3 with RoboZonkyTestingEvent

use of com.github.robozonky.api.notifications.RoboZonkyTestingEvent in project robozonky by RoboZonky.

the class Checker method notifications.

public static boolean notifications(final String username, final List<EventListenerSupplier<RoboZonkyTestingEvent>> refreshables) {
    final Collection<EventListener<RoboZonkyTestingEvent>> listeners = refreshables.stream().flatMap(r -> r.get().map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
    if (listeners.size() > 0) {
        final SessionInfo sessionInfo = new SessionInfo(username);
        final RoboZonkyTestingEvent evt = new RoboZonkyTestingEvent();
        listeners.forEach(l -> l.handle(evt, sessionInfo));
        return true;
    } else {
        return false;
    }
}
Also used : EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Logger(org.slf4j.Logger) Collection(java.util.Collection) ApiProvider(com.github.robozonky.common.remote.ApiProvider) LoggerFactory(org.slf4j.LoggerFactory) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) List(java.util.List) Stream(java.util.stream.Stream) RequestId(com.github.robozonky.api.confirmations.RequestId) EventListener(com.github.robozonky.api.notifications.EventListener) Optional(java.util.Optional) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) Comparator(java.util.Comparator) ConfirmationProvider(com.github.robozonky.api.confirmations.ConfirmationProvider) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) EventListener(com.github.robozonky.api.notifications.EventListener) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent)

Aggregations

RoboZonkyTestingEvent (com.github.robozonky.api.notifications.RoboZonkyTestingEvent)3 ConfirmationProvider (com.github.robozonky.api.confirmations.ConfirmationProvider)1 RequestId (com.github.robozonky.api.confirmations.RequestId)1 EventListener (com.github.robozonky.api.notifications.EventListener)1 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)1 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)1 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)1 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)1 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)1 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)1 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)1 InvestmentSoldEvent (com.github.robozonky.api.notifications.InvestmentSoldEvent)1 LoanDefaultedEvent (com.github.robozonky.api.notifications.LoanDefaultedEvent)1 LoanDelinquent10DaysOrMoreEvent (com.github.robozonky.api.notifications.LoanDelinquent10DaysOrMoreEvent)1 LoanDelinquent30DaysOrMoreEvent (com.github.robozonky.api.notifications.LoanDelinquent30DaysOrMoreEvent)1 LoanDelinquent60DaysOrMoreEvent (com.github.robozonky.api.notifications.LoanDelinquent60DaysOrMoreEvent)1 LoanDelinquent90DaysOrMoreEvent (com.github.robozonky.api.notifications.LoanDelinquent90DaysOrMoreEvent)1 LoanNoLongerDelinquentEvent (com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent)1 LoanNowDelinquentEvent (com.github.robozonky.api.notifications.LoanNowDelinquentEvent)1 LoanRepaidEvent (com.github.robozonky.api.notifications.LoanRepaidEvent)1