From 711039050e5c6a3753127a5ba7d810af29a77d11 Mon Sep 17 00:00:00 2001
From: buildmaster
Spring Cloud Contract comes with a series of predefined regular expressions that you can use in your contracts, as shown in the following example:
protected static final Pattern TRUE_OR_FALSE = Pattern.compile(/(true|false)/) protected static final Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/) -protected static final Pattern NUMBER = Pattern.compile('-?\\d*(\\.\\d+)?') +protected static final Pattern NUMBER = Pattern.compile('-?(\\d*\\.\\d+|\\d+)') protected static final Pattern IP_ADDRESS = Pattern.compile('([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])') protected static final Pattern HOSTNAME_PATTERN = Pattern.compile('((http[s]?|ftp):/)/?([^:/\\s]+)(:[0-9]{1,5})?') protected static final Pattern EMAIL = Pattern.compile('[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}') @@ -376,60 +376,60 @@ use in your contracts, as shown in the following example:return Pattern.compile(values.collect({"^$it\$"}).join("|")) } -String onlyAlphaUnicode() { - return ONLY_ALPHA_UNICODE.pattern() +Pattern onlyAlphaUnicode() { + return ONLY_ALPHA_UNICODE } -String number() { - return NUMBER.pattern() +Pattern number() { + return NUMBER } -String anyBoolean() { - return TRUE_OR_FALSE.pattern() +Pattern anyBoolean() { + return TRUE_OR_FALSE } -String ipAddress() { - return IP_ADDRESS.pattern() +Pattern ipAddress() { + return IP_ADDRESS } -String hostname() { - return HOSTNAME_PATTERN.pattern() +Pattern hostname() { + return HOSTNAME_PATTERN } -String email() { - return EMAIL.pattern() +Pattern email() { + return EMAIL } -String url() { - return URL.pattern() +Pattern url() { + return URL } -String uuid(){ - return UUID.pattern() +Pattern uuid(){ + return UUID } -String isoDate() { - return ANY_DATE.pattern() +Pattern isoDate() { + return ANY_DATE } -String isoDateTime() { - return ANY_DATE_TIME.pattern() +Pattern isoDateTime() { + return ANY_DATE_TIME } -String isoTime() { - return ANY_TIME.pattern() +Pattern isoTime() { + return ANY_TIME } -String iso8601WithOffset() { - return ISO8601_WITH_OFFSET.pattern() +Pattern iso8601WithOffset() { + return ISO8601_WITH_OFFSET } -String nonEmpty() { - return NON_EMPTY.pattern() +Pattern nonEmpty() { + return NON_EMPTY } -String nonBlank() { - return NON_BLANK.pattern() +Pattern nonBlank() { + return NON_BLANK }In your contract, you can use it as shown in the following example:
Contract dslWithOptionalsInString = Contract.make { priority 1 request { @@ -934,7 +934,7 @@ the method name and passed the proper JSON path as a parameter to it. }, { "matchesJsonPath" : "$[?(@.alpha == 'abc')]" }, { - "matchesJsonPath" : "$[?(@.number =~ /(-?\\\\d*(\\\\.\\\\d+)?)/)]" + "matchesJsonPath" : "$[?(@.number =~ /(-?(\\\\d*\\\\.\\\\d+|\\\\d+))/)]" }, { "matchesJsonPath" : "$[?(@.aBoolean =~ /((true|false))/)]" }, { @@ -1060,7 +1060,7 @@ socket.Consider the following contract:
or } }The following example shows how to set up a base class and Rest Assured:
import io.restassured.RestAssured; import org.junit.Before; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest(classes = ContextPathTestingBaseClass.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) diff --git a/multi/multi__migrations.html b/multi/multi__migrations.html index 7e5efdbd88..6c7c589f4c 100644 --- a/multi/multi__migrations.html +++ b/multi/multi__migrations.html @@ -92,4 +92,5 @@ you manually set versions of Spring Cloud Contract and the release train you might see the following exception:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project some-project: Compilation failure: Compilation failure: [ERROR] /some/path/SomeClass.java:[4,39] package com.jayway.restassured.response does not existThis exception will occur due to the fact that the tests got generated with an old version of plugin and at test execution time you have an incompatible -version of the release train (and vice versa).
Done via issue 267