Search in sources :

Example 11 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class SessionTest method underAmount.

@Test
void underAmount() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(0);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan recommendation = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(Defaults.MINIMUM_INVESTMENT_IN_CZK).get();
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.singleton(recommendation.descriptor()), getInvestor(auth), auth);
    final boolean result = t.invest(recommendation);
    // verify result
    assertThat(result).isFalse();
    final List<Event> newEvents = this.getNewEvents();
    assertThat(newEvents).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) ExecutionCompletedEvent(com.github.robozonky.api.notifications.ExecutionCompletedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) Event(com.github.robozonky.api.notifications.Event) InvestmentRequestedEvent(com.github.robozonky.api.notifications.InvestmentRequestedEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) InvestmentSkippedEvent(com.github.robozonky.api.notifications.InvestmentSkippedEvent) LoanRecommendedEvent(com.github.robozonky.api.notifications.LoanRecommendedEvent) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 12 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated 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();
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 13 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class RepaymentsTest method registerNewRepayments.

@Test
void registerNewRepayments() {
    final Loan l = Loan.custom().setId(1).setAmount(200).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setRemainingInvestment(0).build();
    final Investment i = Investment.fresh(l, 200).setPaymentStatus(PaymentStatus.OK).build();
    // first, portfolio contains one active investment; no repaid
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(l.getId()))).thenReturn(l);
    final Portfolio p = new Portfolio(Collections.singletonList(i), mockBalance(z));
    final Authenticated a = mockAuthentication(z);
    final Repayments r = new Repayments();
    r.accept(p, a);
    assertThat(getNewEvents()).isEmpty();
    // now, portfolio has the same investment marked as paid; event will be triggered
    Investment.markAsPaid(i);
    r.accept(p, a);
    assertThat(getNewEvents()).first().isInstanceOf(LoanRepaidEvent.class);
    // make sure the loan was retrieved from Zonky
    verify(z).getLoan(eq(l.getId()));
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 14 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class SessionTest method empty.

@Test
void empty() {
    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.empty(), null, true);
    assertThat(i).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 15 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class SessionTest method properReal.

@Test
void properReal() {
    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()), false);
    assertThat(i).hasSize(1);
    assertThat(this.getNewEvents()).hasSize(5);
    verify(z).purchase(eq(p));
    verify(portfolio).newBlockedAmount(eq(auth), argThat((a) -> a.getLoanId() == l.getId()));
}
Also used : SoftAssertions(org.assertj.core.api.SoftAssertions) Collection(java.util.Collection) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Event(com.github.robozonky.api.notifications.Event) Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PurchaseRequestedEvent(com.github.robozonky.api.notifications.PurchaseRequestedEvent) Authenticated(com.github.robozonky.app.authentication.Authenticated) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Condition(org.assertj.core.api.Condition) Rating(com.github.robozonky.api.remote.enums.Rating) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Participation(com.github.robozonky.api.remote.entities.Participation) Participation(com.github.robozonky.api.remote.entities.Participation) Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) PurchaseStrategy(com.github.robozonky.api.strategies.PurchaseStrategy) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) ParticipationDescriptor(com.github.robozonky.api.strategies.ParticipationDescriptor) Stream(java.util.stream.Stream) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

Authenticated (com.github.robozonky.app.authentication.Authenticated)44 Test (org.junit.jupiter.api.Test)37 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)32 Zonky (com.github.robozonky.common.remote.Zonky)31 Portfolio (com.github.robozonky.app.portfolio.Portfolio)28 Event (com.github.robozonky.api.notifications.Event)13 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)11 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)10 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)9 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)9 Optional (java.util.Optional)9 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)8 ExecutionStartedEvent (com.github.robozonky.api.notifications.ExecutionStartedEvent)8 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)8 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)8 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)8 InvestmentRequestedEvent (com.github.robozonky.api.notifications.InvestmentRequestedEvent)8 InvestmentSkippedEvent (com.github.robozonky.api.notifications.InvestmentSkippedEvent)8 LoanRecommendedEvent (com.github.robozonky.api.notifications.LoanRecommendedEvent)8 Collection (java.util.Collection)8