Search in sources :

Example 26 with LoanDescriptor

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

the class AbstractZonkyLeveragingTest method mockLoanDescriptor.

private static LoanDescriptor mockLoanDescriptor(final int loanId, final boolean withCaptcha) {
    final LoanBuilder b = Loan.custom().setId(loanId).setRemainingInvestment(Integer.MAX_VALUE).setDatePublished(OffsetDateTime.now()).setMyInvestment(mockMyInvestment());
    if (withCaptcha) {
        // enable CAPTCHA for the rating
        System.setProperty(Settings.Key.CAPTCHA_DELAY_D.getName(), "120");
        b.setRating(Rating.D);
    } else {
        // disable CAPTCHA for the rating
        System.setProperty(Settings.Key.CAPTCHA_DELAY_AAAAA.getName(), "0");
        b.setRating(Rating.AAAAA);
    }
    return new LoanDescriptor(b.build());
}
Also used : LoanBuilder(com.github.robozonky.api.remote.entities.sanitized.LoanBuilder) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor)

Example 27 with LoanDescriptor

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

the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.

@Test
void rechecksMarketplaceIfFirstCheckFailed() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final Loan loan = Loan.custom().build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Collection<LoanDescriptor> marketplace = Collections.singleton(ld);
    // prepare the executor, have it fail when executing the investment operation
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = new AlwaysFreshNeverInvesting();
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> mocked = spy(e);
    doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
    Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
    // now the method won't throw, but must be executed again
    reset(mocked);
    mocked.apply(p, marketplace);
    verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
    // marketplace stays the same + balance stays the same+  previous update passed = no update should be triggered
    reset(mocked);
    when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
    mocked.apply(p, marketplace);
    verify(mocked, never()).execute(any(), any(), any());
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 28 with LoanDescriptor

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

the class StrategyExecutorTest method doesNotInvestOnEmptyMarketplace.

@Test
void doesNotInvestOnEmptyMarketplace() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = spy(new AlwaysFreshNeverInvesting());
    e.apply(p, Collections.emptyList());
    verify(e, never()).execute(any(), any(), any());
}
Also used : Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 29 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor 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 30 with LoanDescriptor

use of com.github.robozonky.api.strategies.LoanDescriptor 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

LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)34 Test (org.junit.jupiter.api.Test)29 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)17 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)15 Portfolio (com.github.robozonky.app.portfolio.Portfolio)15 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)13 Zonky (com.github.robozonky.common.remote.Zonky)12 InvestmentStrategy (com.github.robozonky.api.strategies.InvestmentStrategy)11 Authenticated (com.github.robozonky.app.authentication.Authenticated)11 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)10 Event (com.github.robozonky.api.notifications.Event)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 PortfolioOverview (com.github.robozonky.api.strategies.PortfolioOverview)8 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)7 MarketplaceLoan (com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan)7 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)6 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)6 Restrictions (com.github.robozonky.api.remote.entities.Restrictions)6