1
|
|
|
package dev.hltech.dredd.interfaces.rest.validation; |
2
|
|
|
|
3
|
|
|
import com.google.common.collect.Ordering; |
4
|
|
|
import dev.hltech.dredd.domain.validation.EnvironmentValidatorResult; |
5
|
|
|
|
6
|
|
|
import java.util.Comparator; |
7
|
|
|
import java.util.List; |
8
|
|
|
import java.util.Map; |
9
|
|
|
import java.util.stream.Collectors; |
10
|
|
|
|
11
|
|
|
import static com.google.common.collect.Maps.newHashMap; |
12
|
|
|
|
13
|
|
|
public class Converters { |
14
|
|
|
|
15
|
|
|
private Converters() { |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public static List<ContractValidationReportDto> toDtos(List<EnvironmentValidatorResult> validationResults, String serviceName, String serviceVersion) { |
19
|
|
|
Map<ConsumerAndProviderDto, ContractValidationReportDto> result = newHashMap(); |
20
|
|
|
validationResults |
21
|
|
|
.stream() |
22
|
|
|
.forEach(environmentValidatorResult -> { |
23
|
|
|
environmentValidatorResult.getCapabilitiesValidationResults() |
24
|
|
|
.stream() |
25
|
|
|
.forEach(cvr -> { |
26
|
|
|
ConsumerAndProviderDto key = new ConsumerAndProviderDto(cvr.getConsumerName(), cvr.getConsumerVersion(), serviceName, serviceVersion); |
27
|
|
|
if (!result.containsKey(key)) { |
28
|
|
|
result.put( |
29
|
|
|
key, |
30
|
|
|
new ContractValidationReportDto(key) |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
result.get(key).addInteractions( |
34
|
|
|
cvr.getInteractionValidationResults() |
35
|
|
|
.stream() |
36
|
|
|
.map(ivr -> new InteractionValidationReportDto( |
37
|
|
|
environmentValidatorResult.getCommunicationInterface(), |
38
|
|
|
ivr.getName(), |
39
|
|
|
ivr.getStatus(), |
40
|
|
|
ivr.getErrors() |
41
|
|
|
)) |
42
|
|
|
.collect(Collectors.toList()) |
43
|
|
|
); |
44
|
|
|
}); |
45
|
|
|
environmentValidatorResult.getExpectationValidationResults() |
46
|
|
|
.stream() |
47
|
|
|
.forEach(evr -> { |
48
|
|
|
ConsumerAndProviderDto key = new ConsumerAndProviderDto(serviceName, serviceVersion, evr.getProviderName(), evr.getProviderVersion()); |
49
|
|
|
if (!result.containsKey(key)) { |
50
|
|
|
result.put( |
51
|
|
|
key, |
52
|
|
|
new ContractValidationReportDto(key) |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
result.get(key).addInteractions( |
56
|
|
|
evr.getInteractionValidationResults() |
57
|
|
|
.stream() |
58
|
|
|
.map(ivr -> new InteractionValidationReportDto( |
59
|
|
|
environmentValidatorResult.getCommunicationInterface(), |
60
|
|
|
ivr.getName(), |
61
|
|
|
ivr.getStatus(), |
62
|
|
|
ivr.getErrors() |
63
|
|
|
)) |
64
|
|
|
.collect(Collectors.toList()) |
65
|
|
|
); |
66
|
|
|
}); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
return Ordering |
70
|
|
|
.from((Comparator<ContractValidationReportDto>) (o1, o2) -> o1.getConsumerAndProvider().toString().compareTo(o2.getConsumerAndProvider().toString())) |
71
|
|
|
.sortedCopy(result.values()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|