Search in sources :

Example 1 with Zonky

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

the class ZonkySettingsValidator method validateDataPossiblyThrowingException.

@Override
public DataValidator.Status validateDataPossiblyThrowingException(final InstallData installData) {
    final String username = Variables.ZONKY_USERNAME.getValue(installData);
    final String password = Variables.ZONKY_PASSWORD.getValue(installData);
    final ApiProvider p = apiSupplier.get();
    return p.oauth((oauth) -> {
        try {
            LOGGER.info("Logging in.");
            final ZonkyApiToken token = oauth.login(username, password.toCharArray());
            LOGGER.info("Logging out.");
            p.authenticated(token, Zonky::logout);
            return DataValidator.Status.OK;
        } catch (final ServerErrorException t) {
            LOGGER.log(Level.SEVERE, "Failed accessing Zonky.", t);
            return DataValidator.Status.ERROR;
        } catch (final Exception t) {
            LOGGER.log(Level.WARNING, "Failed logging in.", t);
            return DataValidator.Status.WARNING;
        }
    });
}
Also used : ApiProvider(com.github.robozonky.common.remote.ApiProvider) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) ServerErrorException(javax.ws.rs.ServerErrorException) ServerErrorException(javax.ws.rs.ServerErrorException) Zonky(com.github.robozonky.common.remote.Zonky)

Example 2 with Zonky

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

the class PortfolioTest method newSale.

@Test
void newSale() {
    final Loan l = Loan.custom().setId(1).setAmount(1000).setMyInvestment(mockMyInvestment()).build();
    final Investment i = Investment.fresh(l, 200);
    final BlockedAmount ba = new BlockedAmount(l.getId(), BigDecimal.valueOf(l.getAmount()), TransactionCategory.SMP_SALE_FEE);
    final Zonky z = harmlessZonky(10_000);
    when(z.getLoan(eq(l.getId()))).thenReturn(l);
    final Authenticated auth = mockAuthentication(z);
    final Portfolio portfolio = new Portfolio(Collections.singletonList(i), mockBalance(z));
    assertThat(portfolio.wasOnceSold(l)).isFalse();
    Investment.putOnSmp(i);
    assertThat(portfolio.wasOnceSold(l)).isTrue();
    portfolio.newBlockedAmount(auth, ba);
    assertSoftly(softly -> {
        softly.assertThat(i.isOnSmp()).isFalse();
        softly.assertThat(i.getStatus()).isEqualTo(InvestmentStatus.SOLD);
    });
    final List<Event> events = this.getNewEvents();
    assertThat(events).first().isInstanceOf(InvestmentSoldEvent.class);
    // doing the same thing again shouldn't do anything
    this.readPreexistingEvents();
    portfolio.newBlockedAmount(auth, ba);
    assertSoftly(softly -> {
        softly.assertThat(i.isOnSmp()).isFalse();
        softly.assertThat(i.getStatus()).isEqualTo(InvestmentStatus.SOLD);
        softly.assertThat(portfolio.wasOnceSold(l)).isTrue();
    });
    final List<Event> newEvents = this.getNewEvents();
    assertThat(newEvents).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Event(com.github.robozonky.api.notifications.Event) InvestmentSoldEvent(com.github.robozonky.api.notifications.InvestmentSoldEvent) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) 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 3 with Zonky

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

the class RemoteBalanceImplTest method testDryRunWithPresetBalance.

@Test
void testDryRunWithPresetBalance() {
    System.setProperty(PROPERTY, THOUSAND.toString());
    final BigDecimal startingBalance = BigDecimal.valueOf(1_001);
    final Zonky z = harmlessZonky(startingBalance.intValue());
    final Authenticated a = mockAuthentication(z);
    final RefreshableBalance rb = new RefreshableBalance(a);
    rb.run();
    final RemoteBalance b = new RemoteBalanceImpl(rb, true);
    Assertions.assertThat(b.get()).isEqualTo(startingBalance);
    b.update(THOUSAND.negate());
    // minimum is set to be a thousand
    Assertions.assertThat(b.get()).isEqualTo(THOUSAND);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) BigDecimal(java.math.BigDecimal) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 4 with Zonky

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

the class RemoteBalanceImplTest method testDryRun.

@Test
void testDryRun() {
    final BigDecimal startingBalance = BigDecimal.valueOf(2_000);
    final Zonky z = harmlessZonky(startingBalance.intValue());
    final Authenticated a = mockAuthentication(z);
    final RefreshableBalance rb = new RefreshableBalance(a);
    rb.run();
    final RemoteBalance b = new RemoteBalanceImpl(rb, true);
    Assertions.assertThat(b.get()).isEqualTo(startingBalance);
    // test some local updates
    b.update(THOUSAND.negate());
    Assertions.assertThat(b.get()).isEqualTo(THOUSAND);
    b.update(THOUSAND.negate());
    Assertions.assertThat(b.get()).isEqualTo(BigDecimal.ZERO);
    // make a remote update to ensure local updates are still persisted
    when(z.getWallet()).thenReturn(new Wallet(startingBalance.subtract(THOUSAND)));
    // register the remote update
    rb.run();
    Assertions.assertThat(b.get()).isEqualTo(THOUSAND.negate());
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Wallet(com.github.robozonky.api.remote.entities.Wallet) BigDecimal(java.math.BigDecimal) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 5 with Zonky

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

the class PurchasingDaemonTest method standard.

@Test
void standard() {
    final Zonky z = harmlessZonky(10_000);
    final Authenticated a = mockAuthentication(z);
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Supplier<Optional<PurchaseStrategy>> s = Optional::empty;
    final PurchasingDaemon d = new PurchasingDaemon(t -> {
    }, a, s, () -> Optional.of(portfolio), Duration.ZERO, true);
    d.run();
    verify(z, times(1)).getAvailableParticipations(any());
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Optional(java.util.Optional) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

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