groovy.lang.MissingMethodException: No signature of method:…
- User
groovy.lang.MissingMethodException: No signature of method: com.github.tomakehurst.wiremock.client.BasicMappingBuilder.call() is applicable for argument types: (java.lang.String, com.github.tomakehurst.wiremock.matching.RegexPattern) values: [$.cashMoney.crable3, matches .*] Possible solutions: wait(), any(), build(), grep(), collect(), dump()
- Assistant
This error is occurring because the
call()method is not found in theBasicMappingBuilderclass of the WireMock library. The error message suggests that you are trying to call thecall()method with two arguments, a String ($.cashMoney.crable3) and aRegexPattern(matches .*).To fix this error, you need to use the correct method from the
BasicMappingBuilderclass that matches your requirements. Check the WireMock documentation or the available methods in theBasicMappingBuilderclass to see which method you should be using. - User
.withRequestBody(WireMock.matchingJsonPath('$.cashMoney.crable3', WireMock.matching(".*"))) нужен один аргумент, а я передаю два как передать один, но не потерять суть
- Assistant
Используйте метод
withRequestBodyMatching, который позволяет вам передать только один аргумент -RegexPatternдля соответствия формата. Вам не нужно вызыватьmatchingJsonPath(), посколькуRegexPatternуже содержит информацию о пути к JSON.Вот пример использования:
.withRequestBodyMatching(WireMock.matching(".*")) - User
не существует такого
- Assistant
Извините за недоразумение. В WireMock библиотеке нет прямого метода для сопоставления запроса с использованием JSON пути и регулярного выражения. Однако, вы можете использовать кастомный
RequestMatcherдля этого.Вот пример использования:
import com.github.tomakehurst.wiremock.matching.RequestMatcher import com.github.tomakehurst.wiremock.http.Request class JsonPathAndRegexMatcher extends RequestMatcher { def jsonPath def regexPattern JsonPathAndRegexMatcher(String jsonPath, String regexPattern) { this.jsonPath = jsonPath this.regexPattern = regexPattern } boolean match(Request request) { def jsonValue = request.getBodyAsString(jsonPath) return jsonValue =~ regexPattern } } def matcher = new JsonPathAndRegexMatcher('$.cashMoney.crable3', '.*') .withRequestBodyMatching(matcher)Вы создаете новый класс,
JsonPathAndRegexMatcher, который реализует и переопределяет метод . В этом методе, вы получаете значение из с использованием JSON пути и затем проверяете его с помощью регулярного выражения .