Search in sources :

Example 36 with ResponseContentType

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

the class ResponseContentTypesRepositoryTest method shouldReturnNullForInvalidMultipartType.

@ParameterizedTest
@ValueSource(strings = { "multipart/mixed", "multipart/alternative", "multipart/related", "multipart/form-data" })
void shouldReturnNullForInvalidMultipartType(String multiPartResponseType) {
    // Act
    ResponseContentType responseType = responseContentTypesRepository.findByContentType(multiPartResponseType);
    // Assert
    assertNull(responseType);
}
Also used : ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with ResponseContentType

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

the class ResponseContentTypesRepositoryTest method shouldReturnNullForInvalidApplicationType.

@ParameterizedTest
@ValueSource(strings = { "application/EDI-X12", "application/EDIFACT", "application/javascript", "application/xhtm,xml", "application/l,json", "application/excel", "application/x-www-form-urlencoded" })
void shouldReturnNullForInvalidApplicationType(String applicationResponseType) {
    // Act
    ResponseContentType responseType = responseContentTypesRepository.findByContentType(applicationResponseType);
    // Assert
    assertNull(responseType);
}
Also used : ResponseContentType(com.arbindo.mimock.entities.ResponseContentType) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with ResponseContentType

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

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 39 with ResponseContentType

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

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 40 with ResponseContentType

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

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)

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