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;
}
});
}
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();
}
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);
}
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());
}
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());
}
Aggregations