Search in sources :

Example 1 with ResponseContentType

use of com.arbindo.mimock.entities.ResponseContentType in project mimock by arbindo.

the class DomainModelMapperTest method shouldReturnModelWithTextResponseFactory.

@Test
void shouldReturnModelWithTextResponseFactory() {
    ResponseContentType responseContentType = ResponseContentType.builder().contentType("application/json").build();
    TextualResponse textualResponse = TextualResponse.builder().responseBody("{'message': 'Hello World!'}").build();
    Mock testMock = Mock.builder().responseContentType(responseContentType).statusCode(200).textualResponse(textualResponse).binaryResponse(null).build();
    DomainModelForMock mappedModel = domainModelMapper.mappedModel(testMock);
    assertEquals("{'message': 'Hello World!'}", mappedModel.getResponseBody());
    assertEquals(200, mappedModel.getStatusCode());
    assertEquals("application/json", mappedModel.getResponseContentType());
    assertEquals(TypeOfResponse.TEXTUAL_RESPONSE, mappedModel.getTypeOfResponse());
}
Also used : DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) TextualResponse(com.arbindo.mimock.entities.TextualResponse) ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) Mock(com.arbindo.mimock.entities.Mock) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ResponseContentType

use of com.arbindo.mimock.entities.ResponseContentType in project mimock by arbindo.

the class DomainModelMapperTest method shouldReturnModelWithTextResponseFactoryWhenResponseHeaderIsNotNull.

@Test
void shouldReturnModelWithTextResponseFactoryWhenResponseHeaderIsNotNull() {
    ResponseContentType responseContentType = ResponseContentType.builder().contentType("application/json").build();
    TextualResponse textualResponse = TextualResponse.builder().responseBody("{'message': 'Hello World!'}").build();
    Mock testMock = Mock.builder().responseContentType(responseContentType).statusCode(200).textualResponse(textualResponse).responseHeaders(MocksGenerator.generateResponseHeader()).binaryResponse(null).build();
    DomainModelForMock mappedModel = domainModelMapper.mappedModel(testMock);
    assertEquals("{'message': 'Hello World!'}", mappedModel.getResponseBody());
    assertEquals(200, mappedModel.getStatusCode());
    assertEquals("application/json", mappedModel.getResponseContentType());
    assertEquals(TypeOfResponse.TEXTUAL_RESPONSE, mappedModel.getTypeOfResponse());
    assertNotNull(mappedModel.getResponseHeaders());
}
Also used : DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) TextualResponse(com.arbindo.mimock.entities.TextualResponse) ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) Mock(com.arbindo.mimock.entities.Mock) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ResponseContentType

use of com.arbindo.mimock.entities.ResponseContentType in project mimock by arbindo.

the class DomainModelMapperTest method shouldReturnModelWithBinaryResponseFactory.

@Test
void shouldReturnModelWithBinaryResponseFactory() {
    ResponseContentType responseContentType = ResponseContentType.builder().contentType("application/json").build();
    byte[] bytes = "Test string".getBytes(StandardCharsets.UTF_8);
    BinaryResponse binaryResponse = BinaryResponse.builder().responseFile(bytes).build();
    Mock testMock = Mock.builder().responseContentType(responseContentType).statusCode(200).textualResponse(null).binaryResponse(binaryResponse).build();
    DomainModelForMock mappedModel = domainModelMapper.mappedModel(testMock);
    assertEquals(bytes, mappedModel.getResponseBody());
    assertEquals(200, mappedModel.getStatusCode());
    assertEquals(TypeOfResponse.BINARY_RESPONSE, mappedModel.getTypeOfResponse());
    assertEquals("application/json", mappedModel.getResponseContentType());
}
Also used : BinaryResponse(com.arbindo.mimock.entities.BinaryResponse) DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) DomainModelForMock(com.arbindo.mimock.generic.model.DomainModelForMock) Mock(com.arbindo.mimock.entities.Mock) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ResponseContentType

use of com.arbindo.mimock.entities.ResponseContentType in project mimock by arbindo.

the class GetStaticRecordsControllerTest method listAllSupportedResponseContentTypes.

@Test
void listAllSupportedResponseContentTypes() throws Exception {
    String route = UrlConfig.STATIC_RECORDS_PATH + UrlConfig.RESPONSE_CONTENT_TYPE_STATIC_RECORDS;
    List<ResponseContentType> contentTypesFromDB = new ArrayList<>();
    ResponseContentType jsonType = ResponseContentType.builder().contentType("application/json").build();
    ResponseContentType xmlType = ResponseContentType.builder().contentType("application/xml").build();
    contentTypesFromDB.add(jsonType);
    contentTypesFromDB.add(xmlType);
    lenient().when(mockGetStaticRecordsService.listAllSupportedResponseContentTypes()).thenReturn(contentTypesFromDB);
    MvcResult result = mockMvc.perform(get(route).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andReturn();
    String response = result.getResponse().getContentAsString();
    assertNotNull(response);
    ObjectMapper objectMapper = new ObjectMapper();
    List<ResponseContentType> contentTypes = Arrays.asList(objectMapper.readValue(response, ResponseContentType[].class));
    assertNotNull(contentTypes);
    assertFalse(contentTypes.isEmpty());
    assertEquals("application/json", contentTypes.get(0).getContentType());
    assertEquals("application/xml", contentTypes.get(1).getContentType());
}
Also used : ArrayList(java.util.ArrayList) ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) MvcResult(org.springframework.test.web.servlet.MvcResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 5 with ResponseContentType

use of com.arbindo.mimock.entities.ResponseContentType in project mimock by arbindo.

the class ResponseContentTypesRepositoryTest method shouldReturnNullForInvalidTextType.

@ParameterizedTest
@ValueSource(strings = { "text/xml" })
void shouldReturnNullForInvalidTextType(String textResponseType) {
    // Act
    ResponseContentType responseType = responseContentTypesRepository.findByContentType(textResponseType);
    // Assert
    assertNull(responseType);
}
Also used : ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ResponseContentType (com.arbindo.mimock.entities.ResponseContentType)40 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Mock (com.arbindo.mimock.entities.Mock)6 DomainModelForMock (com.arbindo.mimock.generic.model.DomainModelForMock)6 TextualResponse (com.arbindo.mimock.entities.TextualResponse)4 BinaryResponse (com.arbindo.mimock.entities.BinaryResponse)2 ArrayList (java.util.ArrayList)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 MvcResult (org.springframework.test.web.servlet.MvcResult)1