Search in sources :

Example 6 with BlockedAmount

use of com.github.robozonky.api.remote.entities.BlockedAmount in project robozonky by RoboZonky.

the class Session method markSuccessfulInvestment.

private void markSuccessfulInvestment(final Investment i) {
    investmentsMadeNow.add(i);
    loansStillAvailable.removeIf(l -> isSameLoan(l, i));
    final BlockedAmount b = new BlockedAmount(i.getLoanId(), i.getOriginalPrincipal(), TransactionCategory.INVESTMENT);
    portfolio.newBlockedAmount(authenticated, b);
    portfolio.getRemoteBalance().update(i.getOriginalPrincipal().negate());
    portfolioOverview = portfolio.calculateOverview();
}
Also used : BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount)

Example 7 with BlockedAmount

use of com.github.robozonky.api.remote.entities.BlockedAmount in project robozonky by RoboZonky.

the class Session method markSuccessfulPurchase.

private void markSuccessfulPurchase(final Investment i) {
    investmentsMadeNow.add(i);
    final int id = i.getLoanId();
    stillAvailable.removeIf(l -> l.item().getLoanId() == id);
    portfolio.newBlockedAmount(authenticated, new BlockedAmount(id, i.getOriginalPrincipal(), TransactionCategory.SMP_BUY));
    portfolio.getRemoteBalance().update(i.getOriginalPrincipal().negate());
    portfolioOverview = portfolio.calculateOverview();
}
Also used : BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount)

Example 8 with BlockedAmount

use of com.github.robozonky.api.remote.entities.BlockedAmount in project robozonky by RoboZonky.

the class BlockedAmountsTest method newBlockedAmounts.

@Test
void newBlockedAmounts() {
    final Zonky zonky = harmlessZonky(10_000);
    when(zonky.getBlockedAmounts()).thenReturn(Stream.of(BA1, BA2));
    final Authenticated auth = mockAuthentication(zonky);
    final Portfolio p = mock(Portfolio.class);
    final BlockedAmounts blockedAmounts = new BlockedAmounts();
    // verify the first two blocked amounts were registered
    blockedAmounts.accept(p, auth);
    verify(p).newBlockedAmount(eq(auth), eq(BA1));
    verify(p).newBlockedAmount(eq(auth), eq(BA2));
    // verify only the new blocked amount was registered, and that it only happened the first time
    reset(p);
    when(zonky.getBlockedAmounts()).thenAnswer((Answer<Stream<BlockedAmount>>) invocation -> Stream.of(BA1, BA2, BA3));
    blockedAmounts.accept(p, auth);
    blockedAmounts.accept(p, auth);
    verify(p, times(1)).newBlockedAmount(eq(auth), eq(BA3));
}
Also used : Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Answer(org.mockito.stubbing.Answer) Mockito(org.mockito.Mockito) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) Stream(java.util.stream.Stream) Authenticated(com.github.robozonky.app.authentication.Authenticated) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Zonky(com.github.robozonky.common.remote.Zonky) Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) Stream(java.util.stream.Stream) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 9 with BlockedAmount

use of com.github.robozonky.api.remote.entities.BlockedAmount in project robozonky by RoboZonky.

the class ZonkyTest method purchase.

@Test
void purchase() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Participation p = mock(Participation.class);
    when(p.getRemainingPrincipal()).thenReturn(BigDecimal.TEN);
    when(p.getId()).thenReturn(1);
    z.purchase(p);
    verify(control).purchase(eq(p.getId()), any());
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 10 with BlockedAmount

use of com.github.robozonky.api.remote.entities.BlockedAmount in project robozonky by RoboZonky.

the class ZonkyTest method cancel.

@Test
void cancel() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    final PaginatedApi<RawInvestment, PortfolioApi> pa = mockApi();
    final PaginatedApi<Participation, ParticipationApi> sa = mockApi();
    final PaginatedApi<RawDevelopment, CollectionsApi> caa = mockApi();
    final Zonky z = new Zonky(ca, la, sa, pa, wa, caa);
    final Investment i = mock(Investment.class);
    when(i.getId()).thenReturn(1);
    z.cancel(i);
    verify(control).cancel(eq(i.getId()));
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) LoanApi(com.github.robozonky.api.remote.LoanApi) PortfolioApi(com.github.robozonky.api.remote.PortfolioApi) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) ControlApi(com.github.robozonky.api.remote.ControlApi) RawDevelopment(com.github.robozonky.api.remote.entities.RawDevelopment) CollectionsApi(com.github.robozonky.api.remote.CollectionsApi) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Aggregations

BlockedAmount (com.github.robozonky.api.remote.entities.BlockedAmount)10 Test (org.junit.jupiter.api.Test)8 CollectionsApi (com.github.robozonky.api.remote.CollectionsApi)5 ControlApi (com.github.robozonky.api.remote.ControlApi)5 LoanApi (com.github.robozonky.api.remote.LoanApi)5 ParticipationApi (com.github.robozonky.api.remote.ParticipationApi)5 PortfolioApi (com.github.robozonky.api.remote.PortfolioApi)5 WalletApi (com.github.robozonky.api.remote.WalletApi)5 Participation (com.github.robozonky.api.remote.entities.Participation)5 RawDevelopment (com.github.robozonky.api.remote.entities.RawDevelopment)5 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)5 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)5 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)4 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)3 Authenticated (com.github.robozonky.app.authentication.Authenticated)3 Zonky (com.github.robozonky.common.remote.Zonky)3 Loan (com.github.robozonky.api.remote.entities.sanitized.Loan)2 Portfolio (com.github.robozonky.app.portfolio.Portfolio)2 Event (com.github.robozonky.api.notifications.Event)1 InvestmentSoldEvent (com.github.robozonky.api.notifications.InvestmentSoldEvent)1