1
|
|
|
package com.hltech.judged.server.domain.validation.jms; |
2
|
|
|
|
3
|
|
|
import com.hltech.vaunt.core.VauntSerializer; |
4
|
|
|
import com.hltech.vaunt.core.domain.model.Contract; |
5
|
|
|
import com.hltech.vaunt.validator.ValidationResult; |
6
|
|
|
import com.hltech.vaunt.validator.VauntValidator; |
7
|
|
|
import com.hltech.judged.server.domain.validation.InterfaceContractValidator; |
8
|
|
|
import lombok.extern.slf4j.Slf4j; |
9
|
|
|
|
10
|
|
|
import java.util.List; |
11
|
|
|
import java.util.stream.Collectors; |
12
|
|
|
|
13
|
|
|
import static com.hltech.vaunt.validator.ValidationResult.ValidationStatus.FAILED; |
14
|
|
|
|
15
|
|
|
@Slf4j |
16
|
|
|
public class JmsContractValidator extends InterfaceContractValidator<List<Contract>, List<Contract>> { |
17
|
|
|
|
18
|
|
|
public static final String COMMUNICATION_INTERFACE = "jms"; |
19
|
|
|
|
20
|
|
|
public JmsContractValidator() { |
21
|
|
|
super(COMMUNICATION_INTERFACE); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
@Override |
25
|
|
|
public List<Contract> asCapabilities(String rawCapabilities) { |
26
|
|
|
return new VauntSerializer().parseContracts(rawCapabilities); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
@Override |
30
|
|
|
public List<Contract> asExpectations(String rawExpectations) { |
31
|
|
|
return new VauntSerializer().parseContracts(rawExpectations); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
@Override |
35
|
|
|
public List<InteractionValidationResult> validate(List<Contract> expectations, List<Contract> capabilities) { |
36
|
|
|
List<ValidationResult> validationResults = new VauntValidator().validate(expectations, capabilities); |
37
|
|
|
|
38
|
|
|
return validationResults.stream() |
39
|
|
|
.map(this::toInteractionValidationResult) |
40
|
|
|
.collect(Collectors.toList()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private InteractionValidationResult toInteractionValidationResult(ValidationResult validationResult) { |
44
|
|
|
if (validationResult.getResult().equals(FAILED)) { |
45
|
|
|
return InteractionValidationResult.fail(validationResult.getName(), validationResult.getErrors()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return InteractionValidationResult.success(validationResult.getName()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|