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