Revert "Fixed invalid multiline json reading"
This reverts commit 923faef7d3.
This commit is contained in:
@@ -33,7 +33,7 @@ import java.nio.charset.Charset
|
||||
class FromFileProperty implements Serializable {
|
||||
|
||||
final File file
|
||||
final String charset
|
||||
final Charset charset
|
||||
final Class type
|
||||
|
||||
FromFileProperty(File file, Class type) {
|
||||
@@ -43,7 +43,7 @@ class FromFileProperty implements Serializable {
|
||||
FromFileProperty(File file, Class type, Charset charset) {
|
||||
this.file = file
|
||||
this.type = type
|
||||
this.charset = charset.toString()
|
||||
this.charset = charset
|
||||
}
|
||||
|
||||
boolean isString() {
|
||||
|
||||
@@ -91,8 +91,7 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
return "assertThat(response.getPayloadAsByteArray()).isEqualTo(" +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
}
|
||||
return "assertThat(response.getPayload()).isEqualTo(" +
|
||||
readStringFromFileString(value, CommunicationType.RESPONSE) +")"
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -126,7 +126,7 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
|
||||
return "assertThat(response.getBody().asByteArray()).isEqualTo(" +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
}
|
||||
return "assertThat(response.getBody()).isEqualTo(" + readStringFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -164,15 +164,6 @@ class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
bb.addLine("assertThat(response.getStatus()).isEqualTo($response.status.serverValue);")
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
if (value.isByte()) {
|
||||
return "assertThat(response.readEntity(byte[].class)).isEqualTo(" +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
}
|
||||
return "assertThat(response.readEntity(String.class)).isEqualTo(" + readStringFromFileString(value, CommunicationType.RESPONSE) + ")"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateResponseHeadersBlock(BlockBuilder bb) {
|
||||
response.headers?.executeForEachHeader { Header header ->
|
||||
|
||||
@@ -77,15 +77,6 @@ class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequ
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseBodyPropertyComparisonString(String property, FromFileProperty value) {
|
||||
if (value.isByte()) {
|
||||
return "response.readEntity(byte[]) == " +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE)
|
||||
}
|
||||
return "response.readEntity(String) == " + readStringFromFileString(value, CommunicationType.RESPONSE)
|
||||
}
|
||||
|
||||
protected void appendRequestWithRequiredResponseContentType(BlockBuilder bb) {
|
||||
String acceptHeader = getHeader("Accept")
|
||||
if (acceptHeader) {
|
||||
|
||||
@@ -169,8 +169,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
return "response.payloadAsByteArray == " +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE)
|
||||
}
|
||||
return "response.payload == " +
|
||||
readStringFromFileString(value, CommunicationType.RESPONSE)
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -113,7 +113,7 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
|
||||
return "response.body.asByteArray() == " +
|
||||
readBytesFromFileString(value, CommunicationType.RESPONSE)
|
||||
}
|
||||
return "response.body == " + readStringFromFileString(value, CommunicationType.RESPONSE)
|
||||
return getResponseBodyPropertyComparisonString(property, value.asString())
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -90,9 +90,7 @@ class WireMockResponseStubStrategy extends BaseWireMockStubStrategy {
|
||||
if (contentType == ContentType.UNKNOWN) {
|
||||
contentType = recognizeContentTypeFromContent(body)
|
||||
}
|
||||
if (body instanceof byte[]) {
|
||||
builder.withBody(body)
|
||||
} else if (body instanceof FromFileProperty && body.isByte()) {
|
||||
if (body instanceof FromFileProperty && body.isByte()) {
|
||||
builder.withBody(body.asBytes())
|
||||
} else {
|
||||
builder.withBody(parseBody(body, contentType))
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.contract.verifier.util
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.FromFileProperty
|
||||
import org.springframework.cloud.contract.verifier.template.HandlebarsTemplateProcessor
|
||||
import org.springframework.cloud.contract.verifier.template.TemplateProcessor
|
||||
/**
|
||||
@@ -131,8 +130,6 @@ class MapConverter {
|
||||
}
|
||||
return it
|
||||
})
|
||||
} else if (it instanceof FromFileProperty) {
|
||||
return it.isByte() ? it.asBytes() : it.asString()
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
||||
@@ -785,43 +785,6 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
def 'should work with files that have new lines [#methodBuilderName]'() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method('PUT')
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
body(file("classpath/request.json"))
|
||||
url("/1")
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
body(file("classpath/response.json"))
|
||||
headers {
|
||||
contentType(textPlain())
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(' ')
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
String test = blockBuilder.toString()
|
||||
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, test)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
MockMvcJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) }
|
||||
}
|
||||
|
||||
@Issue('#509')
|
||||
def 'classToCheck() should return class of object'() {
|
||||
given:
|
||||
@@ -935,7 +898,6 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
String test = blockBuilder.toString()
|
||||
requestMatcher(test)
|
||||
responseMatcher(test)
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, test)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestMatcher | responseMatcher
|
||||
HttpSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new HttpSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) } | { String string ->
|
||||
@@ -951,12 +913,12 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties, classDataForMethod) } | { String string ->
|
||||
string.contains('entity(fileToBytes(this, "some_method_request_request.pdf")')
|
||||
} | { String string ->
|
||||
string.contains('response.readEntity(byte[]) == fileToBytes(this, "some_method_response_response.pdf")')
|
||||
string.contains('response.body.asByteArray() == fileToBytes(this, "some_method_response_response.pdf")')
|
||||
}
|
||||
JaxRsClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) } | { String string ->
|
||||
string.contains('entity(fileToBytes(this, "some_method_request_request.pdf")')
|
||||
} | { String string ->
|
||||
string.contains('assertThat(response.readEntity(byte[].class)).isEqualTo(fileToBytes(this, "some_method_response_response.pdf"));')
|
||||
string.contains('assertThat(response.getBody().asByteArray()).isEqualTo(fileToBytes(this, "some_method_response_response.pdf"));')
|
||||
}
|
||||
WebTestClientJUnitMethodBodyBuilder.simpleName | { Contract dsl -> new WebTestClientJUnitMethodBodyBuilder(dsl, properties, classDataForMethod) } | { String string ->
|
||||
string.contains('.body(fileToBytes(this, "some_method_request_request.pdf"));')
|
||||
|
||||
@@ -614,7 +614,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('readFromFile_response_response.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
}
|
||||
@@ -639,7 +639,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('readFromFile_response_response.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
}
|
||||
@@ -664,7 +664,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('readFromFile_response_response.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
}
|
||||
@@ -689,7 +689,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
String test = new File(temp, "a/b/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('readFromFile_response_response.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
}
|
||||
@@ -713,7 +713,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
and:
|
||||
String test = new File(temp, "org/springframework/cloud/contract/verifier/tests/ContractVerifier${getTestName(testFramework)}").text
|
||||
test.contains('readFromFile_request_request.json')
|
||||
test.contains('readFromFile_response_response.json')
|
||||
test.contains('RESPONSE')
|
||||
where:
|
||||
testFramework << [JUNIT, JUNIT5, SPOCK]
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ class SyntaxChecker {
|
||||
"${RestAssuredMockMvc.name}.when",
|
||||
"${RestAssured.name}.*",
|
||||
"${Entity.name}.*",
|
||||
"${ContractVerifierUtil.name}.fileToBytes",
|
||||
"${ContractVerifierMessagingUtil.name}.headers",
|
||||
"${JsonAssertion.name}.assertThatJson",
|
||||
"${SpringCloudContractAssertions.name}.assertThat"
|
||||
@@ -76,7 +75,6 @@ class SyntaxChecker {
|
||||
private static final String WEB_TEST_CLIENT_STATIC_IMPORTS = [
|
||||
"${RestAssuredWebTestClient.name}.*",
|
||||
"${Entity.name}.*",
|
||||
"${ContractVerifierUtil.name}.fileToBytes",
|
||||
"${ContractVerifierMessagingUtil.name}.headers",
|
||||
"${JsonAssertion.name}.assertThatJson",
|
||||
"${SpringCloudContractAssertions.name}.assertThat"
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
{
|
||||
"status" : "REQUEST"
|
||||
}
|
||||
{ "status" : "REQUEST" }
|
||||
@@ -1,3 +1 @@
|
||||
{
|
||||
"status" : "RESPONSE"
|
||||
}
|
||||
{ "status" : "RESPONSE" }
|
||||
Reference in New Issue
Block a user