Search in sources :

Example 1 with Authenticated

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();
}
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 2 with Authenticated

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);
}
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 3 with Authenticated

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());
}
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 4 with Authenticated

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

Example 5 with Authenticated

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();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) 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)

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