RestUtils { public static String expandPath(String path, RestParamsPropertyHolder params, RestRequestInterface request) { DefaultPropertyExpansionContext context = new DefaultPropertyExpansionContext(request); for (int c = 0; c < params.getPropertyCount(); c++) { RestParamProperty param = params.getPropertyAt(c); String value = PropertyExpander.expandProperties(context, param.getValue()); if (!StringUtils.hasContent(value) && !param.getRequired()) { continue; } if (value != null && !param.isDisableUrlEncoding()) { try { String encoding = System.getProperty("soapui.request.encoding", request.getEncoding()); encoding = StringUtils.hasContent(encoding) ? encoding : Charset.defaultCharset().toString(); value = URLEncoder.encode(value, encoding); } catch (UnsupportedEncodingException e1) { SoapUI.logError(e1); value = urlEncodeWithUtf8(value); } } if (param.getStyle() == ParameterStyle.TEMPLATE) { path = path.replaceAll("\\{" + param.getName() + "\\}", value); } } return path + makeSuffixParameterString(request); }  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 expandsRestRequestPathsWithoutTemplateParameters() throws Exception { RestRequest restRequest = makeRestRequest(); restRequest.getResource().setPath("/the/path"); addParameter(restRequest, RestParamsPropertyHolder.ParameterStyle.QUERY, "queryName", "queryValue"); addParameter(restRequest, RestParamsPropertyHolder.ParameterStyle.MATRIX, "matrixName", "theMatrixValue"); addParameter(restRequest, TEMPLATE, "templateName", "templateValue"); addParameter(restRequest, RestParamsPropertyHolder.ParameterStyle.MATRIX, "matrixName2", "theMatrixValue2"); addParameter(restRequest, RestParamsPropertyHolder.ParameterStyle.QUERY, "queryName2", "queryValue2"); assertThat(RestUtils.expandPath("/the/path", restRequest.getParams(), restRequest), is("/the/path;matrixName=theMatrixValue;matrixName2=theMatrixValue2?queryName=queryValue&queryName2=queryValue2")); }
@Test public void expandsRestRequestPathsWithTemplateParameter() throws Exception { RestRequest restRequest = makeRestRequest(); String templateParameterName = "templateName"; String templateParameterValue = "templateValue"; restRequest.getResource().setPath("/the/{" + templateParameterName + "}/path"); addParameter(restRequest, TEMPLATE, templateParameterName, templateParameterValue); assertThat(RestUtils.expandPath(restRequest.getResource().getFullPath(), restRequest.getParams(), restRequest), is("/the/" + templateParameterValue + "/path")); }