boolean isContentTypeMatch(HttpServletRequest request, MockData mock) { String mockContentType = mock.getRequestMediaType(); if (mockContentType != null) { MediaType requestContentType = getContentType(request).orElse(MediaType.ALL); return MediaType.parseMediaType(mockContentType).includes(requestContentType); } return true; }
Map<String, String> extractRequestParams(MockData mock, String urlPath) { String requestUrl = mock.getRequestUrl(); int numberOfSlashesInMock = requestUrl.length() - requestUrl.replace("/", "").length(); int numberOfSlashesInRequest = urlPath.length() - urlPath.replace("/", "").length(); int delta = numberOfSlashesInRequest - numberOfSlashesInMock; urlPath = Stream.of(urlPath.split("/")) // .filter(part -> !Strings.isNullOrEmpty(part)) // .skip(delta) // .collect(Collectors.joining("/", "/", "")); return pathMatcher.extractUriTemplateVariables(requestUrl, urlPath); }
boolean isHttpMethodMatch(HttpServletRequest request, MockData mock) { return HttpMethod.resolve(request.getMethod()).matches(mock.getRequestMethod()); }