1
|
|
|
package dev.hltech.dredd.domain; |
2
|
|
|
|
3
|
|
|
import dev.hltech.dredd.domain.contracts.ServiceContracts; |
4
|
|
|
import dev.hltech.dredd.domain.contracts.ServiceContractsRepository; |
5
|
|
|
import dev.hltech.dredd.domain.environment.EnvironmentRepository; |
6
|
|
|
import dev.hltech.dredd.domain.validation.EnvironmentValidatorResult; |
7
|
|
|
import dev.hltech.dredd.domain.validation.InterfaceContractValidator; |
8
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
9
|
|
|
import org.springframework.stereotype.Component; |
10
|
|
|
|
11
|
|
|
import java.util.List; |
12
|
|
|
import java.util.Optional; |
13
|
|
|
|
14
|
|
|
import static java.util.stream.Collectors.toList; |
15
|
|
|
|
16
|
|
|
@Component |
17
|
|
|
public class JudgeD { |
18
|
|
|
|
19
|
|
|
private EnvironmentRepository environmentRepository; |
20
|
|
|
private ServiceContractsRepository serviceContractsRepository; |
21
|
|
|
|
22
|
|
|
@Autowired |
23
|
|
|
public JudgeD(EnvironmentRepository environmentRepository, ServiceContractsRepository serviceContractsRepository) { |
24
|
|
|
this.environmentRepository = environmentRepository; |
25
|
|
|
this.serviceContractsRepository = serviceContractsRepository; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public <C, E> EnvironmentValidatorResult validateServiceAgainstEnvironments(ServiceContracts validatedService, List<String> environments, InterfaceContractValidator<C, E> validator) { |
29
|
|
|
List<ServiceContracts> environmentContracts = environments.stream() |
30
|
|
|
.flatMap(env -> this.environmentRepository.get(env).getAllServices().stream()) |
31
|
|
|
.map(sv -> this.serviceContractsRepository.find(sv.getName(), sv.getVersion())) |
32
|
|
|
.filter(Optional::isPresent) |
33
|
|
|
.map(Optional::get) |
34
|
|
|
.collect(toList()); |
35
|
|
|
|
36
|
|
|
return getValidatorResult(validatedService, environmentContracts, validator); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public <C, E> EnvironmentValidatorResult getValidatorResult( |
40
|
|
|
ServiceContracts validatedService, |
41
|
|
|
List<ServiceContracts> environmentContracts, |
42
|
|
|
InterfaceContractValidator<C, E> validator |
43
|
|
|
) { |
44
|
|
|
return new EnvironmentValidatorResult( |
45
|
|
|
validator.getCommunicationInterface(), |
46
|
|
|
validator.validateCapabilities(validatedService, environmentContracts), |
47
|
|
|
validator.validateExpectations(validatedService, environmentContracts) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|