Search in sources :

Example 11 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class PurchasingTest method noneAccepted.

@Test
void noneAccepted() {
    final Zonky zonky = mockApi();
    final Participation mock = mock(Participation.class);
    when(mock.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(250));
    final Purchasing exec = new Purchasing(NONE_ACCEPTING, mockAuthentication(zonky), true);
    final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
    final List<Event> e = this.getNewEvents();
    assertThat(e).hasSize(2);
    assertSoftly(softly -> {
        softly.assertThat(e).first().isInstanceOf(PurchasingStartedEvent.class);
        softly.assertThat(e).last().isInstanceOf(PurchasingCompletedEvent.class);
    });
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Portfolio(com.github.robozonky.app.portfolio.Portfolio) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) PurchaseRecommendedEvent(com.github.robozonky.api.notifications.PurchaseRecommendedEvent) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 12 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class PurchasingTest method noStrategy.

@Test
void noStrategy() {
    final Participation mock = mock(Participation.class);
    final Purchasing exec = new Purchasing(Optional::empty, null, true);
    final Portfolio portfolio = mock(Portfolio.class);
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
    // check events
    final List<Event> events = this.getNewEvents();
    assertThat(events).isEmpty();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) PurchaseRecommendedEvent(com.github.robozonky.api.notifications.PurchaseRecommendedEvent) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 13 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class PurchasingTest method someAccepted.

@Test
void someAccepted() {
    final int loanId = 1;
    final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setRemainingInvestment(1000).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
    final Zonky zonky = mockApi();
    when(zonky.getLoan(eq(loanId))).thenReturn(loan);
    final Participation mock = mock(Participation.class);
    when(mock.getId()).thenReturn(1);
    when(mock.getLoanId()).thenReturn(loan.getId());
    when(mock.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(250));
    when(mock.getRating()).thenReturn(loan.getRating());
    final Purchasing exec = new Purchasing(ALL_ACCEPTING, mockAuthentication(zonky), true);
    final Portfolio portfolio = Portfolio.create(zonky, mockBalance(zonky));
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isNotEmpty();
    // purchase as balance changed
    verify(zonky, never()).purchase(eq(mock));
    final List<Event> e = this.getNewEvents();
    assertThat(e).hasSize(5);
    assertSoftly(softly -> {
        softly.assertThat(e).first().isInstanceOf(PurchasingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(PurchaseRecommendedEvent.class);
        softly.assertThat(e.get(2)).isInstanceOf(PurchaseRequestedEvent.class);
        softly.assertThat(e.get(3)).isInstanceOf(InvestmentPurchasedEvent.class);
        softly.assertThat(e).last().isInstanceOf(PurchasingCompletedEvent.class);
    });
    // purchase as marketplace first initialized
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isNotEmpty();
    // no balance change, no marketplace change => don't purchase
    assertThat(exec.apply(portfolio, Collections.singleton(mock))).isEmpty();
    // nothing changed, so no more purchase
    verify(zonky, never()).purchase(eq(mock));
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) PurchasingStartedEvent(com.github.robozonky.api.notifications.PurchasingStartedEvent) PurchasingCompletedEvent(com.github.robozonky.api.notifications.PurchasingCompletedEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) Event(com.github.robozonky.api.notifications.Event) PurchaseRecommendedEvent(com.github.robozonky.api.notifications.PurchaseRecommendedEvent) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 14 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class SessionTest method empty.

@Test
void empty() {
    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.empty(), null, true);
    assertThat(i).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 15 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class SessionTest method properReal.

@Test
void properReal() {
    final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setRemainingInvestment(200).setMyInvestment(mockMyInvestment()).build();
    final Participation p = mock(Participation.class);
    when(p.getLoanId()).thenReturn(l.getId());
    when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
    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 Zonky z = mockZonky(BigDecimal.valueOf(100_000));
    when(z.getLoan(eq(l.getId()))).thenReturn(l);
    final Authenticated auth = mockAuthentication(z);
    final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
    final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
    final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), false);
    assertThat(i).hasSize(1);
    assertThat(this.getNewEvents()).hasSize(5);
    verify(z).purchase(eq(p));
    verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
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) 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) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Stream(java.util.stream.Stream) 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

Portfolio (com.github.robozonky.app.portfolio.Portfolio)38 Test (org.junit.jupiter.api.Test)34 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)33 Zonky (com.github.robozonky.common.remote.Zonky)30 Authenticated (com.github.robozonky.app.authentication.Authenticated)29 Event (com.github.robozonky.api.notifications.Event)16 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)13 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)12 Optional (java.util.Optional)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)9 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)8 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 InvestmentRequestedEvent (com.github.robozonky.api.notifications.InvestmentRequestedEvent)8 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)8 LoanRecommendedEvent (com.github.robozonky.api.notifications.LoanRecommendedEvent)8 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)8 PurchaseRequestedEvent (com.github.robozonky.api.notifications.PurchaseRequestedEvent)7