Search in sources :

Example 1 with BlockedAmount

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

the class ZonkyTest method wallet.

@Test
void wallet() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final PaginatedApi<BlockedAmount, WalletApi> wa = mockApi();
    when(wa.execute((Function<WalletApi, Wallet>) any())).thenReturn(mock(Wallet.class));
    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 Wallet w = z.getWallet();
    assertThat(w).isNotNull();
}
Also used : Participation(com.github.robozonky.api.remote.entities.Participation) ParticipationApi(com.github.robozonky.api.remote.ParticipationApi) WalletApi(com.github.robozonky.api.remote.WalletApi) Wallet(com.github.robozonky.api.remote.entities.Wallet) 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 2 with BlockedAmount

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

the class ZonkyTest method sell.

@Test
void sell() {
    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 p = Investment.custom().setRemainingPrincipal(BigDecimal.TEN).setSmpFee(BigDecimal.ONE).setId(1).build();
    z.sell(p);
    verify(control).offer(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) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) Test(org.junit.jupiter.api.Test)

Example 3 with BlockedAmount

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

the class ZonkyTest method investAndlogout.

@Test
void investAndlogout() {
    final ControlApi control = mock(ControlApi.class);
    final Api<ControlApi> ca = mockApi(control);
    final PaginatedApi<RawLoan, LoanApi> la = mockApi();
    final int loanId = 1;
    final RawLoan loan = mock(RawLoan.class);
    when(loan.getId()).thenReturn(loanId);
    when(loan.getAmount()).thenReturn(200.0);
    when(loan.getRemainingInvestment()).thenReturn(200.0);
    when(la.execute((Function<LoanApi, RawLoan>) any())).thenReturn(loan);
    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 Loan l = z.getLoan(loanId);
    final Investment i = Investment.fresh((MarketplaceLoan) l, 200);
    z.invest(i);
    z.logout();
    verify(control, times(1)).invest(any());
    verify(control, times(1)).logout();
}
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) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) 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)

Example 4 with BlockedAmount

use of com.github.robozonky.api.remote.entities.BlockedAmount 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 5 with BlockedAmount

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

the class SessionTest method discardingInvestments.

@Test
void discardingInvestments() {
    final int loanId = 1, loanId2 = 2;
    final LoanDescriptor ld = AbstractZonkyLeveragingTest.mockLoanDescriptor(loanId);
    final LoanDescriptor ld2 = AbstractZonkyLeveragingTest.mockLoanDescriptor(loanId2);
    final Collection<LoanDescriptor> lds = Arrays.asList(ld, ld2, AbstractZonkyLeveragingTest.mockLoanDescriptor());
    // discard the loan
    final SessionState sst = new SessionState(lds);
    sst.discard(ld);
    // setup APIs
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    when(z.getLoan(eq(loanId2))).thenReturn(ld2.item());
    final Authenticated auth = mockAuthentication(z);
    // prepare portfolio that has the other loan as pending
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    portfolio.newBlockedAmount(auth, new BlockedAmount(loanId2, BigDecimal.valueOf(200), TransactionCategory.SMP_BUY));
    // test that the loans are not available
    final Session it = new Session(portfolio, new LinkedHashSet<>(lds), getInvestor(auth), auth);
    assertSoftly(softly -> {
        softly.assertThat(it.getAvailable()).hasSize(1).doesNotContain(ld, ld2);
        softly.assertThat(it.getResult()).isEmpty();
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) Portfolio(com.github.robozonky.app.portfolio.Portfolio) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) BlockedAmount(com.github.robozonky.api.remote.entities.BlockedAmount) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) 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