use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.
the class PurchasingDaemonTest method standard.
@Test
void standard() {
final Zonky z = harmlessZonky(10_000);
final Authenticated a = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Supplier<Optional<PurchaseStrategy>> s = Optional::empty;
final PurchasingDaemon d = new PurchasingDaemon(t -> {
}, a, s, () -> Optional.of(portfolio), Duration.ZERO, true);
d.run();
verify(z, times(1)).getAvailableParticipations(any());
}
use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.
the class InvestingTest method noneAccepted.
@Test
void noneAccepted() {
// new ID every time to avoid caches
final int loanId = (int) (Math.random() * 1000);
final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
final LoanDescriptor ld = new LoanDescriptor(loan);
final Investor.Builder builder = new Investor.Builder().asDryRun();
final Zonky z = harmlessZonky(9000);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
when(z.getLoan(eq(loanId))).thenReturn(loan);
final Authenticated auth = mockAuthentication(z);
final Investing exec = new Investing(builder, NONE_ACCEPTING, auth);
assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.
the class InvestingTest method noStrategy.
@Test
void noStrategy() {
// new ID every time to avoid caches
final int loanId = (int) (Math.random() * 1000);
final Loan loan = Loan.custom().setId(loanId).setAmount(2).build();
final LoanDescriptor ld = new LoanDescriptor(loan);
final Investing exec = new Investing(null, Optional::empty, null);
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(1000);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
assertThat(exec.apply(portfolio, Collections.singletonList(ld))).isEmpty();
// check events
final List<Event> events = this.getNewEvents();
assertThat(events).isEmpty();
}
use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.
the class InvestingTest method someAccepted.
@Test
void someAccepted() {
// new ID every time to avoid caches
final int loanId = (int) (Math.random() * 1000);
final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setRemainingInvestment(20_000).setDatePublished(OffsetDateTime.now()).build();
final LoanDescriptor ld = new LoanDescriptor(loan);
final Investor.Builder builder = new Investor.Builder().asDryRun();
final Zonky z = harmlessZonky(10_000);
when(z.getLoan(eq(loanId))).thenReturn(loan);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Authenticated auth = mockAuthentication(z);
final Investing exec = new Investing(builder, ALL_ACCEPTING, auth);
final Collection<Investment> result = exec.apply(portfolio, Collections.singleton(ld));
// dry run
verify(z, never()).invest(any());
assertThat(result).extracting(Investment::getLoanId).isEqualTo(Collections.singletonList(loanId));
// re-check; no balance changed, no marketplace changed, nothing should happen
assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.
the class SessionTest method investmentDelegatedButExpectedConfirmed.
@Test
void investmentDelegatedButExpectedConfirmed() {
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
final RecommendedLoan r = ld.recommend(200, true).get();
final Collection<LoanDescriptor> availableLoans = Collections.singletonList(ld);
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
final Authenticated auth = mockAuthentication(z);
final Investor p = mock(Investor.class);
doReturn(new ZonkyResponse(ZonkyResponseType.DELEGATED)).when(p).invest(eq(r), anyBoolean());
doReturn(Optional.of("something")).when(p).getConfirmationProviderId();
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Session t = new Session(portfolio, new LinkedHashSet<>(availableLoans), p, auth);
final boolean result = t.invest(r);
assertThat(result).isFalse();
// validate event
final List<Event> newEvents = this.getNewEvents();
assertThat(newEvents).hasSize(2);
assertSoftly(softly -> {
softly.assertThat(newEvents.get(0)).isInstanceOf(InvestmentRequestedEvent.class);
softly.assertThat(newEvents.get(1)).isInstanceOf(InvestmentDelegatedEvent.class);
});
}
Aggregations