Search in sources :

Example 6 with RawInvestment

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

the class AuthenticatedTest method passwordProper.

@Test
void passwordProper() {
    // prepare SUT
    final SecretProvider sp = SecretProvider.fallback(UUID.randomUUID().toString(), new char[0]);
    final String username = sp.getUsername();
    final char[] password = sp.getPassword();
    final ZonkyApiToken token = new ZonkyApiToken(UUID.randomUUID().toString(), UUID.randomUUID().toString(), 299);
    final OAuth oauth = mock(OAuth.class);
    when(oauth.login(eq(username), eq(password))).thenReturn(token);
    final Zonky z = mock(Zonky.class);
    final ApiProvider api = mockApiProvider(oauth, z);
    final Authenticated a = Authenticated.passwordBased(api, sp);
    // call SUT
    final Function<Zonky, Collection<RawInvestment>> f = mock(Function.class);
    final Collection<RawInvestment> expectedResult = Collections.emptyList();
    when(f.apply(eq(z))).thenReturn(expectedResult);
    final Collection<RawInvestment> result = a.call(f);
    assertThat(result).isSameAs(expectedResult);
    verify(oauth).login(eq(username), eq(password));
    verify(oauth, never()).refresh(any());
    verify(z).logout();
}
Also used : ApiProvider(com.github.robozonky.common.remote.ApiProvider) Collection(java.util.Collection) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) OAuth(com.github.robozonky.common.remote.OAuth) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 7 with RawInvestment

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

the class Zonky method sell.

public void sell(final Investment investment) {
    LOGGER.info("Offering to sell investment in loan #{}.", investment.getLoanId());
    controlApi.execute(api -> {
        api.offer(new SellRequest(new RawInvestment(investment)));
    });
}
Also used : SellRequest(com.github.robozonky.api.remote.entities.SellRequest) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment)

Example 8 with RawInvestment

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

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

RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)9 Test (org.junit.jupiter.api.Test)7 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 BlockedAmount (com.github.robozonky.api.remote.entities.BlockedAmount)5 Participation (com.github.robozonky.api.remote.entities.Participation)5 RawDevelopment (com.github.robozonky.api.remote.entities.RawDevelopment)5 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)5 Investment (com.github.robozonky.api.remote.entities.sanitized.Investment)3 ZonkyApiToken (com.github.robozonky.api.remote.entities.ZonkyApiToken)2 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)2 ApiProvider (com.github.robozonky.common.remote.ApiProvider)2 OAuth (com.github.robozonky.common.remote.OAuth)2 Zonky (com.github.robozonky.common.remote.Zonky)2 SecretProvider (com.github.robozonky.common.secrets.SecretProvider)2 Collection (java.util.Collection)2