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;
}
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);
}
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);
}
Aggregations