Search in sources :

Example 31 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class SessionTest method investmentFailed.

@Test
void investmentFailed() {
    final Zonky z = AbstractZonkyLeveragingTest.harmlessZonky(10_000);
    final Authenticated auth = mockAuthentication(z);
    final RecommendedLoan r = AbstractZonkyLeveragingTest.mockLoanDescriptor().recommend(200).get();
    final Exception thrown = new ServiceUnavailableException();
    final Investor p = mock(Investor.class);
    doThrow(thrown).when(p).invest(eq(r), anyBoolean());
    final Portfolio portfolio = Portfolio.create(z, mockBalance(z));
    final Session t = new Session(portfolio, Collections.emptySet(), p, auth);
    assertThatThrownBy(() -> t.invest(r)).isSameAs(thrown);
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Portfolio(com.github.robozonky.app.portfolio.Portfolio) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Zonky(com.github.robozonky.common.remote.Zonky) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Test(org.junit.jupiter.api.Test)

Example 32 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class OperatingModeTest method withConfirmationAndNoSecret.

@Test
void withConfirmationAndNoSecret() {
    final CommandLine cli = mock(CommandLine.class);
    when(cli.getTweaksFragment()).thenReturn(mock(TweaksCommandLineFragment.class));
    final SecretProvider secretProvider = SecretProvider.fallback("user", "pass".toCharArray());
    final Authenticated auth = Authenticated.passwordBased(secretProvider);
    final ConfirmationCommandLineFragment fragment = new ConfirmationCommandLineFragment();
    fragment.confirmationCredentials = SERVICE;
    when(cli.getConfirmationFragment()).thenReturn(fragment);
    final OperatingMode mode = new DaemonOperatingMode(t -> {
    });
    final Optional<InvestmentMode> config = mode.configure(cli, auth);
    assertThat(config).isEmpty();
    assertThat(secretProvider.getSecret(SERVICE)).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) DaemonInvestmentMode(com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) Test(org.junit.jupiter.api.Test)

Example 33 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class OperatingModeTest method withoutConfirmation.

@Test
void withoutConfirmation() {
    final CommandLine cli = mock(CommandLine.class);
    when(cli.getTweaksFragment()).thenReturn(mock(TweaksCommandLineFragment.class));
    when(cli.getConfirmationFragment()).thenReturn(mock(ConfirmationCommandLineFragment.class));
    final SecretProvider secretProvider = SecretProvider.fallback("user", new char[0]);
    final Authenticated auth = Authenticated.passwordBased(secretProvider);
    final OperatingMode mode = new DaemonOperatingMode(t -> {
    });
    final Optional<InvestmentMode> config = mode.configure(cli, auth);
    assertThat(config).isPresent();
    assertThat(secretProvider.getSecret(SERVICE)).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) DaemonInvestmentMode(com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) Test(org.junit.jupiter.api.Test)

Example 34 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class OperatingModeTest method withConfirmation.

@Test
void withConfirmation() {
    final TweaksCommandLineFragment f = mock(TweaksCommandLineFragment.class);
    when(f.isDryRunEnabled()).thenReturn(true);
    final CommandLine cli = mock(CommandLine.class);
    when(cli.getTweaksFragment()).thenReturn(f);
    final SecretProvider secretProvider = SecretProvider.fallback("user", "pass".toCharArray());
    final Authenticated auth = Authenticated.passwordBased(secretProvider);
    final ConfirmationCommandLineFragment fragment = new ConfirmationCommandLineFragment();
    fragment.confirmationCredentials = SERVICE + ":" + SERVICE_TOKEN;
    when(cli.getConfirmationFragment()).thenReturn(fragment);
    final OperatingMode mode = new DaemonOperatingMode(t -> {
    });
    final Optional<InvestmentMode> config = mode.configure(cli, auth);
    assertSoftly(softly -> {
        softly.assertThat(config).containsInstanceOf(DaemonInvestmentMode.class);
        softly.assertThat(secretProvider.getSecret(SERVICE)).contains(SERVICE_TOKEN.toCharArray());
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) DaemonInvestmentMode(com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) Test(org.junit.jupiter.api.Test)

Example 35 with Authenticated

use of com.github.robozonky.app.authentication.Authenticated in project robozonky by RoboZonky.

the class OperatingModeTest method withConfirmationAndUnknownId.

@Test
void withConfirmationAndUnknownId() {
    final CommandLine cli = mock(CommandLine.class);
    when(cli.getTweaksFragment()).thenReturn(mock(TweaksCommandLineFragment.class));
    final SecretProvider secretProvider = SecretProvider.fallback("user", "pass".toCharArray());
    final Authenticated auth = Authenticated.passwordBased(secretProvider);
    final ConfirmationCommandLineFragment fragment = new ConfirmationCommandLineFragment();
    fragment.confirmationCredentials = UUID.randomUUID().toString();
    when(cli.getConfirmationFragment()).thenReturn(fragment);
    final OperatingMode mode = new DaemonOperatingMode(t -> {
    });
    final Optional<InvestmentMode> config = mode.configure(cli, auth);
    assertThat(config).isEmpty();
    assertThat(secretProvider.getSecret(SERVICE)).isEmpty();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) DaemonInvestmentMode(com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) Test(org.junit.jupiter.api.Test)

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