Search in sources :

Example 1 with ProcessedMockRequest

use of com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest in project mimock by arbindo.

the class RequestModelMapperTest method shouldMapRequestModelToProcessedRequestModal.

@Test
void shouldMapRequestModelToProcessedRequestModal() {
    MockRequest request = MocksGenerator.createMockRequest();
    String requestHeadersAsString = RandomDataGenerator.generateRequestHeadersAsString();
    String responseHeadersAsString = RandomDataGenerator.generateResponseHeadersAsString();
    String requestBodyAsString = RandomDataGenerator.generateRequestBodyAsString();
    MockRequest requestToBeMapped = MockRequest.builder().name(request.getName()).description(request.getDescription()).route(request.getRoute()).httpMethod(request.getHttpMethod()).statusCode(request.getStatusCode()).responseContentType(request.getResponseContentType()).queryParams(request.getQueryParams()).requestHeader(requestHeadersAsString).shouldDoExactHeaderMatching(request.isHeaderMatchingSetToStrict()).requestBody(requestBodyAsString).requestBodyType(request.getRequestBodyType()).responseHeaders(responseHeadersAsString).expectedTextResponse(request.getExpectedTextResponse()).build();
    ProcessedMockRequest expectedRequest = ProcessedMockRequest.builder().name(request.getName()).description(request.getDescription()).route(request.getRoute()).httpMethod(request.getHttpMethod()).statusCode(request.getStatusCode()).responseContentType(request.getResponseContentType()).queryParams(request.getQueryParams()).requestHeader(JsonMapper.convertJSONStringToMapWithLowerCaseKeys(requestHeadersAsString)).shouldDoExactHeaderMatching(request.isHeaderMatchingSetToStrict()).requestBody(JsonMapper.convertJSONStringToMapWithLowerCaseKeys(requestBodyAsString)).requestBodyType(request.getRequestBodyType()).responseHeaders(JsonMapper.convertJSONStringToMapWithLowerCaseKeys(responseHeadersAsString)).expectedTextResponse(request.getExpectedTextResponse()).build();
    ProcessedMockRequest mappedRequest = RequestModelMapper.map(requestToBeMapped);
    assertEquals(expectedRequest.getName(), mappedRequest.getName());
    assertEquals(expectedRequest.getDescription(), mappedRequest.getDescription());
    assertEquals(expectedRequest.getRoute(), mappedRequest.getRoute());
    assertEquals(expectedRequest.getHttpMethod(), mappedRequest.getHttpMethod());
    assertEquals(expectedRequest.getStatusCode(), mappedRequest.getStatusCode());
    assertEquals(expectedRequest.getResponseContentType(), mappedRequest.getResponseContentType());
    assertEquals(expectedRequest.getQueryParams(), mappedRequest.getQueryParams());
    assertEquals(expectedRequest.getRequestHeader(), mappedRequest.getRequestHeader());
    assertEquals(expectedRequest.getShouldDoExactHeaderMatching(), mappedRequest.getShouldDoExactHeaderMatching());
    assertEquals(expectedRequest.getRequestBody(), mappedRequest.getRequestBody());
    assertEquals(expectedRequest.getRequestBodyType(), mappedRequest.getRequestBodyType());
    assertEquals(expectedRequest.getResponseHeaders(), mappedRequest.getResponseHeaders());
    assertEquals(expectedRequest.getExpectedTextResponse(), mappedRequest.getExpectedTextResponse());
}
Also used : ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest) MockRequest(com.arbindo.mimock.manage.mimocks.models.request.MockRequest) ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessedMockRequest

use of com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest in project mimock by arbindo.

the class MockManagementServiceTest method shouldReturnNull_ForCreateMock_WhenMockNameAlreadyExists.

@Test
void shouldReturnNull_ForCreateMock_WhenMockNameAlreadyExists() {
    // Arrange
    ProcessedMockRequest request = createProcessedMockRequest();
    Optional<Mock> existingMock = generateOptionalMock(request);
    lenient().when(mockRepository.findOneByMockName(anyString())).thenReturn(existingMock);
    // Act
    Mock result = mockManagementService.createMock(request);
    // Assert
    assertNull(result);
    verify(mockRepository, times(0)).save(any(Mock.class));
}
Also used : ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ProcessedMockRequest

use of com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest in project mimock by arbindo.

the class MockManagementServiceTest method shouldReturnNull_ForUpdateMock_WhenMockNameAlreadyExists.

@Test
void shouldReturnNull_ForUpdateMock_WhenMockNameAlreadyExists() {
    // Arrange
    ProcessedMockRequest request = createProcessedMockRequest();
    Optional<Mock> existingMock = generateOptionalMock(request);
    assertTrue(existingMock.isPresent());
    lenient().when(mockRepository.findOneByMockName(anyString())).thenReturn(existingMock);
    // Act
    Mock result = mockManagementService.updateMock(existingMock.get().getId().toString(), request);
    // Assert
    assertNull(result);
    verify(mockRepository, times(0)).save(any(Mock.class));
}
Also used : ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ProcessedMockRequest

use of com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest in project mimock by arbindo.

the class MockManagementServiceTest method shouldReturnMock_ForCreateMock_WhenMockRequestIsValidWithRequestHeadersAndBody.

