@Test(timeout = 1000) public void saveOneProfileMulti(final TestContext testContext) { profiles.put(CLIENT1, PROFILE1); webContext.setRequestAttribute(USER_PROFILES, profiles); testProfilesInSessionAfter(profileManager.save(true, PROFILE2, true), v -> completedFuture(null), assertProfileListReturned(PROFILE1, PROFILE2), testContext); }
public CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile) { final String clientName = retrieveClientName(profile); final CompletableFuture<Map<String, U>> profilesFuture; if (multiProfile) { profilesFuture = retrieveAll(saveInSession).thenApply(profiles -> { profiles.remove(clientName); return profiles; }); } else { profilesFuture = completedFuture(new LinkedHashMap<String, U>()); } final CompletableFuture<Map<String, U>> updatedProfilesFuture = profilesFuture.thenApply(profiles -> { profiles.put(clientName, profile); return profiles; }); return updatedProfilesFuture.thenCompose(profiles -> { CompletableFuture<Void> saveFuture = (saveInSession ? this.context.getSessionStore().set(context, USER_PROFILES, profiles) : completedFuture(null)) .thenAccept(v -> this.context.setRequestAttribute(USER_PROFILES, profiles)); return saveFuture; }); }
AsyncProfileManager { public CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile) { final String clientName = retrieveClientName(profile); final CompletableFuture<Map<String, U>> profilesFuture; if (multiProfile) { profilesFuture = retrieveAll(saveInSession).thenApply(profiles -> { profiles.remove(clientName); return profiles; }); } else { profilesFuture = completedFuture(new LinkedHashMap<String, U>()); } final CompletableFuture<Map<String, U>> updatedProfilesFuture = profilesFuture.thenApply(profiles -> { profiles.put(clientName, profile); return profiles; }); return updatedProfilesFuture.thenCompose(profiles -> { CompletableFuture<Void> saveFuture = (saveInSession ? this.context.getSessionStore().set(context, USER_PROFILES, profiles) : completedFuture(null)) .thenAccept(v -> this.context.setRequestAttribute(USER_PROFILES, profiles)); return saveFuture; }); } }
AsyncProfileManager { public CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile) { final String clientName = retrieveClientName(profile); final CompletableFuture<Map<String, U>> profilesFuture; if (multiProfile) { profilesFuture = retrieveAll(saveInSession).thenApply(profiles -> { profiles.remove(clientName); return profiles; }); } else { profilesFuture = completedFuture(new LinkedHashMap<String, U>()); } final CompletableFuture<Map<String, U>> updatedProfilesFuture = profilesFuture.thenApply(profiles -> { profiles.put(clientName, profile); return profiles; }); return updatedProfilesFuture.thenCompose(profiles -> { CompletableFuture<Void> saveFuture = (saveInSession ? this.context.getSessionStore().set(context, USER_PROFILES, profiles) : completedFuture(null)) .thenAccept(v -> this.context.setRequestAttribute(USER_PROFILES, profiles)); return saveFuture; }); } AsyncProfileManager(final C context); }
AsyncProfileManager { public CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile) { final String clientName = retrieveClientName(profile); final CompletableFuture<Map<String, U>> profilesFuture; if (multiProfile) { profilesFuture = retrieveAll(saveInSession).thenApply(profiles -> { profiles.remove(clientName); return profiles; }); } else { profilesFuture = completedFuture(new LinkedHashMap<String, U>()); } final CompletableFuture<Map<String, U>> updatedProfilesFuture = profilesFuture.thenApply(profiles -> { profiles.put(clientName, profile); return profiles; }); return updatedProfilesFuture.thenCompose(profiles -> { CompletableFuture<Void> saveFuture = (saveInSession ? this.context.getSessionStore().set(context, USER_PROFILES, profiles) : completedFuture(null)) .thenAccept(v -> this.context.setRequestAttribute(USER_PROFILES, profiles)); return saveFuture; }); } AsyncProfileManager(final C context); CompletableFuture<Optional<U>> get(final boolean readFromSession); CompletableFuture<List<U>> getAll(final boolean readFromSession); CompletableFuture<Void> remove(final boolean removeFromSession); CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile); CompletableFuture<Void> logout(); CompletableFuture<Boolean> isAuthenticated(); }
AsyncProfileManager { public CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile) { final String clientName = retrieveClientName(profile); final CompletableFuture<Map<String, U>> profilesFuture; if (multiProfile) { profilesFuture = retrieveAll(saveInSession).thenApply(profiles -> { profiles.remove(clientName); return profiles; }); } else { profilesFuture = completedFuture(new LinkedHashMap<String, U>()); } final CompletableFuture<Map<String, U>> updatedProfilesFuture = profilesFuture.thenApply(profiles -> { profiles.put(clientName, profile); return profiles; }); return updatedProfilesFuture.thenCompose(profiles -> { CompletableFuture<Void> saveFuture = (saveInSession ? this.context.getSessionStore().set(context, USER_PROFILES, profiles) : completedFuture(null)) .thenAccept(v -> this.context.setRequestAttribute(USER_PROFILES, profiles)); return saveFuture; }); } AsyncProfileManager(final C context); CompletableFuture<Optional<U>> get(final boolean readFromSession); CompletableFuture<List<U>> getAll(final boolean readFromSession); CompletableFuture<Void> remove(final boolean removeFromSession); CompletableFuture<Void> save(final boolean saveInSession, final U profile, final boolean multiProfile); CompletableFuture<Void> logout(); CompletableFuture<Boolean> isAuthenticated();  }