Search in sources :

Example 1 with VerificationTimesDTO

use of org.mockserver.serialization.model.VerificationTimesDTO in project mockserver by mock-server.

the class VerificationTimesDTODeserializer method deserialize.

@Override
public VerificationTimesDTO deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
    VerificationTimesDTO verificationTimesDTO = null;
    Integer count = null;
    Boolean exact = null;
    Integer atLeast = null;
    Integer atMost = null;
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jsonParser.getCurrentName();
        if ("count".equals(fieldName)) {
            jsonParser.nextToken();
            count = jsonParser.getIntValue();
        } else if ("exact".equals(fieldName)) {
            jsonParser.nextToken();
            exact = jsonParser.getBooleanValue();
        } else if ("atLeast".equals(fieldName)) {
            jsonParser.nextToken();
            atLeast = jsonParser.getIntValue();
        } else if ("atMost".equals(fieldName)) {
            jsonParser.nextToken();
            atMost = jsonParser.getIntValue();
        }
        if (atLeast != null || atMost != null) {
            verificationTimesDTO = new VerificationTimesDTO(VerificationTimes.between(atLeast != null ? atLeast : -1, atMost != null ? atMost : -1));
        } else if (count != null) {
            if (exact != null && exact) {
                verificationTimesDTO = new VerificationTimesDTO(VerificationTimes.exactly(count));
            } else {
                verificationTimesDTO = new VerificationTimesDTO(VerificationTimes.atLeast(count));
            }
        }
    }
    return verificationTimesDTO;
}
Also used : VerificationTimesDTO(org.mockserver.serialization.model.VerificationTimesDTO)

Example 2 with VerificationTimesDTO

use of org.mockserver.serialization.model.VerificationTimesDTO in project mockserver by mock-server.

the class VerificationSerializerIntegrationTest method shouldSerializeCompleteObject.

@Test
public void shouldSerializeCompleteObject() {
    // when
    String jsonExpectation = new VerificationSerializer(new MockServerLogger()).serialize(new VerificationDTO().setHttpRequest(new HttpRequestDTO(request().withMethod("GET").withPath("somepath"))).setTimes(new VerificationTimesDTO(VerificationTimes.between(2, 3))).buildObject());
    // then
    assertEquals("{" + NEW_LINE + "  \"httpRequest\" : {" + NEW_LINE + "    \"method\" : \"GET\"," + NEW_LINE + "    \"path\" : \"somepath\"" + NEW_LINE + "  }," + NEW_LINE + "  \"times\" : {" + NEW_LINE + "    \"atLeast\" : 2," + NEW_LINE + "    \"atMost\" : 3" + NEW_LINE + "  }" + NEW_LINE + "}", jsonExpectation);
}
Also used : MockServerLogger(org.mockserver.logging.MockServerLogger) VerificationDTO(org.mockserver.serialization.model.VerificationDTO) VerificationTimesDTO(org.mockserver.serialization.model.VerificationTimesDTO) HttpRequestDTO(org.mockserver.serialization.model.HttpRequestDTO) Test(org.junit.Test)

Example 3 with VerificationTimesDTO

use of org.mockserver.serialization.model.VerificationTimesDTO in project mockserver by mock-server.

the class VerificationSerializerIntegrationTest method shouldDeserializeCompleteObject.

@Test
public void shouldDeserializeCompleteObject() {
    // given
    String requestBytes = "{" + NEW_LINE + "  \"httpRequest\" : {" + NEW_LINE + "    \"method\" : \"GET\"," + NEW_LINE + "    \"path\" : \"somepath\"" + NEW_LINE + "  }," + NEW_LINE + "  \"times\" : {" + NEW_LINE + "    \"atLeast\" : 2," + NEW_LINE + "    \"atMost\" : 3" + NEW_LINE + "  }" + NEW_LINE + "}";
    // when
    Verification verification = new VerificationSerializer(new MockServerLogger()).deserialize(requestBytes);
    // then
    assertEquals(new VerificationDTO().setHttpRequest(new HttpRequestDTO(request().withMethod("GET").withPath("somepath"))).setTimes(new VerificationTimesDTO(VerificationTimes.between(2, 3))).buildObject(), verification);
}
Also used : MockServerLogger(org.mockserver.logging.MockServerLogger) VerificationDTO(org.mockserver.serialization.model.VerificationDTO) VerificationTimesDTO(org.mockserver.serialization.model.VerificationTimesDTO) Verification(org.mockserver.verify.Verification) HttpRequestDTO(org.mockserver.serialization.model.HttpRequestDTO) Test(org.junit.Test)

Aggregations

VerificationTimesDTO (org.mockserver.serialization.model.VerificationTimesDTO)3 Test (org.junit.Test)2 MockServerLogger (org.mockserver.logging.MockServerLogger)2 HttpRequestDTO (org.mockserver.serialization.model.HttpRequestDTO)2 VerificationDTO (org.mockserver.serialization.model.VerificationDTO)2 Verification (org.mockserver.verify.Verification)1