@Test
void shouldReturnMock_ForCreateMock_WhenMockRequestIsValidWithRequestHeadersAndBody() {
    // Arrange
    ProcessedMockRequest request = createProcessedMockRequestWithHeadersAndBody();
    Mock expectedMock = generateMockWithHeadersAndBody(request);
    RequestHeader expectedRequestHeader = generateRequestHeader();
    ResponseHeader expectedResponseHeader = generateResponseHeader();
    RequestBodyType expectedRequestType = generateRequestBodyType();
    RequestBodiesForMock expectedRequestBody = generateRequestBodiesForMock();
    HttpMethod httpMethod = generateHttpMethod();
    ResponseContentType responseContentType = generateResponseContentType();
    EntityStatus entityStatus = generateDefaultEntityStatus();
    Optional<Mock> emptyMock = Optional.empty();
    lenient().when(mockRepository.findOneByMockName(anyString())).thenReturn(emptyMock);
    lenient().when(mockEntityStatusService.findByEntityStatus(anyString())).thenReturn(entityStatus);
    lenient().when(mockHttpMethodsRepository.findByMethod(anyString())).thenReturn(httpMethod);
    lenient().when(mockResponseContentTypesRepository.findByContentType(anyString())).thenReturn(responseContentType);
    lenient().when(mockRequestHeadersRepository.save(any(RequestHeader.class))).thenReturn(expectedRequestHeader);
    lenient().when(mockRequestBodyTypeRepository.findOneByRequestBodyType(any(String.class))).thenReturn(expectedRequestType);
    lenient().when(mockRequestBodiesForMockRepository.save(any(RequestBodiesForMock.class))).thenReturn(expectedRequestBody);
    lenient().when(mockResponseHeadersRepository.save(any(ResponseHeader.class))).thenReturn(expectedResponseHeader);
    lenient().when(mockRepository.save(any(Mock.class))).thenReturn(expectedMock);
    // Act
    Mock result = mockManagementService.createMock(request);
    // Assert
    assertEquals(expectedMock, result);
    verify(mockTextualResponseRepository, times(1)).save(any(TextualResponse.class));
    verify(mockBinaryResponseRepository, times(1)).save(any(BinaryResponse.class));
    verify(mockRepository, times(1)).save(any(Mock.class));
}
Also used : ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ProcessedMockRequest

use of com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest in project mimock by arbindo.

the class MockManagementServiceTest method shouldReturnMock_ForUpdateMock_WhenMockRequestIsValid.

@Test
void shouldReturnMock_ForUpdateMock_WhenMockRequestIsValid() {
    // Arrange
    ProcessedMockRequest request = createProcessedMockRequest();
    Optional<Mock> optionalMock = generateOptionalMock(request);
    assertTrue(optionalMock.isPresent());
    Mock expectedMock = optionalMock.get();
    HttpMethod httpMethod = optionalMock.get().getHttpMethod();
    ResponseContentType responseContentType = optionalMock.get().getResponseContentType();
    EntityStatus entityStatus = generateDefaultEntityStatus();
    Optional<Mock> emptyMock = Optional.empty();
    lenient().when(mockRepository.findOneByMockName(anyString())).thenReturn(emptyMock);
    lenient().when(mockRepository.findById(any(UUID.class))).thenReturn(optionalMock);
    lenient().when(mockEntityStatusService.getDefaultMockEntityStatus()).thenReturn(entityStatus);
    lenient().when(mockHttpMethodsRepository.findByMethod(anyString())).thenReturn(httpMethod);
    lenient().when(mockResponseContentTypesRepository.findByContentType(anyString())).thenReturn(responseContentType);
    lenient().when(mockRepository.save(any(Mock.class))).thenReturn(expectedMock);
    // Act
    Mock result = mockManagementService.updateMock(expectedMock.getId().toString(), request);
    // Assert
    assertNotNull(result);
    assertEquals(expectedMock.getId(), result.getId());
    assertEquals(expectedMock.getRoute(), result.getRoute());
    assertEquals(expectedMock.getHttpMethod().getMethod(), result.getHttpMethod().getMethod());
    assertEquals(expectedMock.getResponseContentType().getContentType(), result.getResponseContentType().getContentType());
    assertEquals(expectedMock.getStatusCode(), result.getStatusCode());
    assertEquals(expectedMock.getQueryParams(), result.getQueryParams());
    assertEquals(expectedMock.getTextualResponse(), result.getTextualResponse());
    assertEquals(expectedMock.getBinaryResponse(), result.getBinaryResponse());
    assertEquals(expectedMock.getEntityStatus().getStatus(), result.getEntityStatus().getStatus());
    assertEquals(expectedMock.getCreatedAt(), result.getCreatedAt());
    assertNotEquals(expectedMock.getUpdatedAt(), result.getUpdatedAt());
    verify(mockTextualResponseRepository, times(1)).save(any(TextualResponse.class));
    verify(mockBinaryResponseRepository, times(1)).save(any(BinaryResponse.class));
    verify(mockRepository, times(1)).save(any(Mock.class));
}
Also used : ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessedMockRequest (com.arbindo.mimock.manage.mimocks.models.request.ProcessedMockRequest)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 MockRequest (com.arbindo.mimock.manage.mimocks.models.request.MockRequest)1 UUID (java.util.UUID)1