@Test public void shouldCreateUser() { DefaultUser user = new DefaultUser("johndoe"); stubFor(post(urlPathEqualTo("/api/users")) .withHeader(HttpHeaders.CONTENT_TYPE, containing("application/")) .withRequestBody(matching(".*")) .willReturn(okJson("{\"id\" : \"123456789\", \"username\" : \"johndoe\"}"))); TestObserver<User> testObserver = userProvider.create(user).test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete(); testObserver.assertNoErrors(); testObserver.assertValue(u -> "123456789".equals(u.getId())); testObserver.assertValue(u -> "johndoe".equals(u.getUsername())); }
@Override public Single<User> create(User user) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration createResourceConfiguration = usersResourceConfiguration.getPaths().getCreateResource(); final String createUserURI = usersResourceConfiguration.getBaseURL() + createResourceConfiguration.getBaseURL(); final HttpMethod createUserHttpMethod = HttpMethod.valueOf(createResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> createUserHttpHeaders = createResourceConfiguration.getHttpHeaders(); final String createUserBody = createResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, createUserURI, createUserHttpMethod, createUserHttpHeaders, createUserBody); return requestHandler .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = createResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Single.error(ex); } LOGGER.error("An error has occurred while creating user {} from the remote HTTP identity provider", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while creating the user {}", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating the user", ex)); } }
HttpUserProvider implements UserProvider { @Override public Single<User> create(User user) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration createResourceConfiguration = usersResourceConfiguration.getPaths().getCreateResource(); final String createUserURI = usersResourceConfiguration.getBaseURL() + createResourceConfiguration.getBaseURL(); final HttpMethod createUserHttpMethod = HttpMethod.valueOf(createResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> createUserHttpHeaders = createResourceConfiguration.getHttpHeaders(); final String createUserBody = createResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, createUserURI, createUserHttpMethod, createUserHttpHeaders, createUserBody); return requestHandler .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = createResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Single.error(ex); } LOGGER.error("An error has occurred while creating user {} from the remote HTTP identity provider", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while creating the user {}", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating the user", ex)); } } }
HttpUserProvider implements UserProvider { @Override public Single<User> create(User user) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration createResourceConfiguration = usersResourceConfiguration.getPaths().getCreateResource(); final String createUserURI = usersResourceConfiguration.getBaseURL() + createResourceConfiguration.getBaseURL(); final HttpMethod createUserHttpMethod = HttpMethod.valueOf(createResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> createUserHttpHeaders = createResourceConfiguration.getHttpHeaders(); final String createUserBody = createResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, createUserURI, createUserHttpMethod, createUserHttpHeaders, createUserBody); return requestHandler .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = createResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Single.error(ex); } LOGGER.error("An error has occurred while creating user {} from the remote HTTP identity provider", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while creating the user {}", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating the user", ex)); } }  }
HttpUserProvider implements UserProvider { @Override public Single<User> create(User user) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration createResourceConfiguration = usersResourceConfiguration.getPaths().getCreateResource(); final String createUserURI = usersResourceConfiguration.getBaseURL() + createResourceConfiguration.getBaseURL(); final HttpMethod createUserHttpMethod = HttpMethod.valueOf(createResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> createUserHttpHeaders = createResourceConfiguration.getHttpHeaders(); final String createUserBody = createResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, createUserURI, createUserHttpMethod, createUserHttpHeaders, createUserBody); return requestHandler .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = createResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Single.error(ex); } LOGGER.error("An error has occurred while creating user {} from the remote HTTP identity provider", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while creating the user {}", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating the user", ex)); } }  @Override Maybe<User> findByUsername(String username); @Override Single<User> create(User user); @Override Single<User> update(String id, User updateUser); @Override Completable delete(String id); }
HttpUserProvider implements UserProvider { @Override public Single<User> create(User user) { try { AuthenticationContext authenticationContext = new SimpleAuthenticationContext(); TemplateEngine templateEngine = authenticationContext.getTemplateEngine(); templateEngine.getTemplateContext().setVariable(USER_CONTEXT_KEY, user); final HttpUsersResourceConfiguration usersResourceConfiguration = configuration.getUsersResource(); final HttpResourceConfiguration createResourceConfiguration = usersResourceConfiguration.getPaths().getCreateResource(); final String createUserURI = usersResourceConfiguration.getBaseURL() + createResourceConfiguration.getBaseURL(); final HttpMethod createUserHttpMethod = HttpMethod.valueOf(createResourceConfiguration.getHttpMethod().toString()); final List<HttpHeader> createUserHttpHeaders = createResourceConfiguration.getHttpHeaders(); final String createUserBody = createResourceConfiguration.getHttpBody(); final Single<HttpResponse<Buffer>> requestHandler = processRequest(templateEngine, createUserURI, createUserHttpMethod, createUserHttpHeaders, createUserBody); return requestHandler .map(httpResponse -> { final List<HttpResponseErrorCondition> errorConditions = createResourceConfiguration.getHttpResponseErrorConditions(); Map<String, Object> userAttributes = processResponse(templateEngine, errorConditions, httpResponse); return convert(user.getUsername(), userAttributes); }) .onErrorResumeNext(ex -> { if (ex instanceof AbstractManagementException) { return Single.error(ex); } LOGGER.error("An error has occurred while creating user {} from the remote HTTP identity provider", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating user from the remote HTTP identity provider", ex)); }); } catch (Exception ex) { LOGGER.error("An error has occurred while creating the user {}", user.getUsername(), ex); return Single.error(new TechnicalManagementException("An error has occurred while creating the user", ex)); } }  @Override Maybe<User> findByUsername(String username); @Override Single<User> create(User user); @Override Single<User> update(String id, User updateUser); @Override Completable delete(String id);  }