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