Merge branch 'master' into new_docs

This commit is contained in:
Marcin Grzejszczak
2019-07-24 11:27:24 +02:00
33 changed files with 524 additions and 36 deletions

View File

@@ -1,6 +1,6 @@
FROM ubuntu:18.10 FROM ubuntu:18.10
ARG SDKMAN_JAVA_INSTALLATION=8.0.212-zulu ARG SDKMAN_JAVA_INSTALLATION=8.0.222-zulu
MAINTAINER Marcin Grzejszczak <mgrzejszczak@pivotal.io> MAINTAINER Marcin Grzejszczak <mgrzejszczak@pivotal.io>

View File

@@ -1,6 +1,6 @@
FROM ubuntu:18.10 FROM ubuntu:18.10
ARG SDKMAN_JAVA_INSTALLATION=8.0.212-zulu ARG SDKMAN_JAVA_INSTALLATION=8.0.222-zulu
MAINTAINER Marcin Grzejszczak <mgrzejszczak@pivotal.io> MAINTAINER Marcin Grzejszczak <mgrzejszczak@pivotal.io>

View File

@@ -70,7 +70,7 @@ messaging configuration, so you only need the one annotation.
Having the `input` or `outputMessage` sections in your DSL results in creation of tests Having the `input` or `outputMessage` sections in your DSL results in creation of tests
on the publisher's side. By default, JUnit 4 tests are created. However, there is also a on the publisher's side. By default, JUnit 4 tests are created. However, there is also a
possibility to create JUnit 5 or Spock tests. possibility to create JUnit 5, TestNG or Spock tests.
There are 3 main scenarios that we should take into consideration: There are 3 main scenarios that we should take into consideration:

View File

@@ -11,15 +11,14 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1 <spring-cloud.version>Hoxton.BUILD-SNAPSHOT</spring-cloud.version>
</spring-cloud.version>
</properties> </properties>
<dependencies> <dependencies>

View File

@@ -11,15 +11,15 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository --> <relativePath /> <!-- lookup parent from repository -->
</parent> </parent>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version> <spring-cloud.version>Hoxton.BUILD-SNAPSHOT</spring-cloud.version>
<spring-cloud-contract.version>2.1.1.RELEASE</spring-cloud-contract.version> <spring-cloud-contract.version>2.2.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
</properties> </properties>
<dependencies> <dependencies>

View File

@@ -11,7 +11,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -11,15 +11,15 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository --> <relativePath /> <!-- lookup parent from repository -->
</parent> </parent>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version> <spring-cloud.version>Hoxton.BUILD-SNAPSHOT</spring-cloud.version>
<spring-cloud-contract.version>2.0.2.RELEASE</spring-cloud-contract.version> <spring-cloud-contract.version>2.2.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
</properties> </properties>
<dependencies> <dependencies>

View File

@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M4</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M4</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M4</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M4</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M4</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.M4</version> <version>2.2.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>

View File

@@ -16,4 +16,4 @@
wiremockVersion=2.23.2 wiremockVersion=2.23.2
jsonAssertVersion=0.4.13 jsonAssertVersion=0.4.13
verifierVersion=2.2.0.BUILD-SNAPSHOT verifierVersion=2.2.0.BUILD-SNAPSHOT
bootVersion=2.2.0.M4 bootVersion=2.2.0.BUILD-SNAPSHOT

View File

@@ -16,4 +16,4 @@
wiremockVersion=2.23.2 wiremockVersion=2.23.2
jsonAssertVersion=0.4.13 jsonAssertVersion=0.4.13
verifierVersion=2.2.0.BUILD-SNAPSHOT verifierVersion=2.2.0.BUILD-SNAPSHOT
bootVersion=2.2.0.M4 bootVersion=2.2.0.BUILD-SNAPSHOT

View File

@@ -16,5 +16,5 @@
wiremockVersion=2.23.2 wiremockVersion=2.23.2
jsonAssertVersion=0.4.13 jsonAssertVersion=0.4.13
verifierVersion=2.2.0.BUILD-SNAPSHOT verifierVersion=2.2.0.BUILD-SNAPSHOT
bootVersion=2.2.0.M4 bootVersion=2.2.0.BUILD-SNAPSHOT
groovyVersion=2.4.17 groovyVersion=2.4.17

View File

