use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class SessionStateTest method discardPersistence.
@Test
void discardPersistence() {
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
final Collection<LoanDescriptor> lds = Arrays.asList(ld, AbstractZonkyLeveragingTest.mockLoanDescriptor());
// ignore the loan and persist
final SessionState it = new SessionState(lds);
it.discard(ld);
assertThat(it.getSeenLoans()).isEmpty();
assertThat(it.getDiscardedLoans()).isNotEmpty().contains(ld);
// load again and check that persisted
final SessionState it2 = new SessionState(lds);
assertThat(it.getSeenLoans()).isEmpty();
assertThat(it2.getDiscardedLoans()).isNotEmpty().contains(ld);
}
use of com.github.robozonky.api.strategies.LoanDescriptor 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);
});
}
use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class SessionTest method makeInvestment.
@Test
void makeInvestment() {
// setup APIs
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(200);
// run test
final int amount = 200;
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptorWithoutCaptcha();
final int loanId = ld.item().getId();
when(z.getLoan(eq(loanId))).thenReturn(ld.item());
final Authenticated auth = mockAuthentication(z);
final Collection<LoanDescriptor> lds = Arrays.asList(ld, AbstractZonkyLeveragingTest.mockLoanDescriptor());
final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
final Collection<Investment> i = Session.invest(portfolio, getInvestor(auth), auth, lds, mockStrategy(loanId, amount));
// check that one investment was made
assertThat(i).hasSize(1);
final List<Event> newEvents = this.getNewEvents();
assertThat(newEvents).hasSize(5);
assertSoftly(softly -> {
softly.assertThat(newEvents.get(0)).isInstanceOf(ExecutionStartedEvent.class);
softly.assertThat(newEvents.get(1)).isInstanceOf(LoanRecommendedEvent.class);
softly.assertThat(newEvents.get(2)).isInstanceOf(InvestmentRequestedEvent.class);
softly.assertThat(newEvents.get(3)).isInstanceOf(InvestmentMadeEvent.class);
softly.assertThat(newEvents.get(4)).isInstanceOf(ExecutionCompletedEvent.class);
});
verify(portfolio).newBlockedAmount(eq(auth), argThat(a -> a.getLoanId() == loanId));
}
use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class SessionTest method investmentDelegated.
@Test
void investmentDelegated() {
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor();
final RecommendedLoan r = ld.recommend(200).get();
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 Collection<LoanDescriptor> availableLoans = Collections.singletonList(ld);
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);
});
}
use of com.github.robozonky.api.strategies.LoanDescriptor in project robozonky by RoboZonky.
the class SessionTest method discardingInvestments.
@Test
void discardingInvestments() {
final int loanId = 1, loanId2 = 2;
final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor(loanId);
final LoanDescriptor ld2 = AbstractZonkyLeveragingTest.mockLoanDescriptor(loanId2);
final Collection<LoanDescriptor> lds = Arrays.asList(ld, ld2, AbstractZonkyLeveragingTest.mockLoanDescriptor());
// discard the loan
final SessionState sst = new SessionState(lds);
sst.discard(ld);
// setup APIs
final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
when(z.getLoan(eq(loanId2))).thenReturn(ld2.item());
final Authenticated auth = mockAuthentication(z);
// prepare portfolio that has the other loan as pending
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
portfolio.newBlockedAmount(auth, new BlockedAmount(loanId2, BigDecimal.valueOf(200), TransactionCategory.SMP_BUY));
// test that the loans are not available
final Session it = new Session(portfolio, new LinkedHashSet<>(lds), getInvestor(auth), auth);
assertSoftly(softly -> {
softly.assertThat(it.getAvailable()).hasSize(1).doesNotContain(ld, ld2);
softly.assertThat(it.getResult()).isEmpty();
});
}
Aggregations