ResponseUtil { public static String replaceQueryParam(String uri, String param, String value) { boolean isQuestion = uri.indexOf('?') != -1; boolean isPresent = uri.indexOf(param + "=") != -1; if (!isQuestion) { return uri + "?" + param + "=" + value; } if (isPresent) { String paramToken = uri.substring(uri.indexOf(param)); int separator = paramToken.indexOf('&'); if (separator != -1) { paramToken = paramToken.substring(0, separator); } return uri.replace(paramToken, param + "=" + value); } else { return uri + "&" + param + "=" + value; } }  static void badRequest(RoutingContext routing, String errorMsg); static void internalServerError(RoutingContext routing, String errorMsg); static void notFound(RoutingContext routing, String errorMsg); static void ok(RoutingContext routing, Object o); static void ok(RoutingContext routing); static void paginatedOk(RoutingContext routing, Page<T> page); static String tenant(RoutingContext routing); static void createPagingHeaders(RoutingContext routing, Page<T> resultList); static String replaceQueryParam(String uri, String param, String value); static Pager extractPaging(MultiMap params); static Map<String, String> parseTags(String tags); @SuppressWarnings("unchecked") static String parseTagQuery(Map<String, String> tags); static void checkForUnknownQueryParams(MultiMap params, final Set<String> expected); static boolean checkTags(Event event); static boolean checkTags(Trigger trigger); static boolean checkTags(GroupMemberInfo groupMemberInfo); static boolean checkTags(UnorphanMemberInfo groupMemberInfo); static String checkTenant(RoutingContext routing); static Set<String> getTenants(String tenantId); static Dampening getCleanDampening(Dampening dampening); @SuppressWarnings("unchecked") static void result(RoutingContext routing, AsyncResult result); static final String ACCEPT; static final String CONTENT_TYPE; static final String APPLICATION_JSON; static final String TENANT_HEADER_NAME; static final String PARAM_PAGE; static final String PARAM_PER_PAGE; static final String PARAM_SORT; static final String PARAM_ORDER; static final String PARAM_IGNORE_UNKNOWN_QUERY_PARAMS; static final Collection<String> PARAMS_PAGING; }
@Test public void replaceQueryParams() { String uri = "http: Assert.assertEquals(uri + "?page=1", ResponseUtil.replaceQueryParam(uri, "page", "1")); String uri2 = uri + "?page2=3"; Assert.assertEquals(uri2 + "&page=1", ResponseUtil.replaceQueryParam(uri2, "page", "1")); String uri3 = uri + "?page2=3&page=4"; String expected3 = uri + "?page2=5&page=4"; Assert.assertEquals(expected3, ResponseUtil.replaceQueryParam(uri3, "page2", "5")); }