Search in sources :

Example 1 with Mock

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

the class ResponseFactoryExecutorTest method shouldReturnImplementationForBinaryResponse.

@Test
void shouldReturnImplementationForBinaryResponse() {
    byte[] bytes = "Test string".getBytes(StandardCharsets.UTF_8);
    BinaryResponse binaryResponse = BinaryResponse.builder().responseFile(bytes).build();
    Mock binaryResponseMock = Mock.builder().textualResponse(null).binaryResponse(binaryResponse).build();
    ResponseFactory responseFactory = responseFactoryExecutor.responseFactory(binaryResponseMock);
    assertEquals(BinaryResponseImpl.class, responseFactory.getClass());
    assertEquals(binaryResponse.getResponseFile(), responseFactory.responseBody());
}
Also used : BinaryResponse(com.arbindo.mimock.entities.BinaryResponse) Mock(com.arbindo.mimock.entities.Mock) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Mock

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

the class ResponseFactoryExecutorTest method shouldReturnImplementationForTextualResponse.

@Test
void shouldReturnImplementationForTextualResponse() {
    TextualResponse textualResponse = TextualResponse.builder().responseBody("{'message': 'Hello World!'}").build();
    Mock textualResponseMock = Mock.builder().textualResponse(textualResponse).binaryResponse(null).build();
    ResponseFactory responseFactory = responseFactoryExecutor.responseFactory(textualResponseMock);
    assertEquals(TextualResponseImpl.class, responseFactory.getClass());
    assertEquals(textualResponse.getResponseBody(), responseFactory.responseBody());
}
Also used : TextualResponse(com.arbindo.mimock.entities.TextualResponse) Mock(com.arbindo.mimock.entities.Mock) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Mock

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

the class MockManagementController method createMock.

@Operation(summary = "Create Mock", description = "Creates a mock as per the given data in multi-part form.", tags = { "Mock Management" })
@PostMapping(consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<GenericResponseWrapper<Mock>> createMock(@Valid MockRequest request) {
    Mock mock = mockManagementService.createMock(RequestModelMapper.map(request));
    if (mock != null) {
        final URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path(UrlConfig.MOCKS_PATH + "/{mockId}").build().expand(mock.getId()).toUri();
        GenericResponseWrapper<Mock> genericResponseWrapper = getGenericResponseWrapper(HttpStatus.CREATED, Messages.createResourceSuccess(location.toString()), mock);
        return ResponseEntity.created(location).body(genericResponseWrapper);
    }
    GenericResponseWrapper<Mock> genericResponseWrapper = getGenericResponseWrapper(HttpStatus.BAD_REQUEST, Messages.CREATE_RESOURCE_FAILED, null);
    return ResponseEntity.badRequest().body(genericResponseWrapper);
}
Also used : URI(java.net.URI) Mock(com.arbindo.mimock.entities.Mock) Operation(io.swagger.v3.oas.annotations.Operation)

Example 4 with Mock

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

the class MockManagementController method updateMockById.

@Operation(summary = "Update Mock", description = "Updates mock for the given mockId using the data in multi-part form.", tags = { "Mock Management" })
@PutMapping(value = "{mockId}", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<GenericResponseWrapper<Mock>> updateMockById(@PathVariable String mockId, @Valid MockRequest request) {
    Mock updatedMock = mockManagementService.updateMock(mockId, RequestModelMapper.map(request));
    if (updatedMock != null) {
        GenericResponseWrapper<Mock> genericResponseWrapper = getGenericResponseWrapper(HttpStatus.OK, Messages.UPDATE_RESOURCE_SUCCESS, updatedMock);
        return ResponseEntity.ok(genericResponseWrapper);
    }
    GenericResponseWrapper<Mock> genericResponseWrapper = getGenericResponseWrapper(HttpStatus.BAD_REQUEST, Messages.UPDATE_RESOURCE_FAILED, null);
    return ResponseEntity.badRequest().body(genericResponseWrapper);
}
Also used : Mock(com.arbindo.mimock.entities.Mock) Operation(io.swagger.v3.oas.annotations.Operation)

Example 5 with Mock

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

the class ExportImportServiceImpl method writeData.

private void writeData(List<Mock> mockList, ICsvBeanWriter csvWriter) throws IOException {
    String[] nameMapping = getNameMappings();
    CellProcessor[] cellProcessors = getExportCellProcessors();
    for (Mock mock : mockList) {
        csvWriter.write(mock, nameMapping, cellProcessors);
    }
    log.log(Level.DEBUG, "CSV Data Write Completed!");
}
Also used : CellProcessor(org.supercsv.cellprocessor.ift.CellProcessor) Mock(com.arbindo.mimock.entities.Mock)

Aggregations

Mock (com.arbindo.mimock.entities.Mock)84 Test (org.junit.jupiter.api.Test)66 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)48 JsonMapper.convertObjectToJsonString (com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString)42 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)42 MvcResult (org.springframework.test.web.servlet.MvcResult)40 RandomDataGenerator.generateRandomAlphabeticString (com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString)38 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)24 DomainModelForMock (com.arbindo.mimock.generic.model.DomainModelForMock)10 MocksGenerator.deleteMock (com.arbindo.mimock.helpers.entities.MocksGenerator.deleteMock)10 Operation (io.swagger.v3.oas.annotations.Operation)10 TextualResponse (com.arbindo.mimock.entities.TextualResponse)8 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)8 ResponseContentType (com.arbindo.mimock.entities.ResponseContentType)6 Pageable (org.springframework.data.domain.Pageable)6 HttpStatus (org.springframework.http.HttpStatus)6 BinaryResponse (com.arbindo.mimock.entities.BinaryResponse)4 MocksGenerator.generateMock (com.arbindo.mimock.helpers.entities.MocksGenerator.generateMock)4 MockRequest (com.arbindo.mimock.manage.mimocks.models.request.MockRequest)4