use of com.arbindo.mimock.entities.HttpMethod in project mimock by neel1996.
the class GenericMockRequestService method serveMockRequest.
public DomainModelForMock serveMockRequest(GenericRequestModel request) throws MatchingMockNotFoundException, IOException {
log.log(Level.INFO, "Fetching matching mock from the DB");
String route = request.getRoute();
HttpMethod httpMethod = httpMethod(request.getHttpMethod());
String queryParam = request.getQueryParam();
Optional<Mock> resultFromDB = repository.findOneByRouteAndHttpMethodAndQueryParams(route, httpMethod, queryParam);
if (resultFromDB.isEmpty()) {
log.log(Level.ERROR, "No matching rows returned from DB");
String errorMessage = "Matching mock does not exist";
throw new MatchingMockNotFoundException(errorMessage);
}
log.log(Level.INFO, "Returning matching mock");
Mock matchingMock = resultFromDB.get();
if (shouldValidateRequestHeaders(matchingMock, request)) {
validateRequestHeaders(request, matchingMock);
}
if (shouldValidateRequestBody(matchingMock, request)) {
validateRequestBody(matchingMock.getRequestBodiesForMock().getRequestBody(), request.getRequestBody());
}
return domainModelMapper.mappedModel(matchingMock);
}
use of com.arbindo.mimock.entities.HttpMethod in project mimock by neel1996.
the class HttpMethodsRepositoryTest method shouldReturnHttpMethodForValidMethod.
@ParameterizedTest
@ValueSource(strings = { "GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH" })
void shouldReturnHttpMethodForValidMethod(String method) {
// Act
HttpMethod httpMethod = httpMethodsRepository.findByMethod(method);
// Assert
assertNotNull(httpMethod);
assertEquals(method, httpMethod.getMethod());
}
use of com.arbindo.mimock.entities.HttpMethod in project mimock by neel1996.
the class HttpMethodsRepositoryTest method shouldReturnNullForCaseSensitiveMethodStrings.
@ParameterizedTest
@ValueSource(strings = { "get", "Head", "pOSt", "put", "Delete", "connect", "Options", "trace", "PaTch" })
void shouldReturnNullForCaseSensitiveMethodStrings(String method) {
// Act
HttpMethod httpMethod = httpMethodsRepository.findByMethod(method);
// Assert
assertNull(httpMethod);
}
use of com.arbindo.mimock.entities.HttpMethod in project mimock by neel1996.
the class HttpMethodsRepositoryTest method shouldReturnNullForInvalidMethod.
@ParameterizedTest
@ValueSource(strings = { "TEST", "RANDOM", "EXEC", "123X" })
void shouldReturnNullForInvalidMethod(String method) {
// Act
HttpMethod httpMethod = httpMethodsRepository.findByMethod(method);
// Assert
assertNull(httpMethod);
}
Aggregations