Search in sources :

Example 36 with Investment

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

the class PortfolioTest method getActiveForSecondaryMarketplace.

@Test
void getActiveForSecondaryMarketplace() {
    final Investment i = mockInvestment(true, true);
    final Investment i2 = mockInvestment(true, false);
    final Investment i3 = mockInvestment(false, false);
    final Investment i4 = mockInvestment(false, true);
    // ignored because sold
    final Investment i5 = mockSold();
    final Portfolio instance = new Portfolio(Arrays.asList(i, i2, i3, i4, i5), null);
    assertThat(instance.getActiveForSecondaryMarketplace()).containsExactly(i2);
}
Also used : Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 37 with Investment

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

the class PortfolioTest method getActiveWithPaymentStatus.

@Test
void getActiveWithPaymentStatus() {
    final Investment i = mockInvestment(PaymentStatus.OK);
    final Investment i2 = mockInvestment(PaymentStatus.DUE);
    // ignored because not interested
    final Investment i3 = mockInvestment(PaymentStatus.WRITTEN_OFF);
    // ignored because sold
    final Investment i4 = mockSold();
    final Portfolio instance = new Portfolio(Arrays.asList(i, i2, i3, i4), null);
    final PaymentStatuses p = PaymentStatuses.of(PaymentStatus.OK, PaymentStatus.DUE);
    assertThat(instance.getActiveWithPaymentStatus(p)).containsExactly(i, i2);
}
Also used : PaymentStatuses(com.github.robozonky.api.remote.enums.PaymentStatuses) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 38 with Investment

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

the class SellingTest method saleMade.

private void saleMade(final boolean isDryRun) {
    final Investment i = mockInvestment();
    final Zonky zonky = mockApi();
    final Portfolio portfolio = new Portfolio(Collections.singleton(i), mockBalance(zonky));
    new Selling(ALL_ACCEPTING, isDryRun).accept(portfolio, mockAuthentication(zonky));
    final List<Event> e = getNewEvents();
    assertThat(e).hasSize(5);
    assertSoftly(softly -> {
        softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(SaleRecommendedEvent.class);
        softly.assertThat(e.get(2)).isInstanceOf(SaleRequestedEvent.class);
        softly.assertThat(e.get(3)).isInstanceOf(SaleOfferedEvent.class);
        softly.assertThat(e.get(4)).isInstanceOf(SellingCompletedEvent.class);
    });
    final VerificationMode m = isDryRun ? never() : times(1);
    assertThat(i.isOnSmp()).isTrue();
    verify(zonky, m).sell(argThat(inv -> i.getLoanId() == inv.getLoanId()));
}
Also used : InvestmentStatus(com.github.robozonky.api.remote.enums.InvestmentStatus) SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky) Supplier(java.util.function.Supplier) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) Test(org.junit.jupiter.api.Test) VerificationMode(org.mockito.verification.VerificationMode) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) VerificationMode(org.mockito.verification.VerificationMode) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Zonky(com.github.robozonky.common.remote.Zonky)

Example 39 with Investment

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

the class SellingTest method noSaleDueToStrategyForbidding.

@Test
void noSaleDueToStrategyForbidding() {
    final Investment i = mockInvestment();
    final Zonky zonky = mockApi();
    final Portfolio portfolio = new Portfolio(Collections.singleton(i), mockBalance(zonky));
    new Selling(NONE_ACCEPTING, true).accept(portfolio, mockAuthentication(zonky));
    final List<Event> e = getNewEvents();
    assertThat(e).hasSize(2);
    assertSoftly(softly -> {
        softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(SellingCompletedEvent.class);
    });
    verify(zonky, never()).sell(eq(i));
}
Also used : SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 40 with Investment

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

the class SessionTest method underBalance.

@Test
void underBalance() {
    final Participation p = mock(Participation.class);
    when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
    final Loan l = Loan.custom().build();
    final PurchaseStrategy s = mock(PurchaseStrategy.class);
    when(s.recommend(any(), any(), any())).thenAnswer(i -> {
        final Collection<ParticipationDescriptor> participations = i.getArgument(0);
        return participations.stream().map(ParticipationDescriptor::recommend).flatMap(o -> o.map(Stream::of).orElse(Stream.empty()));
    });
    final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
    final Zonky z = mockZonky();
    final Authenticated auth = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
    assertSoftly(softly -> {
        softly.assertThat(i).isEmpty();
        softly.assertThat(this.getNewEvents()).has(new Condition<List<? extends Event>>() {

            @Override
            public boolean matches(final List<? extends Event> events) {
                return events.stream().noneMatch(e -> e instanceof PurchaseRequestedEvent);
            }
        });
    });
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Event(com.github.robozonky.api.notifications.Event) Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Authenticated(com.github.robozonky.app.authentication.Authenticated) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Condition(org.assertj.core.api.Condition) Rating(com.github.robozonky.api.remote.enums.Rating) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Participation(com.github.robozonky.api.remote.entities.Participation) Participation(com.github.robozonky.api.remote.entities.Participation) Authenticated(com.github.robozonky.app.authentication.Authenticated) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Event(com.github.robozonky.api.notifications.Event) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Stream(java.util.stream.Stream) List(java.util.List) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)52 Test (org.junit.jupiter.api.Test)34 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)24 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)20 BigDecimal (java.math.BigDecimal)20 Event (com.github.robozonky.api.notifications.Event)13 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)13 Authenticated (com.github.robozonky.app.authentication.Authenticated)13 Zonky (com.github.robozonky.common.remote.Zonky)13 Collection (java.util.Collection)13 Assertions (org.assertj.core.api.Assertions)13 SoftAssertions (org.assertj.core.api.SoftAssertions)13 Mockito (org.mockito.Mockito)13 Collections (java.util.Collections)12 Stream (java.util.stream.Stream)11 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)10 Portfolio (com.github.robozonky.app.portfolio.Portfolio)9 Participation (com.github.robozonky.api.remote.entities.Participation)8 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7