Search in sources :

Example 6 with Participation

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

the class ZonkyTest method sell.

@Test
void sell() {
    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 p = Investment.custom().setRemainingPrincipal(BigDecimal.TEN).setSmpFee(BigDecimal.ONE).setId(1).build();
    z.sell(p);
    verify(control).offer(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) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 7 with Participation

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

the class ZonkyTest method investAndlogout.

@Test
void investAndlogout() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final int loanId = 1;
    final RawLoan loan = mock(RawLoan.class);
    when(loan.getId()).thenReturn(loanId);
    when(loan.getAmount()).thenReturn(200.0);
    when(loan.getRemainingInvestment()).thenReturn(200.0);
    when(la.execute((Function<LoanApi, RawLoan>) any())).thenReturn(loan);
    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 Loan l = z.getLoan(loanId);
    final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
    z.invest(i);
    z.logout();
    verify(control, times(1)).invest(any());
    verify(control, times(1)).logout();
}
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) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) 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)

Example 8 with Participation

use of com.github.robozonky.api.remote.entities.Participation 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 9 with Participation

use of com.github.robozonky.api.remote.entities.Participation 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 10 with Participation

use of com.github.robozonky.api.remote.entities.Participation 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)

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