use of org.springframework.cloud.contract.spec.internal.MatchingTypeValue in project spring-cloud-contract by spring-cloud.
the class YamlToContracts method mapResponseBodyMatchers.
private void mapResponseBodyMatchers(YamlContract.Response yamlContractResponse, Response dslContractResponse) {
dslContractResponse.bodyMatchers(bodyMatchers -> Optional.ofNullable(yamlContractResponse.matchers).map(yamlContractResponseTestMatchers -> yamlContractResponseTestMatchers.body).ifPresent(yamlContractBodyTestMatchers -> yamlContractBodyTestMatchers.forEach(yamlContractBodyTestMatcher -> {
ContentType contentType = evaluateClientSideContentType(yamlHeadersToContractHeaders(yamlContractResponse.headers), yamlContractResponse.body);
MatchingTypeValue value;
switch(yamlContractBodyTestMatcher.type) {
case by_date:
value = bodyMatchers.byDate();
break;
case by_time:
value = bodyMatchers.byTime();
break;
case by_timestamp:
value = bodyMatchers.byTimestamp();
break;
case by_regex:
String regex = yamlContractBodyTestMatcher.value;
if (yamlContractBodyTestMatcher.predefined != null) {
regex = predefinedToPattern(yamlContractBodyTestMatcher.predefined).pattern();
}
value = bodyMatchers.byRegex(regex);
break;
case by_equality:
value = bodyMatchers.byEquality();
break;
case by_type:
value = bodyMatchers.byType(v -> {
if (yamlContractBodyTestMatcher.minOccurrence != null) {
v.minOccurrence(yamlContractBodyTestMatcher.minOccurrence);
}
if (yamlContractBodyTestMatcher.maxOccurrence != null) {
v.maxOccurrence(yamlContractBodyTestMatcher.maxOccurrence);
}
});
break;
case by_command:
value = bodyMatchers.byCommand(yamlContractBodyTestMatcher.value);
break;
case by_null:
value = bodyMatchers.byNull();
break;
default:
throw new UnsupportedOperationException("The type [" + yamlContractBodyTestMatcher.type + "] is unsupported. " + "Hint: If you're using <predefined> remember to pass < type:by_regex > ");
}
if (yamlContractBodyTestMatcher.path != null) {
if (XML == contentType) {
bodyMatchers.xPath(yamlContractBodyTestMatcher.path, value);
} else {
bodyMatchers.jsonPath(yamlContractBodyTestMatcher.path, value);
}
}
})));
}
use of org.springframework.cloud.contract.spec.internal.MatchingTypeValue in project spring-cloud-contract by spring-cloud.
the class YamlToContracts method mapRequestBodyMatchers.
private void mapRequestBodyMatchers(YamlContract.Request yamlContractRequest, Request dslContractRequest) {
dslContractRequest.bodyMatchers((bodyMatchers) -> Optional.ofNullable(yamlContractRequest.matchers).map(stubMatchers -> stubMatchers.body).ifPresent(stubMatchers -> stubMatchers.forEach(stubMatcher -> {
ContentType contentType = evaluateClientSideContentType(yamlHeadersToContractHeaders(Optional.ofNullable(yamlContractRequest.headers).orElse(new HashMap<>())), Optional.ofNullable(yamlContractRequest.body).orElse(null));
MatchingTypeValue value = null;
switch(stubMatcher.type) {
case by_date:
value = bodyMatchers.byDate();
break;
case by_time:
value = bodyMatchers.byTime();
break;
case by_timestamp:
value = bodyMatchers.byTimestamp();
break;
case by_regex:
String regex = stubMatcher.value;
if (stubMatcher.predefined != null) {
regex = predefinedToPattern(stubMatcher.predefined).pattern();
}
value = bodyMatchers.byRegex(regex);
break;
case by_equality:
value = bodyMatchers.byEquality();
break;
case by_type:
value = bodyMatchers.byType(matchingTypeValueHolder -> {
if (stubMatcher.minOccurrence != null) {
matchingTypeValueHolder.minOccurrence(stubMatcher.minOccurrence);
}
if (stubMatcher.maxOccurrence != null) {
matchingTypeValueHolder.maxOccurrence(stubMatcher.maxOccurrence);
}
});
break;
case by_null:
// do nothing
break;
default:
throw new UnsupportedOperationException("The type [" + stubMatcher.type + "] is" + " unsupported.Hint:If you 're using <predefined> remember to pass <type:by_regex > ");
}
if (value != null) {
if (XML == contentType) {
bodyMatchers.xPath(stubMatcher.path, value);
} else {
bodyMatchers.jsonPath(stubMatcher.path, value);
}
}
})));
}
use of org.springframework.cloud.contract.spec.internal.MatchingTypeValue in project spring-cloud-contract by spring-cloud.
the class YamlToContracts method mapOutputBodyMatchers.
private void mapOutputBodyMatchers(YamlContract.OutputMessage yamlContractOutputMessage, OutputMessage dslContractOutputMessage) {
if (yamlContractOutputMessage.matchers != null) {
dslContractOutputMessage.bodyMatchers(dslContractOutputMessageBodyMatchers -> Optional.ofNullable(yamlContractOutputMessage.matchers.body).ifPresent(yamlContractBodyTestMatchers -> yamlContractBodyTestMatchers.forEach(yamlContractBodyTestMatcher -> {
ContentType contentType = evaluateClientSideContentType(yamlHeadersToContractHeaders(yamlContractOutputMessage.headers), yamlContractOutputMessage.body);
MatchingTypeValue value;
switch(yamlContractBodyTestMatcher.type) {
case by_date:
value = dslContractOutputMessageBodyMatchers.byDate();
break;
case by_time:
value = dslContractOutputMessageBodyMatchers.byTime();
break;
case by_timestamp:
value = dslContractOutputMessageBodyMatchers.byTimestamp();
break;
case by_regex:
String regex = yamlContractBodyTestMatcher.value;
if (yamlContractBodyTestMatcher.predefined != null) {
regex = predefinedToPattern(yamlContractBodyTestMatcher.predefined).pattern();
}
value = dslContractOutputMessageBodyMatchers.byRegex(regex);
break;
case by_equality:
value = dslContractOutputMessageBodyMatchers.byEquality();
break;
case by_type:
value = dslContractOutputMessageBodyMatchers.byType(v -> {
if (yamlContractBodyTestMatcher.minOccurrence != null) {
v.minOccurrence(yamlContractBodyTestMatcher.minOccurrence);
}
if (yamlContractBodyTestMatcher.maxOccurrence != null) {
v.maxOccurrence(yamlContractBodyTestMatcher.maxOccurrence);
}
});
break;
case by_command:
value = dslContractOutputMessageBodyMatchers.byCommand(yamlContractBodyTestMatcher.value);
break;
case by_null:
value = dslContractOutputMessageBodyMatchers.byNull();
break;
default:
throw new UnsupportedOperationException("The type " + "[" + yamlContractBodyTestMatcher.type + "] is unsupported. Hint: If " + "you're using <predefined> remember to pass < type:by_regex > ");
}
if (XML == contentType) {
dslContractOutputMessageBodyMatchers.xPath(yamlContractBodyTestMatcher.path, value);
} else {
dslContractOutputMessageBodyMatchers.jsonPath(yamlContractBodyTestMatcher.path, value);
}
})));
}
}
use of org.springframework.cloud.contract.spec.internal.MatchingTypeValue in project spring-cloud-contract by spring-cloud.
the class YamlToContracts method mapInputBodyMatchers.
private void mapInputBodyMatchers(YamlContract.Input yamlContractInput, Input dslContractInput) {
dslContractInput.bodyMatchers(dslContractInputBodyMatchers -> Optional.ofNullable(yamlContractInput.matchers.body).ifPresent(yamlContractBodyStubMatchers -> yamlContractBodyStubMatchers.forEach(yamlContractBodyStubMatcher -> {
ContentType contentType = evaluateClientSideContentType(yamlHeadersToContractHeaders(Optional.ofNullable(yamlContractInput.messageHeaders).orElse(new HashMap<>())), Optional.ofNullable(yamlContractInput.messageBody).orElse(null));
MatchingTypeValue value;
switch(yamlContractBodyStubMatcher.type) {
case by_date:
value = dslContractInputBodyMatchers.byDate();
break;
case by_time:
value = dslContractInputBodyMatchers.byTime();
break;
case by_timestamp:
value = dslContractInputBodyMatchers.byTimestamp();
break;
case by_regex:
String regex = yamlContractBodyStubMatcher.value;
if (yamlContractBodyStubMatcher.predefined != null) {
regex = predefinedToPattern(yamlContractBodyStubMatcher.predefined).pattern();
}
value = dslContractInputBodyMatchers.byRegex(regex);
break;
case by_equality:
value = dslContractInputBodyMatchers.byEquality();
break;
default:
throw new UnsupportedOperationException("The type " + "[" + yamlContractBodyStubMatcher.type + "] is unsupported. " + "Hint: If you're using <predefined> remember to pass < type:by_regex > ");
}
if (XML == contentType) {
dslContractInputBodyMatchers.xPath(yamlContractBodyStubMatcher.path, value);
} else {
dslContractInputBodyMatchers.jsonPath(yamlContractBodyStubMatcher.path, value);
}
})));
}
Aggregations