Search in sources :

Example 31 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class SessionTest method investmentFailed.

@Test
void investmentFailed() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
    final Exception thrown = new ServiceUnavailableException();
    final Investor p = mock(Investor.class);
    doThrow(thrown).when(p).invest(eq(r), anyBoolean());
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
    assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 32 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class BlockedAmountsTest method newBlockedAmounts.

@Test
void newBlockedAmounts() {
    final Zonky zonky = harmlessZonky(10_000);
    when(zonky.getBlockedAmounts()).thenReturn(Stream.of(BA1, BA2));
    final Authenticated auth = mockAuthentication(zonky);
    final Portfolio p = mock(Portfolio.class);
    final BlockedAmounts blockedAmounts = new BlockedAmounts();
    // verify the first two blocked amounts were registered
    blockedAmounts.accept(p, auth);
    verify(p).newBlockedAmount(eq(auth), eq(BA1));
    verify(p).newBlockedAmount(eq(auth), eq(BA2));
    // verify only the new blocked amount was registered, and that it only happened the first time
    reset(p);
    when(zonky.getBlockedAmounts()).thenAnswer((Answer<Stream<BlockedAmount>>) invocation -> Stream.of(BA1, BA2, BA3));
    blockedAmounts.accept(p, auth);
    blockedAmounts.accept(p, auth);
    verify(p, times(1)).newBlockedAmount(eq(auth), eq(BA3));
}
Also used : Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Answer(org.mockito.stubbing.Answer) Mockito(org.mockito.Mockito) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) Stream(java.util.stream.Stream) Authenticated(com.github.robozonky.app.authentication.Authenticated) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Stream(java.util.stream.Stream) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 33 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class DaemonOperationTest method standard.

@Test
void standard() {
    final Authenticated a = mock(Authenticated.class);
    final BiConsumer<Portfolio, Authenticated> operation = mock(BiConsumer.class);
    final DaemonOperation d = new CustomOperation(a, operation);
    d.run();
    verify(operation).accept(any(), eq(a));
    assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 34 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class InvestmentDaemonTest method underBalance.

@Test
void underBalance() {
    final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK - 1);
    final Authenticated a = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Supplier<Optional<InvestmentStrategy>> s = Optional::empty;
    final InvestingDaemon d = new InvestingDaemon(t -> {
    }, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
    d.run();
    verify(z, never()).getAvailableLoans((Select) notNull());
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Investor(com.github.robozonky.app.investing.Investor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 35 with Portfolio

use of com.github.robozonky.app.portfolio.Portfolio in project robozonky by RoboZonky.

the class InvestmentDaemonTest method standard.

@Test
void standard() {
    final int loanId = 1;
    final MarketplaceLoan ml = MarketplaceLoan.custom().setId(loanId).setRating(Rating.A).build();
    final Loan l = Loan.custom().setId(loanId).setRating(Rating.A).build();
    final Zonky z = harmlessZonky(Defaults.MINIMUM_INVESTMENT_IN_CZK);
    when(z.getAvailableLoans((Select) notNull())).thenReturn(Stream.of(ml));
    when(z.getLoan(eq(loanId))).thenReturn(l);
    final Authenticated a = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final InvestmentStrategy is = mock(InvestmentStrategy.class);
    final Supplier<Optional<InvestmentStrategy>> s = () -> Optional.of(is);
    final InvestingDaemon d = new InvestingDaemon(t -> {
    }, a, new Investor.Builder(), s, () -> Optional.of(portfolio), Duration.ofSeconds(1));
    d.run();
    verify(z).getAvailableLoans((Select) notNull());
    verify(z).getLoan(ml.getId());
    verify(is).recommend(any(), any(), any());
    assertThat(d.getRefreshInterval()).isEqualByComparingTo(Duration.ofSeconds(1));
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) Investor(com.github.robozonky.app.investing.Investor) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

Portfolio (com.github.robozonky.app.portfolio.Portfolio)38 Test (org.junit.jupiter.api.Test)34 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)33 Zonky (com.github.robozonky.common.remote.Zonky)30 Authenticated (com.github.robozonky.app.authentication.Authenticated)29 Event (com.github.robozonky.api.notifications.Event)16 LoanDescriptor (com.github.robozonky.api.strategies.LoanDescriptor)13 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)12 Optional (java.util.Optional)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)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 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)8 PurchaseRequestedEvent (com.github.robozonky.api.notifications.PurchaseRequestedEvent)7