-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented validator for jms fqw fw fw fa
- Loading branch information
Showing
3 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
language: java | ||
sudo: true | ||
jdk: | ||
- openjdk8 | ||
|
||
cache: | ||
directories: | ||
|
65 changes: 65 additions & 0 deletions
65
...e-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/JmsContractValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import dev.hltech.dredd.domain.validation.InterfaceContractValidator; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class JmsContractValidator extends InterfaceContractValidator<List<Contract>, List<Contract>> { | ||
|
||
public static final String COMMUNICATION_INTERFACE = "jms"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public JmsContractValidator() { | ||
super(COMMUNICATION_INTERFACE); | ||
objectMapper = new ObjectMapper(); | ||
} | ||
|
||
@Override | ||
public List<Contract> asCapabilities(String rawCapabilities) { | ||
try { | ||
return objectMapper.readValue(rawCapabilities, new TypeReference<List<Contract>>(){}); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public List<Contract> asExpectations(String rawExpectations) { | ||
try { | ||
return objectMapper.readValue(rawExpectations, new TypeReference<List<Contract>>(){}); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public List<InteractionValidationResult> validate(List<Contract> expectations, List<Contract> capabilities) { | ||
VauntValidator vauntValidator = new VauntValidator(); | ||
|
||
List<ValidationResult> validationResults = vauntValidator.validate(expectations, capabilities); | ||
|
||
return validationResults.stream() | ||
.map(this::toInteractionValidationResult) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private InteractionValidationResult toInteractionValidationResult(ValidationResult validationResult) { | ||
if (!validationResult.isValid()) { | ||
List<String> errors = validationResult.getErrors().stream() | ||
.map(ValidationError::getDescription) | ||
.collect(Collectors.toList()); | ||
return InteractionValidationResult.fail(validationResult.toString(), errors); | ||
} | ||
return InteractionValidationResult.success(validationResult.toString()); | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
...rver/src/test/groovy/dev/hltech/dredd/domain/validation/jms/JmsContractValidatorUT.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package dev.hltech.dredd.domain.validation.jms | ||
|
||
import com.fasterxml.jackson.module.jsonSchema.types.NullSchema | ||
import com.fasterxml.jackson.module.jsonSchema.types.NumberSchema | ||
import com.fasterxml.jackson.module.jsonSchema.types.StringSchema | ||
import dev.hltech.dredd.domain.validation.InterfaceContractValidator | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
class JmsContractValidatorUT extends Specification { | ||
|
||
@Subject | ||
def validator = new JmsContractValidator() | ||
|
||
def "Should map raw capabilities"() { | ||
given: | ||
def dstType = DestinationType.QUEUE | ||
def dstName = 'dst' | ||
def rawCapabilities = """ | ||
[ | ||
{ | ||
"destinationType":"${dstType}", | ||
"destinationName":"${dstName}", | ||
"body": { | ||
"type":"string" | ||
} | ||
} | ||
] | ||
""" | ||
|
||
expect: | ||
validator.asCapabilities(rawCapabilities) == [new Contract(dstType, dstName, new StringSchema())] | ||
} | ||
|
||
def "Should map raw expectations"() { | ||
given: | ||
def dstType = DestinationType.QUEUE | ||
def dstName = 'dst' | ||
def rawExpectations = """ | ||
[ | ||
{ | ||
"destinationType":"${dstType}", | ||
"destinationName":"${dstName}", | ||
"body": { | ||
"type":"string" | ||
} | ||
} | ||
] | ||
""" | ||
|
||
expect: | ||
validator.asExpectations(rawExpectations) == [new Contract(dstType, dstName, new StringSchema())] | ||
} | ||
|
||
def "If there are no expectations and capabilities - results are empty"() { | ||
given: | ||
def expectations = [] | ||
|
||
and: | ||
def capabilities = [] | ||
|
||
when: | ||
def results = validator.validate(expectations, capabilities) | ||
|
||
then: | ||
results.size() == 0 | ||
} | ||
|
||
def "If there are no expectations - results are empty"() { | ||
given: | ||
def expectations = [] | ||
|
||
and: | ||
def capabilities = [new Contract(DestinationType.QUEUE, 'dst', new StringSchema())] | ||
|
||
when: | ||
def results = validator.validate(expectations, capabilities) | ||
|
||
then: | ||
results.size() == 0 | ||
} | ||
|
||
def "If there is matching capability for each expectations - validation results with success"() { | ||
given: | ||
def expectations = [new Contract(DestinationType.QUEUE, 'dst', new StringSchema()), | ||
new Contract(DestinationType.TOPIC, 'dst', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst2', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst', new NumberSchema())] | ||
|
||
and: | ||
def capabilities = [new Contract(DestinationType.QUEUE, 'dst', new NumberSchema()), | ||
new Contract(DestinationType.TOPIC, 'dst', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst2', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'weirdDst', new NumberSchema())] | ||
|
||
when: | ||
def results = validator.validate(expectations, capabilities) | ||
|
||
then: | ||
results.size() == 4 | ||
results.every { result -> | ||
result.status == InterfaceContractValidator.InteractionValidationStatus.OK | ||
result.errors.size() == 0 | ||
} | ||
} | ||
|
||
def "If there are some umnatched expectatuions - validation results with success"() { | ||
given: | ||
def expectations = [new Contract(DestinationType.QUEUE, 'dst', new StringSchema()), | ||
new Contract(DestinationType.TOPIC, 'dst', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst2', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst', new NumberSchema()), | ||
new Contract(DestinationType.QUEUE, 'weirdDst', new NumberSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst', new NullSchema())] | ||
|
||
and: | ||
def capabilities = [new Contract(DestinationType.QUEUE, 'dst', new NumberSchema()), | ||
new Contract(DestinationType.TOPIC, 'dst', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst2', new StringSchema()), | ||
new Contract(DestinationType.QUEUE, 'dst', new StringSchema())] | ||
|
||
when: | ||
def results = validator.validate(expectations, capabilities) | ||
|
||
then: | ||
results.size() == 6 | ||
results.any { result -> | ||
result.status == InterfaceContractValidator.InteractionValidationStatus.FAILED | ||
result.errors.size() == 1 | ||
result.errors[0] == 'Missing endpoint required by consumer' | ||
} | ||
results.any { result -> | ||
result.status == InterfaceContractValidator.InteractionValidationStatus.FAILED | ||
result.errors.size() == 1 | ||
result.errors[0] == 'Wrong schema of the message' | ||
} | ||
results.count { result -> | ||
result.status == InterfaceContractValidator.InteractionValidationStatus.OK | ||
result.errors.size() == 0 | ||
} == 4 | ||
} | ||
} |