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