use of com.github.robozonky.app.authentication.Authenticated 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.app.authentication.Authenticated 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.app.authentication.Authenticated 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.app.authentication.Authenticated 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());
}
use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.
the class InvestingTest method noneAccepted.
@Test
void noneAccepted() {
// new ID every time to avoid caches
final int loanId = (int) (Math.random() * 1000);
final Loan loan = Loan.custom().setId(loanId).setAmount(100_000).setRating(Rating.D).setMyInvestment(mockMyInvestment()).setDatePublished(OffsetDateTime.now()).build();
final LoanDescriptor ld = new LoanDescriptor(loan);
final Investor.Builder builder = new Investor.Builder().asDryRun();
final Zonky z = harmlessZonky(9000);
final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
when(z.getLoan(eq(loanId))).thenReturn(loan);
final Authenticated auth = mockAuthentication(z);
final Investing exec = new Investing(builder, NONE_ACCEPTING, auth);
assertThat(exec.apply(portfolio, Collections.singleton(ld))).isEmpty();
}
Aggregations