|
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
|
|
|
|
|
13
|
|
|
import static java.util.stream.Collectors.toList; |
|
14
|
|
|
|
|
15
|
|
|
@Component |
|
16
|
|
|
public class JudgeD { |
|
17
|
|
|
|
|
18
|
|
|
private EnvironmentRepository environmentRepository; |
|
19
|
|
|
private ServiceContractsRepository serviceContractsRepository; |
|
20
|
|
|
|
|
21
|
|
|
@Autowired |
|
22
|
|
|
public JudgeD(EnvironmentRepository environmentRepository, ServiceContractsRepository serviceContractsRepository) { |
|
23
|
|
|
this.environmentRepository = environmentRepository; |
|
24
|
|
|
this.serviceContractsRepository = serviceContractsRepository; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public <C, E> EnvironmentValidatorResult validateServiceAgainstEnv(ServiceContracts validatedService, String environment, InterfaceContractValidator<C, E> validator) { |
|
28
|
|
|
List<ServiceContracts> environmentContracts = this.environmentRepository.get(environment) |
|
29
|
|
|
.getAllServices() |
|
30
|
|
|
.stream() |
|
31
|
|
|
.map(sv -> this.serviceContractsRepository.find(sv.getName(), sv.getVersion())) |
|
32
|
|
|
.filter(it -> it.isPresent()) |
|
33
|
|
|
.map(it -> it.get()) |
|
34
|
|
|
.collect(toList()); |
|
35
|
|
|
|
|
36
|
|
|
return new EnvironmentValidatorResult( |
|
37
|
|
|
validator.getCommunicationInterface(), |
|
38
|
|
|
validator.validateCapabilities(validatedService, environmentContracts), |
|
39
|
|
|
validator.validateExpectations(validatedService, environmentContracts) |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|