@Test(timeout = 1000, expected = IntentionalException.class) public void testGetProfileSuccessfullyWithFailingProfileModifier(final TestContext testContext) { testContext.async(); final AsyncBaseClient<TestCredentials, TestProfile> client = happyPathClient(); client.addAuthorizationGenerator(successfulPermissionAuthGenerator(PERMISSION_ADMIN)); client.addAuthorizationGenerator(failingProfileModifierGenerator()); final TestCredentials credentials = new TestCredentials(HAPPY_PATH_NAME, HAPPY_PATH_PASSWORD); final CompletableFuture<Optional<TestProfile>> profileFuture = client.getUserProfileFuture(credentials, webContext); expectIntentionalFailureOf(profileFuture); }
@Override public CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context) { init(context); logger.debug("credentials : {}", credentials); if (credentials == null) { return CompletableFuture.completedFuture(Optional.empty()); } final CompletableFuture<Optional<U>> profileFuture = retrieveUserProfileFuture(credentials, context); return profileFuture.thenCompose(profileOption -> { final Optional<CompletableFuture<Optional<U>>> optionalCompletableFuture = profileOption.map(p -> { p.setClientName(getName()); final List<CompletableFuture<Consumer<U>>> profileModifierFutures = authorizationGenerators .stream() .map(g -> g.generate(context, p)) .collect(toList()); return combineFuturesToList(profileModifierFutures).thenApply(l -> { context.getExecutionContext().runOnContext(() -> l.forEach(c -> c.accept(p))); return Optional.of(p); }); }); return optionalCompletableFuture. orElse(CompletableFuture.completedFuture(Optional.empty())); }); }
AsyncBaseClient extends CommonBaseClient<C, U, AsyncWebContext, AsyncAuthorizationGenerator<U>> implements AsyncClient<C, U>, ConfigurableByClientsObject<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> { @Override public CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context) { init(context); logger.debug("credentials : {}", credentials); if (credentials == null) { return CompletableFuture.completedFuture(Optional.empty()); } final CompletableFuture<Optional<U>> profileFuture = retrieveUserProfileFuture(credentials, context); return profileFuture.thenCompose(profileOption -> { final Optional<CompletableFuture<Optional<U>>> optionalCompletableFuture = profileOption.map(p -> { p.setClientName(getName()); final List<CompletableFuture<Consumer<U>>> profileModifierFutures = authorizationGenerators .stream() .map(g -> g.generate(context, p)) .collect(toList()); return combineFuturesToList(profileModifierFutures).thenApply(l -> { context.getExecutionContext().runOnContext(() -> l.forEach(c -> c.accept(p))); return Optional.of(p); }); }); return optionalCompletableFuture. orElse(CompletableFuture.completedFuture(Optional.empty())); }); } }
AsyncBaseClient extends CommonBaseClient<C, U, AsyncWebContext, AsyncAuthorizationGenerator<U>> implements AsyncClient<C, U>, ConfigurableByClientsObject<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> { @Override public CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context) { init(context); logger.debug("credentials : {}", credentials); if (credentials == null) { return CompletableFuture.completedFuture(Optional.empty()); } final CompletableFuture<Optional<U>> profileFuture = retrieveUserProfileFuture(credentials, context); return profileFuture.thenCompose(profileOption -> { final Optional<CompletableFuture<Optional<U>>> optionalCompletableFuture = profileOption.map(p -> { p.setClientName(getName()); final List<CompletableFuture<Consumer<U>>> profileModifierFutures = authorizationGenerators .stream() .map(g -> g.generate(context, p)) .collect(toList()); return combineFuturesToList(profileModifierFutures).thenApply(l -> { context.getExecutionContext().runOnContext(() -> l.forEach(c -> c.accept(p))); return Optional.of(p); }); }); return optionalCompletableFuture. orElse(CompletableFuture.completedFuture(Optional.empty())); }); }  }
AsyncBaseClient extends CommonBaseClient<C, U, AsyncWebContext, AsyncAuthorizationGenerator<U>> implements AsyncClient<C, U>, ConfigurableByClientsObject<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> { @Override public CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context) { init(context); logger.debug("credentials : {}", credentials); if (credentials == null) { return CompletableFuture.completedFuture(Optional.empty()); } final CompletableFuture<Optional<U>> profileFuture = retrieveUserProfileFuture(credentials, context); return profileFuture.thenCompose(profileOption -> { final Optional<CompletableFuture<Optional<U>>> optionalCompletableFuture = profileOption.map(p -> { p.setClientName(getName()); final List<CompletableFuture<Consumer<U>>> profileModifierFutures = authorizationGenerators .stream() .map(g -> g.generate(context, p)) .collect(toList()); return combineFuturesToList(profileModifierFutures).thenApply(l -> { context.getExecutionContext().runOnContext(() -> l.forEach(c -> c.accept(p))); return Optional.of(p); }); }); return optionalCompletableFuture. orElse(CompletableFuture.completedFuture(Optional.empty())); }); }  @Override CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context); @Override void configureFromClientsObject(Clients<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> toConfigureFrom); @Override final CompletableFuture<C> getCredentials(AsyncWebContext context); AsyncCredentialsExtractor<C> getCredentialsExtractor(); void setCredentialsExtractor(final AsyncCredentialsExtractor<C> credentialsExtractor); AsyncProfileCreator<C, U> getProfileCreator(); void setProfileCreator(AsyncProfileCreator<C, U> profileCreator); AsyncAuthenticator<C> getAuthenticator(); void setAuthenticator(AsyncAuthenticator<C> authenticator); }
AsyncBaseClient extends CommonBaseClient<C, U, AsyncWebContext, AsyncAuthorizationGenerator<U>> implements AsyncClient<C, U>, ConfigurableByClientsObject<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> { @Override public CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context) { init(context); logger.debug("credentials : {}", credentials); if (credentials == null) { return CompletableFuture.completedFuture(Optional.empty()); } final CompletableFuture<Optional<U>> profileFuture = retrieveUserProfileFuture(credentials, context); return profileFuture.thenCompose(profileOption -> { final Optional<CompletableFuture<Optional<U>>> optionalCompletableFuture = profileOption.map(p -> { p.setClientName(getName()); final List<CompletableFuture<Consumer<U>>> profileModifierFutures = authorizationGenerators .stream() .map(g -> g.generate(context, p)) .collect(toList()); return combineFuturesToList(profileModifierFutures).thenApply(l -> { context.getExecutionContext().runOnContext(() -> l.forEach(c -> c.accept(p))); return Optional.of(p); }); }); return optionalCompletableFuture. orElse(CompletableFuture.completedFuture(Optional.empty())); }); }  @Override CompletableFuture<Optional<U>> getUserProfileFuture(final C credentials, final AsyncWebContext context); @Override void configureFromClientsObject(Clients<AsyncClient<C, U>, AsyncAuthorizationGenerator<U>> toConfigureFrom); @Override final CompletableFuture<C> getCredentials(AsyncWebContext context); AsyncCredentialsExtractor<C> getCredentialsExtractor(); void setCredentialsExtractor(final AsyncCredentialsExtractor<C> credentialsExtractor); AsyncProfileCreator<C, U> getProfileCreator(); void setProfileCreator(AsyncProfileCreator<C, U> profileCreator); AsyncAuthenticator<C> getAuthenticator(); void setAuthenticator(AsyncAuthenticator<C> authenticator);  }