Search in sources :

Example 6 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan 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);
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) TestFactory(org.junit.jupiter.api.TestFactory) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) BeforeAll(org.junit.jupiter.api.BeforeAll) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Assertions(org.assertj.core.api.Assertions) ShutdownHook(com.github.robozonky.app.ShutdownHook) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) EventListener(com.github.robozonky.api.notifications.EventListener) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) DynamicTest(org.junit.jupiter.api.DynamicTest) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest) Collections(java.util.Collections) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) SoftAssertions(org.assertj.core.api.SoftAssertions) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment)

Example 7 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan 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);
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) TestFactory(org.junit.jupiter.api.TestFactory) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) AfterAll(org.junit.jupiter.api.AfterAll) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) BeforeAll(org.junit.jupiter.api.BeforeAll) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Assertions(org.assertj.core.api.Assertions) ShutdownHook(com.github.robozonky.app.ShutdownHook) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) EventListener(com.github.robozonky.api.notifications.EventListener) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) DynamicTest(org.junit.jupiter.api.DynamicTest) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest) Collections(java.util.Collections) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) SoftAssertions(org.assertj.core.api.SoftAssertions) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor)

Example 8 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class DelinquentsTest method noLongerDelinquent.

@Test
void noLongerDelinquent() {
    final PortfolioOverview po = mock(PortfolioOverview.class);
    final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
    final Function<Investment, Loan> f = (id) -> l;
    // register delinquence
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    // ignore events just emitted
    this.readPreexistingEvents();
    // the investment is no longer delinquent
    Delinquents.update(Collections.emptyList(), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanNoLongerDelinquentEvent.class);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 9 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class DelinquentsTest method paid.

@Test
void paid() {
    final PortfolioOverview po = mock(PortfolioOverview.class);
    final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.PAID).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
    final Function<Investment, Loan> f = (id) -> l;
    // register delinquence
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    // ignore events just emitted
    this.readPreexistingEvents();
    // the investment is paid
    Delinquents.update(Collections.emptyList(), Collections.singletonList(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanRepaidEvent.class);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 10 with Loan

use of com.github.robozonky.api.remote.entities.sanitized.Loan in project robozonky by RoboZonky.

the class DelinquentsTest method defaulted.

@Test
void defaulted() {
    final PortfolioOverview po = mock(PortfolioOverview.class);
    final Loan l = Loan.custom().setId(RANDOM.nextInt(10000)).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.PAID_OFF).setNextPaymentDate(OffsetDateTime.ofInstant(Instant.EPOCH, Defaults.ZONE_ID)).build();
    final Function<Investment, Loan> f = (id) -> l;
    // register delinquency
    Delinquents.update(Collections.singleton(i), Collections.emptyList(), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    // ignore events just emitted
    this.readPreexistingEvents();
    // the investment is defaulted
    Delinquents.update(Collections.emptyList(), Collections.singletonList(i), po, INVESTMENT_SUPPLIER, f, COLLECTIONS_SUPPLIER);
    assertThat(this.getNewEvents()).hasSize(1).first().isInstanceOf(LoanDefaultedEvent.class);
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Random(java.util.Random) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) Development(com.github.robozonky.api.remote.entities.sanitized.Development) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Instant(java.time.Instant) Function(java.util.function.Function) PaymentStatus(com.github.robozonky.api.remote.enums.PaymentStatus) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) LocalDate(java.time.LocalDate) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Defaults(com.github.robozonky.internal.api.Defaults) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)53 Test (org.junit.jupiter.api.Test)46 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)25 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)20 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)19 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)14 Zonky (com.github.robozonky.common.remote.Zonky)14 SoftAssertions (org.assertj.core.api.SoftAssertions)14 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Assertions (org.assertj.core.api.Assertions)13 Mockito (org.mockito.Mockito)13 Event (com.github.robozonky.api.notifications.Event)12 Portfolio (com.github.robozonky.app.portfolio.Portfolio)12 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 Stream (java.util.stream.Stream)10 Optional (java.util.Optional)9 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)8 Participation (com.github.robozonky.api.remote.entities.Participation)8