Search in sources :

Example 11 with HttpMethod

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);
}
Also used : HttpMethod(com.arbindo.mimock.entities.HttpMethod) DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) Mock(com.arbindo.mimock.entities.Mock)

Example 12 with HttpMethod

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());
}
Also used : HttpMethod(com.arbindo.mimock.entities.HttpMethod) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with HttpMethod

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);
}
Also used : HttpMethod(com.arbindo.mimock.entities.HttpMethod) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with 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);
}
Also used : HttpMethod(com.arbindo.mimock.entities.HttpMethod) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HttpMethod (com.arbindo.mimock.entities.HttpMethod)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 ValueSource (org.junit.jupiter.params.provider.ValueSource)8 Mock (com.arbindo.mimock.entities.Mock)2 DomainModelForMock (com.arbindo.mimock.generic.model.DomainModelForMock)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 EmptySource (org.junit.jupiter.params.provider.EmptySource)2 NullSource (org.junit.jupiter.params.provider.NullSource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1