Search in sources :

Example 51 with Zonky

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

the class AuthenticatedTest method restrictions.

@Test
void restrictions() {
    final Zonky z = mock(Zonky.class);
    when(z.getRestrictions()).thenAnswer(invocation -> mock(Restrictions.class));
    final AbstractAuthenticated a = new AbstractAuthenticated() {

        @Override
        public <T> T call(final Function<Zonky, T> operation) {
            return operation.apply(z);
        }

        @Override
        public SecretProvider getSecretProvider() {
            return null;
        }
    };
    // stale
    final Restrictions r = a.getRestrictions(Instant.now().minus(Duration.ofMinutes(10)));
    assertThat(r).isNotNull();
    // should refresh
    final Restrictions r2 = a.getRestrictions();
    assertThat(r2).isNotNull().isNotEqualTo(r);
}
Also used : Function(java.util.function.Function) Restrictions(com.github.robozonky.api.remote.entities.Restrictions) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 52 with Zonky

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

the class LoanCacheTest method emptyGetLoan.

@Test
void emptyGetLoan() {
    final LoanCache c = new LoanCache();
    final int loanId = 1;
    // nothing returned at first
    assertThat(c.getLoan(loanId)).isEmpty();
    final MyInvestment mi = mock(MyInvestment.class);
    when(mi.getTimeCreated()).thenReturn(OffsetDateTime.now());
    final Loan loan = Loan.custom().setId(loanId).setMyInvestment(mi).build();
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(loanId))).thenReturn(loan);
    // return the freshly retrieved loan
    assertThat(c.getLoan(loanId, z)).isEqualTo(loan);
    final Investment i = Investment.custom().setLoanId(loanId).build();
    assertThat(c.getLoan(i, z)).isEqualTo(loan);
    assertThat(i.getInvestmentDate()).isNotEmpty();
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Zonky(com.github.robozonky.common.remote.Zonky) MyInvestment(com.github.robozonky.api.remote.entities.MyInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 53 with Zonky

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

the class StrategyExecutorTest method rechecksMarketplaceIfFirstCheckFailed.

@Test
void rechecksMarketplaceIfFirstCheckFailed() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final Loan loan = Loan.custom().build();
    final LoanDescriptor ld = new LoanDescriptor(loan);
    final Collection<LoanDescriptor> marketplace = Collections.singleton(ld);
    // prepare the executor, have it fail when executing the investment operation
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = new AlwaysFreshNeverInvesting();
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> mocked = spy(e);
    doThrow(new IllegalStateException()).when(mocked).execute(any(), any(), any());
    Assertions.assertThatThrownBy(() -> mocked.apply(p, marketplace)).isInstanceOf(IllegalStateException.class);
    // now the method won't throw, but must be executed again
    reset(mocked);
    mocked.apply(p, marketplace);
    verify(mocked).execute(eq(p), eq(ALL_ACCEPTING_STRATEGY), eq(marketplace));
    // marketplace stays the same + balance stays the same+  previous update passed = no update should be triggered
    reset(mocked);
    when(mocked.hasMarketplaceUpdates(eq(marketplace))).thenReturn(false);
    mocked.apply(p, marketplace);
    verify(mocked, never()).execute(any(), any(), any());
}
Also used : Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) 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 54 with Zonky

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

the class StrategyExecutorTest method doesNotInvestOnEmptyMarketplace.

@Test
void doesNotInvestOnEmptyMarketplace() {
    final Zonky zonky = harmlessZonky(10_000);
    final Portfolio p = Portfolio.create(zonky, mockBalance(zonky));
    final StrategyExecutor<LoanDescriptor, InvestmentStrategy> e = spy(new AlwaysFreshNeverInvesting());
    e.apply(p, Collections.emptyList());
    verify(e, never()).execute(any(), any(), any());
}
Also used : Portfolio(com.github.robozonky.app.portfolio.Portfolio) InvestmentStrategy(com.github.robozonky.api.strategies.InvestmentStrategy) 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 55 with Zonky

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

the class ZonkySettingsValidatorTest method properLogin.

@Test
void properLogin() {
    // mock data
    final ZonkyApiToken token = mock(ZonkyApiToken.class);
    final OAuth oauth = mock(OAuth.class);
    when(oauth.login(any(), any())).thenReturn(token);
    final Zonky zonky = mock(Zonky.class);
    final ApiProvider provider = mockApiProvider(oauth, token, zonky);
    // execute SUT
    final ZonkySettingsValidator validator = new ZonkySettingsValidator(() -> provider);
    final InstallData d = ZonkySettingsValidatorTest.mockInstallData();
    final DataValidator.Status result = validator.validateData(d);
    // test
    assertThat(result).isEqualTo(DataValidator.Status.OK);
    verify(oauth).login(eq(ZonkySettingsValidatorTest.USERNAME), eq(ZonkySettingsValidatorTest.PASSWORD.toCharArray()));
    verify(zonky).logout();
}
Also used : InstallData(com.izforge.izpack.api.data.InstallData) DataValidator(com.izforge.izpack.api.installer.DataValidator) ApiProvider(com.github.robozonky.common.remote.ApiProvider) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) OAuth(com.github.robozonky.common.remote.OAuth) Zonky(com.github.robozonky.common.remote.Zonky) 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