use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class PurchasingDaemon method execute.
@Override
protected void execute(final Portfolio portfolio, final Authenticated authenticated) {
final long balance = portfolio.getRemoteBalance().get().longValue();
final Select s = new Select().lessThanOrEquals("remainingPrincipal", balance);
final Collection<Participation> p = authenticated.call(zonky -> zonky.getAvailableParticipations(s).collect(Collectors.toList()));
purchasing.apply(portfolio, p);
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class ParticipationDescriptorTest method equals.
@Test
void equals() {
final Participation p = ParticipationDescriptorTest.mockParticipation(BigDecimal.TEN);
final ParticipationDescriptor pd = new ParticipationDescriptor(p);
assertSoftly(softly -> {
softly.assertThat(pd).isNotEqualTo(null);
softly.assertThat(pd).isNotEqualTo(UUID.randomUUID().toString());
softly.assertThat(pd).isEqualTo(pd);
});
final ParticipationDescriptor pd2 = new ParticipationDescriptor(p);
assertSoftly(softly -> {
softly.assertThat(pd).isEqualTo(pd2);
softly.assertThat(pd2).isEqualTo(pd);
});
final ParticipationDescriptor pd3 = new ParticipationDescriptor(ParticipationDescriptorTest.mockParticipation(BigDecimal.ONE));
assertSoftly(softly -> {
softly.assertThat(pd).isNotEqualTo(pd3);
});
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class SessionTest method underBalance.
@Test
void underBalance() {
final Participation p = mock(Participation.class);
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
final Loan l = Loan.custom().build();
final PurchaseStrategy s = mock(PurchaseStrategy.class);
when(s.recommend(any(), any(), any())).thenAnswer(i -> {
final Collection<ParticipationDescriptor> participations = i.getArgument(0);
return participations.stream().map(ParticipationDescriptor::recommend).flatMap(o -> o.map(Stream::of).orElse(Stream.empty()));
});
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
final Zonky z = mockZonky();
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
assertSoftly(softly -> {
softly.assertThat(i).isEmpty();
softly.assertThat(this.getNewEvents()).has(new Condition<List<? extends Event>>() {
@Override
public boolean matches(final List<? extends Event> events) {
return events.stream().noneMatch(e -> e instanceof PurchaseRequestedEvent);
}
});
});
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class SessionTest method properDryRun.
@Test
void properDryRun() {
final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setRemainingInvestment(200).setMyInvestment(mockMyInvestment()).build();
final Participation p = mock(Participation.class);
when(p.getLoanId()).thenReturn(l.getId());
when(p.getRemainingPrincipal()).thenReturn(BigDecimal.valueOf(200));
final PurchaseStrategy s = mock(PurchaseStrategy.class);
when(s.recommend(any(), any(), any())).thenAnswer(i -> {
final Collection<ParticipationDescriptor> participations = i.getArgument(0);
return participations.stream().map(ParticipationDescriptor::recommend).flatMap(o -> o.map(Stream::of).orElse(Stream.empty()));
});
final Zonky z = mockZonky(BigDecimal.valueOf(100_000));
when(z.getLoan(eq(l.getId()))).thenReturn(l);
final Authenticated auth = mockAuthentication(z);
final Portfolio portfolio = spy(Portfolio.create(z, mockBalance(z)));
final ParticipationDescriptor pd = new ParticipationDescriptor(p, l);
final Collection<Investment> i = Session.purchase(portfolio, auth, Stream.of(pd), new RestrictedPurchaseStrategy(s, new Restrictions()), true);
assertThat(i).hasSize(1);
assertThat(this.getNewEvents()).hasSize(5);
verify(z, never()).purchase(eq(p));
verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
use of com.github.robozonky.api.remote.entities.Participation in project robozonky by RoboZonky.
the class NaturalLanguagePurchaseStrategyTest method nothingRecommendedDueToRatingOverinvested.
@Test
void nothingRecommendedDueToRatingOverinvested() {
final ParsedStrategy p = new ParsedStrategy(DefaultPortfolio.EMPTY);
final PurchaseStrategy s = new NaturalLanguagePurchaseStrategy(p);
final PortfolioOverview portfolio = mock(PortfolioOverview.class);
when(portfolio.getCzkAvailable()).thenReturn(p.getMinimumBalance());
when(portfolio.getCzkInvested()).thenReturn(p.getMaximumInvestmentSizeInCzk() - 1);
when(portfolio.getShareOnInvestment(any())).thenReturn(BigDecimal.ZERO);
final Participation l = mockParticipation();
doReturn(Rating.A).when(l).getRating();
final Stream<RecommendedParticipation> result = s.recommend(Collections.singletonList(mockDescriptor(l)), portfolio, new Restrictions());
assertThat(result).isEmpty();
}
Aggregations