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());
}
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();
}
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);
});
}
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();
}
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));
}
Aggregations