RestUtils { public static String extractParams(String pathOrEndpoint, RestParamsPropertyHolder params, boolean keepHost) { return extractParams(pathOrEndpoint, params, keepHost, TemplateExtractionOption.EXTRACT_TEMPLATE_PARAMETERS); }  static String[] extractTemplateParams(String path); static String extractParams(String pathOrEndpoint, RestParamsPropertyHolder params, boolean keepHost); static String extractParams(String pathOrEndpoint, RestParamsPropertyHolder params, boolean keepHost, TemplateExtractionOption templateExtractionOptions); static void extractParamsFromQueryString(RestParamsPropertyHolder params, String queryString); static String expandPath(String path, RestParamsPropertyHolder params, RestRequestInterface request); static String makeSuffixParameterString(RestRequestInterface request); static String getQueryParamsString(RestRequestInterface request); static List<String> splitMultipleParameters(String paramStr, String delimiter); static List<String> splitMultipleParametersEmptyIncluded(String paramStr, String delimiter); static List<RestResource> extractAncestorsParentFirst(RestResource childResource); static String getExpandedPath(String path, RestParamsPropertyHolder params, ModelItem context);  }
@Test public void extractsTemplateParameterFromCurlyBrackets() throws Exception { String path = "/{id}/42"; RestParamsPropertyHolder params = ModelItemFactory.makeRestRequest().getParams(); String extractedPath = RestUtils.extractParams(path, params, true, EXTRACT_TEMPLATE_PARAMETERS); assertThat(extractedPath, is(path)); assertEquals(params.getPropertyCount(), 1); RestParamProperty id = params.getProperty("id"); assertThat(id.getStyle(), is(TEMPLATE)); assertThat(id.getValue(), is("id")); }
@Test public void extractsTemplateParameterFromInteger() throws Exception { String path = "/{id}/42"; RestParamsPropertyHolder params = ModelItemFactory.makeRestRequest().getParams(); String extractedPath = RestUtils.extractParams(path, params, true, IGNORE_TEMPLATE_PARAMETERS); assertThat(extractedPath, is("/{id}/42")); assertEquals(params.getPropertyCount(), 0); }
@Test public void extractsEmbeddedTemplateParameters() throws Exception { String path = "/conversation/date-{date}/time-{time}?userId=1234"; RestParamsPropertyHolder params = ModelItemFactory.makeRestRequest().getParams(); String extractedPath = RestUtils.extractParams(path, params, true, EXTRACT_TEMPLATE_PARAMETERS); assertThat(extractedPath, is("/conversation/date-{date}/time-{time}")); assertThat(params.getProperty("date").getStyle(), is(TEMPLATE)); assertThat(params.getProperty("time").getStyle(), is(TEMPLATE)); }
@Test public void extractsEmbeddedTemplateAndMatrixParameters() throws Exception { String path = "/{templateParam};matrixParam=matrixValue?queryParam=value"; RestParamsPropertyHolder params = ModelItemFactory.makeRestRequest().getParams(); String extractedPath = RestUtils.extractParams(path, params, true, EXTRACT_TEMPLATE_PARAMETERS); assertThat(extractedPath, is("/{templateParam}")); assertThat(params.getProperty("templateParam").getStyle(), is(TEMPLATE)); assertThat(params.getProperty("matrixParam").getStyle(), is(MATRIX)); assertThat(params.getProperty("queryParam").getStyle(), is(QUERY)); }