Search in sources :

Example 21 with Participation

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

the class NaturalLanguagePurchaseStrategyTest method recommendationIsMade.

@Test
void recommendationIsMade() {
    final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
    final ParsedStrategy ps = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap(), new FilterSupplier(v, null, Collections.emptySet()));
    final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(ps);
    final PortfolioOverview portfolio = mock(PortfolioOverview.class);
    when(portfolio.getCzkAvailable()).thenReturn(ps.getMinimumBalance());
    when(portfolio.getCzkInvested()).thenReturn(ps.getMaximumInvestmentSizeInCzk() - 1);
    when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
    final Participation p = spy(mockParticipation());
    // not recommended due to balance
    doReturn(BigDecimal.valueOf(100000)).when(p).getRemainingPrincipal();
    doReturn(Rating.A).when(p).getRating();
    final Participation p2 = spy(mockParticipation());
    // check amounts under Zonky investment minimum
    final int amount = Defaults.MINIMUM_INVESTMENT_IN_CZK - 1;
    doReturn(BigDecimal.valueOf(amount)).when(p2).getRemainingPrincipal();
    doReturn(Rating.A).when(p2).getRating();
    final ParticipationDescriptor pd = mockDescriptor(p2);
    final List<RecommendedParticipation> result = s.recommend(Arrays.asList(mockDescriptor(p), pd), portfolio, new Restrictions()).collect(Collectors.toList());
    assertThat(result).hasSize(1);
    final RecommendedParticipation r = result.get(0);
    assertSoftly(softly -> {
        softly.assertThat(r.descriptor()).isEqualTo(pd);
        softly.assertThat(r.amount()).isEqualTo(pd.item().getRemainingPrincipal());
    });
}
Also used : RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Participation(com.github.robozonky.api.remote.entities.Participation) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) RecommendedParticipation(com.github.robozonky.api.strategies.RecommendedParticipation) Test(org.junit.jupiter.api.Test)

Example 22 with Participation

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

the class ParsedStrategyTest method matchesAlsoSellFilter.

@Test
void matchesAlsoSellFilter() {
    final MarketplaceFilter accepting = MarketplaceFilter.of(MarketplaceFilterCondition.alwaysAccepting());
    final Collection<MarketplaceFilter> filters = Collections.singleton(accepting);
    final DefaultValues v = new DefaultValues(DefaultPortfolio.PROGRESSIVE);
    final FilterSupplier s = new FilterSupplier(v, Collections.emptySet(), Collections.emptySet(), filters);
    final ParsedStrategy ps = new ParsedStrategy(v, Collections.emptyList(), Collections.emptyMap(), s);
    final Loan l = mockLoan(200_000);
    final LoanDescriptor ld = new LoanDescriptor(l);
    assertThat(ps.getApplicableLoans(Collections.singleton(ld))).isEmpty();
    final Participation p = mock(Participation.class);
    final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
    assertThat(ps.getApplicableParticipations(Collections.singleton(pd))).isEmpty();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) MarketplaceFilter(com.github.robozonky.strategy.natural.conditions.MarketplaceFilter) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Test(org.junit.jupiter.api.Test)

Example 23 with Participation

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

the class ZonkyTest method purchase.

@Test
void purchase() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Participation p = mock(Participation.class);
    when(p.getRemainingPrincipal()).thenReturn(BigDecimal.TEN);
    when(p.getId()).thenReturn(1);
    z.purchase(p);
    verify(control).purchase(eq(p.getId()), any());
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 24 with Participation

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

the class ZonkyTest method cancel.

@Test
void cancel() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Investment i = mock(Investment.class);
    when(i.getId()).thenReturn(1);
    z.cancel(i);
    verify(control).cancel(eq(i.getId()));
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Aggregations

Participation (com.github.robozonky.api.remote.entities.Participation)24 Test (org.junit.jupiter.api.Test)18 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)8 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)8 PurchaseRequestedEvent (com.github.robozonky.api.notifications.PurchaseRequestedEvent)7 ParticipationDescriptor (com.github.robozonky.api.strategies.ParticipationDescriptor)7 Portfolio (com.github.robozonky.app.portfolio.Portfolio)7 Event (com.github.robozonky.api.notifications.Event)6 PurchaseStrategy (com.github.robozonky.api.strategies.PurchaseStrategy)6 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)6 CollectionsApi (com.github.robozonky.api.remote.CollectionsApi)5 ControlApi (com.github.robozonky.api.remote.ControlApi)5 LoanApi (com.github.robozonky.api.remote.LoanApi)5 ParticipationApi (com.github.robozonky.api.remote.ParticipationApi)5 PortfolioApi (com.github.robozonky.api.remote.PortfolioApi)5 WalletApi (com.github.robozonky.api.remote.WalletApi)5 BlockedAmount (com.github.robozonky.api.remote.entities.BlockedAmount)5 RawDevelopment (com.github.robozonky.api.remote.entities.RawDevelopment)5 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)5 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)5