Search in sources :

Example 1 with Verification

use of com.sequenceiq.it.cloudbreak.dto.mock.Verification in project cloudbreak by hortonworks.

the class DefaultResponseConfigure method verify.

public T verify() {
    String callsJson;
    if (crnless) {
        callsJson = executeQuery.execute("/tests/calls", w -> w.queryParam("path", pathReplaced(path)), r -> r.readEntity(String.class));
    } else {
        callsJson = executeQuery.execute("/tests/calls/" + testDto.getCrn(), w -> w.queryParam("path", pathReplaced(path)), r -> r.readEntity(String.class));
    }
    Call[] calls;
    try {
        calls = new ObjectMapper().readValue(callsJson, Call[].class);
    } catch (JsonProcessingException e) {
        throw new TestFailException("Cannot deserialize calls: " + e.getMessage(), e);
    }
    if (calls == null) {
        calls = new Call[0];
    }
    List<Call> collect = Arrays.stream(calls).filter(this::isPathMatched).filter(call -> call.getMethod().equalsIgnoreCase(method.toString())).filter(call -> parameterCheck(call.getParameters())).collect(Collectors.toList());
    VerificationContext verificationContext = new VerificationContext(collect);
    verifications.forEach(v -> {
        v.handle(path, method, verificationContext);
    });
    List<String> errors = verificationContext.getErrors();
    if (!errors.isEmpty()) {
        throw new TestFailException("URL verification failed: " + System.lineSeparator() + String.join(System.lineSeparator(), errors));
    }
    return testDto;
}
Also used : Arrays(java.util.Arrays) Method(com.sequenceiq.it.cloudbreak.dto.mock.Method) CloudbreakTestDto(com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto) TextBodyContainsVerification(com.sequenceiq.it.cloudbreak.dto.mock.verification.TextBodyContainsVerification) ExecuteQueryToMockInfrastructure(com.sequenceiq.it.cloudbreak.mock.ExecuteQueryToMockInfrastructure) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) Consumer(java.util.function.Consumer) Call(com.sequenceiq.it.verification.Call) List(java.util.List) Response(javax.ws.rs.core.Response) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) Verification(com.sequenceiq.it.cloudbreak.dto.mock.Verification) Optional(java.util.Optional) VerificationContext(com.sequenceiq.it.cloudbreak.dto.mock.verification.VerificationContext) LinkedList(java.util.LinkedList) CheckCount(com.sequenceiq.it.cloudbreak.dto.mock.CheckCount) MockResponse(com.sequenceiq.it.cloudbreak.testcase.mock.response.MockResponse) Call(com.sequenceiq.it.verification.Call) VerificationContext(com.sequenceiq.it.cloudbreak.dto.mock.verification.VerificationContext) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CloudbreakTestDto (com.sequenceiq.it.cloudbreak.dto.CloudbreakTestDto)1 CheckCount (com.sequenceiq.it.cloudbreak.dto.mock.CheckCount)1 Method (com.sequenceiq.it.cloudbreak.dto.mock.Method)1 Verification (com.sequenceiq.it.cloudbreak.dto.mock.Verification)1 TextBodyContainsVerification (com.sequenceiq.it.cloudbreak.dto.mock.verification.TextBodyContainsVerification)1 VerificationContext (com.sequenceiq.it.cloudbreak.dto.mock.verification.VerificationContext)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 ExecuteQueryToMockInfrastructure (com.sequenceiq.it.cloudbreak.mock.ExecuteQueryToMockInfrastructure)1 MockResponse (com.sequenceiq.it.cloudbreak.testcase.mock.response.MockResponse)1 Call (com.sequenceiq.it.verification.Call)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1