Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {}
Original file line number Diff line number Diff line change
@@ -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: {}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -723,9 +724,7 @@ private void mapInputBodyMatchers(YamlContract.Input yamlContractInput, Input ds
.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) {
Expand Down Expand Up @@ -764,8 +763,9 @@ private void mapInputBodyMatchers(YamlContract.Input yamlContractInput, Input ds
}

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;
Expand Down