private static boolean notifyProvider(final RawLoan loan, final ConfirmationProvider zonkoid, final String username, final char... secret) { final RequestId id = new RequestId(username, secret); return zonkoid.requestConfirmation(id, loan.getId(), 200); }
private static boolean notifyProvider(final RawLoan loan, final ConfirmationProvider zonkoid, final String username, final char... secret) { final RequestId id = new RequestId(username, secret); return zonkoid.requestConfirmation(id, loan.getId(), 200); }
private Either<InvestmentFailure, BigDecimal> delegateOrReject(final RecommendedLoan r) { LOGGER.debug("Asking to confirm investment: {}.", r); final boolean delegationSucceeded = this.provider.requestConfirmation(this.requestId, r.descriptor().item().getId(), r.amount().intValue()); if (delegationSucceeded) { LOGGER.debug("Investment confirmed delegated, not investing: {}.", r); return Either.left(InvestmentFailure.DELEGATED); } else { LOGGER.debug("Investment not confirmed delegated, not investing: {}.", r); return Either.left(InvestmentFailure.REJECTED); } }
private Either<InvestmentFailure, BigDecimal> delegateOrReject(final RecommendedLoan r) { LOGGER.debug("Asking to confirm investment: {}.", r); final boolean delegationSucceeded = this.provider.requestConfirmation(this.requestId, r.descriptor().item().getId(), r.amount().intValue()); if (delegationSucceeded) { LOGGER.debug("Investment confirmed delegated, not investing: {}.", r); return Either.left(InvestmentFailure.DELEGATED); } else { LOGGER.debug("Investment not confirmed delegated, not investing: {}.", r); return Either.left(InvestmentFailure.REJECTED); } }
@Test void zonkoidPresentButRejecting() { final ConfirmationProvider cp = mock(ConfirmationProvider.class); when(cp.requestConfirmation(any(), anyInt(), anyInt())).thenReturn(false); final InstallData d = ZonkoidSettingsValidatorTest.mockInstallData(); // execute SUT final DataValidator validator = new ZonkoidSettingsValidator(() -> Optional.of(cp)); final DataValidator.Status result = validator.validateData(d); // run test assertThat(result).isEqualTo(DataValidator.Status.WARNING); }
@Test void zonkoidProper() { final ConfirmationProvider cp = mock(ConfirmationProvider.class); when(cp.requestConfirmation(any(), anyInt(), anyInt())).thenReturn(true); final InstallData d = ZonkoidSettingsValidatorTest.mockInstallData(); // execute SUT final DataValidator validator = new ZonkoidSettingsValidator(() -> Optional.of(cp)); final DataValidator.Status result = validator.validateData(d); // run test assertThat(result).isEqualTo(DataValidator.Status.OK); } }
@Test void confirmationsProper() { final ConfirmationProvider cp = Mockito.mock(ConfirmationProvider.class); Mockito.when(cp.requestConfirmation(ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(false); final boolean result = Checker.confirmations(cp, "", SECRET, CheckerTest::mockApiThatReturnsOneLoan); assertThat(result).isFalse(); }
@Test void confirmationsNotConfirming() { final ConfirmationProvider cp = Mockito.mock(ConfirmationProvider.class); Mockito.when(cp.requestConfirmation(ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(false); final boolean result = Checker.confirmations(cp, "", SECRET, CheckerTest::mockApiThatReturnsOneLoan); assertThat(result).isFalse(); }
@Test void confirmationsRejecting() { final ConfirmationProvider cp = Mockito.mock(ConfirmationProvider.class); Mockito.when(cp.requestConfirmation(ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(false); final boolean result = Checker.confirmations(cp, "", SECRET, CheckerTest::mockApiThatReturnsOneLoan); assertThat(result).isFalse(); }
private Investor getZonkyProxy(final ProxyType proxyType, final RemoteResponse confirmationResponse, final Tenant auth) { switch (proxyType) { case SIMPLE: return Investor.build(auth); case CONFIRMING: final ConfirmationProvider cp = mock(ConfirmationProvider.class); when(cp.getId()).thenReturn("something"); switch (confirmationResponse) { case ACK: when(cp.requestConfirmation(any(), anyInt(), anyInt())).thenReturn(true); break; case NAK: when(cp.requestConfirmation(any(), anyInt(), anyInt())).thenReturn(false); break; default: throw new IllegalStateException(); } return Investor.build(auth, cp); default: throw new IllegalStateException(); } }
@Test void openProperExistingSuccess() throws IOException, SetupFailedException, KeyStoreException, TestFailedException { final File f = newTempFile(); final String pwd = UUID.randomUUID().toString(); SecretProvider.keyStoreBased(KeyStoreHandler.create(f, KEYSTORE_PASSWORD.toCharArray()), "user"); // prep final Feature feature = new ZonkoidPasswordFeature(f, KEYSTORE_PASSWORD.toCharArray(), pwd.toCharArray()); feature.setup(); final SecretProvider s = SecretProvider.keyStoreBased(KeyStoreHandler.open(f, KEYSTORE_PASSWORD.toCharArray())); assertThat(s.getSecret(ZonkoidPasswordFeature.ZONKOID_ID)).contains(pwd.toCharArray()); when(TestingZonkoidProviderService.INSTANCE.requestConfirmation(any(), anyInt(), anyInt())).thenReturn(true); feature.test(); verify(TestingZonkoidProviderService.INSTANCE).requestConfirmation(any(), anyInt(), anyInt()); }