diff --git a/README.adoc b/README.adoc
index 43c5b4f045..ec3c7e4919 100644
--- a/README.adoc
+++ b/README.adoc
@@ -41,7 +41,7 @@ produced by Spring Cloud Contract Verifier.
* Messaging routes, if you're using a messaging service. We integrate with Spring
Integration, Spring Cloud Stream, Spring AMQP, and Apache Camel. You can also set your
own integrations.
-* Acceptance tests (in JUnit 4, JUnit 5 or Spock) are used to verify if server-side implementation
+* Acceptance tests (in JUnit 4, JUnit 5, TestNG or Spock) are used to verify if server-side implementation
of the API is compliant with the contract (__server tests__). A full test is generated by
Spring Cloud Contract Verifier.
@@ -426,8 +426,8 @@ Here is an example of a test generated in `WEBTESTCLIENT` test mode:
}
----
-Apart from the default JUnit 4, you can instead use JUnit 5 or Spock tests, by setting the plugin
-`testFramework` property to either `JUNIT5` or `Spock`.
+Apart from the default JUnit 4, you can instead use JUnit 5, TestNG or Spock tests, by setting the plugin
+`testFramework` property to either `JUNIT5`, `TESTNG` or `Spock`.
TIP: You can now also generate WireMock scenarios based on the contracts, by including an
order number followed by an underscore at the beginning of the contract file names.
diff --git a/docs/src/main/asciidoc/verifier_introduction.adoc b/docs/src/main/asciidoc/verifier_introduction.adoc
index f2342dd43f..38de8a003f 100644
--- a/docs/src/main/asciidoc/verifier_introduction.adoc
+++ b/docs/src/main/asciidoc/verifier_introduction.adoc
@@ -12,7 +12,7 @@ produced by Spring Cloud Contract Verifier.
* Messaging routes, if you're using a messaging service. We integrate with Spring
Integration, Spring Cloud Stream, Spring AMQP, and Apache Camel. You can also set your
own integrations.
-* Acceptance tests (in JUnit 4, JUnit 5 or Spock) are used to verify if server-side implementation
+* Acceptance tests (in JUnit 4, JUnit 5, TestNG or Spock) are used to verify if server-side implementation
of the API is compliant with the contract (__server tests__). A full test is generated by
Spring Cloud Contract Verifier.
@@ -395,8 +395,8 @@ Here is an example of a test generated in `WEBTESTCLIENT` test mode:
}
----
-Apart from the default JUnit 4, you can instead use JUnit 5 or Spock tests, by setting the plugin
-`testFramework` property to either `JUNIT5` or `Spock`.
+Apart from the default JUnit 4, you can instead use JUnit 5, TestNG or Spock tests, by setting the plugin
+`testFramework` property to either `JUNIT5`, `TESTNG` or `Spock`.
TIP: You can now also generate WireMock scenarios based on the contracts, by including an
order number followed by an underscore at the beginning of the contract file names.
diff --git a/docs/src/main/asciidoc/verifier_messaging.adoc b/docs/src/main/asciidoc/verifier_messaging.adoc
index 811353d1ff..7e3a419100 100644
--- a/docs/src/main/asciidoc/verifier_messaging.adoc
+++ b/docs/src/main/asciidoc/verifier_messaging.adoc
@@ -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
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:
diff --git a/docs/src/main/asciidoc/verifier_setup.adoc b/docs/src/main/asciidoc/verifier_setup.adoc
index 24c4a7a32e..f5126d6ef1 100644
--- a/docs/src/main/asciidoc/verifier_setup.adoc
+++ b/docs/src/main/asciidoc/verifier_setup.adoc
@@ -249,7 +249,7 @@ from the Groovy DSL should be placed. By default its value is
`$buildDir/generated-test-resources/contracts`.
* *stubsOutputDir*: Specifies the directory where the generated WireMock stubs from
the Groovy DSL should be placed.
-* *testFramework*: Specifies the target test framework to be used. Currently, Spock, JUnit 4 (`TestFramework.JUNIT`) and
+* *testFramework*: Specifies the target test framework to be used. Currently, Spock, JUnit 4 (`TestFramework.JUNIT`), TestNG and
JUnit 5 are supported with JUnit 4 being the default framework.
* *contractsProperties*: a map containing properties to be passed to Spring Cloud Contract
components. Those properties might be used by e.g. inbuilt or custom Stub Downloaders.
diff --git a/spring-cloud-contract-verifier/pom.xml b/spring-cloud-contract-verifier/pom.xml
index 1da11ad111..16ecdc00eb 100644
--- a/spring-cloud-contract-verifier/pom.xml
+++ b/spring-cloud-contract-verifier/pom.xml
@@ -167,6 +167,11 @@
org.junit.jupiter
junit-jupiter-api
+
+ org.codehaus.groovy
+ groovy-testng
+ test
+
org.springframework.boot
spring-boot-starter-jersey
@@ -233,6 +238,9 @@
org.apache.maven.plugins
maven-surefire-plugin
+
+ none:none
+
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ImportsBuilder.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ImportsBuilder.java
index e9f8221fd9..633d096aa0 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ImportsBuilder.java
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/ImportsBuilder.java
@@ -67,6 +67,11 @@ class ImportsBuilder {
return this;
}
+ ImportsBuilder testNG() {
+ this.parentBuilder.imports(new TestNGImports(builder, metaData));
+ return this;
+ }
+
ImportsBuilder spock() {
this.parentBuilder.imports(new SpockImports(builder, metaData),
new SpockIgnoreImports(builder, metaData),
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaClassMetaData.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaClassMetaData.java
index 6b72228ecb..633d683bda 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaClassMetaData.java
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaClassMetaData.java
@@ -97,7 +97,9 @@ class JavaClassMetaData implements ClassMetaData, DefaultClassMetadata {
return this.generatedClassMetaData.configProperties
.getTestFramework() == TestFramework.JUNIT
|| this.generatedClassMetaData.configProperties
- .getTestFramework() == TestFramework.JUNIT5;
+ .getTestFramework() == TestFramework.JUNIT5
+ || this.generatedClassMetaData.configProperties
+ .getTestFramework() == TestFramework.TESTNG;
}
}
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaTestGenerator.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaTestGenerator.java
index 4503cb2881..37770ad339 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaTestGenerator.java
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/JavaTestGenerator.java
@@ -73,6 +73,7 @@ public class JavaTestGenerator implements SingleTestGenerator {
.json()
.jUnit4()
.jUnit5()
+ .testNG()
.spock()
.xml()
.messaging()
@@ -107,6 +108,7 @@ public class JavaTestGenerator implements SingleTestGenerator {
.methodAnnotation()
.jUnit4()
.jUnit5()
+ .testNG()
.spock()
.build()
.methodMetadata()
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodAnnotationBuilder.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodAnnotationBuilder.java
index c2e2fb8ab7..12211e5cf8 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodAnnotationBuilder.java
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/MethodAnnotationBuilder.java
@@ -44,6 +44,12 @@ class MethodAnnotationBuilder {
return this;
}
+ MethodAnnotationBuilder testNG() {
+ this.singleMethodBuilder.methodAnnotation(
+ new TestNGMethodAnnotation(this.builder, this.metaData));
+ return this;
+ }
+
MethodAnnotationBuilder spock() {
this.singleMethodBuilder.methodAnnotation(
new SpockIgnoreMethodAnnotation(this.builder, this.metaData));
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/TestNGImports.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/TestNGImports.java
new file mode 100644
index 0000000000..f34b2eb7a8
--- /dev/null
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/TestNGImports.java
@@ -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;
+ }
+
+}
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/TestNGMethodAnnotation.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/TestNGMethodAnnotation.java
new file mode 100644
index 0000000000..7ff7af7a5b
--- /dev/null
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/TestNGMethodAnnotation.java
@@ -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 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;
+ }
+
+}
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/BaseImportProvider.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/BaseImportProvider.groovy
index 2da3931588..8bf4e25615 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/BaseImportProvider.groovy
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/BaseImportProvider.groovy
@@ -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.JUNIT5
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.
@@ -47,12 +48,14 @@ class BaseImportProvider {
(JUNIT) : new ImportDefinitions(['org.junit.Test']),
(JUNIT5): new ImportDefinitions(['org.junit.jupiter.api.Test']),
(SPOCK) : new ImportDefinitions([]),
+ (TESTNG): new ImportDefinitions(['org.testng.annotations.Test']),
(CUSTOM): new ImportDefinitions([])]
private static final Map RULE_IMPORT = [
(JUNIT) : 'org.junit.Rule',
(JUNIT5): 'org.junit.jupiter.api.extension.ExtendWith',
(SPOCK) : 'org.junit.Rule',
+ (TESTNG): 'org.junit.Rule',
(CUSTOM): 'org.junit.Rule'
]
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/HttpImportProvider.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/HttpImportProvider.groovy
index 4fe63d76cd..730ef4260a 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/HttpImportProvider.groovy
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/imports/HttpImportProvider.groovy
@@ -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.JUNIT5
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.JAXRSCLIENT
import static org.springframework.cloud.contract.verifier.config.TestMode.MOCKMVC
@@ -47,6 +48,7 @@ class HttpImportProvider {
private final Map, ImportDefinitions> FRAMEWORK_AND_TEST_MODE_SPECIFIC_IMPORTS = [
(new Tuple2(JUNIT, 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([
"${restAssuredPackage}.module.mockmvc.specification.MockMvcRequestSpecification",
"${restAssuredPackage}.response.ResponseOptions"]),
@@ -59,10 +61,18 @@ class HttpImportProvider {
(new Tuple2(JUNIT5, WEBTESTCLIENT)): new ImportDefinitions([
'io.restassured.module.webtestclient.specification.WebTestClientRequestSpecification',
'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",
"${restAssuredPackage}.response.Response"]),
(new Tuple2(JUNIT5, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification",
"${restAssuredPackage}.response.Response"]),
+ (new Tuple2(TESTNG, EXPLICIT)) : new ImportDefinitions(["${restAssuredPackage}.specification.RequestSpecification",
+ "${restAssuredPackage}.response.Response"]),
(new Tuple2(SPOCK, JAXRSCLIENT)) : new ImportDefinitions([]),
(new Tuple2(CUSTOM, JAXRSCLIENT)) : new ImportDefinitions([]),
(new Tuple2(SPOCK, MOCKMVC)) : new ImportDefinitions([]),
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.java
index ae7e0f6aaf..1464da93fe 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.java
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestFramework.java
@@ -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.SpockDefinition;
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.
@@ -46,6 +47,10 @@ public enum TestFramework {
* JUnit5 test framework.
*/
JUNIT5(new JUnit5Definition()),
+ /**
+ * TestNG test framework.
+ */
+ TESTNG(new TestNGDefinition()),
/**
* Custom test framework.
*/
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/framework/TestNGDefinition.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/framework/TestNGDefinition.groovy
new file mode 100644
index 0000000000..a6ed1f3a5f
--- /dev/null
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/framework/TestNGDefinition.groovy
@@ -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 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.')
+ }
+}
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilderSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilderSpec.groovy
index 4a5f042cbc..de74e73f8b 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilderSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MethodBodyBuilderSpec.groovy
@@ -154,6 +154,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#588')
@@ -196,6 +199,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#521')
@@ -241,6 +247,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#269')
@@ -288,6 +297,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#289')
@@ -333,6 +345,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#313')
@@ -375,6 +390,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@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-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" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String testBody ->
@@ -491,6 +516,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#424')
@@ -535,6 +563,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#458')
@@ -571,6 +602,11 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
} | { String string ->
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" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String string ->
@@ -636,6 +672,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#702')
@@ -701,6 +740,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#465')
@@ -753,6 +795,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
def 'should use fixed delay milliseconds in the generated test [#methodBuilderName]'() {
@@ -829,6 +874,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#578')
@@ -893,6 +941,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#493')
@@ -953,6 +1004,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
def 'should work with files that have new lines [#methodBuilderName]'() {
@@ -999,6 +1053,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue('#509')
@@ -1075,6 +1132,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
def 'should not escape a regex pattern when matching raw body value [#methodBuilderName]'() {
@@ -1114,6 +1174,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#664")
@@ -1145,6 +1208,13 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
} | { String string ->
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" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String string ->
@@ -1245,6 +1315,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#852")
@@ -1291,6 +1364,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#844")
@@ -1348,6 +1424,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#652")
@@ -1448,6 +1527,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#727")
@@ -1497,6 +1579,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@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-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" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String testContent ->
@@ -1599,6 +1691,9 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#1052")
@@ -1656,6 +1751,9 @@ response:
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
@Issue("#1049")
@@ -1695,6 +1793,9 @@ response:
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
def 'should resolve headers from request correctly'() {
@@ -1744,7 +1845,9 @@ response:
"jaxrs" | {
properties.testFramework = TestFramework.JUNIT; properties.testMode = TestMode.JAXRSCLIENT
}
-
+ "testNG" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
}
}
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy
index 86f547d8f3..1565ef0899 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderWithMatchersSpec.groovy
@@ -245,6 +245,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -320,6 +321,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -380,6 +382,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -420,6 +423,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -461,6 +465,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -504,6 +509,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder | rootElement
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -555,6 +561,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -602,6 +609,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy
index e02a3483d4..01f6c0b2e9 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy
@@ -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.JUNIT5
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.JAXRSCLIENT
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.*;',
'@Test', '@Disabled', 'import io.restassured.specification.RequestSpecification;',
'import io.restassured.response.Response;', 'import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat']
+ private static
+ final List 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 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 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 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 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
JUNIT5 | null | MOCKMVC | mockMvcJUnit5RestAssured3ClassStrings | 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 | EXPLICIT | explicitSpockRestAssured3ClassStrings | GROOVY_ASSERTER
}
@@ -218,6 +247,8 @@ class SingleTestGeneratorSpec extends Specification {
JUNIT | EXPLICIT | JAVA_ASSERTER | 'ContractsTest.java'
JUNIT5 | MOCKMVC | 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 | 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 }
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 }
+ 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 | 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
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
+ 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
}
@@ -364,6 +398,7 @@ class SingleTestGeneratorSpec extends Specification {
testFramework | order | classStrings | asserter
JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | JAVA_ASSERTER
JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | JAVA_ASSERTER
+ TESTNG | null | mockMvcTestNGRestAssured3ClassStrings | JAVA_ASSERTER
SPOCK | 2 | spockClassRestAssured3Strings | GROOVY_ASSERTER
}
@@ -403,10 +438,26 @@ class SingleTestGeneratorSpec extends Specification {
asserter(clazz)
where:
- testFramework | order | classStrings | ignoreAnnotation | asserter
- JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | '@Ignore' | JAVA_ASSERTER
- JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | '@Disabled' | JAVA_ASSERTER
- SPOCK | 2 | spockClassRestAssured3Strings | '@Ignore' | GROOVY_ASSERTER
+ testFramework | order | classStrings | ignoreAnnotation | asserter
+ JUNIT | 2 | mockMvcJUnitRestAssured3ClassStrings | '@Ignore' | JAVA_ASSERTER
+ JUNIT5 | null | mockMvcJUnit5RestAssured3ClassStrings | '@Disabled' | JAVA_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')
@@ -490,7 +541,7 @@ class SingleTestGeneratorSpec extends Specification {
then:
clazz.contains('validate_mySuperMethod()')
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"() {
@@ -523,7 +574,7 @@ class SingleTestGeneratorSpec extends Specification {
clazz.contains('validate_shouldHaveIndex1()')
clazz.contains('validate_shouldHaveIndex2()')
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'() {
@@ -555,7 +606,7 @@ class SingleTestGeneratorSpec extends Specification {
clazz.contains('_0() throws Exception')
clazz.contains('_1() throws Exception')
where:
- testFramework << [JUNIT, JUNIT5, SPOCK]
+ testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
}
@Issue('#359')
@@ -581,7 +632,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json')
test.contains('RESPONSE')
where:
- testFramework << [JUNIT, JUNIT5, SPOCK]
+ testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
}
@Issue('#260')
@@ -606,7 +657,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json')
test.contains('RESPONSE')
where:
- testFramework << [JUNIT, JUNIT5, SPOCK]
+ testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
}
@Issue('#260')
@@ -631,7 +682,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json')
test.contains('RESPONSE')
where:
- testFramework << [JUNIT, JUNIT5, SPOCK]
+ testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
}
@Issue('#260')
@@ -656,7 +707,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json')
test.contains('RESPONSE')
where:
- testFramework << [JUNIT, JUNIT5, SPOCK]
+ testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
}
@Issue('#260')
@@ -680,7 +731,7 @@ class SingleTestGeneratorSpec extends Specification {
test.contains('readFromFile_request_request.json')
test.contains('RESPONSE')
where:
- testFramework << [JUNIT, JUNIT5, SPOCK]
+ testFramework << [JUNIT, JUNIT5, TESTNG, SPOCK]
}
def 'should throw exception in JUnit5 when contract belongs to scenario'() {
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SpringTestMethodBodyBuildersSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SpringTestMethodBodyBuildersSpec.groovy
index 2d853d05be..9794a874e4 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SpringTestMethodBodyBuildersSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SpringTestMethodBodyBuildersSpec.groovy
@@ -214,6 +214,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -277,6 +278,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -314,6 +316,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -354,6 +357,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -388,6 +392,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
} | '.body("{\\"items\\":[\\"HOP\\"]}")'
+ "testng" | {
+ properties.testFramework = TestFramework.TESTNG
+ } | '.body("{\\"items\\":[\\"HOP\\"]}")'
"webclient" | {
properties.testMode = TestMode.WEBTESTCLIENT
} | '.body("{\\"items\\":[\\"HOP\\"]}")'
@@ -420,6 +427,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | """.body('''property1=VAL1''')"""
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '.body("property1=VAL1")'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.body("property1=VAL1")'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '.body("property1=VAL1")'
}
@@ -455,6 +463,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -490,6 +499,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -524,6 +534,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -558,6 +569,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -596,6 +608,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -630,6 +643,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -664,6 +678,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -720,6 +735,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -777,6 +793,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -805,6 +822,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | ".body('''''')"
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '.body("")'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.body("")'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '.body("")'
}
@@ -836,6 +854,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
"spock" | {
properties.testFramework = TestFramework.SPOCK
} | 'String responseBody = response.body.asString()' | "responseBody == 'test'"
+ "testng" | {
+ properties.testFramework = TestFramework.TESTNG
+ } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
} | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
@@ -880,6 +901,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder | headerEvaluationString
"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" | {
properties.testMode = TestMode.MOCKMVC
} | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
@@ -924,6 +948,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
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]+')'''
+ "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" | {
properties.testMode = TestMode.MOCKMVC
} | '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:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1004,6 +1032,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1045,6 +1074,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1133,6 +1163,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
"spock" | {
properties.testFramework = TestFramework.SPOCK
} | ['''assertThatRejectionReasonIsNull(parsedJson.read("\\$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
+ "testng" | {
+ properties.testFramework = TestFramework.TESTNG
+ } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
} | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
@@ -1205,6 +1238,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '"street":"Light Street"'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '\\"street\\":\\"Light Street\\"'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '\\"street\\":\\"Light Street\\"'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '\\"street\\":\\"Light Street\\"'
@@ -1238,6 +1272,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '"street":"Light Street"'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '\\"street\\":\\"Light Street\\"'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '\\"street\\":\\"Light Street\\"'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '\\"street\\":\\"Light Street\\"'
@@ -1278,6 +1313,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1307,6 +1343,7 @@ World.''')
methodBuilderName | methodBuilder | bodyString
"spock" | { properties.testFramework = TestFramework.SPOCK } | """'''hello,
World.'''"""
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '"hello,\\nWorld."'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '"hello,\\nWorld."'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '"hello,\\nWorld."'
}
@@ -1359,6 +1396,12 @@ World.'''"""
""".param('formParameter', '''"formParameterValue"'''""",
""".param('someBooleanParameter', 'true')""",
""".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" | {
properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1418,6 +1461,12 @@ World.'''"""
""".param('formParameter', '''"formParameterValue"'''""",
""".param('someBooleanParameter', 'true')""",
""".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" | {
properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1470,6 +1519,10 @@ World.'''"""
properties.testFramework = TestFramework.SPOCK
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
""".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" | {
properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1520,6 +1573,12 @@ World.'''"""
""".param('formParameter', '''"formParameterValue"'''""",
""".param('someBooleanParameter', 'true')""",
""".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" | {
properties.testMode = TestMode.MOCKMVC
} | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
@@ -1572,6 +1631,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1666,6 +1726,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1731,6 +1792,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1768,6 +1830,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1801,6 +1864,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -1830,6 +1894,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder | bodyDefinitionString
"spock" | { properties.testFramework = TestFramework.SPOCK } | '.when().async()'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '.when().async()'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '.when().async()'
}
@@ -1863,6 +1928,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
}
@@ -1896,6 +1962,7 @@ World.'''"""
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -2298,6 +2365,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where:
methodBuilderName | methodBuilder | endOfLineRegExSymbol
"spock" | { properties.testFramework = TestFramework.SPOCK } | '\\$'
+ "testng" | { properties.testFramework = TestFramework.TESTNG }| '$'
"mockmvc" | { properties.testMode = TestMode.MOCKMVC } | '$'
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '$'
}
@@ -2330,6 +2398,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -2366,6 +2435,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@@ -2398,6 +2468,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
//order is inverted cause Intellij didn't parse this properly
methodBuilderName | methodBuilder | expectedAssertion
"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}'''
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
}
@@ -2432,6 +2503,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | {
properties.testFramework = TestFramework.SPOCK
} | { 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" | {
properties.testMode = TestMode.MOCKMVC
} | { 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
methodBuilderName | methodBuilder | expectedAssertion
"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}'''
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
}
@@ -2507,6 +2582,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | {
properties.testFramework = TestFramework.SPOCK
}
+ "testng" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
}
@@ -2548,6 +2626,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -2584,6 +2663,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | {
properties.testFramework = TestFramework.SPOCK
} | { 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" | {
properties.testMode = TestMode.MOCKMVC
} | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
@@ -2682,6 +2764,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
"spock" | {
properties.testFramework = TestFramework.SPOCK
} | { 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" | {
properties.testMode = TestMode.MOCKMVC
} | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
@@ -2742,6 +2827,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
@@ -2867,6 +2953,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
+ "testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/XmlMethodBodyBuilderSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/XmlMethodBodyBuilderSpec.groovy
index 43bc79eed4..bfb46cfc0f 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/XmlMethodBodyBuilderSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/XmlMethodBodyBuilderSpec.groovy
@@ -162,6 +162,9 @@ class XmlMethodBodyBuilderSpec extends Specification {
"spock" | {
properties.testFramework = TestFramework.SPOCK
}
+ "testng" | {
+ properties.testFramework = TestFramework.TESTNG
+ }
"junit" | {
properties.testMode = TestMode.MOCKMVC
}
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/YamlMockMvcMethodBodyBuilderSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/YamlMockMvcMethodBodyBuilderSpec.groovy
index 4467e1fca9..dde39d47c8 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/YamlMockMvcMethodBodyBuilderSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/YamlMockMvcMethodBodyBuilderSpec.groovy
@@ -1739,6 +1739,9 @@ response:
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
} | { 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" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile("true|false")""") }
@@ -1814,6 +1817,9 @@ response:
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
}
+ "mockmvc-testng" | {
+ properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
+ }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
}
@@ -1851,6 +1857,9 @@ response:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
+ "mockmvc-testng" | {
+ properties.testFramework = TestFramework.TESTNG; properties.testMode = TestMode.MOCKMVC
+ }
"jaxrs-spock" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
}
@@ -1889,6 +1898,9 @@ response:
"mockmvc" | {
properties.testMode = TestMode.MOCKMVC
} | { 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" | {
properties.testFramework = TestFramework.SPOCK; properties.testMode = TestMode.JAXRSCLIENT
} | { String body -> body.contains(""".build("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('responseBody == "12000"') }