Search in sources :

Example 16 with RecommendedLoan

use of com.github.robozonky.api.strategies.RecommendedLoan in project robozonky by RoboZonky.

the class SessionTest method investmentFailed.

@Test
void investmentFailed() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
    final Exception thrown = new ServiceUnavailableException();
    final Investor p = mock(Investor.class);
    doThrow(thrown).when(p).invest(eq(r), anyBoolean());
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
    assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 17 with RecommendedLoan

use of com.github.robozonky.api.strategies.RecommendedLoan in project robozonky by RoboZonky.

the class NaturalLanguageInvestmentStrategyTest method recommendationIsMade.

@Test
void recommendationIsMade() {
    final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.PROGRESSIVE, Collections.emptySet());
    final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
    when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
    final Loan l = mockLoan(100_000);
    final Loan l2 = mockLoan(100);
    final LoanDescriptor ld = new LoanDescriptor(l);
    final List<RecommendedLoan> result = s.recommend(Arrays.asList(new LoanDescriptor(l2), ld), portfolio, new Restrictions()).collect(Collectors.toList());
    assertThat(result).hasSize(1);
    final RecommendedLoan r = result.get(0);
    assertSoftly(softly -> {
        softly.assertThat(r.descriptor()).isEqualTo(ld);
        softly.assertThat(r.amount()).isEqualTo(BigDecimal.valueOf(Defaults.MINIMUM_INVESTMENT_IN_CZK));
        softly.assertThat(r.isConfirmationRequired()).isFalse();
    });
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Example 18 with RecommendedLoan

use of com.github.robozonky.api.strategies.RecommendedLoan in project robozonky by RoboZonky.

the class NaturalLanguageInvestmentStrategyTest method unacceptablePortfolioDueToOverInvestment.

@Test
void unacceptablePortfolioDueToOverInvestment() {
    final DefaultValues v = new DefaultValues(DefaultPortfolio.EMPTY);
    v.setTargetPortfolioSize(1000);
    final ParsedStrategy p = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap());
    final InvestmentStrategy s = new NaturalLanguageInvestmentStrategy(p);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk());
    final Stream<RecommendedLoan> result = s.recommend(Collections.singletonList(new LoanDescriptor(mockLoan(2))), portfolio, new Restrictions());
    assertThat(result).isEmpty();
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) Test(org.junit.jupiter.api.Test)

Aggregations

RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)18 Test (org.junit.jupiter.api.Test)15 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)12 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)11 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)11 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)11 Event (com.github.robozonky.api.notifications.Event)10 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)10 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)9 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)9 Authenticated (com.github.robozonky.app.authentication.Authenticated)9 Portfolio (com.github.robozonky.app.portfolio.Portfolio)9 InvestmentRequestedEvent (com.github.robozonky.api.notifications.InvestmentRequestedEvent)8 LoanRecommendedEvent (com.github.robozonky.api.notifications.LoanRecommendedEvent)8 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)8 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)8 Zonky (com.github.robozonky.common.remote.Zonky)8 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)5 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)5 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)5