use of com.arbindo.mimock.manage.mimocks.models.request.MockRequest in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForHttpMethodInRequest_ReturnsValidationErrors.
@ParameterizedTest
@NullSource
@EmptySource
void shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForHttpMethodInRequest_ReturnsValidationErrors(String testData) throws Exception {
// Arrange
MockMultipartFile file = getMockMultipartFile();
MockRequest mockRequest = createMockRequestWithFile(file);
// Modify the MockRequest.HttpMethod to check
mockRequest.setHttpMethod(testData);
String route = UrlConfig.MOCKS_PATH;
// Act and Assert
mockMvc.perform(multipart(route).file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("statusCode", String.valueOf(mockRequest.getStatusCode())).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("HttpMethod is required"))).andReturn();
}
use of com.arbindo.mimock.manage.mimocks.models.request.MockRequest in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForStatusCodeInRequest_ReturnsValidationErrors.
@Test
void shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForStatusCodeInRequest_ReturnsValidationErrors() throws Exception {
// Arrange
MockMultipartFile file = getMockMultipartFile();
MockRequest mockRequest = createMockRequestWithFile(file);
String route = UrlConfig.MOCKS_PATH;
// Act and Assert
mockMvc.perform(multipart(route).file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("statusCode"))).andReturn();
}
use of com.arbindo.mimock.manage.mimocks.models.request.MockRequest in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForRouteInRequest_ReturnsValidationErrors.
@ParameterizedTest
@NullSource
@EmptySource
void shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForRouteInRequest_ReturnsValidationErrors(String testData) throws Exception {
// Arrange
MockMultipartFile file = getMockMultipartFile();
MockRequest mockRequest = createMockRequestWithFile(file);
// Modify the MockRequest.Route to check
mockRequest.setRoute(testData);
String route = UrlConfig.MOCKS_PATH;
// Act and Assert
mockMvc.perform(multipart(route).file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("statusCode", String.valueOf(mockRequest.getStatusCode())).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("Route is required"))).andReturn();
}
use of com.arbindo.mimock.manage.mimocks.models.request.MockRequest in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_UpdateMockByIdApi_ReturnsNullMockData.
@Test
void shouldReturnHttpBadRequest_UpdateMockByIdApi_ReturnsNullMockData() throws Exception {
// Arrange
MockMultipartFile file = getMockMultipartFile();
MockRequest mockRequest = createMockRequestWithFile(file);
Mock mock = generateMock(mockRequest);
String route = UrlConfig.MOCKS_PATH + "/" + mock.getId();
lenient().when(mockManagementService.updateMock(anyString(), any(ProcessedMockRequest.class))).thenReturn(null);
GenericResponseWrapper<Mock> genericResponseWrapper = getGenericResponseWrapper(HttpStatus.BAD_REQUEST, Messages.UPDATE_RESOURCE_FAILED, null);
String expectedResponseBody = convertObjectToJsonString(genericResponseWrapper);
String expectedContentType = "application/json";
// Act
MockMultipartHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart(route);
builder.with(request -> {
request.setMethod("PUT");
return request;
});
MvcResult result = mockMvc.perform(builder.file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("statusCode", String.valueOf(mockRequest.getStatusCode())).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(content().contentType(expectedContentType)).andReturn();
// Assert
assertEquals(expectedResponseBody, result.getResponse().getContentAsString());
}
use of com.arbindo.mimock.manage.mimocks.models.request.MockRequest in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForDescriptionInRequest_ReturnsValidationErrors.
@Test
void shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForDescriptionInRequest_ReturnsValidationErrors() throws Exception {
// Arrange
MockMultipartFile file = getMockMultipartFile();
MockRequest mockRequest = createMockRequestWithFile(file);
// Modify the MockRequest.Description with empty value
mockRequest.setDescription("");
String route = UrlConfig.MOCKS_PATH;
// Act and Assert
mockMvc.perform(multipart(route).file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("statusCode", String.valueOf(mockRequest.getStatusCode())).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("Description should be at least 1-250 characters"))).andReturn();
// Modify the MockRequest.Description with longer value
mockRequest.setDescription(generateRandomAlphabeticString(300));
// Act and Assert
mockMvc.perform(multipart(route).file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("statusCode", String.valueOf(mockRequest.getStatusCode())).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("Description should be at least 1-250 characters"))).andReturn();
}
Aggregations