Fixes gh-1876 (#1877)
This commit is contained in:
committed by
GitHub
parent
622aef7bd2
commit
77b05b6a16
@@ -47,6 +47,28 @@ class RecursiveFilesConverterSpec extends Specification {
|
||||
@Rule
|
||||
public TemporaryFolder tmpFolder = new TemporaryFolder()
|
||||
|
||||
def "should recursively convert all matching files with stubs"() {
|
||||
given:
|
||||
File originalSourceRootDirectory = new File(this.getClass()
|
||||
.getResource("/converter/dir3").toURI())
|
||||
File contractsDslDir = tmpFolder.newFolder("source")
|
||||
File stubsOutputDir = tmpFolder.newFolder("target")
|
||||
FileSystemUtils
|
||||
.copyRecursively(originalSourceRootDirectory, contractsDslDir)
|
||||
and:
|
||||
RecursiveFilesConverter recursiveFilesConverter = new RecursiveFilesConverter(stubsOutputDir, contractsDslDir, new ArrayList<>(), ".*", false)
|
||||
when:
|
||||
recursiveFilesConverter.processFiles()
|
||||
then:
|
||||
Collection<File> createdFiles = [] as List
|
||||
stubsOutputDir.
|
||||
eachFileRecurse(FileType.FILES) { createdFiles << it }
|
||||
Set<String> relativizedCreatedFiles =
|
||||
getRelativePathsForFilesInDirectory(createdFiles, stubsOutputDir)
|
||||
relativizedCreatedFiles == [Paths.get("Account creating.json"),
|
||||
Paths.get("Test route.json")] as Set<Path>
|
||||
}
|
||||
|
||||
def "should recursively convert all matching files"() {
|
||||
given:
|
||||
File originalSourceRootDirectory = new File(this.getClass()
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
request:
|
||||
method: "POST"
|
||||
url: null
|
||||
urlPath: "/post-route"
|
||||
queryParameters: {}
|
||||
headers:
|
||||
Content-Type: "application/json"
|
||||
cookies: null
|
||||
body:
|
||||
age: 35
|
||||
name: "Jonh"
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
url: null
|
||||
body: []
|
||||
headers:
|
||||
- key: "Content-Type"
|
||||
regex: "application/json.*"
|
||||
predefined: null
|
||||
command: null
|
||||
regexType: "as_string"
|
||||
queryParameters: []
|
||||
cookies: []
|
||||
multipart: null
|
||||
multipart: null
|
||||
response:
|
||||
status: 200
|
||||
headers: null
|
||||
cookies: null
|
||||
body:
|
||||
age: 35
|
||||
name: "Jonh"
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
body: []
|
||||
headers: []
|
||||
cookies: []
|
||||
async: false
|
||||
fixedDelayMilliseconds: null
|
||||
input: null
|
||||
outputMessage: null
|
||||
description: null
|
||||
label: null
|
||||
name: "Account creating"
|
||||
priority: 1
|
||||
ignored: false
|
||||
inProgress: false
|
||||
metadata: {}
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
request:
|
||||
method: "GET"
|
||||
url: null
|
||||
urlPath: "/my-first-route"
|
||||
queryParameters: {}
|
||||
headers:
|
||||
Content-Type: "application/json"
|
||||
cookies: null
|
||||
body: null
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
url: null
|
||||
body: []
|
||||
headers:
|
||||
- key: "Content-Type"
|
||||
regex: "application/json.*"
|
||||
predefined: null
|
||||
command: null
|
||||
regexType: "as_string"
|
||||
queryParameters: []
|
||||
cookies: []
|
||||
multipart: null
|
||||
multipart: null
|
||||
response:
|
||||
status: 200
|
||||
headers: null
|
||||
cookies: null
|
||||
body:
|
||||
test: "MVZWIKTLUUXDCDGKXMDC"
|
||||
bodyFromFile: null
|
||||
bodyFromFileAsBytes: null
|
||||
matchers:
|
||||
body:
|
||||
- path: "$.['test']"
|
||||
type: "by_regex"
|
||||
value: "^\\s*\\S[\\S\\s]*"
|
||||
minOccurrence: null
|
||||
maxOccurrence: null
|
||||
predefined: null
|
||||
regexType: "as_string"
|
||||
headers: []
|
||||
cookies: []
|
||||
async: false
|
||||
fixedDelayMilliseconds: null
|
||||
input: null
|
||||
outputMessage: null
|
||||
description: null
|
||||
label: null
|
||||
name: "Test route"
|
||||
priority: 1
|
||||
ignored: false
|
||||
inProgress: false
|
||||
metadata: {}
|
||||
@@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -723,9 +724,7 @@ class YamlToContracts {
|
||||
.ifPresent(yamlContractBodyStubMatchers -> yamlContractBodyStubMatchers
|
||||
.forEach(yamlContractBodyStubMatcher -> {
|
||||
ContentType contentType = evaluateClientSideContentType(
|
||||
yamlHeadersToContractHeaders(
|
||||
Optional.ofNullable(yamlContractInput.messageHeaders)
|
||||
.orElse(new HashMap<>())),
|
||||
yamlHeadersToContractHeaders(yamlContractInput.messageHeaders),
|
||||
Optional.ofNullable(yamlContractInput.messageBody).orElse(null));
|
||||
MatchingTypeValue value;
|
||||
switch (yamlContractBodyStubMatcher.type) {
|
||||
@@ -764,8 +763,9 @@ class YamlToContracts {
|
||||
}
|
||||
|
||||
private Headers yamlHeadersToContractHeaders(Map<String, Object> headers) {
|
||||
Set<Header> convertedHeaders = headers.keySet().stream()
|
||||
.map(header -> Header.build(header, headers.get(header))).collect(toSet());
|
||||
Set<Header> convertedHeaders = headers != null
|
||||
? headers.keySet().stream().map(header -> Header.build(header, headers.get(header))).collect(toSet())
|
||||
: new HashSet<>();
|
||||
Headers contractHeaders = new Headers();
|
||||
contractHeaders.headers(convertedHeaders);
|
||||
return contractHeaders;
|
||||
|
||||
Reference in New Issue
Block a user