Search in sources :

Example 36 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated 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 37 with Authenticated

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

the class DaemonInvestmentModeTest method get.

@Test
void get() throws Exception {
    final Authenticated a = mockAuthentication(mock(Zonky.class));
    final Investor.Builder b = new Investor.Builder().asDryRun();
    final ExecutorService e = Executors.newFixedThreadPool(1);
    final PortfolioUpdater p = mock(PortfolioUpdater.class);
    try {
        final DaemonInvestmentMode d = new DaemonInvestmentMode(t -> {
        }, a, p, b, mock(StrategyProvider.class), Duration.ofSeconds(1), Duration.ofSeconds(1));
        // will block
        final Future<ReturnCode> f = e.submit(() -> d.apply(lifecycle));
        assertThatThrownBy(() -> f.get(1, TimeUnit.SECONDS)).isInstanceOf(TimeoutException.class);
        // unblock
        lifecycle.resumeToShutdown();
        // should now finish
        assertThat(f.get()).isEqualTo(ReturnCode.OK);
        verify(p).run();
    } finally {
        e.shutdownNow();
    }
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) ReturnCode(com.github.robozonky.api.ReturnCode) ExecutorService(java.util.concurrent.ExecutorService) 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 38 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated 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 39 with Authenticated

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

the class DaemonOperationTest method exceptional.

@Test
void exceptional() {
    final Authenticated a = mock(Authenticated.class);
    doThrow(IllegalStateException.class).when(a).run(any());
    final DaemonOperation d = new CustomOperation(a, null);
    d.run();
    assertThat(this.getNewEvents()).first().isInstanceOf(RoboZonkyDaemonFailedEvent.class);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 40 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated 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)

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