Adds support for binary payloads (#818)
with this change we're adding support for binary payloads both for HTTP and messaging. fixes #664
This commit is contained in:
committed by
GitHub
parent
928b32ecce
commit
0058b987ae
@@ -741,7 +741,7 @@ Annotate your test class with `@AutoConfigureStubRunner`. In the annotation prov
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"},
|
||||
stubsMode = StubRunnerProperties.StubsMode.LOCAL)
|
||||
public class LoanApplicationServiceTests {
|
||||
@@ -1226,7 +1226,7 @@ can also provide the offline work switch (`StubRunnerProperties.StubsMode.LOCAL`
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"},
|
||||
stubsMode = StubRunnerProperties.StubsMode.LOCAL)
|
||||
public class LoanApplicationServiceTests {
|
||||
@@ -1323,9 +1323,8 @@ start the server side `FraudDetectionController`.
|
||||
----
|
||||
package com.example.fraud;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import io.restassured.module.mockmvc.RestAssuredMockMvc;
|
||||
import org.junit.Before;
|
||||
|
||||
public class FraudBase {
|
||||
@Before
|
||||
|
||||
@@ -168,6 +168,23 @@ When test or stub generation takes place, the contents of the file is passed to
|
||||
of a request or a response. The name of the file needs to be a file with location
|
||||
relative to the folder in which the contract lays.
|
||||
|
||||
If you need to pass the contents of a file in a binary form
|
||||
it's enough for you to use the `fileAsBytes` method in Groovy DSL or `bodyFromFileAsBytes` field in YAML.
|
||||
|
||||
.Groovy DSL
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/resources/body_builder/worksWithPdf.groovy[indent=0]
|
||||
----
|
||||
|
||||
.YAML
|
||||
[source,yml,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/resources/yml/contract_pdf.yml[indent=0]
|
||||
----
|
||||
|
||||
IMPORTANT: You should use this approach whenever you want to work with binary payloads both for HTTP and messaging.
|
||||
|
||||
[[contract-dsl-http-top-level-elements]]
|
||||
==== HTTP Top-Level Elements
|
||||
|
||||
@@ -1645,7 +1662,7 @@ following code listing shows the `SingleTestGenerator` interface:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::{verifier_core_path}/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy[indent=0,lines=17..-1]
|
||||
include::{verifier_core_path}/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.java[indent=0,lines=17..-1]
|
||||
----
|
||||
|
||||
Again, you must provide a `spring.factories` file, such as the one shown in the following
|
||||
|
||||
@@ -156,6 +156,7 @@ contracts {
|
||||
testFramework ='JUNIT'
|
||||
testMode = 'MockMvc'
|
||||
generatedTestSourcesDir = project.file("${project.buildDir}/generated-test-sources/contracts")
|
||||
generatedTestResourcesDir = project.file("${project.buildDir}/generated-test-resources/contracts")
|
||||
contractsDslDir = "${project.rootDir}/src/test/resources/contracts"
|
||||
basePackageForTests = 'org.springframework.cloud.verifier.tests'
|
||||
stubsOutputDir = project.file("${project.buildDir}/stubs")
|
||||
@@ -242,7 +243,10 @@ should be skipped. By default, it is an empty array.
|
||||
GroovyDSL. By default, its value is `$rootDir/src/test/resources/contracts`.
|
||||
* *generatedTestSourcesDir*: Specifies the test source directory where tests generated
|
||||
from the Groovy DSL should be placed. By default its value is
|
||||
`$buildDir/generated-test-sources/contractVerifier`.
|
||||
`$buildDir/generated-test-sources/contracts`.
|
||||
* *generatedTestResourcesDir*: Specifies the test resource directory where resources used by the tests generated
|
||||
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
|
||||
@@ -581,6 +585,10 @@ classes.
|
||||
use Spock classes, the class is `spock.lang.Specification`.
|
||||
* *contractsDirectory*: Specifies a directory containing contracts written with the
|
||||
GroovyDSL. The default directory is `/src/test/resources/contracts`.
|
||||
* *generatedTestSourcesDir*: Specifies the test source directory where tests generated
|
||||
from the Groovy DSL should be placed. By default its value is
|
||||
`$buildDir/generated-test-sources/contracts`.
|
||||
* *generatedTestResourcesDir*: Specifies the test resource directory where resources used by the tests generated
|
||||
* *testFramework*: Specifies the target test framework to be used. Currently, Spock, JUnit 4 (`TestFramework.JUNIT`) and
|
||||
JUnit 5 are supported with JUnit 4 being the default framework.
|
||||
* *packageWithBaseClasses*: Defines a package where all the base classes reside. This
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
package com.example.loan;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ResponseOptions;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.example.loan.model.Client;
|
||||
import com.example.loan.model.LoanApplication;
|
||||
@@ -18,13 +11,28 @@ import com.example.loan.model.LoanApplicationResult;
|
||||
import com.example.loan.model.LoanApplicationStatus;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.response.ResponseOptions;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
// tag::autoconfigure_stubrunner[]
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"},
|
||||
stubsMode = StubRunnerProperties.StubsMode.LOCAL)
|
||||
public class LoanApplicationServiceTests {
|
||||
@@ -93,7 +101,8 @@ public class LoanApplicationServiceTests {
|
||||
.header("Content-Type", "multipart/form-data")
|
||||
.multiPart("file1", "filename1", "content1".getBytes())
|
||||
.multiPart("file2", "filename1", "content2".getBytes())
|
||||
.multiPart("test", "filename1", "{\n \"status\": \"test\"\n}".getBytes(), "application/json");
|
||||
.multiPart("test", "filename1", "{\n \"status\": \"test\"\n}"
|
||||
.getBytes(), "application/json");
|
||||
|
||||
// when:
|
||||
ResponseOptions response = RestAssured.given().spec(request)
|
||||
@@ -107,4 +116,26 @@ public class LoanApplicationServiceTests {
|
||||
assertThatJson(parsedJson).field("['status']").isEqualTo("ok");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSuccessfullyWorkWithBinary() throws IOException {
|
||||
// given:
|
||||
File request = new File(LoanApplicationServiceTests.class
|
||||
.getResource("/binary/request.pdf").getFile());
|
||||
File response = new File(LoanApplicationServiceTests.class
|
||||
.getResource("/binary/response.pdf").getFile());
|
||||
|
||||
// when:
|
||||
ResponseEntity<byte[]> exchange = new RestTemplate().exchange(
|
||||
RequestEntity.put(URI.create("http://localhost:6565/1"))
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(Files.readAllBytes(request.toPath())), byte[].class);
|
||||
|
||||
// then:
|
||||
assertThat(exchange.getStatusCodeValue()).isEqualTo(200);
|
||||
assertThat(exchange.getHeaders().get("Content-Type").get(0))
|
||||
.isEqualTo("application/octet-stream");
|
||||
// and:
|
||||
assertThat(exchange.getBody()).isEqualTo(Files.readAllBytes(response.toPath()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,16 @@
|
||||
package com.example.fraud;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -8,29 +18,58 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
@RestController
|
||||
public class TestController {
|
||||
|
||||
@PostMapping("/tests")
|
||||
public Test createNew(@RequestPart MultipartFile file1,
|
||||
@RequestPart MultipartFile file2,
|
||||
@RequestPart Test test) {
|
||||
return new Test("ok");
|
||||
}
|
||||
private final byte[] request;
|
||||
private final byte[] response;
|
||||
|
||||
public TestController() {
|
||||
this.request = toByte(TestController.class
|
||||
.getResource("/contracts/binary/request.pdf"));
|
||||
this.response = toByte(TestController.class
|
||||
.getResource("/contracts/binary/response.pdf"));
|
||||
}
|
||||
|
||||
private byte[] toByte(URL url) {
|
||||
try {
|
||||
return Files.readAllBytes(new File(url.toURI()).toPath());
|
||||
}
|
||||
catch (URISyntaxException | IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/tests")
|
||||
public Test createNew(@RequestPart MultipartFile file1,
|
||||
@RequestPart MultipartFile file2,
|
||||
@RequestPart Test test) {
|
||||
return new Test("ok");
|
||||
}
|
||||
|
||||
@PutMapping(value = "/1",
|
||||
consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE,
|
||||
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public byte[] response(@RequestBody byte[] requestBody) {
|
||||
if (!Arrays.equals(this.request, requestBody)) {
|
||||
throw new IllegalStateException("Invalid request body");
|
||||
}
|
||||
return this.response;
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
private String status;
|
||||
private String status;
|
||||
|
||||
public Test(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
public Test(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Test() {
|
||||
}
|
||||
public Test() {
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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 com.example.fraud;
|
||||
|
||||
import io.restassured.module.mockmvc.RestAssuredMockMvc;
|
||||
import org.junit.Before;
|
||||
|
||||
public class BinaryBase {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RestAssuredMockMvc.standaloneSetup(new TestController());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.example.fraud;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import io.restassured.module.mockmvc.RestAssuredMockMvc;
|
||||
import org.junit.Before;
|
||||
|
||||
public class FraudBase {
|
||||
@Before
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.example.fraud;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
import io.restassured.module.mockmvc.RestAssuredMockMvc;
|
||||
import org.junit.Before;
|
||||
|
||||
public class FraudnameBase {
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.example.fraud;
|
||||
|
||||
import com.example.fraud.TestController;
|
||||
import io.restassured.module.mockmvc.RestAssuredMockMvc;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
public class MultipartBase {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RestAssuredMockMvc.standaloneSetup(new TestController());
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RestAssuredMockMvc.standaloneSetup(new TestController());
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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 contracts
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
|
||||
Contract.make {
|
||||
request {
|
||||
url("/1")
|
||||
method(PUT())
|
||||
headers {
|
||||
contentType(applicationOctetStream())
|
||||
}
|
||||
body(fileAsBytes("request.pdf"))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(fileAsBytes("response.pdf"))
|
||||
headers {
|
||||
contentType(applicationOctetStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
|
||||
Contract.make {
|
||||
request {
|
||||
method 'POST'
|
||||
url '/tests'
|
||||
multipart(
|
||||
[
|
||||
file1: named(
|
||||
name: value(consumer(regex(nonEmpty())), producer('filename1')),
|
||||
content: value(consumer(regex(nonEmpty())), producer('content1'))),
|
||||
file2: named(
|
||||
name: value(consumer(regex(nonEmpty())), producer('filename1')),
|
||||
content: value(c(regex(nonEmpty())), producer('content2'))),
|
||||
test : named(
|
||||
name: value(consumer(regex(nonEmpty())), producer('filename1')),
|
||||
content: value(c(regex(nonEmpty())), producer(fileAsBytes("test.json"))),
|
||||
contentType: "application/json")
|
||||
]
|
||||
)
|
||||
|
||||
headers {
|
||||
contentType('multipart/form-data')
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body([
|
||||
status: 'ok'
|
||||
])
|
||||
headers {
|
||||
contentType('application/json')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,29 @@
|
||||
package com.example.source;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableBinding(Source.class)
|
||||
@EnableBinding({Source.class, MyProcessor.class})
|
||||
public class ContractVerifierSampleStreamSourceApplication {
|
||||
|
||||
@Autowired
|
||||
@@ -19,6 +34,51 @@ public class ContractVerifierSampleStreamSourceApplication {
|
||||
}
|
||||
|
||||
public void poll() {
|
||||
source.output().send(MessageBuilder.withPayload("{\"id\":\"99\",\"temperature\":\"123.45\"}").build());
|
||||
this.source.output().send(MessageBuilder
|
||||
.withPayload("{\"id\":\"99\",\"temperature\":\"123.45\"}").build());
|
||||
}
|
||||
}
|
||||
|
||||
interface MyProcessor extends Sink {
|
||||
String MY_OUTPUT = "my_output";
|
||||
|
||||
@Output("my_output")
|
||||
MessageChannel output();
|
||||
}
|
||||
|
||||
@Component
|
||||
class MyProcessorListener {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MyProcessorListener.class);
|
||||
|
||||
private final MyProcessor processor;
|
||||
private final byte[] expectedInput;
|
||||
private final byte[] expectedOutput;
|
||||
|
||||
MyProcessorListener(MyProcessor processor) {
|
||||
this.processor = processor;
|
||||
this.expectedInput = forFile("/contracts/input.pdf");
|
||||
this.expectedOutput = forFile("/contracts/output.pdf");
|
||||
}
|
||||
|
||||
private byte[] forFile(String relative) {
|
||||
URL resource = MyProcessorListener.class.getResource(relative);
|
||||
try {
|
||||
return Files.readAllBytes(new File(resource.toURI()).toPath());
|
||||
}
|
||||
catch (IOException | URISyntaxException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@StreamListener(Sink.INPUT)
|
||||
void listen(byte[] payload) {
|
||||
log.info("Got the message!");
|
||||
if (!Arrays.equals(payload, this.expectedInput)) {
|
||||
throw new IllegalStateException("Wrong input");
|
||||
}
|
||||
this.processor.output().send(
|
||||
MessageBuilder.withPayload(this.expectedOutput)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,6 @@
|
||||
spring.cloud.stream.bindings.output.contentType=application/json
|
||||
spring.cloud.stream.bindings.input.contentType=application/octet-stream
|
||||
spring.cloud.stream.bindings.input.destination=bytes_input
|
||||
spring.cloud.stream.bindings.my_output.contentType=application/octet-stream
|
||||
spring.cloud.stream.bindings.my_output.destination=bytes_output
|
||||
server.port=0
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
package contracts
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
|
||||
Contract.make {
|
||||
label("positive")
|
||||
input {
|
||||
messageFrom("bytes_input")
|
||||
messageBody(fileAsBytes("input.pdf"))
|
||||
messageHeaders {
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
}
|
||||
outputMessage {
|
||||
sentTo("bytes_output")
|
||||
body(fileAsBytes("output.pdf"))
|
||||
headers {
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,10 @@ class Body extends DslProperty {
|
||||
this("${bodyAsValue}")
|
||||
}
|
||||
|
||||
Body(byte[] bodyAsValue) {
|
||||
super(bodyAsValue)
|
||||
}
|
||||
|
||||
Body(Number bodyAsValue) {
|
||||
super(bodyAsValue)
|
||||
}
|
||||
@@ -65,6 +69,10 @@ class Body extends DslProperty {
|
||||
super(bodyAsValue.clientValue, bodyAsValue.serverValue)
|
||||
}
|
||||
|
||||
Body(Serializable serializable) {
|
||||
super(serializable, serializable)
|
||||
}
|
||||
|
||||
Body(MatchingStrategy matchingStrategy) {
|
||||
super(matchingStrategy, matchingStrategy)
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.contract.spec.internal
|
||||
|
||||
import groovy.transform.PackageScope
|
||||
import java.nio.charset.Charset
|
||||
|
||||
import groovy.transform.TypeChecked
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* Contains useful common methods for the DSL.
|
||||
*
|
||||
@@ -29,7 +31,6 @@ import java.util.regex.Pattern
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@TypeChecked
|
||||
@PackageScope
|
||||
class Common {
|
||||
|
||||
@Delegate private final RegexPatterns regexPatterns = new RegexPatterns()
|
||||
@@ -170,12 +171,49 @@ class Common {
|
||||
return new ServerDslProperty(serverValue)
|
||||
}
|
||||
|
||||
String file(String relativePath) {
|
||||
/**
|
||||
* Read file contents as String
|
||||
*
|
||||
* @param relativePath of the file to read
|
||||
* @return String file contents
|
||||
*/
|
||||
FromFileProperty file(String relativePath) {
|
||||
return file(relativePath, Charset.defaultCharset())
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file contents as bytes[]
|
||||
*
|
||||
* @param relativePath of the file to read
|
||||
* @return String file contents
|
||||
*/
|
||||
FromFileProperty fileAsBytes(String relativePath) {
|
||||
return new FromFileProperty(fileLocation(relativePath), byte[])
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file contents as String with the given Charset
|
||||
*
|
||||
* @param relativePath of the file to read
|
||||
* @param charset to use for converting the bytes to String
|
||||
* @return String file contents
|
||||
*/
|
||||
FromFileProperty file(String relativePath, Charset charset) {
|
||||
return new FromFileProperty(fileLocation(relativePath), String, charset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file contents as array of bytes
|
||||
*
|
||||
* @param relativePath of the file to read
|
||||
* @return file contents as an array of bytes
|
||||
*/
|
||||
private File fileLocation(String relativePath) {
|
||||
URL resource = Thread.currentThread().getContextClassLoader().getResource(relativePath)
|
||||
if (resource == null) {
|
||||
throw new IllegalStateException("File [${relativePath}] is not present")
|
||||
}
|
||||
return new File(resource.toURI()).text
|
||||
return new File(resource.toURI())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@ import groovy.transform.ToString
|
||||
*/
|
||||
@CompileStatic
|
||||
@ToString(includePackage = false, includeNames = true)
|
||||
class DslProperty<T> {
|
||||
class DslProperty<T> implements Serializable {
|
||||
|
||||
final T clientValue
|
||||
final T serverValue
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.spec.internal
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
|
||||
import java.nio.charset.Charset
|
||||
|
||||
/**
|
||||
* Represents a property that will become a File content
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@ToString(includePackage = false, includeNames = true)
|
||||
class FromFileProperty implements Serializable {
|
||||
|
||||
final File file
|
||||
final Charset charset
|
||||
final Class type
|
||||
|
||||
FromFileProperty(File file, Class type) {
|
||||
this(file, type, Charset.defaultCharset())
|
||||
}
|
||||
|
||||
FromFileProperty(File file, Class type, Charset charset) {
|
||||
this.file = file
|
||||
this.type = type
|
||||
this.charset = charset
|
||||
}
|
||||
|
||||
boolean isString() {
|
||||
return this.type == String
|
||||
}
|
||||
|
||||
boolean isByte() {
|
||||
return this.type == byte[]
|
||||
}
|
||||
|
||||
String asString() {
|
||||
return new String(this.file.bytes, this.charset)
|
||||
}
|
||||
|
||||
String fileName() {
|
||||
return this.file.getName()
|
||||
}
|
||||
|
||||
byte[] asBytes() {
|
||||
return this.file.bytes
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class MatchingStrategy extends DslProperty {
|
||||
|
||||
enum Type {
|
||||
EQUAL_TO("equalTo"), CONTAINS("containing"), MATCHING("matching"), NOT_MATCHING("notMatching"),
|
||||
EQUAL_TO_JSON("equalToJson"), EQUAL_TO_XML("equalToXml"), ABSENT("absent")
|
||||
EQUAL_TO_JSON("equalToJson"), EQUAL_TO_XML("equalToXml"), ABSENT("absent"), BINARY_EQUAL_TO("binaryEqualTo")
|
||||
|
||||
final String name
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.contract.stubrunner.messaging.camel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -34,8 +35,11 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatcher;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils;
|
||||
import org.springframework.cloud.contract.verifier.util.JsonPaths;
|
||||
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter;
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter;
|
||||
@@ -90,8 +94,64 @@ class StubRunnerCamelPredicate implements Predicate {
|
||||
return null;
|
||||
}
|
||||
Object inputMessage = message.getBody();
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
Object dslBody = MapConverter.getStubSideValues(groovyDsl.getInput().getMessageBody());
|
||||
Object dslBody = MapConverter
|
||||
.getStubSideValues(groovyDsl.getInput().getMessageBody());
|
||||
if (dslBody instanceof FromFileProperty) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Will compare file content");
|
||||
}
|
||||
FromFileProperty property = (FromFileProperty) dslBody;
|
||||
if (property.isString()) {
|
||||
// continue processing as if body was pure string
|
||||
dslBody = property.asString();
|
||||
}
|
||||
else if (!(inputMessage instanceof byte[])) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Contract provided byte comparison, but the input message is of type [" + inputMessage.getClass() + "]. Can't compare the two.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
boolean matches = Arrays.equals(property.asBytes(), (byte[]) inputMessage);
|
||||
if (log.isDebugEnabled() && !matches) {
|
||||
log.debug("Contract provided byte comparison, but the byte arrays don't match");
|
||||
}
|
||||
return matches ? groovyDsl : null;
|
||||
}
|
||||
}
|
||||
if (matchViaContent(groovyDsl, inputMessage, dslBody)) {
|
||||
return groovyDsl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) {
|
||||
boolean matches;
|
||||
ContentType type = ContentUtils
|
||||
.getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders());
|
||||
if (type == ContentType.JSON) {
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
|
||||
}
|
||||
else if (dslBody instanceof Pattern && inputMessage instanceof String) {
|
||||
Pattern pattern = (Pattern) dslBody;
|
||||
matches = pattern.matcher((String) inputMessage).matches();
|
||||
bodyUnmatchedLog(dslBody, matches, pattern);
|
||||
} else {
|
||||
matches = dslBody.equals(inputMessage);
|
||||
bodyUnmatchedLog(dslBody, matches, inputMessage);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private void bodyUnmatchedLog(Object dslBody, boolean matches, Object pattern) {
|
||||
if (log.isDebugEnabled() && !matches) {
|
||||
log.debug("Body was supposed to " + unmatchedText(pattern) + " but the value is [" + dslBody
|
||||
.toString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) {
|
||||
Object matchingInputMessage = JsonToJsonPathsConverter
|
||||
.removeMatchingJsonPaths(dslBody, matchers);
|
||||
JsonPaths jsonPaths = JsonToJsonPathsConverter
|
||||
@@ -119,14 +179,11 @@ class StubRunnerCamelPredicate implements Predicate {
|
||||
}
|
||||
if (!unmatchedJsonPath.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Contract [" + groovyDsl + "] didn't much the body due to "
|
||||
log.debug("Contract [" + groovyDsl + "] didn't match the body due to "
|
||||
+ unmatchedJsonPath);
|
||||
}
|
||||
}
|
||||
if (matches) {
|
||||
return groovyDsl;
|
||||
}
|
||||
return null;
|
||||
return matches;
|
||||
}
|
||||
|
||||
private boolean matchesJsonPath(List<String> unmatchedJsonPath,
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.verifier.util.BodyExtractor;
|
||||
|
||||
@@ -55,8 +56,7 @@ class StubRunnerCamelProcessor implements Processor {
|
||||
}
|
||||
return;
|
||||
}
|
||||
input.setBody(BodyExtractor
|
||||
.extractStubValueFrom(groovyDsl.getOutputMessage().getBody()));
|
||||
input.setBody(outputBody(groovyDsl));
|
||||
if (groovyDsl.getOutputMessage().getHeaders() != null) {
|
||||
for (Header entry : groovyDsl.getOutputMessage().getHeaders().getEntries()) {
|
||||
input.setHeader(entry.getName(), entry.getClientValue());
|
||||
@@ -64,6 +64,16 @@ class StubRunnerCamelProcessor implements Processor {
|
||||
}
|
||||
}
|
||||
|
||||
private Object outputBody(Contract groovyDsl) {
|
||||
Object outputBody =
|
||||
BodyExtractor.extractClientValueFromBody(groovyDsl.getOutputMessage().getBody());
|
||||
if (outputBody instanceof FromFileProperty) {
|
||||
FromFileProperty property = (FromFileProperty) outputBody;
|
||||
return property.asBytes();
|
||||
}
|
||||
return BodyExtractor.extractStubValueFrom(outputBody);
|
||||
}
|
||||
|
||||
private void setStubRunnerDestinationHeader(Exchange exchange, StubRunnerCamelPayload body) {
|
||||
boolean outputPart = body.contract.getOutputMessage() != null;
|
||||
String url = DUMMY_BEAN_URL;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.contract.stubrunner.messaging.integration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -33,8 +34,11 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatcher;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils;
|
||||
import org.springframework.cloud.contract.verifier.util.JsonPaths;
|
||||
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter;
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter;
|
||||
@@ -51,9 +55,10 @@ import org.springframework.messaging.Message;
|
||||
class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
|
||||
private static final Map<Message, Contract> CACHE =
|
||||
Collections.synchronizedMap(new WeakHashMap<Message, Contract>());
|
||||
Collections.synchronizedMap(new WeakHashMap<>());
|
||||
|
||||
private static final Log log = LogFactory.getLog(StubRunnerIntegrationMessageSelector.class);
|
||||
private static final Log log = LogFactory
|
||||
.getLog(StubRunnerIntegrationMessageSelector.class);
|
||||
|
||||
private final List<Contract> groovyDsls;
|
||||
|
||||
@@ -107,8 +112,64 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
return null;
|
||||
}
|
||||
Object inputMessage = message.getPayload();
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
Object dslBody = MapConverter.getStubSideValues(groovyDsl.getInput().getMessageBody());
|
||||
Object dslBody = MapConverter
|
||||
.getStubSideValues(groovyDsl.getInput().getMessageBody());
|
||||
if (dslBody instanceof FromFileProperty) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Will compare file content");
|
||||
}
|
||||
FromFileProperty property = (FromFileProperty) dslBody;
|
||||
if (property.isString()) {
|
||||
// continue processing as if body was pure string
|
||||
dslBody = property.asString();
|
||||
}
|
||||
else if (!(inputMessage instanceof byte[])) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Contract provided byte comparison, but the input message is of type [" + inputMessage.getClass() + "]. Can't compare the two.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
boolean matches = Arrays.equals(property.asBytes(), (byte[]) inputMessage);
|
||||
if (log.isDebugEnabled() && !matches) {
|
||||
log.debug("Contract provided byte comparison, but the byte arrays don't match");
|
||||
}
|
||||
return matches ? groovyDsl : null;
|
||||
}
|
||||
}
|
||||
if (matchViaContent(groovyDsl, inputMessage, dslBody)) {
|
||||
return groovyDsl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) {
|
||||
boolean matches;
|
||||
ContentType type = ContentUtils
|
||||
.getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders());
|
||||
if (type == ContentType.JSON) {
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
|
||||
}
|
||||
else if (dslBody instanceof Pattern && inputMessage instanceof String) {
|
||||
Pattern pattern = (Pattern) dslBody;
|
||||
matches = pattern.matcher((String) inputMessage).matches();
|
||||
bodyUnmatchedLog(dslBody, matches, pattern);
|
||||
} else {
|
||||
matches = dslBody.equals(inputMessage);
|
||||
bodyUnmatchedLog(dslBody, matches, inputMessage);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private void bodyUnmatchedLog(Object dslBody, boolean matches, Object pattern) {
|
||||
if (log.isDebugEnabled() && !matches) {
|
||||
log.debug("Body was supposed to " + unmatchedText(pattern) + " but the value is [" + dslBody
|
||||
.toString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) {
|
||||
Object matchingInputMessage = JsonToJsonPathsConverter
|
||||
.removeMatchingJsonPaths(dslBody, matchers);
|
||||
JsonPaths jsonPaths = JsonToJsonPathsConverter
|
||||
@@ -136,14 +197,11 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
}
|
||||
if (!unmatchedJsonPath.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Contract [" + groovyDsl + "] didn't much the body due to "
|
||||
log.debug("Contract [" + groovyDsl + "] didn't match the body due to "
|
||||
+ unmatchedJsonPath);
|
||||
}
|
||||
}
|
||||
if (matches) {
|
||||
return groovyDsl;
|
||||
}
|
||||
return null;
|
||||
return matches;
|
||||
}
|
||||
|
||||
private boolean matchesJsonPath(List<String> unmatchedJsonPath,
|
||||
@@ -189,5 +247,4 @@ class StubRunnerIntegrationMessageSelector implements MessageSelector {
|
||||
? "match pattern [" + ((Pattern) expectedValue).pattern() + "]"
|
||||
: "be equal to [" + expectedValue + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.verifier.util.BodyExtractor;
|
||||
import org.springframework.integration.transformer.GenericTransformer;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -51,17 +52,26 @@ class StubRunnerIntegrationTransformer
|
||||
if (groovyDsl == null || groovyDsl.getOutputMessage() == null) {
|
||||
return source;
|
||||
}
|
||||
String payload = BodyExtractor
|
||||
.extractStubValueFrom(groovyDsl.getOutputMessage().getBody());
|
||||
Object outputBody = outputBody(groovyDsl);
|
||||
Map<String, Object> headers = groovyDsl.getOutputMessage().getHeaders()
|
||||
.asStubSideMap();
|
||||
MessageHeaders messageHeaders = new MessageHeaders(headers);
|
||||
Message<String> message = MessageBuilder.createMessage(payload,
|
||||
Message<Object> message = MessageBuilder.createMessage(outputBody,
|
||||
messageHeaders);
|
||||
this.selector.updateCache(message, groovyDsl);
|
||||
return message;
|
||||
}
|
||||
|
||||
private Object outputBody(Contract groovyDsl) {
|
||||
Object outputBody =
|
||||
BodyExtractor.extractClientValueFromBody(groovyDsl.getOutputMessage().getBody());
|
||||
if (outputBody instanceof FromFileProperty) {
|
||||
FromFileProperty property = (FromFileProperty) outputBody;
|
||||
return property.asBytes();
|
||||
}
|
||||
return BodyExtractor.extractStubValueFrom(outputBody);
|
||||
}
|
||||
|
||||
Contract matchingContract(Message<?> source) {
|
||||
return this.selector.matchingContract(source);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.contract.stubrunner.messaging.stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -33,8 +34,11 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatcher;
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.spec.internal.Header;
|
||||
import org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierObjectMapper;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType;
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils;
|
||||
import org.springframework.cloud.contract.verifier.util.JsonPaths;
|
||||
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter;
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter;
|
||||
@@ -51,7 +55,7 @@ import org.springframework.messaging.Message;
|
||||
class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
|
||||
private static final Map<Message, Contract> CACHE =
|
||||
Collections.synchronizedMap(new WeakHashMap<Message, Contract>());
|
||||
Collections.synchronizedMap(new WeakHashMap<>());
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(StubRunnerStreamMessageSelector.class);
|
||||
@@ -108,9 +112,63 @@ class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
return null;
|
||||
}
|
||||
Object inputMessage = message.getPayload();
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
Object dslBody = MapConverter
|
||||
.getStubSideValues(groovyDsl.getInput().getMessageBody());
|
||||
if (dslBody instanceof FromFileProperty) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Will compare file content");
|
||||
}
|
||||
FromFileProperty property = (FromFileProperty) dslBody;
|
||||
if (property.isString()) {
|
||||
// continue processing as if body was pure string
|
||||
dslBody = property.asString();
|
||||
}
|
||||
else if (!(inputMessage instanceof byte[])) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Contract provided byte comparison, but the input message is of type [" + inputMessage.getClass() + "]. Can't compare the two.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
boolean matches = Arrays.equals(property.asBytes(), (byte[]) inputMessage);
|
||||
if (log.isDebugEnabled() && !matches) {
|
||||
log.debug("Contract provided byte comparison, but the byte arrays don't match");
|
||||
}
|
||||
return matches ? groovyDsl : null;
|
||||
}
|
||||
}
|
||||
if (matchViaContent(groovyDsl, inputMessage, dslBody)) {
|
||||
return groovyDsl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) {
|
||||
boolean matches;
|
||||
ContentType type = ContentUtils.getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders());
|
||||
if (type == ContentType.JSON) {
|
||||
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
|
||||
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
|
||||
}
|
||||
else if (dslBody instanceof Pattern && inputMessage instanceof String) {
|
||||
Pattern pattern = (Pattern) dslBody;
|
||||
matches = pattern.matcher((String) inputMessage).matches();
|
||||
bodyUnmatchedLog(dslBody, matches, pattern);
|
||||
} else {
|
||||
matches = dslBody.equals(inputMessage);
|
||||
bodyUnmatchedLog(dslBody, matches, inputMessage);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private void bodyUnmatchedLog(Object dslBody, boolean matches, Object pattern) {
|
||||
if (log.isDebugEnabled() && !matches) {
|
||||
log.debug("Body was supposed to " + unmatchedText(pattern) + " but the value is [" + dslBody
|
||||
.toString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) {
|
||||
Object matchingInputMessage = JsonToJsonPathsConverter
|
||||
.removeMatchingJsonPaths(dslBody, matchers);
|
||||
JsonPaths jsonPaths = JsonToJsonPathsConverter
|
||||
@@ -138,14 +196,11 @@ class StubRunnerStreamMessageSelector implements MessageSelector {
|
||||
}
|
||||
if (!unmatchedJsonPath.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Contract [" + groovyDsl + "] didn't much the body due to "
|
||||
log.debug("Contract [" + groovyDsl + "] didn't match the body due to "
|
||||
+ unmatchedJsonPath);
|
||||
}
|
||||
}
|
||||
if (matches) {
|
||||
return groovyDsl;
|
||||
}
|
||||
return null;
|
||||
return matches;
|
||||
}
|
||||
|
||||
private boolean matchesJsonPath(List<String> unmatchedJsonPath,
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract;
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty;
|
||||
import org.springframework.cloud.contract.verifier.util.BodyExtractor;
|
||||
import org.springframework.integration.transformer.GenericTransformer;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -50,17 +51,26 @@ class StubRunnerStreamTransformer implements GenericTransformer<Message<?>, Mess
|
||||
if (groovyDsl == null || groovyDsl.getOutputMessage() == null) {
|
||||
return source;
|
||||
}
|
||||
String payload = BodyExtractor
|
||||
.extractStubValueFrom(groovyDsl.getOutputMessage().getBody());
|
||||
byte[] outputBody = outputBodyAsBytes(groovyDsl);
|
||||
Map<String, Object> headers = groovyDsl.getOutputMessage().getHeaders()
|
||||
.asStubSideMap();
|
||||
MessageHeaders messageHeaders = new MessageHeaders(headers);
|
||||
Message<byte[]> message = MessageBuilder.createMessage(payload.getBytes(),
|
||||
Message<byte[]> message = MessageBuilder.createMessage(outputBody,
|
||||
messageHeaders);
|
||||
this.selector.updateCache(message, groovyDsl);
|
||||
return message;
|
||||
}
|
||||
|
||||
private byte[] outputBodyAsBytes(Contract groovyDsl) {
|
||||
Object outputBody =
|
||||
BodyExtractor.extractClientValueFromBody(groovyDsl.getOutputMessage().getBody());
|
||||
if (outputBody instanceof FromFileProperty) {
|
||||
FromFileProperty property = (FromFileProperty) outputBody;
|
||||
return property.asBytes();
|
||||
}
|
||||
return BodyExtractor.extractStubValueFrom(outputBody).getBytes();
|
||||
}
|
||||
|
||||
Contract matchingContract(Message<?> source) {
|
||||
return this.selector.matchingContract(source);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ class StubRunnerCamelPredicateSpec extends Specification {
|
||||
expect:
|
||||
!predicate.matches(exchange)
|
||||
}
|
||||
|
||||
def "should return true if headers and body match"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
@@ -137,4 +138,52 @@ class StubRunnerCamelPredicateSpec extends Specification {
|
||||
expect:
|
||||
predicate.matches(exchange)
|
||||
}
|
||||
|
||||
def "should return true if headers and byte body matches"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
messageBody(fileAsBytes("request.pdf"))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerCamelPredicate predicate = new StubRunnerCamelPredicate([dsl])
|
||||
exchange.in = message
|
||||
message.headers = [
|
||||
foo: 123,
|
||||
contentType: "application/octet-stream"
|
||||
]
|
||||
message.body = StubRunnerCamelPredicate.getResource("/request.pdf").bytes
|
||||
expect:
|
||||
predicate.matches(exchange)
|
||||
}
|
||||
|
||||
def "should return false if byte body types don't match for binary"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
messageBody(fileAsBytes("request.pdf"))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerCamelPredicate predicate = new StubRunnerCamelPredicate([dsl])
|
||||
exchange.in = message
|
||||
message.headers = [
|
||||
foo: 123,
|
||||
contentType: "application/octet-stream"
|
||||
]
|
||||
message.body = "hello world"
|
||||
expect:
|
||||
!predicate.matches(exchange)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,52 @@ class StubRunnerIntegrationMessageSelectorSpec extends Specification {
|
||||
!predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return true if headers and byte body matches"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
messageBody(fileAsBytes("request.pdf"))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(dsl)
|
||||
message.headers >> [
|
||||
foo: 123,
|
||||
contentType: "application/octet-stream"
|
||||
]
|
||||
message.payload >> StubRunnerIntegrationMessageSelector.getResource("/request.pdf").bytes
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return false if byte body types don't match for binary"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
messageBody(fileAsBytes("request.pdf"))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerIntegrationMessageSelector predicate = new StubRunnerIntegrationMessageSelector(dsl)
|
||||
message.headers >> [
|
||||
foo: 123,
|
||||
contentType: "application/octet-stream"
|
||||
]
|
||||
message.payload >> "hello world"
|
||||
expect:
|
||||
!predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return true if headers and body match"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
|
||||
@@ -123,6 +123,75 @@ class StubRunnerStreamMessageSelectorSpec extends Specification {
|
||||
predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return true if headers and text body matches"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(textPlain())
|
||||
}
|
||||
messageBody($(c(regex("[0-9]{3}")), p("123")))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl)
|
||||
message.headers >> [
|
||||
foo: 123,
|
||||
contentType: "text/plain"
|
||||
]
|
||||
message.payload >> "123"
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return true if headers and byte body matches"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
messageBody(fileAsBytes("request.pdf"))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl)
|
||||
message.headers >> [
|
||||
foo: 123,
|
||||
contentType: "application/octet-stream"
|
||||
]
|
||||
message.payload >> StubRunnerStreamMessageSelectorSpec.getResource("/request.pdf").bytes
|
||||
expect:
|
||||
predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return false if byte body types don't match for binary"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
input {
|
||||
messageFrom "foo"
|
||||
messageHeaders {
|
||||
header("foo", 123)
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
messageBody(fileAsBytes("request.pdf"))
|
||||
}
|
||||
}
|
||||
and:
|
||||
StubRunnerStreamMessageSelector predicate = new StubRunnerStreamMessageSelector(dsl)
|
||||
message.headers >> [
|
||||
foo: 123,
|
||||
contentType: "application/octet-stream"
|
||||
]
|
||||
message.payload >> "hello world"
|
||||
expect:
|
||||
!predicate.accept(message)
|
||||
}
|
||||
|
||||
def "should return true if headers and body using matchers match"() {
|
||||
given:
|
||||
Contract dsl = Contract.make {
|
||||
|
||||
BIN
spring-cloud-contract-stub-runner/src/test/resources/request.pdf
Normal file
BIN
spring-cloud-contract-stub-runner/src/test/resources/request.pdf
Normal file
Binary file not shown.
Binary file not shown.
@@ -115,6 +115,11 @@ class ContractVerifierExtension {
|
||||
*/
|
||||
File generatedTestSourcesDir
|
||||
|
||||
/**
|
||||
* Test resource directory where tests generated from Groovy DSL should be referenced
|
||||
*/
|
||||
File generatedTestResourcesDir
|
||||
|
||||
/**
|
||||
* Dir where the generated stubs from Groovy DSL should be placed.
|
||||
* You can then mention them in your packaging task to create jar with stubs
|
||||
|
||||
@@ -26,6 +26,7 @@ class ExtensionToProperties {
|
||||
staticImports: extension.getStaticImports(),
|
||||
contractsDslDir: extension.getContractsDslDir(),
|
||||
generatedTestSourcesDir: extension.getGeneratedTestSourcesDir(),
|
||||
generatedTestResourcesDir: extension.getGeneratedTestResourcesDir(),
|
||||
stubsOutputDir: extension.getStubsOutputDir(),
|
||||
stubsSuffix: extension.getStubsSuffix(),
|
||||
assertJsonSize: extension.getAssertJsonSize(),
|
||||
|
||||
@@ -20,11 +20,13 @@ import org.gradle.api.GradleException
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.internal.ConventionTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
import org.springframework.cloud.contract.spec.ContractVerifierException
|
||||
import org.springframework.cloud.contract.verifier.TestGenerator
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin.COPY_CONTRACTS_TASK_NAME
|
||||
|
||||
/**
|
||||
* Task used to generate server side tests
|
||||
*
|
||||
@@ -54,8 +56,14 @@ class GenerateServerTestsTask extends ConventionTask {
|
||||
project.logger.info("Included contracts are [${props.includedContracts}]")
|
||||
|
||||
project.sourceSets.test.groovy {
|
||||
project.logger.info("Registering ${getConfigProperties().generatedTestSourcesDir} as test source directory")
|
||||
srcDir getConfigProperties().generatedTestSourcesDir
|
||||
project.logger.
|
||||
info("Registering ${getConfigProperties().generatedTestSourcesDir} as test source directory")
|
||||
srcDir getConfigProperties().getGeneratedTestSourcesDir()
|
||||
}
|
||||
project.sourceSets.test.resources {
|
||||
project.logger.
|
||||
info("Registering ${getConfigProperties().generatedTestResourcesDir} as test resource directory")
|
||||
srcDir getConfigProperties().getGeneratedTestResourcesDir()
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -69,13 +69,14 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
addIdeaTestSources(project, extension)
|
||||
}
|
||||
|
||||
private addIdeaTestSources(Project project, extension) {
|
||||
private addIdeaTestSources(Project project, ContractVerifierExtension extension) {
|
||||
def hasIdea = new File(project.rootDir, ".idea").exists()
|
||||
if (hasIdea) {
|
||||
project.apply(plugin: 'idea')
|
||||
project.idea {
|
||||
module {
|
||||
testSourceDirs += extension.generatedTestSourcesDir
|
||||
testSourceDirs += extension.generatedTestResourcesDir
|
||||
testSourceDirs += extension.contractsDslDir
|
||||
}
|
||||
}
|
||||
@@ -86,6 +87,8 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
|
||||
extension.with {
|
||||
generatedTestSourcesDir = generatedTestSourcesDir ?: project.file("${project.buildDir}/generated-test-sources/contracts")
|
||||
generatedTestSourcesDir.mkdirs()
|
||||
generatedTestResourcesDir = generatedTestResourcesDir ?: project.file("${project.buildDir}/generated-test-resources/contracts")
|
||||
generatedTestResourcesDir.mkdirs()
|
||||
contractsDslDir = contractsDslDir ?: defaultContractsDir() //TODO: Use sourceset
|
||||
contractsDslDir.mkdirs()
|
||||
stubsOutputDir = stubsOutputDir ?: project.file("${project.buildDir}/stubs/")
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package org.springframework.cloud.contract.maven.verifier;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
@@ -33,6 +33,7 @@ import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
|
||||
import org.springframework.cloud.contract.maven.verifier.stubrunner.AetherStubDownloaderFactory;
|
||||
import org.springframework.cloud.contract.spec.ContractVerifierException;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
|
||||
@@ -57,6 +58,9 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
@Parameter(defaultValue = "${project.build.directory}/generated-test-sources/contracts")
|
||||
private File generatedTestSourcesDir;
|
||||
|
||||
@Parameter(defaultValue = "${project.build.directory}/generated-test-resources/contracts")
|
||||
private File generatedTestResourcesDir;
|
||||
|
||||
@Parameter
|
||||
private String basePackageForTests;
|
||||
|
||||
@@ -260,12 +264,16 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
|
||||
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest,
|
||||
this.contractsProperties).downloadAndUnpackContractsIfRequired(config,
|
||||
this.contractsDirectory);
|
||||
this.contractsDirectory);
|
||||
getLog().info(
|
||||
"Directory with contract is present at [" + contractsDirectory + "]");
|
||||
setupConfig(config, contractsDirectory);
|
||||
this.project
|
||||
.addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath());
|
||||
Resource resource = new Resource();
|
||||
resource.setDirectory(this.generatedTestResourcesDir.getAbsolutePath());
|
||||
this.project
|
||||
.addTestResource(resource);
|
||||
if (getLog().isInfoEnabled()) {
|
||||
getLog().info("Test Source directory: "
|
||||
+ this.generatedTestSourcesDir.getAbsolutePath() + " added.");
|
||||
@@ -293,6 +301,7 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
File contractsDirectory) {
|
||||
config.setContractsDslDir(contractsDirectory);
|
||||
config.setGeneratedTestSourcesDir(this.generatedTestSourcesDir);
|
||||
config.setGeneratedTestResourcesDir(this.generatedTestResourcesDir);
|
||||
config.setTestFramework(this.testFramework);
|
||||
config.setTestMode(this.testMode);
|
||||
config.setBasePackageForTests(this.basePackageForTests);
|
||||
@@ -311,15 +320,6 @@ public class GenerateTestsMojo extends AbstractMojo {
|
||||
}
|
||||
}
|
||||
|
||||
private URL fileToUrl(File contractsDirectory) {
|
||||
try {
|
||||
return contractsDirectory.toURI().toURL();
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> mappingsToMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (this.baseClassMappings == null) {
|
||||
|
||||
@@ -209,8 +209,13 @@
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addSources</goal>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>generateTestStubs</goal>
|
||||
<goal>compileTests</goal>
|
||||
<goal>removeStubs</goal>
|
||||
<goal>removeTestStubs</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
@@ -46,13 +46,20 @@ class FileSaver {
|
||||
this.properties = properties
|
||||
}
|
||||
|
||||
void saveClassFile(String fileName, String basePackageClass, String includedDirectoryRelativePath, byte[] classBytes) {
|
||||
Path testBaseDir = Paths.get(targetDirectory.absolutePath, packageToDirectory(basePackageClass),
|
||||
beforeLast(includedDirectoryRelativePath, File.separator))
|
||||
Files.createDirectories(testBaseDir)
|
||||
Path classPath = Paths.get(testBaseDir.toString(), capitalize(fileName) + generator.fileExtension(this.properties)).toAbsolutePath()
|
||||
void saveClassFile(Path classPath, byte[] classBytes) {
|
||||
log.info("Creating new class file [$classPath]")
|
||||
Files.write(classPath, classBytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
|
||||
}
|
||||
|
||||
protected Path pathToClass(Path testBaseDir, String fileName) {
|
||||
Paths.get(testBaseDir.toString(), capitalize(fileName) + generator.fileExtension(this.properties)).toAbsolutePath()
|
||||
}
|
||||
|
||||
protected Path generateTestBaseDir(String basePackageClass, String includedDirectoryRelativePath) {
|
||||
Path testBaseDir = Paths.get(targetDirectory.absolutePath, packageToDirectory(basePackageClass),
|
||||
beforeLast(includedDirectoryRelativePath, File.separator))
|
||||
Files.createDirectories(testBaseDir)
|
||||
return testBaseDir
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Path
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
import org.apache.commons.logging.Log
|
||||
import org.apache.commons.logging.LogFactory
|
||||
import wiremock.com.google.common.collect.ListMultimap
|
||||
|
||||
import org.springframework.cloud.contract.spec.ContractVerifierException
|
||||
import org.springframework.cloud.contract.verifier.builder.JavaTestGenerator
|
||||
import org.springframework.cloud.contract.verifier.builder.SingleTestGenerator
|
||||
@@ -35,13 +29,17 @@ import org.springframework.cloud.contract.verifier.file.ContractFileScannerBuild
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader
|
||||
import org.springframework.util.StringUtils
|
||||
import wiremock.com.google.common.collect.ListMultimap
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Path
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.NamesUtil.afterLast
|
||||
import static org.springframework.cloud.contract.verifier.util.NamesUtil.beforeLast
|
||||
import static org.springframework.cloud.contract.verifier.util.NamesUtil.convertIllegalPackageChars
|
||||
import static org.springframework.cloud.contract.verifier.util.NamesUtil.directoryToPackage
|
||||
import static org.springframework.cloud.contract.verifier.util.NamesUtil.toLastDot
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski, codearte.io
|
||||
*/
|
||||
@@ -128,8 +126,11 @@ class TestGenerator {
|
||||
def className = afterLast(includedDirectoryRelativePath.toString(), File.separator) + resolveNameSuffix()
|
||||
def convertedClassName = convertIllegalPackageChars(className)
|
||||
def packageName = buildPackage(basePackageNameForClass, includedDirectoryRelativePath)
|
||||
def classBytes = generator.buildClass(configProperties, contracts, convertedClassName, packageName, includedDirectoryRelativePath).getBytes(StandardCharsets.UTF_8)
|
||||
saver.saveClassFile(convertedClassName, basePackageNameForClass, convertIllegalPackageChars(includedDirectoryRelativePath.toString()), classBytes)
|
||||
Path dir = saver.generateTestBaseDir(basePackageNameForClass, convertIllegalPackageChars(includedDirectoryRelativePath.toString()))
|
||||
Path classPath = saver.pathToClass(dir, convertedClassName)
|
||||
def classBytes = generator.buildClass(configProperties, contracts, includedDirectoryRelativePath,
|
||||
new SingleTestGenerator.GeneratedClassData(className, packageName, classPath)).getBytes(StandardCharsets.UTF_8)
|
||||
saver.saveClassFile(classPath, classBytes)
|
||||
counter.incrementAndGet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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 groovy.transform.CompileStatic
|
||||
|
||||
/**
|
||||
* Describes the type of communication
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@CompileStatic
|
||||
enum CommunicationType {
|
||||
REQUEST, RESPONSE, INPUT, OUTPUT
|
||||
}
|
||||
@@ -32,8 +32,10 @@ import org.springframework.cloud.contract.verifier.config.ContractVerifierConfig
|
||||
@PackageScope
|
||||
class ExplicitJUnitMethodBodyBuilder extends RestAssuredJUnitMethodBodyBuilder {
|
||||
|
||||
ExplicitJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
ExplicitJUnitMethodBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
* @since
|
||||
*/
|
||||
class GeneratedClassDataForMethod {
|
||||
final SingleTestGenerator.GeneratedClassData generatedClassData;
|
||||
final String methodName;
|
||||
|
||||
GeneratedClassDataForMethod(SingleTestGenerator.GeneratedClassData generatedClassData,
|
||||
String methodName) {
|
||||
this.generatedClassData = generatedClassData;
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
private SingleTestGenerator.GeneratedClassData assertClassData() {
|
||||
if (this.generatedClassData == null) {
|
||||
throw new IllegalStateException("No metadata was found for the generated test class");
|
||||
}
|
||||
return this.generatedClassData;
|
||||
}
|
||||
|
||||
String className() {
|
||||
return assertClassData().className;
|
||||
}
|
||||
|
||||
java.nio.file.Path testClassPath() {
|
||||
return assertClassData().testClassPath;
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,10 @@ import java.util.regex.Pattern
|
||||
@TypeChecked
|
||||
class HttpSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder {
|
||||
|
||||
HttpSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
HttpSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.Input
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
@@ -50,8 +51,10 @@ import static org.springframework.cloud.contract.verifier.config.TestFramework.J
|
||||
@TypeChecked
|
||||
class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
|
||||
JUnitMessagingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
JUnitMessagingMethodBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +85,15 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
return ""
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
if (value.isByte()) {
|
||||
return "assertThat(response.getPayloadAsByteArray()).isEqualTo(" +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
}
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) {
|
||||
blockBuilder.addLine("${exec.insertValue("parsedJson.read('\\\$$property')")}")
|
||||
@@ -196,15 +208,27 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
protected String getInputString() {
|
||||
String request = 'ContractVerifierMessage inputMessage = contractVerifierMessaging.create('
|
||||
if (inputMessage.messageBody) {
|
||||
request = "${request}\n\t\t\t\t\"${escapeJava(bodyAsString)}\"\n"
|
||||
request = "${request}${getBodyAsString()}"
|
||||
}
|
||||
if (inputMessage.messageHeaders) {
|
||||
request = "${request}\t\t\t\t, headers()"
|
||||
request = "${request}${indentHeadersString()}"
|
||||
}
|
||||
inputMessage.messageHeaders?.executeForEachHeader { Header header ->
|
||||
request = "${request}\n\t\t\t\t\t\t${getHeaderString(header)}"
|
||||
request = "${request}${indentedHeaderString(header)}"
|
||||
}
|
||||
return "${request}\n\t\t\t)"
|
||||
return finishIndentation(request)
|
||||
}
|
||||
|
||||
private String indentHeadersString() {
|
||||
return "\t\t\t\t, headers()"
|
||||
}
|
||||
|
||||
private String indentedHeaderString(Header header) {
|
||||
return "\n\t\t\t\t\t\t${getHeaderString(header)}"
|
||||
}
|
||||
|
||||
private String finishIndentation(String text) {
|
||||
return "${text}\n\t\t\t)"
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,24 +16,26 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import groovy.json.StringEscapeUtils
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.util.RegexpBuilders
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import static groovy.json.StringEscapeUtils.escapeJava
|
||||
import static org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.getJavaMultipartFileParameterContent
|
||||
|
||||
/**
|
||||
* Root class for JUnit method building
|
||||
*
|
||||
@@ -48,8 +50,9 @@ import static org.springframework.cloud.contract.verifier.util.ContentUtils.getJ
|
||||
@PackageScope
|
||||
abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder {
|
||||
|
||||
JUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
JUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,6 +120,15 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
|
||||
return property.replaceAll('(get\\(\\\\")(.*)(\\\\"\\))', '$2')
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
if (value.isByte()) {
|
||||
return "assertThat(response.getBody().asByteArray()).isEqualTo(" +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
}
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getParsedXmlResponseBodyString(String responseString) {
|
||||
return "Object responseBody = new XmlSlurper().parseText($responseString);"
|
||||
@@ -160,6 +172,11 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
|
||||
String value
|
||||
if (body instanceof ExecutionProperty) {
|
||||
value = body.toString()
|
||||
} else if (body instanceof FromFileProperty) {
|
||||
FromFileProperty fileProperty = (FromFileProperty) body
|
||||
value = fileProperty.isByte() ?
|
||||
readBytesFromFileString(fileProperty, CommunicationType.REQUEST) :
|
||||
readStringFromFileString(fileProperty, CommunicationType.REQUEST)
|
||||
} else {
|
||||
value = "\"$body\""
|
||||
}
|
||||
@@ -168,7 +185,7 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
|
||||
|
||||
@Override
|
||||
protected String getMultipartFileParameterContent(String propertyName, NamedProperty propertyValue) {
|
||||
return getJavaMultipartFileParameterContent(propertyName, propertyValue)
|
||||
return getJavaMultipartFileParameterContent(propertyName, propertyValue, { FromFileProperty fileProp -> readBytesFromFileString(fileProp, CommunicationType.REQUEST) })
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
import java.lang.invoke.MethodHandles
|
||||
|
||||
import groovy.transform.Canonical
|
||||
@@ -40,26 +42,31 @@ import static org.springframework.cloud.contract.verifier.util.NamesUtil.capital
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@CompileStatic
|
||||
class JavaTestGenerator implements SingleTestGenerator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass())
|
||||
|
||||
private static final String JSON_ASSERT_STATIC_IMPORT = 'com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson'
|
||||
private static final String JSON_ASSERT_CLASS = 'com.toomuchcoding.jsonassert.JsonAssertion'
|
||||
@Deprecated
|
||||
// TODO: Remove in next major
|
||||
private static final String REST_ASSURED_2_0_CLASS = 'com.jayway.restassured.RestAssured'
|
||||
|
||||
@PackageScope ClassPresenceChecker checker = new ClassPresenceChecker()
|
||||
|
||||
@Override
|
||||
String buildClass(ContractVerifierConfigProperties configProperties, Collection<ContractMetadata> listOfFiles, String className, String classPackage, String includedDirectoryRelativePath) {
|
||||
String buildClass(ContractVerifierConfigProperties configProperties, Collection<ContractMetadata> listOfFiles, String includedDirectoryRelativePath, GeneratedClassData generatedClassData) {
|
||||
String className = generatedClassData.className
|
||||
String classPackage = generatedClassData.classPackage
|
||||
ClassBuilder clazz = ClassBuilder.createClass(capitalize(className), classPackage, configProperties, includedDirectoryRelativePath)
|
||||
if (configProperties.imports) {
|
||||
configProperties.imports.each {
|
||||
configProperties.imports.each { String it ->
|
||||
clazz.addImport(it)
|
||||
}
|
||||
}
|
||||
if (configProperties.staticImports) {
|
||||
configProperties.staticImports.each {
|
||||
configProperties.staticImports.each { String it ->
|
||||
clazz.addStaticImport(it)
|
||||
}
|
||||
}
|
||||
@@ -68,15 +75,19 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
clazz.addClassLevelAnnotation(configProperties.testFramework.getOrderAnnotation())
|
||||
}
|
||||
addJsonPathRelatedImports(clazz)
|
||||
processContractFiles(listOfFiles, configProperties, clazz)
|
||||
processContractFiles(listOfFiles, configProperties, clazz, generatedClassData)
|
||||
return clazz.build()
|
||||
}
|
||||
|
||||
private void processContractFiles(Collection<ContractMetadata> listOfFiles,
|
||||
ContractVerifierConfigProperties configProperties, ClassBuilder clazz) {
|
||||
@Override
|
||||
String buildClass(ContractVerifierConfigProperties configProperties, Collection<ContractMetadata> listOfFiles, String className, String classPackage, String includedDirectoryRelativePath) {
|
||||
return buildClass(configProperties, listOfFiles, includedDirectoryRelativePath, new GeneratedClassData(className, classPackage, null))
|
||||
}
|
||||
|
||||
private void processContractFiles(Collection<ContractMetadata> listOfFiles, ContractVerifierConfigProperties configProperties, ClassBuilder clazz, GeneratedClassData generatedClassData) {
|
||||
Map<ParsedDsl, TestType> contracts = mapContractsToTheirTestTypes(listOfFiles)
|
||||
boolean conditionalImportsAdded = false
|
||||
boolean toIgnore = listOfFiles.ignored.find {it}
|
||||
boolean toIgnore = listOfFiles.find { it.ignored }
|
||||
contracts.each {ParsedDsl key, TestType value ->
|
||||
if (!conditionalImportsAdded) {
|
||||
clazz.addImports(getImports(configProperties.testFramework))
|
||||
@@ -93,7 +104,8 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
conditionalImportsAdded = true
|
||||
}
|
||||
toIgnore = toIgnore ? true : key.groovyDsl.ignored
|
||||
clazz.addMethod(MethodBuilder.createTestMethod(key.contract, key.stubsFile, key.groovyDsl, configProperties))
|
||||
clazz.addMethod(MethodBuilder.createTestMethod(key.contract, key.stubsFile,
|
||||
key.groovyDsl, configProperties, generatedClassData))
|
||||
}
|
||||
|
||||
if (toIgnore) {
|
||||
@@ -102,7 +114,7 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
}
|
||||
|
||||
private void addRule(ContractVerifierConfigProperties configProperties, ClassBuilder clazz) {
|
||||
clazz.addImport(getRuleImport())
|
||||
clazz.addImport(getRuleImport(configProperties.testFramework))
|
||||
if (configProperties.testFramework.annotationLevelRules()) {
|
||||
clazz.addClassLevelAnnotation(configProperties.testFramework
|
||||
.getRuleAnnotation(configProperties.ruleClassForTests))
|
||||
@@ -139,7 +151,7 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Stub content from file [${stubsFile.text}]")
|
||||
}
|
||||
List<Contract> stubContents = metadata.convertedContract
|
||||
Collection<Contract> stubContents = metadata.convertedContract
|
||||
Map<ParsedDsl, TestType> entries = stubContents.collectEntries { Contract stubContent ->
|
||||
TestType testType = (stubContent.input || stubContent.outputMessage) ? TestType.MESSAGING : TestType.HTTP
|
||||
return [(new ParsedDsl(metadata, stubContent, stubsFile)): testType]
|
||||
@@ -151,6 +163,7 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
|
||||
@Canonical
|
||||
@EqualsAndHashCode(includeFields = true)
|
||||
@CompileStatic
|
||||
private static class ParsedDsl {
|
||||
ContractMetadata contract
|
||||
Contract groovyDsl
|
||||
|
||||
@@ -21,6 +21,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.NotToEscapePattern
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
@@ -47,8 +48,10 @@ import static org.springframework.cloud.contract.verifier.config.TestFramework.J
|
||||
@PackageScope
|
||||
class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
|
||||
JaxRsClientJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
JaxRsClientJUnitMethodBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,9 +112,19 @@ class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
String method = request.method.serverValue.toString().toLowerCase()
|
||||
if (request.body) {
|
||||
String contentType = getHeader('Content-Type') ?: getRequestContentType().mimeType
|
||||
String body = request.body?.serverValue instanceof ExecutionProperty ?
|
||||
request.body?.serverValue?.toString() : "\"${bodyAsString}\""
|
||||
bb.addLine(".method(\"${method.toUpperCase()}\", entity(${body}, \"$contentType\"))")
|
||||
Object body = request.body.serverValue
|
||||
String value
|
||||
if (body instanceof ExecutionProperty) {
|
||||
value = body.toString()
|
||||
} else if (body instanceof FromFileProperty) {
|
||||
FromFileProperty fileProperty = (FromFileProperty) body
|
||||
value = fileProperty.isByte() ?
|
||||
readBytesFromFileString(fileProperty, CommunicationType.REQUEST) :
|
||||
readStringFromFileString(fileProperty, CommunicationType.REQUEST)
|
||||
} else {
|
||||
value = "\"${getBodyAsString()}\""
|
||||
}
|
||||
bb.addLine(".method(\"${method.toUpperCase()}\", entity(${value}, \"$contentType\"))")
|
||||
} else {
|
||||
bb.addLine(".method(\"${method.toUpperCase()}\")")
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.NotToEscapePattern
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
@@ -44,8 +45,10 @@ import java.util.regex.Pattern
|
||||
@TypeChecked
|
||||
class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder {
|
||||
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,9 +117,19 @@ class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequ
|
||||
String method = request.method.serverValue.toString().toLowerCase()
|
||||
if (request.body) {
|
||||
String contentType = getHeader('Content-Type') ?: getRequestContentType().mimeType
|
||||
String body = request.body?.serverValue instanceof ExecutionProperty ?
|
||||
request.body?.serverValue?.toString() : "'${bodyAsString}'"
|
||||
bb.addLine(".method('${method.toUpperCase()}', entity(${body}, '$contentType'))")
|
||||
Object body = request.body.serverValue
|
||||
String value
|
||||
if (body instanceof ExecutionProperty) {
|
||||
value = body.toString()
|
||||
} else if (body instanceof FromFileProperty) {
|
||||
FromFileProperty fileProperty = (FromFileProperty) body
|
||||
value = fileProperty.isByte() ?
|
||||
readBytesFromFileString(fileProperty, CommunicationType.REQUEST) :
|
||||
readStringFromFileString(fileProperty, CommunicationType.REQUEST)
|
||||
} else {
|
||||
value = "'${bodyAsString}'"
|
||||
}
|
||||
bb.addLine(".method('${method.toUpperCase()}', entity(${value}, '$contentType'))")
|
||||
} else {
|
||||
bb.addLine(".method('${method.toUpperCase()}')")
|
||||
}
|
||||
|
||||
@@ -19,13 +19,16 @@ package org.springframework.cloud.contract.verifier.builder
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Input
|
||||
import org.springframework.cloud.contract.spec.internal.OutputMessage
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils
|
||||
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeJava
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromHeader
|
||||
|
||||
@@ -46,8 +49,10 @@ abstract class MessagingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
protected final Input inputMessage
|
||||
protected final OutputMessage outputMessage
|
||||
|
||||
MessagingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(configProperties, stubDefinition)
|
||||
MessagingMethodBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(configProperties, stubDefinition, classDataForMethod)
|
||||
this.inputMessage = stubDefinition.input
|
||||
this.outputMessage = stubDefinition.outputMessage
|
||||
}
|
||||
@@ -101,6 +106,11 @@ abstract class MessagingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
processHeaderElement(blockBuilder, property, gstringValue)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
return null
|
||||
}
|
||||
|
||||
protected ContentType getResponseContentType() {
|
||||
ContentType contentType = recognizeContentTypeFromHeader(outputMessage.headers)
|
||||
if (contentType == ContentType.UNKNOWN) {
|
||||
@@ -111,9 +121,27 @@ abstract class MessagingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
|
||||
protected String getBodyAsString() {
|
||||
Object bodyValue = extractServerValueFromBody(inputMessage.messageBody.serverValue)
|
||||
if (bodyValue instanceof FromFileProperty) {
|
||||
FromFileProperty fileProperty = (FromFileProperty) bodyValue
|
||||
return fileProperty.isByte() ?
|
||||
indentBody(readBytesFromFileString(fileProperty, CommunicationType.REQUEST)) :
|
||||
indentStringBody(readStringFromFileString(fileProperty, CommunicationType.REQUEST))
|
||||
}
|
||||
String json = new JsonOutput().toJson(bodyValue)
|
||||
json = convertUnicodeEscapesIfRequired(json)
|
||||
return trimRepeatedQuotes(json)
|
||||
return indentStringBody(trimRepeatedQuotes(json))
|
||||
}
|
||||
|
||||
protected String indentBody(String text) {
|
||||
return "\n\t\t\t\t${text}\n"
|
||||
}
|
||||
|
||||
protected String indentStringBody(String text) {
|
||||
return indentBody("${quotes()}${escapeJava(text)}${quotes()}")
|
||||
}
|
||||
|
||||
protected String quotes() {
|
||||
return "\""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
@@ -33,8 +31,10 @@ import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.ContractTemplate
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatcher
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingType
|
||||
@@ -76,12 +76,42 @@ abstract class MethodBodyBuilder {
|
||||
protected final TemplateProcessor templateProcessor
|
||||
protected final ContractTemplate contractTemplate
|
||||
protected final Contract contract
|
||||
protected final GeneratedClassDataForMethod classDataForMethod
|
||||
|
||||
protected MethodBodyBuilder(ContractVerifierConfigProperties configProperties, Contract contract) {
|
||||
protected MethodBodyBuilder(ContractVerifierConfigProperties configProperties, Contract contract, GeneratedClassDataForMethod classDataForMethod) {
|
||||
this.configProperties = configProperties
|
||||
this.templateProcessor = processor()
|
||||
this.contractTemplate = template()
|
||||
this.contract = contract
|
||||
this.classDataForMethod = classDataForMethod
|
||||
}
|
||||
|
||||
private String byteBodyToAFileForTestMethod(FromFileProperty property, CommunicationType side) {
|
||||
String newFileName = this.classDataForMethod.methodName + "_" + side.name().toLowerCase() + "_" + property.fileName()
|
||||
File newFile = new File(this.classDataForMethod.testClassPath().parent.toFile(), newFileName)
|
||||
// for IDE
|
||||
newFile.bytes = property.asBytes()
|
||||
// for plugin
|
||||
generatedTestResourcesFileBytes(property, newFile)
|
||||
return newFileName
|
||||
}
|
||||
|
||||
private void generatedTestResourcesFileBytes(FromFileProperty property, File newFile) {
|
||||
java.nio.file.Path relativePath = this.configProperties.generatedTestSourcesDir.
|
||||
toPath().relativize(newFile.toPath())
|
||||
File newFileInGeneratedTestSources = new File(this.configProperties.generatedTestResourcesDir, relativePath.
|
||||
toString())
|
||||
newFileInGeneratedTestSources.parentFile.mkdirs()
|
||||
newFileInGeneratedTestSources.bytes = property.asBytes()
|
||||
}
|
||||
|
||||
protected String readBytesFromFileString(FromFileProperty property, CommunicationType side) {
|
||||
String fileName = byteBodyToAFileForTestMethod(property, side)
|
||||
return "fileToBytes(this, \"${fileName}\")"
|
||||
}
|
||||
|
||||
protected String readStringFromFileString(FromFileProperty property, CommunicationType side) {
|
||||
return "new String(" + readBytesFromFileString(property, side) + ")"
|
||||
}
|
||||
|
||||
private TemplateProcessor processor() {
|
||||
@@ -128,6 +158,12 @@ abstract class MethodBodyBuilder {
|
||||
*/
|
||||
protected abstract String getResponseBodyPropertyComparisonString(String property, Object value)
|
||||
|
||||
/**
|
||||
* Builds the code that for the given {@code property} will compare it to
|
||||
* the given byte[] {@code value}
|
||||
*/
|
||||
protected abstract String getResponseBodyPropertyComparisonString(String property, FromFileProperty value)
|
||||
|
||||
/**
|
||||
* Builds the code that for the given {@code property} will compare it to
|
||||
* the given String {@code value}
|
||||
@@ -340,6 +376,10 @@ abstract class MethodBodyBuilder {
|
||||
protected void validateResponseBodyBlock(BlockBuilder bb, BodyMatchers bodyMatchers, Object responseBody) {
|
||||
ContentType contentType = getResponseContentType()
|
||||
Object convertedResponseBody = responseBody
|
||||
if (convertedResponseBody instanceof FromFileProperty) {
|
||||
byteResponseBodyCheck(bb, convertedResponseBody)
|
||||
return
|
||||
}
|
||||
if (convertedResponseBody instanceof GString) {
|
||||
convertedResponseBody = extractValue(convertedResponseBody as GString, contentType, { Object o -> o instanceof DslProperty ? o.serverValue : o })
|
||||
}
|
||||
@@ -359,6 +399,11 @@ abstract class MethodBodyBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private void byteResponseBodyCheck(BlockBuilder bb, FromFileProperty convertedResponseBody) {
|
||||
processText(bb, "", convertedResponseBody)
|
||||
addColonIfRequired(bb)
|
||||
}
|
||||
|
||||
private void simpleTextResponseBodyCheck(BlockBuilder bb, convertedResponseBody) {
|
||||
bb.addLine(getSimpleResponseBodyString(getResponseAsString()))
|
||||
processText(bb, "", convertedResponseBody)
|
||||
@@ -765,6 +810,4 @@ abstract class MethodBodyBuilder {
|
||||
processBodyElement(blockBuilder, property, prop, listElement)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.contract.verifier.builder
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.util.logging.Commons
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.config.TestMode
|
||||
@@ -44,24 +45,28 @@ class MethodBuilder {
|
||||
private final String methodName
|
||||
private final Contract stubContent
|
||||
private final ContractVerifierConfigProperties configProperties
|
||||
private final GeneratedClassDataForMethod generatedClassDataForMethod
|
||||
private final boolean ignored
|
||||
|
||||
private MethodBuilder(String methodName, Contract stubContent, ContractVerifierConfigProperties configProperties, boolean ignored) {
|
||||
private MethodBuilder(String methodName, Contract stubContent, ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod generatedClassDataForMethod, boolean ignored) {
|
||||
this.ignored = ignored
|
||||
this.stubContent = stubContent
|
||||
this.methodName = methodName
|
||||
this.configProperties = configProperties
|
||||
this.generatedClassDataForMethod = generatedClassDataForMethod
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory method that creates a {@link MethodBuilder} for the given arguments
|
||||
*/
|
||||
static MethodBuilder createTestMethod(ContractMetadata contract, File stubsFile, Contract stubContent, ContractVerifierConfigProperties configProperties) {
|
||||
static MethodBuilder createTestMethod(ContractMetadata contract, File stubsFile, Contract stubContent, ContractVerifierConfigProperties configProperties, SingleTestGenerator.GeneratedClassData generatedClassData) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Stub content Groovy DSL [$stubContent]")
|
||||
}
|
||||
String methodName = MethodBuilder.methodName(contract, stubsFile, stubContent)
|
||||
return new MethodBuilder(methodName, stubContent, configProperties, contract.ignored || stubContent.ignored)
|
||||
String methodName = methodName(contract, stubsFile, stubContent)
|
||||
return new MethodBuilder(methodName, stubContent, configProperties,
|
||||
new GeneratedClassDataForMethod(generatedClassData, methodName), contract.ignored || stubContent.ignored)
|
||||
}
|
||||
|
||||
static String methodName(ContractMetadata contract, File stubsFile, Contract stubContent) {
|
||||
@@ -108,30 +113,30 @@ class MethodBuilder {
|
||||
private MethodBodyBuilder getMethodBodyBuilder() {
|
||||
if (stubContent.input || stubContent.outputMessage) {
|
||||
if (isJUnitType()) {
|
||||
return new JUnitMessagingMethodBodyBuilder(stubContent, configProperties)
|
||||
return new JUnitMessagingMethodBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
return new SpockMessagingMethodBodyBuilder(stubContent, configProperties)
|
||||
return new SpockMessagingMethodBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
if (configProperties.testMode == TestMode.JAXRSCLIENT) {
|
||||
if (isJUnitType()) {
|
||||
return new JaxRsClientJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
return new JaxRsClientJUnitMethodBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
return new JaxRsClientSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
return new JaxRsClientSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
} else if (configProperties.testMode == TestMode.WEBTESTCLIENT) {
|
||||
if (isJUnitType()) {
|
||||
return new WebTestClientJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
return new WebTestClientJUnitMethodBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
} else if (configProperties.testMode == TestMode.EXPLICIT) {
|
||||
if (isJUnitType()) {
|
||||
return new ExplicitJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
return new ExplicitJUnitMethodBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
// in Groovy we're using def so we don't have to update the imports
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
} else if (configProperties.testFramework == SPOCK) {
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
return new MockMvcJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
return new MockMvcJUnitMethodBodyBuilder(stubContent, configProperties, this.generatedClassDataForMethod)
|
||||
}
|
||||
|
||||
private boolean isJUnitType() {
|
||||
|
||||
@@ -32,8 +32,9 @@ import org.springframework.cloud.contract.verifier.config.ContractVerifierConfig
|
||||
@PackageScope
|
||||
class MockMvcJUnitMethodBodyBuilder extends RestAssuredJUnitMethodBodyBuilder {
|
||||
|
||||
MockMvcJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
MockMvcJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.BodyMatchers
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
@@ -57,8 +58,8 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
private static final String DOUBLE_QUOTE = '"'
|
||||
private static final String QUERY_PARAM_METHOD = 'queryParam'
|
||||
|
||||
RequestProcessingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(configProperties, stubDefinition)
|
||||
RequestProcessingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties, GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(configProperties, stubDefinition, classDataForMethod)
|
||||
this.request = stubDefinition.request
|
||||
this.response = stubDefinition.response
|
||||
}
|
||||
@@ -118,8 +119,15 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
}
|
||||
|
||||
if (request.body) {
|
||||
Object body = request.body?.serverValue instanceof ExecutionProperty ?
|
||||
request.body?.serverValue : bodyAsString
|
||||
Object body = null
|
||||
switch (request.body.serverValue) {
|
||||
case ExecutionProperty:
|
||||
case FromFileProperty:
|
||||
body = request.body?.serverValue
|
||||
break;
|
||||
default:
|
||||
body = getBodyAsString()
|
||||
}
|
||||
bb.addLine(getBodyString(body))
|
||||
}
|
||||
if (request.multipart) {
|
||||
|
||||
@@ -38,8 +38,9 @@ import java.util.regex.Pattern
|
||||
@PackageScope
|
||||
class RestAssuredJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
|
||||
RestAssuredJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
RestAssuredJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
/**
|
||||
* Builds a single test.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
interface SingleTestGenerator {
|
||||
|
||||
/**
|
||||
* Creates contents of a single test class in which all test scenarios from
|
||||
* the contract metadata should be placed.
|
||||
*
|
||||
* @param properties - properties passed to the plugin
|
||||
* @param listOfFiles - list of parsed contracts with additional metadata
|
||||
* @param className - the name of the generated test class
|
||||
* @param classPackage - the name of the package in which the test class should be stored
|
||||
* @param includedDirectoryRelativePath - relative path to the included directory
|
||||
* @return contents of a single test class
|
||||
*/
|
||||
String buildClass(ContractVerifierConfigProperties properties, Collection<ContractMetadata> listOfFiles,
|
||||
String className, String classPackage, String includedDirectoryRelativePath)
|
||||
|
||||
/**
|
||||
* Extension that should be appended to the generated test class. E.g. {@code .java} or {@code .php}
|
||||
*
|
||||
* @param properties - properties passed to the plugin
|
||||
*/
|
||||
String fileExtension(ContractVerifierConfigProperties properties)
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.springframework.cloud.contract.verifier.builder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties;
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata;
|
||||
|
||||
/**
|
||||
* Builds a single test.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public interface SingleTestGenerator {
|
||||
/**
|
||||
* Creates contents of a single test class in which all test scenarios from
|
||||
* the contract metadata should be placed.
|
||||
*
|
||||
* @param properties - properties passed to the plugin
|
||||
* @param listOfFiles - list of parsed contracts with additional metadata
|
||||
* @param className - the name of the generated test class
|
||||
* @param classPackage - the name of the package in which the test class should be stored
|
||||
* @param includedDirectoryRelativePath - relative path to the included directory
|
||||
* @return contents of a single test class
|
||||
* @deprecated use {@link SingleTestGenerator#buildClass(ContractVerifierConfigProperties, Collection, String, GeneratedClassData)}
|
||||
*/
|
||||
@Deprecated
|
||||
String buildClass(ContractVerifierConfigProperties properties,
|
||||
Collection<ContractMetadata> listOfFiles, String className, String classPackage, String includedDirectoryRelativePath);
|
||||
|
||||
/**
|
||||
* Creates contents of a single test class in which all test scenarios from
|
||||
* the contract metadata should be placed.
|
||||
*
|
||||
* @param properties - properties passed to the plugin
|
||||
* @param listOfFiles - list of parsed contracts with additional metadata
|
||||
* @param generatedClassData - information about the generated class
|
||||
* @param includedDirectoryRelativePath - relative path to the included directory
|
||||
* @return contents of a single test class
|
||||
*/
|
||||
default String buildClass(ContractVerifierConfigProperties properties,
|
||||
Collection<ContractMetadata> listOfFiles, String includedDirectoryRelativePath, GeneratedClassData generatedClassData) {
|
||||
return buildClass(properties, listOfFiles, generatedClassData.className, generatedClassData.classPackage, includedDirectoryRelativePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension that should be appended to the generated test class. E.g. {@code .java} or {@code .php}
|
||||
*
|
||||
* @param properties - properties passed to the plugin
|
||||
*/
|
||||
String fileExtension(ContractVerifierConfigProperties properties);
|
||||
|
||||
class GeneratedClassData {
|
||||
public final String className;
|
||||
public final String classPackage;
|
||||
public final java.nio.file.Path testClassPath;
|
||||
|
||||
public GeneratedClassData(String className, String classPackage,
|
||||
java.nio.file.Path testClassPath) {
|
||||
this.className = className;
|
||||
this.classPackage = classPackage;
|
||||
this.testClassPath = testClassPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.Input
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
@@ -41,8 +42,10 @@ import static org.apache.commons.text.StringEscapeUtils.escapeJava
|
||||
@TypeChecked
|
||||
class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
|
||||
SpockMessagingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
SpockMessagingMethodBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,6 +163,15 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
return ""
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
if (value.isByte()) {
|
||||
return "response.payloadAsByteArray == " +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE)
|
||||
}
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPropertyInListString(String property, Integer listIndex) {
|
||||
return "$property[$listIndex]" ?: ''
|
||||
@@ -184,7 +196,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
protected String getInputString() {
|
||||
String request = 'ContractVerifierMessage inputMessage = contractVerifierMessaging.create('
|
||||
if (inputMessage.messageBody) {
|
||||
request = "${request}'''${bodyAsString}'''\n "
|
||||
request = "${request}${getBodyAsString()}\n "
|
||||
}
|
||||
if (inputMessage.messageHeaders) {
|
||||
request = "${request},[\n"
|
||||
@@ -200,6 +212,16 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
return "${request})"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String indentBody(String text) {
|
||||
return "\n ${text}\n"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String quotes() {
|
||||
return "'''"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeaderString(Header header) {
|
||||
return "${getTestSideValue(header.name)}: ${getTestSideValue(header.serverValue)}"
|
||||
|
||||
@@ -21,6 +21,7 @@ import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Cookie
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
@@ -45,8 +46,10 @@ import static org.springframework.cloud.contract.verifier.util.ContentUtils.getG
|
||||
@TypeChecked
|
||||
abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessingMethodBodyBuilder {
|
||||
|
||||
SpockMethodRequestProcessingBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
SpockMethodRequestProcessingBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,6 +107,15 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
|
||||
return "def responseBody = new XmlSlurper().parseText($responseString)"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
if (value.isByte()) {
|
||||
return "response.body.asByteArray() == " +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE)
|
||||
}
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSimpleResponseBodyString(String responseString) {
|
||||
return "def responseBody = ($responseString)"
|
||||
@@ -134,6 +146,11 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
|
||||
String value
|
||||
if (body instanceof ExecutionProperty) {
|
||||
value = body.toString()
|
||||
} else if (body instanceof FromFileProperty) {
|
||||
FromFileProperty fileProperty = (FromFileProperty) body
|
||||
value = fileProperty.isByte() ?
|
||||
readBytesFromFileString(fileProperty, CommunicationType.REQUEST) :
|
||||
readStringFromFileString(fileProperty, CommunicationType.REQUEST)
|
||||
} else {
|
||||
value = "'''$body'''"
|
||||
}
|
||||
@@ -142,7 +159,7 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
|
||||
|
||||
@Override
|
||||
protected String getMultipartFileParameterContent(String propertyName, NamedProperty propertyValue) {
|
||||
return getGroovyMultipartFileParameterContent(propertyName, propertyValue)
|
||||
return getGroovyMultipartFileParameterContent(propertyName, propertyValue, { FromFileProperty fileProp -> readBytesFromFileString(fileProp, CommunicationType.REQUEST) })
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,14 +2,13 @@ package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.Immutable
|
||||
import org.apache.commons.text.StringEscapeUtils
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
|
||||
/**
|
||||
* Representation of the request side to be used for response templating in
|
||||
* the generated tests.
|
||||
@@ -100,6 +99,8 @@ class TestSideRequestTemplateModel {
|
||||
Object bodyValue = extractServerValueFromBody(body)
|
||||
if (bodyValue instanceof GString || bodyValue instanceof String) {
|
||||
return bodyValue.toString()
|
||||
} else if (bodyValue instanceof FromFileProperty) {
|
||||
return null
|
||||
}
|
||||
return bodyValue != null ? new JsonOutput().toJson(bodyValue) : bodyValue
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@ import org.springframework.cloud.contract.verifier.config.ContractVerifierConfig
|
||||
@PackageScope
|
||||
class WebTestClientJUnitMethodBodyBuilder extends RestAssuredJUnitMethodBodyBuilder {
|
||||
|
||||
WebTestClientJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
WebTestClientJUnitMethodBodyBuilder(Contract stubDefinition,
|
||||
ContractVerifierConfigProperties configProperties,
|
||||
GeneratedClassDataForMethod classDataForMethod) {
|
||||
super(stubDefinition, configProperties, classDataForMethod)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,6 +81,6 @@ class HttpImportProvider {
|
||||
*/
|
||||
List<String> getStaticImports(TestFramework testFramework, TestMode testMode) {
|
||||
return TEST_MODE_SPECIFIC_IMPORTS.get(testMode).staticImports +
|
||||
FRAMEWORK_AND_TEST_MODE_SPECIFIC_IMPORTS.get(new Tuple2(testFramework, testMode)).staticImports
|
||||
FRAMEWORK_AND_TEST_MODE_SPECIFIC_IMPORTS.get(new Tuple2(testFramework, testMode)).staticImports + ['org.springframework.cloud.contract.verifier.util.ContractVerifierUtil.fileToBytes']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ class MessagingImportProvider {
|
||||
* @return list of static imports for messaging test contracts.
|
||||
*/
|
||||
static List<String> getStaticImports() {
|
||||
return ['org.springframework.cloud.contract.verifier.messaging.util.ContractVerifierMessagingUtil.headers']
|
||||
return ['org.springframework.cloud.contract.verifier.messaging.util.ContractVerifierMessagingUtil.headers','org.springframework.cloud.contract.verifier.util.ContractVerifierUtil.fileToBytes']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,11 @@ class ContractVerifierConfigProperties {
|
||||
*/
|
||||
File generatedTestSourcesDir
|
||||
|
||||
/**
|
||||
* Test resource directory where additional resources for tests will be set
|
||||
*/
|
||||
File generatedTestResourcesDir
|
||||
|
||||
/**
|
||||
* Dir where the generated stubs from the contracts should be placed.
|
||||
* You can then mention them in your packaging task to create jar with stubs
|
||||
|
||||
@@ -51,6 +51,7 @@ class YamlContract {
|
||||
public Map<String, Object> cookies = [:]
|
||||
public Object body
|
||||
public String bodyFromFile
|
||||
public String bodyFromFileAsBytes
|
||||
public StubMatchers matchers = new StubMatchers()
|
||||
public Multipart multipart
|
||||
}
|
||||
@@ -215,6 +216,7 @@ class YamlContract {
|
||||
public Map<String, Object> cookies = [:]
|
||||
public Object body
|
||||
public String bodyFromFile
|
||||
public String bodyFromFileAsBytes
|
||||
public TestMatchers matchers = new TestMatchers()
|
||||
public Boolean async
|
||||
public Integer fixedDelayMilliseconds
|
||||
@@ -238,6 +240,7 @@ class YamlContract {
|
||||
public Map<String, Object> messageHeaders = [:]
|
||||
public Object messageBody
|
||||
public String messageBodyFromFile
|
||||
public String messageBodyFromFileAsBytes
|
||||
public String assertThat
|
||||
public StubMatchers matchers = new StubMatchers()
|
||||
}
|
||||
@@ -250,6 +253,7 @@ class YamlContract {
|
||||
public Map<String, Object> headers = [:]
|
||||
public Object body
|
||||
public String bodyFromFile
|
||||
public String bodyFromFileAsBytes
|
||||
public String assertThat
|
||||
public TestMatchers matchers = new TestMatchers()
|
||||
}
|
||||
|
||||
@@ -126,6 +126,7 @@ class YamlToContracts {
|
||||
}
|
||||
if (yamlContract.request.body != null) body(yamlContract.request.body)
|
||||
if (yamlContract.request.bodyFromFile != null) body(file(yamlContract.request.bodyFromFile))
|
||||
if (yamlContract.request.bodyFromFileAsBytes != null) body(fileAsBytes(yamlContract.request.bodyFromFileAsBytes))
|
||||
if (yamlContract.request.multipart) {
|
||||
Map multipartMap = [:]
|
||||
Map<String, DslProperty> multiPartParams = yamlContract.request
|
||||
@@ -249,6 +250,7 @@ class YamlToContracts {
|
||||
}
|
||||
}
|
||||
if (yamlContract.response.bodyFromFile) body(file(yamlContract.response.bodyFromFile))
|
||||
if (yamlContract.response.bodyFromFileAsBytes) body(fileAsBytes(yamlContract.response.bodyFromFileAsBytes))
|
||||
if (yamlContract.response.async) async()
|
||||
if (yamlContract.response.fixedDelayMilliseconds) fixedDelayMilliseconds(yamlContract.response.fixedDelayMilliseconds)
|
||||
bodyMatchers {
|
||||
@@ -309,6 +311,7 @@ class YamlToContracts {
|
||||
}
|
||||
if (yamlContract.input.messageBody) messageBody(yamlContract.input.messageBody)
|
||||
if (yamlContract.input.messageBodyFromFile) messageBody(file(yamlContract.input.messageBodyFromFile))
|
||||
if (yamlContract.input.messageBodyFromFileAsBytes) messageBody(fileAsBytes(yamlContract.input.messageBodyFromFileAsBytes))
|
||||
bodyMatchers {
|
||||
yamlContract.input.matchers.body?.each { YamlContract.BodyStubMatcher matcher ->
|
||||
MatchingTypeValue value = null
|
||||
@@ -354,6 +357,7 @@ class YamlToContracts {
|
||||
}
|
||||
if (outputMsg.body) body(outputMsg.body)
|
||||
if (outputMsg.bodyFromFile) body(file(outputMsg.bodyFromFile))
|
||||
if (outputMsg.bodyFromFileAsBytes) body(fileAsBytes(outputMsg.bodyFromFileAsBytes))
|
||||
if (outputMsg.matchers) {
|
||||
bodyMatchers {
|
||||
yamlContract.outputMessage?.matchers?.body?.each { YamlContract.BodyTestMatcher testMatcher ->
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.json.JSONObject
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.ContractTemplate
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Headers
|
||||
import org.springframework.cloud.contract.verifier.template.HandlebarsTemplateProcessor
|
||||
import org.springframework.cloud.contract.verifier.template.TemplateProcessor
|
||||
@@ -34,8 +35,8 @@ import org.springframework.cloud.contract.verifier.util.ContentUtils
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.extractValue
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.getClientContentType
|
||||
import static org.springframework.cloud.contract.verifier.util.MapConverter.transformValues
|
||||
|
||||
/**
|
||||
* Common abstraction over WireMock Request / Response conversion implementations
|
||||
*
|
||||
@@ -85,6 +86,13 @@ abstract class BaseWireMockStubStrategy {
|
||||
return parseBody(value.toString(), contentType)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return body as String from file
|
||||
*/
|
||||
String parseBody(FromFileProperty value, ContentType contentType) {
|
||||
return value.asString()
|
||||
}
|
||||
|
||||
/**
|
||||
* For the given {@link ContentType} returns the Boolean version of the body
|
||||
*/
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.dsl.wiremock
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import com.github.tomakehurst.wiremock.client.WireMock
|
||||
import com.github.tomakehurst.wiremock.http.RequestMethod
|
||||
import com.github.tomakehurst.wiremock.matching.ContentPattern
|
||||
import com.github.tomakehurst.wiremock.matching.RequestPattern
|
||||
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder
|
||||
import com.github.tomakehurst.wiremock.matching.StringValuePattern
|
||||
@@ -33,19 +36,18 @@ import groovy.util.logging.Commons
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Body
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.OptionalProperty
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameters
|
||||
import org.springframework.cloud.contract.spec.internal.RegexPatterns
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils
|
||||
import org.springframework.cloud.contract.verifier.util.JsonPaths
|
||||
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter
|
||||
|
||||
import java.util.regex.Pattern
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildGStringRegexpForStubSide
|
||||
import static org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildJSONRegexpMatch
|
||||
@@ -97,8 +99,9 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
if (!request.body) {
|
||||
return
|
||||
}
|
||||
MatchingStrategy matchingStrategy = getMatchingStrategyFromBody(request.body)
|
||||
if (contentType == ContentType.JSON) {
|
||||
def originalBody = getMatchingStrategyFromBody(request.body)?.clientValue
|
||||
def originalBody = matchingStrategy?.clientValue
|
||||
def body = JsonToJsonPathsConverter.removeMatchingJsonPaths(originalBody, request.bodyMatchers)
|
||||
JsonPaths values = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(body)
|
||||
if ((values.empty && !request.bodyMatchers?.hasMatchers()) || onlySizeAssertionsArePresent(values)) {
|
||||
@@ -117,14 +120,17 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
} else if (contentType == ContentType.XML) {
|
||||
requestPattern.withRequestBody(WireMock.equalToXml(getMatchingStrategy(request.body.clientValue).clientValue.toString()))
|
||||
} else if (containsPattern(request?.body)) {
|
||||
MatchingStrategy matchingStrategy = appendBodyRegexpMatchPattern(request.body)
|
||||
requestPattern.withRequestBody(convertToValuePattern(matchingStrategy, contentType))
|
||||
requestPattern.withRequestBody(convertToValuePattern(appendBodyRegexpMatchPattern(request.body), contentType))
|
||||
} else {
|
||||
requestPattern.withRequestBody(convertToValuePattern(
|
||||
getMatchingStrategy(request.body.clientValue), contentType))
|
||||
requestBodyGuessedFromMatchingStrategy(requestPattern, contentType)
|
||||
}
|
||||
}
|
||||
|
||||
private RequestPatternBuilder requestBodyGuessedFromMatchingStrategy(RequestPatternBuilder requestPattern, ContentType contentType) {
|
||||
return requestPattern.withRequestBody(convertToValuePattern(
|
||||
getMatchingStrategy(request.body.clientValue), contentType))
|
||||
}
|
||||
|
||||
private boolean onlySizeAssertionsArePresent(JsonPaths values) {
|
||||
return !values.empty && !request.bodyMatchers?.hasMatchers() && values.every { it.assertsSize() }
|
||||
}
|
||||
@@ -152,7 +158,7 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
return
|
||||
}
|
||||
request.headers.entries.each {
|
||||
requestPattern.withHeader(it.name, convertToValuePattern(it.clientValue, contentType))
|
||||
requestPattern.withHeader(it.name, (StringValuePattern) convertToValuePattern(it.clientValue, contentType))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +167,7 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
return
|
||||
}
|
||||
request.cookies.entries.each {
|
||||
requestPattern.withCookie(it.key, convertToValuePattern(it.clientValue, contentType))
|
||||
requestPattern.withCookie(it.key, (StringValuePattern) convertToValuePattern(it.clientValue, contentType))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,12 +216,12 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
private void appendQueryParameters(RequestPatternBuilder requestPattern, ContentType contentType) {
|
||||
QueryParameters queryParameters = request?.urlPath?.queryParameters ?: request?.url?.queryParameters
|
||||
queryParameters?.parameters?.each {
|
||||
requestPattern.withQueryParam(it.name, convertToValuePattern(it.clientValue, contentType))
|
||||
requestPattern.withQueryParam(it.name, (StringValuePattern) convertToValuePattern(it.clientValue, contentType))
|
||||
}
|
||||
}
|
||||
|
||||
@TypeChecked(TypeCheckingMode.SKIP)
|
||||
private static StringValuePattern convertToValuePattern(Object object, ContentType contentType) {
|
||||
private static ContentPattern convertToValuePattern(Object object, ContentType contentType) {
|
||||
switch (object) {
|
||||
case Pattern:
|
||||
Pattern value = object as Pattern
|
||||
@@ -256,6 +262,8 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
StringEscapeUtils.unescapeJavaScript(it.toString())
|
||||
}.join("&")
|
||||
}
|
||||
} else if (bodyValue instanceof FromFileProperty) {
|
||||
return bodyValue.isByte() ? bodyValue.asBytes() : bodyValue.asString()
|
||||
}
|
||||
return bodyValue
|
||||
}
|
||||
@@ -289,6 +297,10 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
return tryToFindMachingStrategy(bodyValue)
|
||||
}
|
||||
|
||||
private MatchingStrategy getMatchingStrategy(FromFileProperty bodyValue) {
|
||||
return new MatchingStrategy(bodyValue, MatchingStrategy.Type.BINARY_EQUAL_TO)
|
||||
}
|
||||
|
||||
private MatchingStrategy tryToFindMachingStrategy(Object bodyValue) {
|
||||
return new MatchingStrategy(MapConverter.transformToClientValues(bodyValue), getEqualsTypeFromContentTypeHeader())
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.spec.internal.Response
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
import org.springframework.cloud.contract.verifier.util.ContentUtils
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader
|
||||
|
||||
@@ -90,7 +90,11 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
|
||||
if (contentType == ContentType.UNKNOWN) {
|
||||
contentType = recognizeContentTypeFromContent(body)
|
||||
}
|
||||
builder.withBody(parseBody(body, contentType))
|
||||
if (body instanceof FromFileProperty && body.isByte()) {
|
||||
builder.withBody(body.asBytes())
|
||||
} else {
|
||||
builder.withBody(parseBody(body, contentType))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,21 +16,17 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.dsl.wiremock
|
||||
|
||||
import groovy.transform.CompileDynamic
|
||||
import groovy.transform.CompileStatic
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
|
||||
import com.github.tomakehurst.wiremock.http.ResponseDefinition
|
||||
import com.github.tomakehurst.wiremock.matching.RequestPattern
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
/**
|
||||
* Converts a {@link ContractMetadata} into a WireMock stub
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@CompileStatic
|
||||
class WireMockStubStrategy {
|
||||
|
||||
private static final String STEP_START = "Started"
|
||||
@@ -54,7 +50,6 @@ class WireMockStubStrategy {
|
||||
/**
|
||||
* Converts {@link ContractMetadata} to String version of {@link StubMapping}
|
||||
*/
|
||||
@CompileDynamic
|
||||
String toWireMockClientStub() {
|
||||
StubMapping stubMapping = new StubMapping()
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ class HandlebarsTemplateProcessor implements TemplateProcessor, ContractTemplate
|
||||
private static final String LEGACY_JSON_PATH_TEMPLATE_NAME = HandlebarsJsonPathHelper.NAME
|
||||
private static final String JSON_PATH_TEMPLATE_NAME = WireMockHelpers.jsonPath.name()
|
||||
|
||||
@Delegate
|
||||
private final ContractTemplate contractTemplate = new CompositeContractTemplate()
|
||||
final ContractTemplate contractTemplate = new CompositeContractTemplate()
|
||||
|
||||
@Override
|
||||
String transform(Request request, String testContents) {
|
||||
@@ -98,5 +97,135 @@ class HandlebarsTemplateProcessor implements TemplateProcessor, ContractTemplate
|
||||
throw new RuntimeException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean startsWithTemplate(String text) {
|
||||
return this.contractTemplate.startsWithTemplate(text)
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean startsWithEscapedTemplate(String text) {
|
||||
return this.contractTemplate.startsWithEscapedTemplate(text)
|
||||
}
|
||||
|
||||
@Override
|
||||
String openingTemplate() {
|
||||
return this.contractTemplate.openingTemplate()
|
||||
}
|
||||
|
||||
@Override
|
||||
String closingTemplate() {
|
||||
return this.contractTemplate.closingTemplate()
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedOpeningTemplate() {
|
||||
return this.contractTemplate.escapedOpeningTemplate()
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedClosingTemplate() {
|
||||
return this.contractTemplate.escapedClosingTemplate()
|
||||
}
|
||||
|
||||
@Override
|
||||
String url() {
|
||||
return this.contractTemplate.url()
|
||||
}
|
||||
|
||||
@Override
|
||||
String query(String key) {
|
||||
return this.contractTemplate.query(key)
|
||||
}
|
||||
|
||||
@Override
|
||||
String query(String key, int index) {
|
||||
return this.contractTemplate.query(key, index)
|
||||
}
|
||||
|
||||
@Override
|
||||
String path() {
|
||||
return this.contractTemplate.path()
|
||||
}
|
||||
|
||||
@Override
|
||||
String path(int index) {
|
||||
return this.contractTemplate.path(index)
|
||||
}
|
||||
|
||||
@Override
|
||||
String header(String key) {
|
||||
return this.contractTemplate.header(key)
|
||||
}
|
||||
|
||||
@Override
|
||||
String header(String key, int index) {
|
||||
return this.contractTemplate.header(key, index)
|
||||
}
|
||||
|
||||
@Override
|
||||
String cookie(String key) {
|
||||
return this.contractTemplate.cookie(key)
|
||||
}
|
||||
|
||||
@Override
|
||||
String body() {
|
||||
return this.contractTemplate.body()
|
||||
}
|
||||
|
||||
@Override
|
||||
String body(String jsonPath) {
|
||||
return this.contractTemplate.body(jsonPath)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedUrl() {
|
||||
return this.contractTemplate.escapedUrl()
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedQuery(String key) {
|
||||
return this.contractTemplate.escapedQuery(key)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedQuery(String key, int index) {
|
||||
return this.contractTemplate.escapedQuery(key, index)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedPath() {
|
||||
return this.contractTemplate.escapedPath()
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedPath(int index) {
|
||||
return this.contractTemplate.escapedPath(index)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedHeader(String key) {
|
||||
return this.contractTemplate.escapedHeader(key)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedHeader(String key, int index) {
|
||||
return this.contractTemplate.escapedHeader(key, index)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedCookie(String key) {
|
||||
return this.contractTemplate.escapedCookie(key)
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedBody() {
|
||||
return this.contractTemplate.escapedBody()
|
||||
}
|
||||
|
||||
@Override
|
||||
String escapedBody(String jsonPath) {
|
||||
return this.contractTemplate.escapedBody(jsonPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.contract.verifier.util
|
||||
|
||||
/**
|
||||
* Represents content type. Used to pick the way bodies are parsed.
|
||||
*
|
||||
@@ -34,5 +33,4 @@ enum ContentType {
|
||||
ContentType(String mimeType) {
|
||||
this.mimeType = mimeType
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,38 +16,40 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.util
|
||||
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import groovy.json.JsonException
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.transform.TypeChecked
|
||||
import groovy.util.logging.Commons
|
||||
import org.apache.commons.lang3.StringEscapeUtils
|
||||
import groovy.transform.CompileStatic
|
||||
import org.apache.commons.logging.Log
|
||||
import org.apache.commons.logging.LogFactory
|
||||
import org.codehaus.groovy.runtime.GStringImpl
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.Headers
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.OptionalProperty
|
||||
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeJava
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeJson
|
||||
import static org.apache.commons.text.StringEscapeUtils.escapeXml11
|
||||
import static org.apache.commons.text.StringEscapeUtils.unescapeXml
|
||||
|
||||
/**
|
||||
* A utility class that can operate on a message body basing on the provided Content Type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@TypeChecked
|
||||
@Commons
|
||||
@CompileStatic
|
||||
class ContentUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ContentUtils)
|
||||
|
||||
public static final Closure GET_STUB_SIDE = {
|
||||
it instanceof DslProperty ? it.clientValue : it
|
||||
}
|
||||
@@ -134,9 +136,44 @@ class ContentUtils {
|
||||
}
|
||||
|
||||
static ContentType getClientContentType(Object bodyAsValue) {
|
||||
if (bodyAsValue instanceof GString) {
|
||||
return getClientContentType((GString) bodyAsValue)
|
||||
} else if (bodyAsValue instanceof String) {
|
||||
return getClientContentType((String) bodyAsValue)
|
||||
} else if (bodyAsValue instanceof Map) {
|
||||
return getClientContentType((Map) bodyAsValue)
|
||||
} else if (bodyAsValue instanceof List) {
|
||||
return getClientContentType((List) bodyAsValue)
|
||||
} else if (bodyAsValue instanceof MatchingStrategy) {
|
||||
return ContentType.UNKNOWN
|
||||
} else if (bodyAsValue instanceof FromFileProperty) {
|
||||
return ContentType.UNKNOWN
|
||||
}
|
||||
return tryToGuessContentType(bodyAsValue)
|
||||
}
|
||||
|
||||
private static ContentType tryToGuessContentType(Object bodyAsValue) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("No content type passed, will try to guess the type of payload")
|
||||
}
|
||||
return getClientContentType(JsonOutput.toJson(bodyAsValue))
|
||||
} catch (Exception ex) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Failed to assume that body [" + bodyAsValue + "] is json")
|
||||
}
|
||||
}
|
||||
return ContentType.UNKNOWN
|
||||
}
|
||||
|
||||
static ContentType getClientContentType(Object bodyAsValue, Headers headers) {
|
||||
ContentType contentType = recognizeContentTypeFromHeader(headers)
|
||||
if (contentType == ContentType.UNKNOWN) {
|
||||
return getClientContentType(bodyAsValue)
|
||||
}
|
||||
return contentType;
|
||||
}
|
||||
|
||||
static ContentType getClientContentType(Map bodyAsValue) {
|
||||
try {
|
||||
JsonOutput.toJson(bodyAsValue)
|
||||
@@ -194,6 +231,15 @@ class ContentUtils {
|
||||
}
|
||||
|
||||
protected static Object transformJSONStringValue(Object obj, Closure valueProvider) {
|
||||
if (obj instanceof DslProperty) {
|
||||
return transformJSONStringValue((DslProperty) obj, valueProvider)
|
||||
} else if (obj instanceof Pattern) {
|
||||
return transformJSONStringValue((Pattern) obj, valueProvider)
|
||||
} else if (obj instanceof OptionalProperty) {
|
||||
return transformJSONStringValue((OptionalProperty) obj, valueProvider)
|
||||
} else if (obj instanceof ExecutionProperty) {
|
||||
return transformJSONStringValue((ExecutionProperty) obj, valueProvider)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -214,6 +260,9 @@ class ContentUtils {
|
||||
}
|
||||
|
||||
private static String transformXMLStringValue(Object obj, Closure valueProvider) {
|
||||
if (obj instanceof DslProperty) {
|
||||
return transformJSONStringValue((DslProperty) obj, valueProvider)
|
||||
}
|
||||
return escapeXml11(unescapeXml(obj.toString()))
|
||||
}
|
||||
|
||||
@@ -288,7 +337,8 @@ class ContentUtils {
|
||||
}
|
||||
|
||||
static ContentType recognizeContentTypeFromHeader(Headers headers, Closure<Object> closure) {
|
||||
Header header = headers?.entries?.find { it.name == "Content-Type" }
|
||||
Header header = headers?.entries?.find { it.name == "Content-Type" ||
|
||||
it.name == "contentType" }
|
||||
String content = closure(header)?.toString()
|
||||
if (content?.contains("json")) {
|
||||
return ContentType.JSON
|
||||
@@ -337,6 +387,10 @@ class ContentUtils {
|
||||
return ContentType.JSON
|
||||
}
|
||||
|
||||
static ContentType recognizeContentTypeFromContent(byte[] bytes) {
|
||||
return ContentType.UNKNOWN
|
||||
}
|
||||
|
||||
static ContentType recognizeContentTypeFromContent(List jsonList) {
|
||||
return ContentType.JSON
|
||||
}
|
||||
@@ -354,7 +408,20 @@ class ContentUtils {
|
||||
return ContentType.TEXT
|
||||
}
|
||||
|
||||
static ContentType recognizeContentTypeFromContent(Object gstring) {
|
||||
static ContentType recognizeContentTypeFromContent(Object object) {
|
||||
if (object instanceof GString) {
|
||||
return recognizeContentTypeFromContent((GString) object)
|
||||
} else if (object instanceof Map) {
|
||||
return recognizeContentTypeFromContent((Map) object)
|
||||
} else if (object instanceof byte[]) {
|
||||
return recognizeContentTypeFromContent((byte[]) object)
|
||||
} else if (object instanceof List) {
|
||||
return recognizeContentTypeFromContent((List) object)
|
||||
} else if (object instanceof String) {
|
||||
return recognizeContentTypeFromContent((String) object)
|
||||
} else if (object instanceof Number) {
|
||||
return recognizeContentTypeFromContent((Number) object)
|
||||
}
|
||||
return ContentType.UNKNOWN
|
||||
}
|
||||
|
||||
@@ -403,14 +470,16 @@ class ContentUtils {
|
||||
return ContentType.UNKNOWN
|
||||
}
|
||||
|
||||
static String getGroovyMultipartFileParameterContent(String propertyName, NamedProperty propertyValue) {
|
||||
static String getGroovyMultipartFileParameterContent(String propertyName, NamedProperty propertyValue,
|
||||
Closure<String> bytesFromFile) {
|
||||
return "'$propertyName', ${namedPropertyName(propertyValue, "'")}, " +
|
||||
"${groovyNamedPropertyValue(propertyValue, "'")}" + namedContentTypeNameIfPresent(propertyValue, "'")
|
||||
"${groovyNamedPropertyValue(propertyValue, "'", bytesFromFile)}" + namedContentTypeNameIfPresent(propertyValue, "'")
|
||||
}
|
||||
|
||||
static String getJavaMultipartFileParameterContent(String propertyName, NamedProperty propertyValue) {
|
||||
static String getJavaMultipartFileParameterContent(String propertyName, NamedProperty propertyValue,
|
||||
Closure<String> bytesFromFile) {
|
||||
return """"${escapeJava(propertyName)}", ${namedPropertyName(propertyValue, '"')}, """ +
|
||||
"""${javaNamedPropertyValue(propertyValue, '"')}${namedContentTypeNameIfPresent(propertyValue, '"')}"""
|
||||
"""${javaNamedPropertyValue(propertyValue, '"', bytesFromFile)}${namedContentTypeNameIfPresent(propertyValue, '"')}"""
|
||||
}
|
||||
|
||||
static String namedPropertyName(NamedProperty property, String quote) {
|
||||
@@ -427,22 +496,34 @@ class ContentUtils {
|
||||
return ", " + contentType
|
||||
}
|
||||
|
||||
static String groovyNamedPropertyValue(NamedProperty property, String quote) {
|
||||
static String groovyNamedPropertyValue(NamedProperty property, String quote, Closure<String> bytesFromFile) {
|
||||
if (property.value.serverValue instanceof ExecutionProperty) {
|
||||
return property.value.serverValue.toString()
|
||||
} else if (property.value.serverValue instanceof byte[]) {
|
||||
byte[] bytes = (byte[]) property.value.serverValue
|
||||
return "[" + bytes.collect { it }.join(", ") + "] as byte[]"
|
||||
} else if (property.value.serverValue instanceof FromFileProperty) {
|
||||
FromFileProperty fromFileProperty = (FromFileProperty) property.value.serverValue
|
||||
if (fromFileProperty.isByte()) {
|
||||
return bytesFromFile(fromFileProperty)
|
||||
}
|
||||
return "[" + fromFileProperty.asBytes().collect { it }.join(", ") + "] as byte[]"
|
||||
}
|
||||
return quote + escapeJava(property.value.serverValue.toString()) + quote + ".bytes"
|
||||
}
|
||||
|
||||
static String javaNamedPropertyValue(NamedProperty property, String quote) {
|
||||
static String javaNamedPropertyValue(NamedProperty property, String quote, Closure<String> bytesFromFile) {
|
||||
if (property.value.serverValue instanceof ExecutionProperty) {
|
||||
return property.value.serverValue.toString()
|
||||
} else if (property.value.serverValue instanceof byte[]) {
|
||||
byte[] bytes = (byte[]) property.value.serverValue
|
||||
return "new byte[] {" + bytes.collect { it }.join(", ") + "}"
|
||||
} else if (property.value.serverValue instanceof FromFileProperty) {
|
||||
FromFileProperty fromFileProperty = (FromFileProperty) property.value.serverValue
|
||||
if (fromFileProperty.isByte()) {
|
||||
return bytesFromFile(fromFileProperty)
|
||||
}
|
||||
return "new byte[] {" + fromFileProperty.asBytes().collect { it }.join(", ") + "}"
|
||||
}
|
||||
return quote + escapeJava(property.value.serverValue.toString()) + quote + ".getBytes()"
|
||||
}
|
||||
|
||||
@@ -50,6 +50,13 @@ public class ContractVerifierMessage {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public byte[] getPayloadAsByteArray() {
|
||||
if (this.payload instanceof byte[]) {
|
||||
return (byte[]) this.payload;
|
||||
}
|
||||
throw new IllegalStateException("Payload [" + this.payload.getClass() + "]" + "is not instance of byte[]");
|
||||
}
|
||||
|
||||
public Map<String, Object> getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@@ -47,4 +47,12 @@ public class ContractVerifierObjectMapper {
|
||||
return this.objectMapper.writeValueAsString(payload);
|
||||
}
|
||||
|
||||
public byte[] writeValueAsBytes(Object payload) throws JsonProcessingException {
|
||||
if (payload instanceof String) {
|
||||
return payload.toString().getBytes();
|
||||
} else if (payload instanceof byte[]) {
|
||||
return (byte[]) payload;
|
||||
}
|
||||
return this.objectMapper.writeValueAsBytes(payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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.util;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Helper class for the generated tests
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class ContractVerifierUtil {
|
||||
|
||||
/**
|
||||
* Helper method to convert a file to bytes
|
||||
*
|
||||
* @param testClass - test class relative to which the file is stored
|
||||
* @param relativePath - relative path to the file
|
||||
* @return bytes of the file
|
||||
*/
|
||||
public static byte[] fileToBytes(Object testClass, String relativePath) {
|
||||
try {
|
||||
URL url = testClass.getClass().getResource(relativePath);
|
||||
if (url == null) {
|
||||
throw new FileNotFoundException(relativePath);
|
||||
}
|
||||
return Files.readAllBytes(Paths.get(url.toURI()));
|
||||
}
|
||||
catch (IOException | URISyntaxException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.contract.verifier
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.verifier.builder.JavaTestGenerator
|
||||
import org.springframework.cloud.contract.verifier.builder.SingleTestGenerator
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.config.TestFramework.SPOCK
|
||||
@@ -36,7 +37,7 @@ class GeneratorScannerSpec extends Specification {
|
||||
when:
|
||||
testGenerator.generateTestClasses("org.springframework.cloud.contract.verifier")
|
||||
then:
|
||||
6 * classGenerator.buildClass(_, _, _, _, _) >> "qwerty"
|
||||
6 * classGenerator.buildClass(_, _, _, _) >> "qwerty"
|
||||
}
|
||||
|
||||
def "should create class with full package"() {
|
||||
@@ -47,9 +48,9 @@ class GeneratorScannerSpec extends Specification {
|
||||
when:
|
||||
testGenerator.generateTestClasses("org.springframework.cloud.contract.verifier")
|
||||
then:
|
||||
1 * classGenerator.buildClass(_, _, 'exceptionsSpec', 'org.springframework.cloud.contract.verifier', _) >> "spec"
|
||||
1 * classGenerator.buildClass(_, _, 'exceptionsSpec', 'org.springframework.cloud.contract.verifier.v1', _) >> "spec1"
|
||||
1 * classGenerator.buildClass(_, _, 'exceptionsSpec', 'org.springframework.cloud.contract.verifier.v2', _) >> "spec2"
|
||||
1 * classGenerator.buildClass(_, _, _, { SingleTestGenerator.GeneratedClassData it -> it.className == 'exceptionsSpec' && it.classPackage == 'org.springframework.cloud.contract.verifier'} ) >> "spec"
|
||||
1 * classGenerator.buildClass(_, _, _, { SingleTestGenerator.GeneratedClassData it -> it.className == 'exceptionsSpec' && it.classPackage == 'org.springframework.cloud.contract.verifier.v1'} ) >> "spec1"
|
||||
1 * classGenerator.buildClass(_, _, _, { SingleTestGenerator.GeneratedClassData it -> it.className == 'exceptionsSpec' && it.classPackage == 'org.springframework.cloud.contract.verifier.v2'} ) >> "spec2"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
/**
|
||||
* Tests used for the documentation
|
||||
*
|
||||
@@ -303,7 +304,9 @@ class ContractHttpDocsSpec extends Specification {
|
||||
def 'should convert dsl with optionals to proper Spock test'() {
|
||||
given:
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
new HttpSpockMethodRequestProcessingBodyBuilder(optionals, properties).appendTo(blockBuilder)
|
||||
new HttpSpockMethodRequestProcessingBodyBuilder(optionals, properties, new GeneratedClassDataForMethod(
|
||||
new SingleTestGenerator.GeneratedClassData("foo", "bar", new File(".").toPath()), "method"))
|
||||
.appendTo(blockBuilder)
|
||||
expect:
|
||||
String expectedTest =
|
||||
// tag::optionals_test[]
|
||||
|
||||
@@ -33,7 +33,9 @@ import spock.util.environment.RestoreSystemProperties
|
||||
class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
|
||||
@Shared GeneratedClassDataForMethod generatedClassDataForMethod = new GeneratedClassDataForMethod(
|
||||
new SingleTestGenerator.GeneratedClassData("foo", "bar", new File(".").toPath()), "method")
|
||||
|
||||
@Shared
|
||||
// tag::contract_with_cookies[]
|
||||
Contract contractDslWithCookiesValue = Contract.make {
|
||||
@@ -127,8 +129,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#187")
|
||||
@@ -162,8 +164,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
@@ -199,8 +201,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
@@ -239,8 +241,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#82")
|
||||
@@ -270,8 +272,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """entity('{\"items\":[\"HOP\"]}', 'application/json')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'entity("{\\"items\\":[\\"HOP\\"]}", "application/json")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """entity('{\"items\":[\"HOP\"]}', 'application/json')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'entity("{\\"items\\":[\\"HOP\\"]}", "application/json")'
|
||||
}
|
||||
|
||||
@Issue("#88")
|
||||
@@ -301,8 +303,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """entity('property1=VAL1', 'application/octet-stream')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'entity("property1=VAL1", "application/octet-stream")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """entity('property1=VAL1', 'application/octet-stream')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'entity("property1=VAL1", "application/octet-stream")'
|
||||
}
|
||||
|
||||
def "should generate assertions for array in response body with #methodBuilderName"() {
|
||||
@@ -336,8 +338,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should generate assertions for array inside response body element with #methodBuilderName"() {
|
||||
@@ -370,8 +372,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should generate assertions for nested objects in response body with #methodBuilderName"() {
|
||||
@@ -404,8 +406,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for map objects in response body with #methodBodyName"() {
|
||||
@@ -443,8 +445,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for string objects in response body with #methodBuilderName"() {
|
||||
@@ -475,8 +477,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should ignore 'Accept' header and use 'request' method with #methodBuilderName"() {
|
||||
@@ -505,8 +507,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "request('text/plain')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'request("text/plain")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | "request('text/plain')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'request("text/plain")'
|
||||
}
|
||||
|
||||
def "should ignore 'Content-Type' header and use 'entity' method with #methodBuilderName"() {
|
||||
@@ -540,8 +542,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ["""entity('', 'text/plain')""", """header('Timer', '123')"""]
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | ['entity("\\"\\"", "text/plain")', 'header("Timer", "123")']
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ["""entity('', 'text/plain')""", """header('Timer', '123')"""]
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['entity("\\"\\"", "text/plain")', 'header("Timer", "123")']
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters with #methodBuilderName"() {
|
||||
@@ -596,8 +598,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | modifyStringIfRequired
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -653,8 +655,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | modifyStringIfRequired
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
}
|
||||
|
||||
def "should generate test for empty body with #methodBuilderName"() {
|
||||
@@ -683,8 +685,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "entity('', 'application/octet-stream')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'entity("", "application/octet-stream"'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | "entity('', 'application/octet-stream')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'entity("", "application/octet-stream"'
|
||||
}
|
||||
|
||||
def "should not parse the response body if there is no response body specified in the contract"() {
|
||||
@@ -711,8 +713,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyParsingString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "String responseAsString = response.readEntity(String)"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | "String responseAsString = response.readEntity(String.class);"
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | "String responseAsString = response.readEntity(String)"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | "String responseAsString = response.readEntity(String.class);"
|
||||
}
|
||||
|
||||
def "should generate test for String in response body with #methodBodyName"() {
|
||||
@@ -741,8 +743,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "String responseAsString = response.readEntity(String)" | 'responseBody == "test"'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'String responseBody = responseAsString;' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | "String responseAsString = response.readEntity(String)" | 'responseBody == "test"'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'String responseBody = responseAsString;' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
}
|
||||
|
||||
@Issue('#171')
|
||||
@@ -776,8 +778,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | methodString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ".method('GET')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'method("GET")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ".method('GET')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'method("GET")'
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters with JUnit - we'll put it into docs"() {
|
||||
@@ -809,7 +811,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
"""
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -866,7 +868,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -909,7 +911,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -942,7 +944,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -966,7 +968,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
body(value(stub("HELLO FROM STUB"), server(regex(".*"))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -991,7 +993,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
body(value(stub("HELLO FROM STUB"), server(regex(".*"))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1016,7 +1018,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
body(value(stub("HELLO FROM STUB"), server(execute('foo($it)'))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1039,7 +1041,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
body(value(stub("HELLO FROM STUB"), server(execute('foo($it)'))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1086,8 +1088,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#149')
|
||||
@@ -1189,8 +1191,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToRun(methodBuilderName, lines.join("\n"))
|
||||
where:
|
||||
methodBuilderName | methodBuilder | endOfLineRegexSymbol
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder"| { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder"| { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
private String stripped(String string) {
|
||||
@@ -1231,8 +1233,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#261')
|
||||
@@ -1272,7 +1274,7 @@ DATA
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#261')
|
||||
@@ -1305,12 +1307,12 @@ DATA
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should generate test for cookies with string value in JAX-RS JUnit test"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithCookiesValue, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithCookiesValue, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1325,7 +1327,7 @@ DATA
|
||||
|
||||
def "should generate test for cookies with pattern in JAX-RS JUnit test"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithCookiesPattern, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithCookiesPattern, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1340,7 +1342,7 @@ DATA
|
||||
|
||||
def "should not generate cookie assertions with absent value in JAX-RS JUnit test"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithAbsentCookies, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithAbsentCookies, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1353,7 +1355,7 @@ DATA
|
||||
|
||||
def "should generate test for cookies with string value in JAX-RS Spock test"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesValue, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesValue, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1368,7 +1370,7 @@ DATA
|
||||
|
||||
def "should generate test for cookies with pattern in JAX-RS Spock test"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesPattern, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesPattern, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1383,7 +1385,7 @@ DATA
|
||||
|
||||
def "should not generate cookie assertions with absent value in JAX-RS Spock test"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithAbsentCookies, properties)
|
||||
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithAbsentCookies, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
|
||||
@@ -28,7 +28,10 @@ import spock.lang.Specification
|
||||
*/
|
||||
class MessagingMethodBodyBuilderSpec extends Specification {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true, generatedTestSourcesDir: new File("."),
|
||||
generatedTestResourcesDir: new File("."))
|
||||
@Shared GeneratedClassDataForMethod generatedClassDataForMethod = new GeneratedClassDataForMethod(
|
||||
new SingleTestGenerator.GeneratedClassData("foo", "bar", new File("target/test.java").toPath()), "method")
|
||||
|
||||
def "should work for triggered based messaging with Spock"() {
|
||||
given:
|
||||
@@ -48,7 +51,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
// end::trigger_method_dsl[]
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -90,7 +93,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -142,7 +145,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
// end::trigger_message_dsl[]
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -195,7 +198,7 @@ and:
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -243,7 +246,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
// end::trigger_no_output_dsl[]
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -284,7 +287,7 @@ then:
|
||||
assertThat('bookWasDeleted()')
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -329,7 +332,7 @@ then:
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -378,7 +381,7 @@ then:
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -431,7 +434,7 @@ Contract.make {
|
||||
}
|
||||
}
|
||||
// end::consumer_producer[]
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -478,7 +481,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -522,7 +525,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -614,8 +617,8 @@ Contract.make {
|
||||
(error.message ? error.message : error.cause.message).contains('''doesn't match the JSON path [$[?(@.['shouldFail'] =~ ''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder | endOfLineRegExSymbol
|
||||
"SpockMessagingMethodBodyBuilder" | { Contract dsl -> new SpockMessagingMethodBodyBuilder(dsl, properties) } | '\\$'
|
||||
"JUnitMessagingMethodBodyBuilder" | { Contract dsl -> new JUnitMessagingMethodBodyBuilder(dsl, properties) } | '$'
|
||||
"SpockMessagingMethodBodyBuilder" | { Contract dsl -> new SpockMessagingMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
"JUnitMessagingMethodBodyBuilder" | { Contract dsl -> new JUnitMessagingMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue("587")
|
||||
@@ -639,7 +642,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -674,7 +677,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -717,7 +720,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -760,7 +763,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -803,7 +806,7 @@ Contract.make {
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -860,7 +863,7 @@ Contract.make {
|
||||
test == expectedTest
|
||||
where:
|
||||
methodBuilderName | methodBuilder | expectedTest
|
||||
"SpockMessagingMethodBodyBuilder" | { Contract dsl -> new SpockMessagingMethodBodyBuilder(dsl, properties) } | ''' when:
|
||||
"SpockMessagingMethodBodyBuilder" | { Contract dsl -> new SpockMessagingMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ''' when:
|
||||
foo()
|
||||
|
||||
then:
|
||||
@@ -871,7 +874,7 @@ Contract.make {
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
assertThatJson(parsedJson).field("['field']").isEqualTo("value")
|
||||
'''
|
||||
"JUnitMessagingMethodBodyBuilder" | { Contract dsl -> new JUnitMessagingMethodBodyBuilder(dsl, properties) } | ''' // when:
|
||||
"JUnitMessagingMethodBodyBuilder" | { Contract dsl -> new JUnitMessagingMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ''' // when:
|
||||
foo();
|
||||
|
||||
// then:
|
||||
@@ -885,4 +888,72 @@ Contract.make {
|
||||
'''
|
||||
}
|
||||
|
||||
@Issue('#664')
|
||||
def "should generate tests for messages having binary payloads [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
label 'shouldPublishMessage'
|
||||
input {
|
||||
messageFrom("foo")
|
||||
messageBody(fileAsBytes("body_builder/request.pdf"))
|
||||
messageHeaders {
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
}
|
||||
outputMessage {
|
||||
sentTo('messageExchange')
|
||||
body(fileAsBytes("body_builder/response.pdf"))
|
||||
headers {
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
!test.contains('cursor')
|
||||
!test.contains('REGEXP>>')
|
||||
test == expectedTest
|
||||
where:
|
||||
methodBuilderName | methodBuilder | expectedTest
|
||||
"SpockMessagingMethodBodyBuilder" | { Contract dsl -> new SpockMessagingMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ''' given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
fileToBytes(this, "method_request_request.pdf")
|
||||
|
||||
,[
|
||||
"contentType": "application/octet-stream"
|
||||
])
|
||||
|
||||
when:
|
||||
contractVerifierMessaging.send(inputMessage, 'foo')
|
||||
|
||||
then:
|
||||
ContractVerifierMessage response = contractVerifierMessaging.receive('messageExchange')
|
||||
assert response != null
|
||||
response.getHeader('contentType')?.toString() == 'application/octet-stream\'
|
||||
and:
|
||||
response.payloadAsByteArray == fileToBytes(this, "method_response_response.pdf")
|
||||
'''
|
||||
"JUnitMessagingMethodBodyBuilder" | { Contract dsl -> new JUnitMessagingMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ''' // given:
|
||||
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
|
||||
\t\t\t\tfileToBytes(this, "method_request_request.pdf")
|
||||
\t\t\t\t, headers()
|
||||
\t\t\t\t\t\t.header("contentType", "application/octet-stream")
|
||||
\t\t\t);
|
||||
|
||||
// when:
|
||||
contractVerifierMessaging.send(inputMessage, "foo");
|
||||
|
||||
// then:
|
||||
ContractVerifierMessage response = contractVerifierMessaging.receive("messageExchange");
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getHeader("contentType")).isNotNull();
|
||||
assertThat(response.getHeader("contentType").toString()).isEqualTo("application/octet-stream");
|
||||
// and:
|
||||
assertThat(response.getPayloadAsByteArray()).isEqualTo(fileToBytes(this, "method_response_response.pdf"));
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,9 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
assertJsonSize: true
|
||||
)
|
||||
|
||||
@Shared GeneratedClassDataForMethod generatedClassDataForMethod = new GeneratedClassDataForMethod(
|
||||
new SingleTestGenerator.GeneratedClassData("foo", "bar", new File(".").toPath()), "method")
|
||||
|
||||
@Issue('#185')
|
||||
def 'should allow to set dynamic values via stub / test matchers for [#methodBuilderName]'() {
|
||||
given:
|
||||
@@ -203,11 +206,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | rootElement
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue('#217')
|
||||
@@ -273,11 +276,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | rootElement
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
|
||||
@@ -328,11 +331,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | rootElement
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue('#217')
|
||||
@@ -364,11 +367,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
test.contains('foo(parsedJson.read("' + rootElement + '.phoneNumbers[*].number")')
|
||||
where:
|
||||
methodBuilderName | methodBuilder | rootElement
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue('#217')
|
||||
@@ -400,11 +403,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
e.message.contains('Entry for the provided JSON path <$.nonExistingPhoneNumbers[*].number> doesn\'t exist in the body')
|
||||
where:
|
||||
methodBuilderName | methodBuilder | rootElement
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue('#229')
|
||||
@@ -440,11 +443,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
test.contains('assertThat(parsedJson.read("' + rootElement + '[0][0].access_token", String.class)).isEqualTo("123")')
|
||||
where:
|
||||
methodBuilderName | methodBuilder | rootElement
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue('#391')
|
||||
@@ -488,11 +491,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
!test.contains('''assertThatJson(parsedJson).array("['items']").isEmpty()''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#391')
|
||||
@@ -532,11 +535,11 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
!test.contains('''assertThatJson(parsedJson).array("['items']").isEmpty()''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
def 'should build test class for #testFramework'() {
|
||||
given:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
|
||||
properties.testFramework =testFramework
|
||||
properties.testFramework = testFramework
|
||||
properties.testMode = mode
|
||||
ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, order, convertAsCollection(new File('/'), file))
|
||||
contract.ignored >> true
|
||||
@@ -197,7 +197,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
def 'should build test class for #testFramework when the path contains bizarre signs'() {
|
||||
given:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
|
||||
properties.testFramework =testFramework
|
||||
properties.testFramework = testFramework
|
||||
properties.basePackageForTests = 'org.springframework.cloud.contract.verifier.tests'
|
||||
and:
|
||||
File newFolder = tmpFolder.newFolder('META_INF')
|
||||
@@ -208,6 +208,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
writeContract(newFile)
|
||||
properties.contractsDslDir = newFolder
|
||||
properties.generatedTestSourcesDir = newFolder.parentFile
|
||||
properties.generatedTestResourcesDir = newFolder.parentFile
|
||||
when:
|
||||
int size = new TestGenerator(properties).generate()
|
||||
then:
|
||||
@@ -516,7 +517,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
''')
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
|
||||
properties.testFramework =testFramework
|
||||
properties.testFramework = testFramework
|
||||
ContractMetadata contract = new ContractMetadata(secondFile.toPath(), false, 1, null, convertAsCollection(new File('/'), secondFile))
|
||||
JavaTestGenerator testGenerator = new JavaTestGenerator()
|
||||
when:
|
||||
@@ -548,7 +549,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
}''')
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
|
||||
properties.testFramework =testFramework
|
||||
properties.testFramework = testFramework
|
||||
ContractMetadata contract = new ContractMetadata(secondFile.toPath(), false, 1, null, convertAsCollection(new File('/'), secondFile))
|
||||
JavaTestGenerator testGenerator = new JavaTestGenerator()
|
||||
when:
|
||||
@@ -602,7 +603,8 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
basePackageForTests: 'a.b',
|
||||
generatedTestSourcesDir: temp
|
||||
generatedTestSourcesDir: temp,
|
||||
generatedTestResourcesDir: tmpFolder.newFolder()
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
when:
|
||||
@@ -611,7 +613,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
count == 1
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('REQUEST')
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
@@ -626,7 +628,8 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
basePackageForTests: 'a.b', generatedTestSourcesDir: temp
|
||||
basePackageForTests: 'a.b', generatedTestSourcesDir: temp,
|
||||
generatedTestResourcesDir: tmpFolder.newFolder()
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
when:
|
||||
@@ -635,7 +638,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
count == 1
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('REQUEST')
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
@@ -650,7 +653,8 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
baseClassForTests: 'a.b.SomeClass', generatedTestSourcesDir: temp
|
||||
baseClassForTests: 'a.b.SomeClass', generatedTestSourcesDir: temp,
|
||||
generatedTestResourcesDir: tmpFolder.newFolder()
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
when:
|
||||
@@ -659,7 +663,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
count == 1
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('REQUEST')
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
@@ -674,7 +678,8 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
packageWithBaseClasses: 'a.b', generatedTestSourcesDir: temp
|
||||
packageWithBaseClasses: 'a.b', generatedTestSourcesDir: temp,
|
||||
generatedTestResourcesDir: tmpFolder.newFolder()
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
when:
|
||||
@@ -683,7 +688,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
count == 1
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('REQUEST')
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
@@ -698,7 +703,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
generatedTestSourcesDir: temp
|
||||
generatedTestSourcesDir: temp, generatedTestResourcesDir: tmpFolder.newFolder()
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
when:
|
||||
@@ -707,7 +712,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
count == 1
|
||||
and:
|
||||
String test = new File(temp, "org/springframework/cloud/contract/verifier/tests/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('REQUEST')
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
|
||||
@@ -43,6 +43,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
assertJsonSize: true
|
||||
)
|
||||
|
||||
@Shared GeneratedClassDataForMethod generatedClassDataForMethod = new GeneratedClassDataForMethod(
|
||||
new SingleTestGenerator.GeneratedClassData("foo", "bar", new File(".").toPath()), "method")
|
||||
|
||||
@Shared
|
||||
Contract contractDslWithCookiesValue = Contract.make {
|
||||
@@ -201,9 +204,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#187')
|
||||
@@ -237,9 +240,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#79')
|
||||
@@ -275,9 +278,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#79')
|
||||
@@ -316,9 +319,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#82')
|
||||
@@ -348,9 +351,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
}
|
||||
|
||||
@Issue('#88')
|
||||
@@ -380,9 +383,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """.body('''property1=VAL1''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("property1=VAL1")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '.body("property1=VAL1")'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """.body('''property1=VAL1''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("property1=VAL1")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("property1=VAL1")'
|
||||
}
|
||||
|
||||
@Issue('185')
|
||||
@@ -416,9 +419,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate assertions for array in response body with #methodBuilderName'() {
|
||||
@@ -452,9 +455,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate assertions for array inside response body element with #methodBuilderName'() {
|
||||
@@ -487,9 +490,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate assertions for nested objects in response body with #methodBuilderName'() {
|
||||
@@ -522,9 +525,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate regex assertions for map objects in response body with #methodBuilderName'() {
|
||||
@@ -561,9 +564,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate regex assertions for string objects in response body with #methodBuilderName'() {
|
||||
@@ -596,9 +599,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue(['#126', '#143'])
|
||||
@@ -631,9 +634,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate a call with an url path and query parameters with #methodBuilderName'() {
|
||||
@@ -689,9 +692,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -748,9 +751,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate test for empty body with #methodBuilderName'() {
|
||||
@@ -778,9 +781,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ".body('''''')"
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '.body("")'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ".body('''''')"
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("")'
|
||||
}
|
||||
|
||||
def 'should generate test for String in response body with #methodBuilderName'() {
|
||||
@@ -809,9 +812,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
}
|
||||
|
||||
@Issue('113')
|
||||
@@ -851,9 +854,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
@Issue('115')
|
||||
@@ -893,9 +896,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
def 'should work with more complex stuff and jsonpaths with #methodBuilderName'() {
|
||||
@@ -937,9 +940,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should work properly with GString url with #methodBuilderName'() {
|
||||
@@ -973,9 +976,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should resolve properties in GString with regular expression with #methodBuilderName'() {
|
||||
@@ -1016,15 +1019,15 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('42')
|
||||
def 'should not omit the optional field in the test creation with MockMvcSpockMethodBodyBuilder'() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1044,7 +1047,7 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
@Issue('42')
|
||||
def "should not omit the optional field in the test creation with MockMvcJUnitMethodBodyBuilder"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1110,9 +1113,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | assertionStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read(\'\'\'$.rejectionReason\'\'\'))''', '''assertThatLocationIsNull(response.header('Location'))''']
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['''assertThatRejectionReasonIsNull(parsedJson.read(\'\'\'$.rejectionReason\'\'\'))''', '''assertThatLocationIsNull(response.header('Location'))''']
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
}
|
||||
|
||||
def 'should support inner map and list definitions with #methodBuilderName'() {
|
||||
@@ -1180,9 +1183,9 @@ class SpringTestMethodBodyBuildersSpec extends Specification implements WireMock
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '"street":"Light Street"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '\\"street\\":\\"Light Street\\"'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '\\"street\\":\\"Light Street\\"'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '"street":"Light Street"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\"street\\":\\"Light Street\\"'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\"street\\":\\"Light Street\\"'
|
||||
|
||||
}
|
||||
|
||||
@@ -1225,9 +1228,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToRun(methodBuilderName, lines.join("\n"))
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '"street":"Light Street"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '\\"street\\":\\"Light Street\\"'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '\\"street\\":\\"Light Street\\"'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '"street":"Light Street"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\"street\\":\\"Light Street\\"'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\"street\\":\\"Light Street\\"'
|
||||
|
||||
}
|
||||
|
||||
@@ -1267,9 +1270,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('177')
|
||||
@@ -1297,10 +1300,10 @@ World.''')
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """'''hello,
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """'''hello,
|
||||
World.'''"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '"hello,\\nWorld."'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '"hello,\\nWorld."'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '"hello,\\nWorld."'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '"hello,\\nWorld."'
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
@@ -1347,15 +1350,15 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', 'filename.csv', 'file content'.bytes, 'application/json')"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
|
||||
@@ -1402,15 +1405,15 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', 'filename.csv', 'file content'.bytes)"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes());']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes());']
|
||||
@@ -1452,11 +1455,11 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".multiPart('file', 'file', [100, 117, 100, 97] as byte[])"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.multiPart("file", "file", new byte[] {100, 117, 100, 97});']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.multiPart("file", "file", new byte[] {100, 117, 100, 97});']
|
||||
|
||||
}
|
||||
@@ -1496,15 +1499,15 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', toString(), 'file content'.bytes)"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", toString(), "file content".getBytes());']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", toString(), "file content".getBytes());']
|
||||
@@ -1549,9 +1552,9 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#216')
|
||||
@@ -1578,7 +1581,7 @@ World.'''"""
|
||||
)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1613,7 +1616,7 @@ World.'''"""
|
||||
)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1650,9 +1653,9 @@ World.'''"""
|
||||
test.contains('''assertThatRejectionReasonIsNull(''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('262')
|
||||
@@ -1677,7 +1680,7 @@ World.'''"""
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1719,9 +1722,9 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('266')
|
||||
@@ -1758,9 +1761,9 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('266')
|
||||
@@ -1793,9 +1796,9 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('47')
|
||||
@@ -1824,8 +1827,8 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '.when().async()'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.when().async()'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.when().async()'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.when().async()'
|
||||
}
|
||||
|
||||
@Issue('372')
|
||||
@@ -1859,8 +1862,8 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate proper test code with array of primitives using #methodBuilderName'() {
|
||||
@@ -1894,9 +1897,9 @@ World.'''"""
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#273')
|
||||
@@ -1912,7 +1915,7 @@ World.'''"""
|
||||
body(code: 9, message: $(consumer('Wrong credentials'), producer(regex('^(?!\\s*$).+'))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1998,7 +2001,7 @@ World.'''"""
|
||||
def 'should generate the regular expression for the other side of communication'() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(
|
||||
dslWithOnlyOneSideForDocs, properties)
|
||||
dslWithOnlyOneSideForDocs, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -2033,7 +2036,7 @@ World.'''"""
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -2067,7 +2070,7 @@ World.'''"""
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -2097,7 +2100,7 @@ World.'''"""
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -2128,7 +2131,7 @@ World.'''"""
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
@@ -2155,7 +2158,7 @@ World.'''"""
|
||||
body(value(stub("HELLO FROM STUB"), server(regex(".*"))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -2179,7 +2182,7 @@ World.'''"""
|
||||
body(value(stub("HELLO FROM STUB"), server(execute('foo($it)'))))
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -2214,7 +2217,7 @@ World.'''"""
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
@@ -2330,9 +2333,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToRun(methodBuilderName, lines.join("\n"))
|
||||
where:
|
||||
methodBuilderName | methodBuilder | endOfLineRegExSymbol
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '\\$'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '$'
|
||||
}
|
||||
|
||||
@Issue('#162')
|
||||
@@ -2364,9 +2367,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#173')
|
||||
@@ -2402,9 +2405,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#172')
|
||||
@@ -2436,9 +2439,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
where:
|
||||
//order is inverted cause Intellij didn't parse this properly
|
||||
methodBuilderName | methodBuilder | expectedAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
}
|
||||
|
||||
@Issue('#443')
|
||||
@@ -2470,11 +2473,11 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | testAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -2509,9 +2512,9 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
where:
|
||||
//order is inverted cause Intellij didn't parse this properly
|
||||
methodBuilderName | methodBuilder | expectedAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -2542,11 +2545,11 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
!test.contains("'executedMethod()'")
|
||||
where:
|
||||
methodBuilderName | methodBuilder | missingMethodAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("post(executedMethod())") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("path(executedMethod())") }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("post(executedMethod())") }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("post(executedMethod())") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("path(executedMethod())") }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("post(executedMethod())") }
|
||||
}
|
||||
|
||||
@Issue('#203')
|
||||
@@ -2578,11 +2581,11 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
!test.contains('assertThatJson(parsedJson).array("[\'foo\']").isEmpty()')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#226')
|
||||
@@ -2611,11 +2614,11 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
responseAssertion(test)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestAssertion | responseAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String body -> body.contains("body('''12000''')") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String body -> body.contains(""".method('GET', entity('12000', 'text/plain'))""") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains(""".method("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000")') }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains("body('''12000''')") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains(""".method('GET', entity('12000', 'text/plain'))""") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains(""".method("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000")') }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
}
|
||||
|
||||
@Issue('#230')
|
||||
@@ -2702,11 +2705,11 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
responseAssertion(test)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | responseAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String body -> body.contains("response.header('Authorization') == 'foo secret bar'") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String body -> body.contains("response.getHeaderString('Authorization') == 'foo secret bar'") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('assertThat(response.getHeaderString("Authorization")).isEqualTo("foo secret bar");') }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains("response.header('Authorization') == 'foo secret bar'") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains("response.getHeaderString('Authorization') == 'foo secret bar'") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('assertThat(response.getHeaderString("Authorization")).isEqualTo("foo secret bar");') }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('assertThat(response.header("Authorization")).isEqualTo("foo secret bar");') }
|
||||
}
|
||||
|
||||
@Issue('#230')
|
||||
@@ -2757,11 +2760,11 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
test.contains('''assertThatJson(parsedJson).field("['responseBaz2']").isEqualTo("Bla bla bar bla bla")''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate JUnit assertions with cookies [#methodBuilderName]'() {
|
||||
@@ -2779,8 +2782,8 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate JUnit assertions with cookies pattern [#methodBuilderName]'() {
|
||||
@@ -2798,8 +2801,8 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should not generate JUnit cookie assertion with absent cookie [#methodBuilderName]'() {
|
||||
@@ -2815,13 +2818,13 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate spock assertions with cookies'() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesValue, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesValue, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -2836,7 +2839,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
|
||||
def 'should generate spock assertions with cookies pattern'() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesPattern, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesPattern, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -2851,7 +2854,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
|
||||
def 'should not generate spock cookie assertion with absent cookie'() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDslWithAbsentCookies, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDslWithAbsentCookies, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -2890,10 +2893,10 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
test.contains('''assertThatJson(parsedJson).field("['anEmptyMap']").isEmpty()''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ class YamlMockMvcMethodBodyBuilderSpec extends Specification implements WireMock
|
||||
assertJsonSize: true
|
||||
)
|
||||
|
||||
@Shared GeneratedClassDataForMethod generatedClassDataForMethod = new GeneratedClassDataForMethod(
|
||||
new SingleTestGenerator.GeneratedClassData("foo", "bar", new File(".").toPath()), "method")
|
||||
|
||||
static File textToFile(String text) {
|
||||
File temp = File.createTempFile("yaml", ".yml")
|
||||
temp.text = text
|
||||
@@ -200,8 +203,8 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue("#187")
|
||||
@@ -234,8 +237,8 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#79')
|
||||
@@ -269,10 +272,10 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#79')
|
||||
@@ -309,9 +312,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#82')
|
||||
@@ -341,9 +344,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
}
|
||||
|
||||
@Issue('#88')
|
||||
@@ -371,9 +374,9 @@ response:
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """.body('''property1=VAL1''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("property1=VAL1")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '.body("property1=VAL1")'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | """.body('''property1=VAL1''')"""
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("property1=VAL1")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("property1=VAL1")'
|
||||
}
|
||||
|
||||
@Issue('185')
|
||||
@@ -406,9 +409,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate assertions for array in response body with #methodBuilderName'() {
|
||||
@@ -444,9 +447,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate assertions for array inside response body element with #methodBuilderName'() {
|
||||
@@ -481,9 +484,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate assertions for nested objects in response body with #methodBuilderName'() {
|
||||
@@ -515,9 +518,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate regex assertions for map objects in response body with #methodBuilderName'() {
|
||||
@@ -552,9 +555,9 @@ response:
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters with #methodBuilderName"() {
|
||||
@@ -625,9 +628,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -701,9 +704,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate test for empty body with #methodBuilderName'() {
|
||||
@@ -731,9 +734,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ".body('''''')"
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '.body("")'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ".body('''''')"
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("")'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.body("")'
|
||||
}
|
||||
|
||||
def 'should generate test for String in response body with #methodBuilderName'() {
|
||||
@@ -763,9 +766,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'String responseBody = response.getBody().asString();' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
}
|
||||
|
||||
@Issue('113')
|
||||
@@ -814,9 +817,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
def 'should work with more complex stuff and jsonpaths with #methodBuilderName'() {
|
||||
@@ -862,9 +865,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('72')
|
||||
@@ -903,9 +906,9 @@ response:
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | assertionStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("\\\$.rejectionReason"))''', '''assertThatLocationIsNull(response.header('Location'))''']
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("\\\$.rejectionReason"))''', '''assertThatLocationIsNull(response.header('Location'))''']
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
}
|
||||
|
||||
def "shouldn't generate unicode escape characters with #methodBuilderName"() {
|
||||
@@ -952,9 +955,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
@@ -1015,15 +1018,15 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', 'filename.csv', 'file content'.bytes, 'application/json')"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
|
||||
@@ -1088,11 +1091,11 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".multiPart('file', 'filename.csv', 'file content'.bytes, 'application/json')"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes(), "application/json");']
|
||||
|
||||
}
|
||||
@@ -1155,15 +1158,15 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', toString(), 'file content'.bytes, 'application/json')"""]
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", toString(), "file content".getBytes(), "application/json");']
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | ['"Content-Type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", toString(), "file content".getBytes(), "application/json");']
|
||||
@@ -1190,7 +1193,7 @@ response:
|
||||
value: '^[a-zA-Z0-9_\\- ]+$'
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1221,7 +1224,7 @@ response:
|
||||
value: '^[a-zA-Z0-9_\\- ]+$'
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1261,8 +1264,8 @@ response:
|
||||
test.contains('''assertThatRejectionReasonIsNull(''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('262')
|
||||
@@ -1290,7 +1293,7 @@ response:
|
||||
value: "[0-9]+"
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1337,9 +1340,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('266')
|
||||
@@ -1375,9 +1378,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('266')
|
||||
@@ -1409,9 +1412,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('47')
|
||||
@@ -1440,8 +1443,8 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '.when().async()'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.when().async()'
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.when().async()'
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '.when().async()'
|
||||
}
|
||||
|
||||
@Issue('372')
|
||||
@@ -1473,8 +1476,8 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should generate proper test code with array of primitives using #methodBuilderName'() {
|
||||
@@ -1505,9 +1508,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#273')
|
||||
@@ -1530,7 +1533,7 @@ response:
|
||||
value: '^(?!\\s*$).+'
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1563,7 +1566,7 @@ response:
|
||||
value: "assertThatRejectionReasonIsNull($it)"
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -1600,7 +1603,7 @@ response:
|
||||
value: "assertThatUserNameIsNotNull($it)"
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -1633,7 +1636,7 @@ response:
|
||||
value: "assertThatUserNameIsNotNull($it)"
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -1661,7 +1664,7 @@ response:
|
||||
status: 200
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
@@ -1692,7 +1695,7 @@ response:
|
||||
value: ".*"
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1720,7 +1723,7 @@ response:
|
||||
value: "foo($it)"
|
||||
'''
|
||||
Contract contractDsl = fromYaml(contract)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
MethodBodyBuilder builder = new HttpSpockMethodRequestProcessingBodyBuilder(contractDsl, properties, generatedClassDataForMethod)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1769,9 +1772,9 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | matcher
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String s -> 'assertThat(response.header("Content-Type")).matches("application.vnd.fraud.v1.json.*")' }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String s -> "response.header('Content-Type') ==~ java.util.regex.Pattern.compile('application.vnd.fraud.v1.json.*')" }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | { String s -> "response.header('Content-Type') ==~ java.util.regex.Pattern.compile('application.vnd.fraud.v1.json.*')" }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String s -> 'assertThat(response.header("Content-Type")).matches("application.vnd.fraud.v1.json.*")' }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String s -> "response.header('Content-Type') ==~ java.util.regex.Pattern.compile('application.vnd.fraud.v1.json.*')" }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String s -> "response.header('Content-Type') ==~ java.util.regex.Pattern.compile('application.vnd.fraud.v1.json.*')" }
|
||||
}
|
||||
|
||||
@Issue('#172')
|
||||
@@ -1808,9 +1811,9 @@ response:
|
||||
where:
|
||||
//order is inverted cause Intellij didn't parse this properly
|
||||
methodBuilderName | methodBuilder | expectedAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
}
|
||||
|
||||
@Issue('#443')
|
||||
@@ -1846,10 +1849,10 @@ response:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder | testAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""responseBody ==~ java.util.regex.Pattern.compile('true|false')""") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String testContents -> testContents.contains("""assertThat(responseBody).matches("true|false");""") }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -1888,8 +1891,8 @@ response:
|
||||
where:
|
||||
//order is inverted cause Intellij didn't parse this properly
|
||||
methodBuilderName | methodBuilder | expectedAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''responseBody == "{\\"a\\":1}\\n{\\"a\\":2}"'''
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | '''assertThat(responseBody).isEqualTo("{\\"a\\":1}\\n{\\"a\\":2}'''
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -1920,10 +1923,10 @@ response:
|
||||
!test.contains("'executedMethod()'")
|
||||
where:
|
||||
methodBuilderName | methodBuilder | missingMethodAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("post(executedMethod())") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("path(executedMethod())") }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("post(executedMethod())") }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Cannot find matching method Script1#executedMethod") }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { Throwable t, OutputCapture capture -> t.message.contains("Truncated class file") && capture.toString().contains("path(executedMethod())") }
|
||||
}
|
||||
|
||||
@Issue('#203')
|
||||
@@ -1956,11 +1959,11 @@ response:
|
||||
!test.contains('assertThatJson(parsedJson).array("[\'foo\']").isEmpty()')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#226')
|
||||
@@ -1989,10 +1992,10 @@ response:
|
||||
responseAssertion(test)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestAssertion | responseAssertion
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String body -> body.contains("body('''12000''')") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String body -> body.contains(""".method('GET', entity('12000', 'text/plain'))""") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains(""".method("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000")') }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains("body('''12000''')") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains(""".method('GET', entity('12000', 'text/plain'))""") } | { String body -> body.contains('responseBody == "12000"') }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains(""".method("GET", entity("12000", "text/plain"))""") } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000")') }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, generatedClassDataForMethod) } | { String body -> body.contains('body("12000")') } | { String body -> body.contains('assertThat(responseBody).isEqualTo("12000");') }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,15 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.converter
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingType
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
@@ -25,11 +32,7 @@ import org.springframework.cloud.contract.spec.internal.QueryParameters
|
||||
import org.springframework.cloud.contract.spec.internal.RegexPatterns
|
||||
import org.springframework.cloud.contract.spec.internal.Url
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.regex.Pattern
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Tim Ysewyn
|
||||
@@ -60,6 +63,10 @@ class YamlContractConverterSpec extends Specification {
|
||||
File ymlMessagingMatchers = new File(ymlMessagingMatchersFile.toURI())
|
||||
URL ymlCookiesUrl = YamlContractConverterSpec.getResource("/yml/contract_cookies.yml")
|
||||
File ymlCookies = new File(ymlCookiesUrl.toURI())
|
||||
URL ymlBytesUrl = YamlContractConverterSpec.getResource("/yml/contract_pdf.yml")
|
||||
File ymlBytes = new File(ymlBytesUrl.toURI())
|
||||
URL ymlMessagingBytesUrl = YamlContractConverterSpec.getResource("/yml/contract_messaging_pdf.yml")
|
||||
File ymlMessagingBytes = new File(ymlMessagingBytesUrl.toURI())
|
||||
YamlContractConverter converter = new YamlContractConverter()
|
||||
|
||||
def "should convert YAML with Cookies to DSL"() {
|
||||
@@ -499,6 +506,36 @@ class YamlContractConverterSpec extends Specification {
|
||||
contract.outputMessage.body.clientValue == [bookName: "foo"]
|
||||
}
|
||||
|
||||
def "should convert YAML with HTTP binary body to DSL"() {
|
||||
given:
|
||||
assert converter.isAccepted(ymlBytes)
|
||||
when:
|
||||
Collection<Contract> contracts = converter.convertFrom(ymlBytes)
|
||||
then:
|
||||
contracts.size() == 1
|
||||
Contract contract = contracts.first()
|
||||
contract.request.body.clientValue instanceof FromFileProperty
|
||||
((FromFileProperty) contract.request.body.clientValue).type == byte[]
|
||||
and:
|
||||
contract.response.body.clientValue instanceof FromFileProperty
|
||||
((FromFileProperty) contract.response.body.clientValue).type == byte[]
|
||||
}
|
||||
|
||||
def "should convert YAML with messaging binary body to DSL"() {
|
||||
given:
|
||||
assert converter.isAccepted(ymlMessagingBytes)
|
||||
when:
|
||||
Collection<Contract> contracts = converter.convertFrom(ymlMessagingBytes)
|
||||
then:
|
||||
contracts.size() == 1
|
||||
Contract contract = contracts.first()
|
||||
contract.input.messageBody.clientValue instanceof FromFileProperty
|
||||
((FromFileProperty) contract.input.messageBody.clientValue).type == byte[]
|
||||
and:
|
||||
contract.outputMessage.body.clientValue instanceof FromFileProperty
|
||||
((FromFileProperty) contract.outputMessage.body.clientValue).type == byte[]
|
||||
}
|
||||
|
||||
def "should assert request headers when converting YAML to DSL"() {
|
||||
given:
|
||||
File yml = new File(YamlContractConverterSpec.getResource("/yml/contract_broken_request_headers.yml").toURI())
|
||||
@@ -548,6 +585,7 @@ request:
|
||||
cookies: {}
|
||||
body: null
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
url: null
|
||||
body: []
|
||||
@@ -562,6 +600,7 @@ response:
|
||||
cookies: {}
|
||||
body: null
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
body: []
|
||||
headers: []
|
||||
@@ -587,6 +626,7 @@ request:
|
||||
cookies: {}
|
||||
body: null
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
url: null
|
||||
body: []
|
||||
@@ -601,6 +641,7 @@ response:
|
||||
cookies: {}
|
||||
body: null
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
body: []
|
||||
headers: []
|
||||
|
||||
@@ -22,6 +22,9 @@ import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemp
|
||||
import groovy.json.JsonBuilder
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper
|
||||
@@ -30,11 +33,10 @@ import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubMapp
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
import org.springframework.cloud.contract.verifier.util.AssertionUtil
|
||||
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
|
||||
import org.springframework.http.RequestEntity
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.util.SocketUtils
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
|
||||
class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
@@ -400,7 +402,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
header "Content-Type", "customtype/xml"
|
||||
}
|
||||
body """<foo><name>${value(consumer('Jozo'), producer('Denis'))}</name><jobId>${
|
||||
value(consumer("<test>"), producer('1234567890'))
|
||||
value(consumer("<test>"), producer('1234567890'))
|
||||
}</jobId></foo>"""
|
||||
}
|
||||
response {
|
||||
@@ -443,7 +445,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
method 'GET'
|
||||
url "/users"
|
||||
body """<user><name>${value(consumer('Jozo'), producer('Denis'))}</name><jobId>${
|
||||
value(consumer("<test>"), producer('1234567890'))
|
||||
value(consumer("<test>"), producer('1234567890'))
|
||||
}</jobId></user>"""
|
||||
}
|
||||
response {
|
||||
@@ -551,7 +553,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
method 'GET'
|
||||
url "/users"
|
||||
body equalToXml("""<foo><name>${value(consumer('Jozo'), producer('Denis'))}</name><jobId>${
|
||||
value(consumer("<test>"), producer('1234567890'))
|
||||
value(consumer("<test>"), producer('1234567890'))
|
||||
}</jobId></foo>""")
|
||||
}
|
||||
response {
|
||||
@@ -1801,6 +1803,33 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
server?.shutdown()
|
||||
}
|
||||
|
||||
@Issue("#664")
|
||||
def "should work with byte arrays"() {
|
||||
given:
|
||||
File request = new File(WireMockGroovyDslSpec.getResource("/body_builder/request.pdf").file)
|
||||
File response = new File(WireMockGroovyDslSpec.getResource("/body_builder/response.pdf").file)
|
||||
and:
|
||||
File file = new File(WireMockGroovyDslSpec.getResource("/body_builder/worksWithPdf.groovy").file)
|
||||
Contract contract = ContractVerifierDslConverter.convertAsCollection(
|
||||
file.parentFile, file
|
||||
).first()
|
||||
and:
|
||||
def json = toWireMockClientJsonStub(contract)
|
||||
and:
|
||||
int port = SocketUtils.findAvailableTcpPort()
|
||||
WireMockServer server = new WireMockServer(config().port(port))
|
||||
server.start()
|
||||
and:
|
||||
server.addStubMapping(WireMockStubMapping.buildFrom(json))
|
||||
when:
|
||||
ResponseEntity<byte[]> entity = callBytes(port, request)
|
||||
then:
|
||||
entity.statusCodeValue == 200
|
||||
entity.body == response.bytes
|
||||
cleanup:
|
||||
server?.shutdown()
|
||||
}
|
||||
|
||||
@Issue('#540')
|
||||
def "should generate a stub with standard WireMock request template"() {
|
||||
given:
|
||||
@@ -2418,6 +2447,13 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
.body("{\"foo\":\"bar\",\"baz\":5}"), String.class)
|
||||
}
|
||||
|
||||
ResponseEntity<byte[]> callBytes(int port, File request) {
|
||||
return new TestRestTemplate().exchange(
|
||||
RequestEntity.put(URI.create("http://localhost:" + port + "/1"))
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(request.bytes), byte[].class)
|
||||
}
|
||||
|
||||
String callApiCategories(int port) {
|
||||
return new TestRestTemplate().exchange(
|
||||
RequestEntity.post(URI.create("http://localhost:" + port + "/api/categories"))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.springframework.cloud.contract.verifier.messaging.internal
|
||||
|
||||
|
||||
import spock.lang.Specification
|
||||
|
||||
class ContractVerifierObjectMapperSpec extends Specification {
|
||||
@@ -24,7 +25,30 @@ class ContractVerifierObjectMapperSpec extends Specification {
|
||||
result == '''{"foo":"bar"}'''
|
||||
}
|
||||
|
||||
class MyClass {
|
||||
def "should convert an object into a byte[] representation"() {
|
||||
given:
|
||||
MyClass input = new MyClass(foo: "bar")
|
||||
when:
|
||||
byte[] result = mapper.writeValueAsBytes(input)
|
||||
then:
|
||||
result == '''{"foo":"bar"}'''.bytes
|
||||
}
|
||||
|
||||
def "should convert a String into a byte[] representation"() {
|
||||
when:
|
||||
byte[] result = mapper.writeValueAsBytes('''{"foo":"bar"}''')
|
||||
then:
|
||||
result == '''{"foo":"bar"}'''.bytes
|
||||
}
|
||||
|
||||
def "should pass byte[] as a byte[] representation"() {
|
||||
when:
|
||||
byte[] result = mapper.writeValueAsBytes('''{"foo":"bar"}'''.bytes)
|
||||
then:
|
||||
result == '''{"foo":"bar"}'''.bytes
|
||||
}
|
||||
|
||||
static class MyClass {
|
||||
String foo
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,19 @@
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
|
||||
Contract.make {
|
||||
request {
|
||||
url("/1")
|
||||
method(PUT())
|
||||
headers {
|
||||
contentType(applicationOctetStream())
|
||||
}
|
||||
body(fileAsBytes("request.pdf"))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(fileAsBytes("response.pdf"))
|
||||
headers {
|
||||
contentType(applicationOctetStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
label: some_label
|
||||
input:
|
||||
messageFrom: jms:input
|
||||
messageBodyFromFileAsBytes: request.pdf
|
||||
messageHeaders:
|
||||
contentType: application/octet-stream
|
||||
outputMessage:
|
||||
sentTo: jms:output
|
||||
bodyFromFileAsBytes: response.pdf
|
||||
headers:
|
||||
contentType: application/octet-stream
|
||||
@@ -0,0 +1,11 @@
|
||||
request:
|
||||
url: /1
|
||||
method: PUT
|
||||
headers:
|
||||
Content-Type: application/octet-stream
|
||||
bodyFromFileAsBytes: request.pdf
|
||||
response:
|
||||
status: 200
|
||||
bodyFromFileAsBytes: response.pdf
|
||||
headers:
|
||||
Content-Type: application/octet-stream
|
||||
Binary file not shown.
Binary file not shown.
@@ -144,4 +144,31 @@ class StubRunnerStreamTransformerSpec extends Specification {
|
||||
result.payload == '''{"orderId":"40058c70-891c-4176-a033-f70bad0c5f77","description":"This is the order description"}'''.bytes
|
||||
}
|
||||
|
||||
def 'should work for binary payloads from file'() {
|
||||
given:
|
||||
Contract contract = Contract.make {
|
||||
label 'send_order'
|
||||
input {
|
||||
triggeredBy('orderTrigger()')
|
||||
}
|
||||
outputMessage {
|
||||
sentTo('orders')
|
||||
headers {
|
||||
messagingContentType(applicationOctetStream())
|
||||
}
|
||||
body(fileAsBytes("response.pdf"))
|
||||
}
|
||||
}
|
||||
StubRunnerStreamTransformer streamTransformer = new StubRunnerStreamTransformer(contract) {
|
||||
@Override
|
||||
Contract matchingContract(Message<?> source) {
|
||||
return contract
|
||||
}
|
||||
}
|
||||
when:
|
||||
def result = streamTransformer.transform(message)
|
||||
then:
|
||||
result.payload == StubRunnerStreamTransformerSpec.getResource("/response.pdf").bytes
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user