@@ -167,6 +167,11 @@
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId> <artifactId>spring-boot-starter-jersey</artifactId>
@@ -233,6 +238,9 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -67,6 +67,11 @@ class ImportsBuilder {
return this; return this;
} }
ImportsBuilder testNG() {
this.parentBuilder.imports(new TestNGImports(builder, metaData));
return this;
}
ImportsBuilder spock() { ImportsBuilder spock() {
this.parentBuilder.imports(new SpockImports(builder, metaData), this.parentBuilder.imports(new SpockImports(builder, metaData),
new SpockIgnoreImports(builder, metaData), new SpockIgnoreImports(builder, metaData),

View File

@@ -97,7 +97,9 @@ class JavaClassMetaData implements ClassMetaData, DefaultClassMetadata {
return this.generatedClassMetaData.configProperties return this.generatedClassMetaData.configProperties
.getTestFramework() == TestFramework.JUNIT .getTestFramework() == TestFramework.JUNIT
|| this.generatedClassMetaData.configProperties || this.generatedClassMetaData.configProperties
.getTestFramework() == TestFramework.JUNIT5; .getTestFramework() == TestFramework.JUNIT5
|| this.generatedClassMetaData.configProperties
.getTestFramework() == TestFramework.TESTNG;
} }
} }

View File

@@ -73,6 +73,7 @@ public class JavaTestGenerator implements SingleTestGenerator {
.json() .json()
.jUnit4() .jUnit4()
.jUnit5() .jUnit5()
.testNG()
.spock() .spock()
.xml() .xml()
.messaging() .messaging()
@@ -107,6 +108,7 @@ public class JavaTestGenerator implements SingleTestGenerator {
.methodAnnotation() .methodAnnotation()
.jUnit4() .jUnit4()
.jUnit5() .jUnit5()
.testNG()
.spock() .spock()
.build() .build()
.methodMetadata() .methodMetadata()

View File

@@ -44,6 +44,12 @@ class MethodAnnotationBuilder {
return this; return this;
} }
MethodAnnotationBuilder testNG() {
this.singleMethodBuilder.methodAnnotation(
new TestNGMethodAnnotation(this.builder, this.metaData));
return this;
}
MethodAnnotationBuilder spock() { MethodAnnotationBuilder spock() {
this.singleMethodBuilder.methodAnnotation( this.singleMethodBuilder.methodAnnotation(
new SpockIgnoreMethodAnnotation(this.builder, this.metaData)); new SpockIgnoreMethodAnnotation(this.builder, this.metaData));

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.builder;
import java.util.Arrays;
import org.springframework.cloud.contract.verifier.config.TestFramework;
class TestNGImports implements Imports {
private final BlockBuilder blockBuilder;
private final GeneratedClassMetaData generatedClassMetaData;
private static final String[] IMPORTS = { "org.testng.annotations.Test" };
TestNGImports(BlockBuilder blockBuilder,
GeneratedClassMetaData generatedClassMetaData) {
this.blockBuilder = blockBuilder;
this.generatedClassMetaData = generatedClassMetaData;
}
@Override
public Imports call() {
Arrays.stream(IMPORTS)
.forEach(s -> this.blockBuilder.addLineWithEnding("import " + s));
return this;
}
@Override
public boolean accept() {
return this.generatedClassMetaData.configProperties
.getTestFramework() == TestFramework.TESTNG;
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.builder;
import org.springframework.cloud.contract.verifier.config.TestFramework;
import org.springframework.cloud.contract.verifier.file.SingleContractMetadata;
class TestNGMethodAnnotation implements MethodAnnotations {
private final BlockBuilder blockBuilder;
private final GeneratedClassMetaData generatedClassMetaData;
TestNGMethodAnnotation(BlockBuilder blockBuilder,
GeneratedClassMetaData generatedClassMetaData) {
this.blockBuilder = blockBuilder;
this.generatedClassMetaData = generatedClassMetaData;
}
@Override
public MethodVisitor<MethodAnnotations> apply(
SingleContractMetadata singleContractMetadata) {
final String annotation = singleContractMetadata.isIgnored()
? "@Test(enabled = false)" : "@Test";
this.blockBuilder.addIndented(annotation);
return this;
}
@Override
public boolean accept(SingleContractMetadata singleContractMetadata) {
return this.generatedClassMetaData.configProperties
.getTestFramework() == TestFramework.TESTNG;
}
}

View File

@@ -24,6 +24,7 @@ import static org.springframework.cloud.contract.verifier.config.TestFramework.C
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5 import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK
import static org.springframework.cloud.contract.verifier.config.TestFramework.TESTNG
/** /**
* Provides imports based on test framework. * Provides imports based on test framework.
@@ -47,12 +48,14 @@ class BaseImportProvider {
(JUNIT) : new ImportDefinitions(['org.junit.Test']), (JUNIT) : new ImportDefinitions(['org.junit.Test']),
(JUNIT5): new ImportDefinitions(['org.junit.jupiter.api.Test']), (JUNIT5): new ImportDefinitions(['org.junit.jupiter.api.Test']),
(SPOCK) : new ImportDefinitions([]), (SPOCK) : new ImportDefinitions([]),
(TESTNG): new ImportDefinitions(['org.testng.annotations.Test']),
(CUSTOM): new ImportDefinitions([])] (CUSTOM): new ImportDefinitions([])]
private static final Map<TestFramework, String> RULE_IMPORT = [ private static final Map<TestFramework, String> RULE_IMPORT = [
(JUNIT) : 'org.junit.Rule', (JUNIT) : 'org.junit.Rule',
(JUNIT5): 'org.junit.jupiter.api.extension.ExtendWith', (JUNIT5): 'org.junit.jupiter.api.extension.ExtendWith',
(SPOCK) : 'org.junit.Rule', (SPOCK) : 'org.junit.Rule',
(TESTNG): 'org.junit.Rule',
(CUSTOM): 'org.junit.Rule' (CUSTOM): 'org.junit.Rule'
] ]

View File

@@ -23,6 +23,7 @@ import static org.springframework.cloud.contract.verifier.config.TestFramework.C
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5 import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK
import static org.springframework.cloud.contract.verifier.config.TestFramework.TESTNG
import static org.springframework.cloud.contract.verifier.config.TestMode.EXPLICIT import static org.springframework.cloud.contract.verifier.config.TestMode.EXPLICIT
import static org.springframework.cloud.contract.verifier.config.TestMode.JAXRSCLIENT import static org.springframework.cloud.contract.verifier.config.TestMode.JAXRSCLIENT
import static org.springframework.cloud.contract.verifier.config.TestMode.MOCKMVC import static org.springframework.cloud.contract.verifier.config.TestMode.MOCKMVC
@@ -47,6 +48,7 @@ class HttpImportProvider {
private final Map<Tuple2<TestFramework, TestMode>, ImportDefinitions> FRAMEWORK_AND_TEST_MODE_SPECIFIC_IMPORTS = [ private final Map<Tuple2<TestFramework, TestMode>, ImportDefinitions> FRAMEWORK_AND_TEST_MODE_SPECIFIC_IMPORTS = [
(new Tuple2(JUNIT, JAXRSCLIENT)) : new ImportDefinitions(['javax.ws.rs.core.Response']), (new Tuple2(JUNIT, JAXRSCLIENT)) : new ImportDefinitions(['javax.ws.rs.core.Response']),
(new Tuple2(JUNIT5, JAXRSCLIENT)) : new ImportDefinitions(['javax.ws.rs.core.Response']), (new Tuple2(JUNIT5, JAXRSCLIENT)) : new ImportDefinitions(['javax.ws.rs.core.Response']),
(new Tuple2(TESTNG, JAXRSCLIENT)) : new ImportDefinitions(['javax.ws.rs.core.Response']),
(new Tuple2(JUNIT, MOCKMVC)) : new ImportDefinitions([ (new Tuple2(JUNIT, MOCKMVC)) : new ImportDefinitions([
"${restAssuredPackage}.module.mockmvc.specification.MockMvcRequestSpecification", "${restAssuredPackage}.module.mockmvc.specification.MockMvcRequestSpecification",
"${restAssuredPackage}.response.ResponseOptions"]), "${restAssuredPackage}.response.ResponseOptions"]),
@@ -59,10 +61,18 @@ class HttpImportProvider {
(new Tuple2(JUNIT5, WEBTESTCLIENT)): new ImportDefinitions([ (new Tuple2(JUNIT5, WEBTESTCLIENT)): new ImportDefinitions([
'io.restassured.module.webtestclient.specification.WebTestClientRequestSpecification', 'io.restassured.module.webtestclient.specification.WebTestClientRequestSpecification',
'io.restassured.module.webtestclient.response.WebTestClientResponse']), 'io.restassured.module.webtestclient.response.WebTestClientResponse']),
(new Tuple2(TESTNG, MOCKMVC)) : new ImportDefinitions([
"${restAssuredPackage}.module.mockmvc.specification.MockMvcRequestSpecification",
"${restAssuredPackage}.response.ResponseOptions"]),
(new Tuple2(TESTNG, WEBTESTCLIENT)): new ImportDefinitions([
'io.restassured.module.webtestclient.specification.WebTestClientRequestSpecification',
'io.restassured.module.webtestclient.response.WebTestClientResponse']),
(new Tuple2(JUNIT, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification", (new Tuple2(JUNIT, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification",
"${restAssuredPackage}.response.Response"]), "${restAssuredPackage}.response.Response"]),
(new Tuple2(JUNIT5, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification", (new Tuple2(JUNIT5, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification",
"${restAssuredPackage}.response.Response"]), "${restAssuredPackage}.response.Response"]),
(new Tuple2(TESTNG, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification",
"${restAssuredPackage}.response.Response"]),
(new Tuple2(SPOCK, JAXRSCLIENT)) : new ImportDefinitions([]), (new Tuple2(SPOCK, JAXRSCLIENT)) : new ImportDefinitions([]),
(new Tuple2(CUSTOM, JAXRSCLIENT)) : new ImportDefinitions([]), (new Tuple2(CUSTOM, JAXRSCLIENT)) : new ImportDefinitions([]),
(new Tuple2(SPOCK, MOCKMVC)) : new ImportDefinitions([]), (new Tuple2(SPOCK, MOCKMVC)) : new ImportDefinitions([]),

View File

@@ -23,6 +23,7 @@ import org.springframework.cloud.contract.verifier.config.framework.JUnit5Defini
import org.springframework.cloud.contract.verifier.config.framework.JUnitDefinition; import org.springframework.cloud.contract.verifier.config.framework.JUnitDefinition;
import org.springframework.cloud.contract.verifier.config.framework.SpockDefinition; import org.springframework.cloud.contract.verifier.config.framework.SpockDefinition;
import org.springframework.cloud.contract.verifier.config.framework.TestFrameworkDefinition; import org.springframework.cloud.contract.verifier.config.framework.TestFrameworkDefinition;
import org.springframework.cloud.contract.verifier.config.framework.TestNGDefinition;
/** /**
* Contains main building blocks for a test class for the given framework. * Contains main building blocks for a test class for the given framework.
@@ -46,6 +47,10 @@ public enum TestFramework {
* JUnit5 test framework. * JUnit5 test framework.
*/ */
JUNIT5(new JUnit5Definition()), JUNIT5(new JUnit5Definition()),
/**
* TestNG test framework.
*/
TESTNG(new TestNGDefinition()),
/** /**
* Custom test framework. * Custom test framework.
*/ */

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.config.framework
import groovy.transform.CompileStatic
/**
* Defines elements characteristic of TestNG test framework to be used during test class construction.
*
* @author André Hoffmann
*
* @since 2.2.0
*/
@CompileStatic
class TestNGDefinition implements TestFrameworkDefinition {
@Override
String getClassModifier() {
return 'public '
}
@Override
String getMethodModifier() {
return 'public void '
}
@Override
String getLineSuffix() {
return ';'
}
@Override
String getClassExtension() {
'.java'
}
@Override
String getClassNameSuffix() {
return 'Test'
}
@Override
String getIgnoreClass() {
throw new UnsupportedOperationException('There is no @Ignore annotation for TestNG. A test can be disabled directly in the @Test annotation')
}
@Override
List<String> getOrderAnnotationImports() {
throw new UnsupportedOperationException('Not implemented yet in TestNG')
}
@Override
String getOrderAnnotation() {
throw new UnsupportedOperationException('Not implemented yet in TestNG')
}
@Override
String getIgnoreAnnotation() {
throw new UnsupportedOperationException('There is no @Ignore annotation for TestNG. A test can be disabled directly in the @Test annotation')
}
@Override
boolean annotationLevelRules() {
return false
}
@Override
String getRuleAnnotation(String annotationValue) {
throw new UnsupportedOperationException('Not available in TestNG.')
}
}

View File

@@ -154,6 +154,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#588') @Issue('#588')
@@ -196,6 +199,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#521') @Issue('#521')
@@ -241,6 +247,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#269') @Issue('#269')
@@ -288,6 +297,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#289') @Issue('#289')
@@ -333,6 +345,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#313') @Issue('#313')
@@ -375,6 +390,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#318') @Issue('#318')
@@ -423,6 +441,13 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
contains('assertThat(response.header("Content-Length")).isEqualTo(4);') && testBody. contains('assertThat(response.header("Content-Length")).isEqualTo(4);') && testBody.
contains('assertThat(response.header("Content-Type")).matches("application/pdf.*");') contains('assertThat(response.header("Content-Type")).matches("application/pdf.*");')
} }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
} | { String testBody ->
testBody.
contains('assertThat(response.header("Content-Length")).isEqualTo(4);') && testBody.
contains('assertThat(response.header("Content-Type")).matches("application/pdf.*");')
}
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String testBody -> } | { String testBody ->
@@ -491,6 +516,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#424') @Issue('#424')
@@ -535,6 +563,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#458') @Issue('#458')
@@ -571,6 +602,11 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
} | { String string -> } | { String string ->
string.contains('assertThat(responseBody).isEqualTo("My name");') string.contains('assertThat(responseBody).isEqualTo("My name");')
} }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
} | { String string ->
string.contains('assertThat(responseBody).isEqualTo("My name");')
}
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String string -> } | { String string ->
@@ -636,6 +672,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#702') @Issue('#702')
@@ -701,6 +740,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#465') @Issue('#465')
@@ -753,6 +795,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
def 'should use fixed delay milliseconds in the generated test [#methodBuilderName]'() { def 'should use fixed delay milliseconds in the generated test [#methodBuilderName]'() {
@@ -829,6 +874,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#578') @Issue('#578')
@@ -893,6 +941,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#493') @Issue('#493')
@@ -953,6 +1004,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
def 'should work with files that have new lines [#methodBuilderName]'() { def 'should work with files that have new lines [#methodBuilderName]'() {
@@ -999,6 +1053,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue('#509') @Issue('#509')
@@ -1075,6 +1132,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
def 'should not escape a regex pattern when matching raw body value [#methodBuilderName]'() { def 'should not escape a regex pattern when matching raw body value [#methodBuilderName]'() {
@@ -1114,6 +1174,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#664") @Issue("#664")
@@ -1145,6 +1208,13 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
} | { String string -> } | { String string ->
string.contains('assertThat(response.getBody().asByteArray()).isEqualTo(fileToBytes(this, "worksWithPdf_response_response.pdf"));') string.contains('assertThat(response.getBody().asByteArray()).isEqualTo(fileToBytes(this, "worksWithPdf_response_response.pdf"));')
} }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
} | { String string ->
string.contains('.body(fileToBytes(this, "worksWithPdf_request_request.pdf"));')
} | { String string ->
string.contains('assertThat(response.getBody().asByteArray()).isEqualTo(fileToBytes(this, "worksWithPdf_response_response.pdf"));')
}
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String string -> } | { String string ->
@@ -1245,6 +1315,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#852") @Issue("#852")
@@ -1291,6 +1364,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#844") @Issue("#844")
@@ -1348,6 +1424,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#652") @Issue("#652")
@@ -1448,6 +1527,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#727") @Issue("#727")
@@ -1497,6 +1579,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#892") @Issue("#892")
@@ -1543,6 +1628,13 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
contains('''assertThat(response.header("Content-Type")).matches("^\\\\s*\\\\S[\\\\S\\\\s]*")''') && testContent. contains('''assertThat(response.header("Content-Type")).matches("^\\\\s*\\\\S[\\\\S\\\\s]*")''') && testContent.
contains('''assertThat(response.header("Content-Length")).matches("([1-9]\\\\d*)")'''); return true contains('''assertThat(response.header("Content-Length")).matches("([1-9]\\\\d*)")'''); return true
} }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
} | { String testContent ->
assert testContent.
contains('''assertThat(response.header("Content-Type")).matches("^\\\\s*\\\\S[\\\\S\\\\s]*")''') && testContent.
contains('''assertThat(response.header("Content-Length")).matches("([1-9]\\\\d*)")'''); return true
}
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String testContent -> } | { String testContent ->
@@ -1599,6 +1691,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#1052") @Issue("#1052")
@@ -1656,6 +1751,9 @@ response:
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
@Issue("#1049") @Issue("#1049")
@@ -1695,6 +1793,9 @@ response:
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
def 'should resolve headers from request correctly'() { def 'should resolve headers from request correctly'() {
@@ -1744,7 +1845,9 @@ response:
"jaxrs" | { "jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
} }
"testNG" | {
properties.testFramework = TestFramework.TESTNG
}
} }
} }

