Search in sources :

Example 6 with Zonky

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

Example 7 with Zonky

use of com.github.robozonky.common.remote.Zonky 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();
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Event(com.github.robozonky.api.notifications.Event) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 8 with Zonky

use of com.github.robozonky.common.remote.Zonky 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();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) 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 9 with Zonky

use of com.github.robozonky.common.remote.Zonky in project robozonky by RoboZonky.

the class InvestorTest method test.

private void test(final ProxyType proxyType, final ZonkyResponseType responseType, final RecommendedLoan r, final RemoteResponse confirmationResponse, final boolean seenBefore) {
    final Zonky api = mock(Zonky.class);
    final Investor p = getZonkyProxy(proxyType, confirmationResponse, mockAuthentication(api));
    ZonkyResponse result;
    try {
        result = p.invest(r, seenBefore);
    } catch (final Exception ex) {
        if (responseType != null) {
            fail("Thrown an exception when it shouldn't have.", ex);
        }
        return;
    }
    assertSoftly(softly -> {
        if (proxyType == InvestorTest.ProxyType.CONFIRMING) {
            softly.assertThat(p.getConfirmationProviderId()).isPresent();
        } else {
            softly.assertThat(p.getConfirmationProviderId()).isEmpty();
        }
        if (responseType == ZonkyResponseType.DELEGATED && seenBefore) {
            softly.assertThat(result.getType()).isEqualTo(ZonkyResponseType.SEEN_BEFORE);
        } else {
            softly.assertThat(result.getType()).isEqualTo(responseType);
        }
        if (result.getType() == ZonkyResponseType.INVESTED) {
            softly.assertThat(result.getConfirmedAmount()).hasValue(InvestorTest.CONFIRMED_AMOUNT);
        } else {
            softly.assertThat(result.getConfirmedAmount()).isEmpty();
        }
    });
    if (responseType == ZonkyResponseType.INVESTED) {
        verify(api).invest(any());
    } else {
        verify(api, never()).invest(any());
    }
}
Also used : Zonky(com.github.robozonky.common.remote.Zonky)

Example 10 with Zonky

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

Aggregations

Zonky (com.github.robozonky.common.remote.Zonky)55 Test (org.junit.jupiter.api.Test)47 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)46 Authenticated (com.github.robozonky.app.authentication.Authenticated)30 Portfolio (com.github.robozonky.app.portfolio.Portfolio)30 Event (com.github.robozonky.api.notifications.Event)19 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)15 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)13 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)12 Wallet (com.github.robozonky.api.remote.entities.Wallet)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)9 BigDecimal (java.math.BigDecimal)9 Collection (java.util.Collection)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