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