View File

@@ -245,6 +245,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder | rootElement methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -320,6 +321,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder | rootElement methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -380,6 +382,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder | rootElement methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -420,6 +423,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder | rootElement methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -461,6 +465,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder | rootElement methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -504,6 +509,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder | rootElement methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -555,6 +561,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -602,6 +609,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT

View File

@@ -32,6 +32,7 @@ import org.springframework.util.StringUtils
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5 import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK
import static org.springframework.cloud.contract.verifier.config.TestFramework.TESTNG
import static org.springframework.cloud.contract.verifier.config.TestMode.EXPLICIT import static org.springframework.cloud.contract.verifier.config.TestMode.EXPLICIT
import static org.springframework.cloud.contract.verifier.config.TestMode.JAXRSCLIENT import static org.springframework.cloud.contract.verifier.config.TestMode.JAXRSCLIENT
import static org.springframework.cloud.contract.verifier.config.TestMode.MOCKMVC import static org.springframework.cloud.contract.verifier.config.TestMode.MOCKMVC
@@ -94,6 +95,32 @@ class SingleTestGeneratorSpec extends Specification {
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static io.restassured.RestAssured.*;', 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static io.restassured.RestAssured.*;',
'@Test', '@Disabled', 'import io.restassured.specification.RequestSpecification;', '@Test', '@Disabled', 'import io.restassured.specification.RequestSpecification;',
'import io.restassured.response.Response;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat'] 'import io.restassured.response.Response;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat']
private static
final List<String> mockMvcTestNGRestAssured2ClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
'import org.testng.annotations.Test;',
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static com.jayway.restassured.module.mockmvc.RestAssuredMockMvc.*;',
'@Test', 'import com.jayway.restassured.module.mockmvc.specification.MockMvcRequestSpecification;',
'import com.jayway.restassured.response.ResponseOptions;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat']
private static
final List<String> mockMvcTestNGRestAssured3ClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
'import org.testng.annotations.Test;',
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static io.restassured.module.mockmvc.RestAssuredMockMvc.*;',
'@Test', 'import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification;',
'import io.restassured.response.ResponseOptions;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat']
private static
final List<String> explicitTestNGRestAssured2ClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
'org.testng.annotations.Test;',
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static com.jayway.restassured.RestAssured.*;',
'@Test', 'import com.jayway.restassured.specification.RequestSpecification;',
'import com.jayway.restassured.response.Response;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat']
private static
final List<String> explicitTestNGRestAssured3ClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
'import org.testng.annotations.Test;',
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static io.restassured.RestAssured.*;',
'@Test', 'import io.restassured.specification.RequestSpecification;',
'import io.restassured.response.Response;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat']
private static final List<String> spockClassRestAssured2Strings = ['import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath', private static final List<String> spockClassRestAssured2Strings = ['import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
@@ -188,6 +215,8 @@ class SingleTestGeneratorSpec extends Specification {
JUNIT | 2 | EXPLICIT | explicitJUnitRestAssured3ClassStrings | JAVA_ASSERTER JUNIT | 2 | EXPLICIT | explicitJUnitRestAssured3ClassStrings | JAVA_ASSERTER
JUNIT5 | null | MOCKMVC | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER JUNIT5 | null | MOCKMVC | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER
JUNIT5 | null | EXPLICIT | explicitJUnit5RestAssured3ClassStrings | JAVA_ASSERTER JUNIT5 | null | EXPLICIT | explicitJUnit5RestAssured3ClassStrings | JAVA_ASSERTER
TESTNG | null | MOCKMVC | mockMvcTestNGRestAssured3ClassStrings | JAVA_ASSERTER
TESTNG | null | EXPLICIT | explicitTestNGRestAssured3ClassStrings | JAVA_ASSERTER
SPOCK | 2 | MOCKMVC | spockClassRestAssured3Strings | GROOVY_ASSERTER SPOCK | 2 | MOCKMVC | spockClassRestAssured3Strings | GROOVY_ASSERTER
SPOCK | 2 | EXPLICIT | explicitSpockRestAssured3ClassStrings | GROOVY_ASSERTER SPOCK | 2 | EXPLICIT | explicitSpockRestAssured3ClassStrings | GROOVY_ASSERTER
} }
@@ -218,6 +247,8 @@ class SingleTestGeneratorSpec extends Specification {
JUNIT | EXPLICIT | JAVA_ASSERTER | 'ContractsTest.java' JUNIT | EXPLICIT | JAVA_ASSERTER | 'ContractsTest.java'
JUNIT5 | MOCKMVC | JAVA_ASSERTER | 'ContractsTest.java' JUNIT5 | MOCKMVC | JAVA_ASSERTER | 'ContractsTest.java'
JUNIT5 | EXPLICIT | JAVA_ASSERTER | 'ContractsTest.java' JUNIT5 | EXPLICIT | JAVA_ASSERTER | 'ContractsTest.java'
TESTNG | MOCKMVC | JAVA_ASSERTER | 'ContractsTest.java'
TESTNG | EXPLICIT | JAVA_ASSERTER | 'ContractsTest.java'
SPOCK | MOCKMVC | GROOVY_ASSERTER | 'ContractsSpec.groovy' SPOCK | MOCKMVC | GROOVY_ASSERTER | 'ContractsSpec.groovy'
SPOCK | EXPLICIT | GROOVY_ASSERTER | 'ContractsSpec.groovy' SPOCK | EXPLICIT | GROOVY_ASSERTER | 'ContractsSpec.groovy'
} }
@@ -291,6 +322,8 @@ class SingleTestGeneratorSpec extends Specification {
JUNIT | EXPLICIT | explicitJUnitRestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 } JUNIT | EXPLICIT | explicitJUnitRestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 }
JUNIT5 | MOCKMVC | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 } JUNIT5 | MOCKMVC | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 }
JUNIT5 | EXPLICIT | explicitJUnit5RestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 } JUNIT5 | EXPLICIT | explicitJUnit5RestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 }
TESTNG | MOCKMVC | mockMvcTestNGRestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 }
TESTNG | EXPLICIT | explicitTestNGRestAssured3ClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 }
SPOCK | MOCKMVC | spockClassRestAssured3Strings | GROOVY_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 } SPOCK | MOCKMVC | spockClassRestAssured3Strings | GROOVY_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification') == 2 }
SPOCK | EXPLICIT | explicitSpockRestAssured2ClassStrings | GROOVY_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification request') == 2 } SPOCK | EXPLICIT | explicitSpockRestAssured2ClassStrings | GROOVY_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, '\t\t\tMockMvcRequestSpecification request') == 2 }
} }
@@ -317,6 +350,7 @@ class SingleTestGeneratorSpec extends Specification {
testFramework | classStrings | asserter testFramework | classStrings | asserter
JUNIT | ['import static javax.ws.rs.client.Entity.*', 'import javax.ws.rs.core.Response'] | JAVA_JAXRS_ASSERTER JUNIT | ['import static javax.ws.rs.client.Entity.*', 'import javax.ws.rs.core.Response'] | JAVA_JAXRS_ASSERTER
JUNIT5 | ['import static javax.ws.rs.client.Entity.*', 'import javax.ws.rs.core.Response'] | JAVA_JAXRS_ASSERTER JUNIT5 | ['import static javax.ws.rs.client.Entity.*', 'import javax.ws.rs.core.Response'] | JAVA_JAXRS_ASSERTER
TESTNG | ['import static javax.ws.rs.client.Entity.*', 'import javax.ws.rs.core.Response'] | JAVA_JAXRS_ASSERTER
SPOCK | ['import static javax.ws.rs.client.Entity.*'] | GROOVY_ASSERTER SPOCK | ['import static javax.ws.rs.client.Entity.*'] | GROOVY_ASSERTER
} }
@@ -364,6 +398,7 @@ class SingleTestGeneratorSpec extends Specification {
testFramework | order | classStrings | asserter testFramework | order | classStrings | asserter
JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | JAVA_ASSERTER JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | JAVA_ASSERTER
JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER
TESTNG | null | mockMvcTestNGRestAssured3ClassStrings | JAVA_ASSERTER
SPOCK | 2 | spockClassRestAssured3Strings | GROOVY_ASSERTER SPOCK | 2 | spockClassRestAssured3Strings | GROOVY_ASSERTER
} }
@@ -403,10 +438,26 @@ class SingleTestGeneratorSpec extends Specification {
asserter(clazz) asserter(clazz)
where: where:
testFramework | order | classStrings | ignoreAnnotation | asserter testFramework | order | classStrings | ignoreAnnotation | asserter
JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | '@Ignore' | JAVA_ASSERTER JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | '@Ignore' | JAVA_ASSERTER
JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | '@Disabled' | JAVA_ASSERTER JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | '@Disabled' | JAVA_ASSERTER
SPOCK | 2 | spockClassRestAssured3Strings | '@Ignore' | GROOVY_ASSERTER TESTNG | null | mockMvcTestNGRestAssured3ClassStrings | '@Test(enabled = false)' | JAVA_ASSERTER
SPOCK | 2 | spockClassRestAssured3Strings | '@Ignore' | GROOVY_ASSERTER
}
def 'should not allow the usage of ignore annotations for TestNG '() {
given:
TestFramework testNG = TESTNG
when:
testNG.getIgnoreClass()
then:
thrown UnsupportedOperationException
when:
testNG.getIgnoreAnnotation()
then:
thrown UnsupportedOperationException
} }
@Issue('#117') @Issue('#117')
@@ -490,7 +541,7 @@ class SingleTestGeneratorSpec extends Specification {
then: then:
clazz.contains('validate_mySuperMethod()') clazz.contains('validate_mySuperMethod()')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
def "should pick the contract's name as the test method when there are multiple contracts for #testFramework"() { def "should pick the contract's name as the test method when there are multiple contracts for #testFramework"() {
@@ -523,7 +574,7 @@ class SingleTestGeneratorSpec extends Specification {
clazz.contains('validate_shouldHaveIndex1()') clazz.contains('validate_shouldHaveIndex1()')
clazz.contains('validate_shouldHaveIndex2()') clazz.contains('validate_shouldHaveIndex2()')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
def 'should generate the test method when there are multiple contracts without name field for #testFramework'() { def 'should generate the test method when there are multiple contracts without name field for #testFramework'() {
@@ -555,7 +606,7 @@ class SingleTestGeneratorSpec extends Specification {
clazz.contains('_0() throws Exception') clazz.contains('_0() throws Exception')
clazz.contains('_1() throws Exception') clazz.contains('_1() throws Exception')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
@Issue('#359') @Issue('#359')
@@ -581,7 +632,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json') test.contains('readFromFile_request_request.json')
test.contains('RESPONSE') test.contains('RESPONSE')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
@Issue('#260') @Issue('#260')
@@ -606,7 +657,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json') test.contains('readFromFile_request_request.json')
test.contains('RESPONSE') test.contains('RESPONSE')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
@Issue('#260') @Issue('#260')
@@ -631,7 +682,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json') test.contains('readFromFile_request_request.json')
test.contains('RESPONSE') test.contains('RESPONSE')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
@Issue('#260') @Issue('#260')
@@ -656,7 +707,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json') test.contains('readFromFile_request_request.json')
test.contains('RESPONSE') test.contains('RESPONSE')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
@Issue('#260') @Issue('#260')
@@ -680,7 +731,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json') test.contains('readFromFile_request_request.json')
test.contains('RESPONSE') test.contains('RESPONSE')
where: where:
testFramework << [JUNIT, JUNIT5, SPOCK] testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
} }
def 'should throw exception in JUnit5 when contract belongs to scenario'() { def 'should throw exception in JUnit5 when contract belongs to scenario'() {

View File

@@ -214,6 +214,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -277,6 +278,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -314,6 +316,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -354,6 +357,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -388,6 +392,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | '.body("{\\"items\\":[\\"HOP\\"]}")' } | '.body("{\\"items\\":[\\"HOP\\"]}")'
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | '.body("{\\"items\\":[\\"HOP\\"]}")'
"webclient" | { "webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT properties.testMode = TestMode.WEBTESTCLIENT
} | '.body("{\\"items\\":[\\"HOP\\"]}")' } | '.body("{\\"items\\":[\\"HOP\\"]}")'
@@ -420,6 +427,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder | bodyString methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | """.body('''property1=VAL1''')""" "spock" | { properties.testFramework = TestFramework.SPOCK } | """.body('''property1=VAL1''')"""
"testng" | { properties.testFramework = TestFramework.TESTNG }| '.body("property1=VAL1")'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.body("property1=VAL1")' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.body("property1=VAL1")'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '.body("property1=VAL1")' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '.body("property1=VAL1")'
} }
@@ -455,6 +463,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -490,6 +499,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -524,6 +534,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -558,6 +569,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -596,6 +608,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -630,6 +643,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -664,6 +678,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -720,6 +735,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -777,6 +793,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -805,6 +822,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder | bodyString methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | ".body('''''')" "spock" | { properties.testFramework = TestFramework.SPOCK } | ".body('''''')"
"testng" | { properties.testFramework = TestFramework.TESTNG }| '.body("")'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.body("")' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.body("")'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '.body("")' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '.body("")'
} }
@@ -836,6 +854,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} | 'String responseBody = response.body.asString()' | "responseBody == 'test'" } | 'String responseBody = response.body.asString()' | "responseBody == 'test'"
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");' } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
@@ -880,6 +901,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder | headerEvaluationString methodBuilderName | methodBuilder | headerEvaluationString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '''response.header("Location") ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')''' "spock" | { properties.testFramework = TestFramework.SPOCK } | '''response.header("Location") ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");' } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
@@ -924,6 +948,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder | headerEvaluationString methodBuilderName | methodBuilder | headerEvaluationString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '''response.header("Location") ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):/)/?([^:/\\\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')''' "spock" | { properties.testFramework = TestFramework.SPOCK } | '''response.header("Location") ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):/)/?([^:/\\\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/\\\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/\\\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");' } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/\\\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
@@ -970,6 +997,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1004,6 +1032,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1045,6 +1074,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1133,6 +1163,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} | ['''assertThatRejectionReasonIsNull(parsedJson.read("\\$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))'''] } | ['''assertThatRejectionReasonIsNull(parsedJson.read("\\$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))'''] } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
@@ -1205,6 +1238,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder | bodyString methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '"street":"Light Street"' "spock" | { properties.testFramework = TestFramework.SPOCK } | '"street":"Light Street"'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '\\"street\\":\\"Light Street\\"'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '\\"street\\":\\"Light Street\\"' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '\\"street\\":\\"Light Street\\"'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '\\"street\\":\\"Light Street\\"' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '\\"street\\":\\"Light Street\\"'
@@ -1238,6 +1272,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder | bodyString methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '"street":"Light Street"' "spock" | { properties.testFramework = TestFramework.SPOCK } | '"street":"Light Street"'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '\\"street\\":\\"Light Street\\"'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '\\"street\\":\\"Light Street\\"' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '\\"street\\":\\"Light Street\\"'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '\\"street\\":\\"Light Street\\"' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '\\"street\\":\\"Light Street\\"'
@@ -1278,6 +1313,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1307,6 +1343,7 @@ World.''')
methodBuilderName | methodBuilder | bodyString methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | """'''hello, "spock" | { properties.testFramework = TestFramework.SPOCK } | """'''hello,
World.'''""" World.'''"""
"testng" | { properties.testFramework = TestFramework.TESTNG }| '"hello,\\nWorld."'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '"hello,\\nWorld."' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '"hello,\\nWorld."'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '"hello,\\nWorld."' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '"hello,\\nWorld."'
} }
@@ -1359,6 +1396,12 @@ World.'''"""
""".param('formParameter', '''"formParameterValue"'''""", """.param('formParameter', '''"formParameterValue"'''""",
""".param('someBooleanParameter', 'true')""", """.param('someBooleanParameter', 'true')""",
""".multiPart('file', 'filename.csv', 'file content'.bytes, 'application/json')"""] """.multiPart('file', 'filename.csv', 'file content'.bytes, 'application/json')"""]
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
'.param("formParameter", "\\"formParameterValue\\"")',
'.param("someBooleanParameter", "true")',
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"', } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1418,6 +1461,12 @@ World.'''"""
""".param('formParameter', '''"formParameterValue"'''""", """.param('formParameter', '''"formParameterValue"'''""",
""".param('someBooleanParameter', 'true')""", """.param('someBooleanParameter', 'true')""",
""".multiPart('file', 'filename.csv', 'file content'.bytes)"""] """.multiPart('file', 'filename.csv', 'file content'.bytes)"""]
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
'.param("formParameter", "\\"formParameterValue\\"")',
'.param("someBooleanParameter", "true")',
'.multiPart("file", "filename.csv", "file content".getBytes());']
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"', } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1470,6 +1519,10 @@ World.'''"""
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"', } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
""".multiPart('file', 'file', [100, 117, 100, 97] as byte[])"""] """.multiPart('file', 'file', [100, 117, 100, 97] as byte[])"""]
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
'.multiPart("file", "file", new byte[] {100, 117, 100, 97});']
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"', } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1520,6 +1573,12 @@ World.'''"""
""".param('formParameter', '''"formParameterValue"'''""", """.param('formParameter', '''"formParameterValue"'''""",
""".param('someBooleanParameter', 'true')""", """.param('someBooleanParameter', 'true')""",
""".multiPart('file', toString(), 'file content'.bytes)"""] """.multiPart('file', toString(), 'file content'.bytes)"""]
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
'.param("formParameter", "\\"formParameterValue\\"")',
'.param("someBooleanParameter", "true")',
'.multiPart("file", toString(), "file content".getBytes());']
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"', } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1572,6 +1631,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1666,6 +1726,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1731,6 +1792,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1768,6 +1830,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1801,6 +1864,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -1830,6 +1894,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder | bodyDefinitionString methodBuilderName | methodBuilder | bodyDefinitionString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '.when().async()' "spock" | { properties.testFramework = TestFramework.SPOCK } | '.when().async()'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '.when().async()'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.when().async()' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.when().async()'
} }
@@ -1863,6 +1928,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
} }
@@ -1896,6 +1962,7 @@ World.'''"""
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -2298,6 +2365,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where: where:
methodBuilderName | methodBuilder | endOfLineRegExSymbol methodBuilderName | methodBuilder | endOfLineRegExSymbol
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$' "spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
"testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '$' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '$'
} }
@@ -2330,6 +2398,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -2366,6 +2435,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
} }
@@ -2398,6 +2468,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
//order is inverted cause Intellij didn't parse this properly //order is inverted cause Intellij didn't parse this properly
methodBuilderName | methodBuilder | expectedAssertion methodBuilderName | methodBuilder | expectedAssertion
"spock" | { properties.testFramework = TestFramework.SPOCK } | """responseBody == '''{"a":1}\\n{"a":2}'''""" "spock" | { properties.testFramework = TestFramework.SPOCK } | """responseBody == '''{"a":1}\\n{"a":2}'''"""
"testng" | { properties.testFramework = TestFramework.TESTNG }| '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}''' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}''' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
} }
@@ -2432,6 +2503,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") } } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") } } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
@@ -2477,6 +2551,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
//order is inverted cause Intellij didn't parse this properly //order is inverted cause Intellij didn't parse this properly
methodBuilderName | methodBuilder | expectedAssertion methodBuilderName | methodBuilder | expectedAssertion
"spock" | { properties.testFramework = TestFramework.SPOCK } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"''' "spock" | { properties.testFramework = TestFramework.SPOCK } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
"testng" | { properties.testFramework = TestFramework.TESTNG }| '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}''' "mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}''' "webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
} }
@@ -2507,6 +2582,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} }
"testng" | {
properties.testFramework = TestFramework.TESTNG
}
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} }
@@ -2548,6 +2626,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -2584,6 +2663,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} | { String body -> body.contains("body('''12000''')") } | { String body -> body.contains("responseBody == '12000'") } } | { String body -> body.contains("body('''12000''')") } | { String body -> body.contains("responseBody == '12000'") }
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') } } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
@@ -2682,6 +2764,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} | { String body -> body.contains("""response.header("Authorization") == 'foo secret bar'""") } } | { String body -> body.contains("""response.header("Authorization") == 'foo secret bar'""") }
"testng" | {
properties.testFramework = TestFramework.TESTNG
} | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') } } | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
@@ -2742,6 +2827,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -2867,6 +2953,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where: where:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT

View File

@@ -162,6 +162,9 @@ class XmlMethodBodyBuilderSpec extends Specification {
"spock" | { "spock" | {
properties.testFramework = TestFramework.SPOCK properties.testFramework = TestFramework.SPOCK
} }
"testng" | {
properties.testFramework = TestFramework.TESTNG
}
"junit" | { "junit" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} }

View File

@@ -1739,6 +1739,9 @@ response:
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") } } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
} | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile("true|false")""") } } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile("true|false")""") }
@@ -1814,6 +1817,9 @@ response:
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
}
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} }
@@ -1851,6 +1857,9 @@ response:
methodBuilderName | methodBuilder methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK } "spock" | { properties.testFramework = TestFramework.SPOCK }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } "mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
}
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} }
@@ -1889,6 +1898,9 @@ response:
"mockmvc" | { "mockmvc" | {
properties.testMode = TestMode.MOCKMVC properties.testMode = TestMode.MOCKMVC
} | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') } } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
"mockmvc-testng" | {
properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
} | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
"jaxrs-spock" | { "jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String body -> body.contains(""".build("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('responseBody == "12000"') } } | { String body -> body.contains(""".build("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('responseBody == "12000"') }