-
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.
- Loading branch information
Showing
10 changed files
with
141 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: | ||
|
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
10 changes: 10 additions & 0 deletions
10
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/Capabilities.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,10 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class Capabilities { | ||
private final List<Contract> contracts; | ||
} |
11 changes: 11 additions & 0 deletions
11
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/Contract.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,11 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class Contract { | ||
private final DestinationType destinationType; | ||
private final String destinationName; | ||
private final JsonSchema body; | ||
} |
6 changes: 6 additions & 0 deletions
6
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/DestinationType.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,6 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
public enum DestinationType { | ||
QUEUE, | ||
TOPIC | ||
} |
9 changes: 9 additions & 0 deletions
9
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/Expectations.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,9 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import com.google.common.collect.Multimap; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class Expectations { | ||
private final Multimap<String, Contract> providerNameToContracts; | ||
} |
11 changes: 11 additions & 0 deletions
11
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/Service.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,11 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class Service { | ||
|
||
private final String name; | ||
private final Capabilities capabilities; | ||
private final Expectations expectations; | ||
} |
13 changes: 13 additions & 0 deletions
13
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/ValidationError.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,13 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ValidationError { | ||
MISSING_ENDPOINT("Missing endpoint required by consumer"), | ||
WRONG_SCHEMA("Wrong schema of the message"); | ||
|
||
private final String description; | ||
} |
22 changes: 22 additions & 0 deletions
22
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/ValidationResult.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,22 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Data | ||
public class ValidationResult { | ||
private final boolean isValid; | ||
private final String description; | ||
private final List<ValidationError> errors; | ||
|
||
public static ValidationResult success(Contract expectation, List<Contract> capabilities) { | ||
return new ValidationResult(true, String.format("Expectation: %s, capabilities: %s", expectation, capabilities), new ArrayList<>()); | ||
} | ||
|
||
public static ValidationResult failure(Contract expectation, List<Contract> capabilities, ValidationError... errors) { | ||
return new ValidationResult(false, String.format("Expectation: %s, capabilities: %s", expectation, capabilities), Arrays.asList(errors)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
judge-d-server/src/main/java/dev/hltech/dredd/domain/validation/jms/VauntValidator.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,52 @@ | ||
package dev.hltech.dredd.domain.validation.jms; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class VauntValidator { | ||
|
||
public List<ValidationResult> validate(Service consumer, Service provider) { | ||
return consumer.getExpectations().getProviderNameToContracts().get(provider.getName()).stream() | ||
.map(consumerContract -> validateWithMatchingProviderContract( | ||
consumerContract, provider.getCapabilities().getContracts())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<ValidationResult> validate(List<Contract> expectations, List<Contract> capabilities) { | ||
return expectations.stream() | ||
.map(consumerContract -> validateWithMatchingProviderContract(consumerContract, capabilities)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private ValidationResult validateWithMatchingProviderContract( | ||
Contract consumerContract, List<Contract> providerContracts) { | ||
List<Contract> contracts = providerContracts.stream() | ||
.filter(providerContract -> isEndpointMatching(consumerContract, providerContract)) | ||
.collect(Collectors.toList()); | ||
|
||
if (contracts.isEmpty()) { | ||
return ValidationResult.failure(consumerContract, providerContracts, ValidationError.MISSING_ENDPOINT); | ||
} | ||
|
||
Optional<Contract> matchingProviderContract = contracts.stream() | ||
.filter(providerContract -> isSchemaMatching(consumerContract, providerContract)) | ||
.findFirst(); | ||
|
||
if (!matchingProviderContract.isPresent()) { | ||
return ValidationResult.failure(consumerContract, providerContracts, ValidationError.WRONG_SCHEMA); | ||
} | ||
|
||
return ValidationResult.success(consumerContract, providerContracts); | ||
} | ||
|
||
private boolean isEndpointMatching(Contract firstContract, Contract secondContract) { | ||
return firstContract.getDestinationType().equals(secondContract.getDestinationType()) | ||
&& firstContract.getDestinationName().equals(secondContract.getDestinationName()); | ||
} | ||
|
||
private boolean isSchemaMatching(Contract firstContract, Contract secondContract) { | ||
return firstContract.getBody().equals(secondContract.getBody()); | ||
} | ||
|
||
} |