use of com.arbindo.mimock.manage.mimocks.enums.Status in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpOk_FilteredListMocksApi_ReturnsEmpty.
@Test
void shouldReturnHttpOk_FilteredListMocksApi_ReturnsEmpty() throws Exception {
// Arrange
String route = UrlConfig.MOCKS_PATH + "/" + UrlConfig.MOCKS_FILTER;
String expectedContentType = "application/json";
Page<Mock> expectedMocks = new PageImpl<>(new ArrayList<>());
String expectedResponseBody = convertObjectToJsonString(expectedMocks);
lenient().when(mockManagementService.getAllActiveMocks(any(Pageable.class), any(Status.class))).thenReturn(expectedMocks);
// Act
MvcResult result = mockMvc.perform(get(route).param("status", "NONE")).andExpect(status().isOk()).andExpect(content().contentType(expectedContentType)).andReturn();
// Assert
assertEquals(expectedResponseBody, result.getResponse().getContentAsString());
}
use of com.arbindo.mimock.manage.mimocks.enums.Status in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_FilteredListMocksApi_WithoutStatusQueryParam.
@Test
void shouldReturnHttpBadRequest_FilteredListMocksApi_WithoutStatusQueryParam() throws Exception {
// Arrange
String route = UrlConfig.MOCKS_PATH + "/" + UrlConfig.MOCKS_FILTER;
Page<Mock> expectedMocks = new PageImpl<>(new ArrayList<>());
lenient().when(mockManagementService.getAllActiveMocks(any(Pageable.class), any(Status.class))).thenReturn(expectedMocks);
// Act
MvcResult result = mockMvc.perform(get(route)).andExpect(status().isBadRequest()).andReturn();
// Assert
assertEquals("", result.getResponse().getContentAsString());
}
use of com.arbindo.mimock.manage.mimocks.enums.Status in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForQueryParamsInRequest_ReturnsValidationErrors.
@Test
void shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForQueryParamsInRequest_ReturnsValidationErrors() throws Exception {
// Arrange
MockMultipartFile file = getMockMultipartFile();
MockRequest mockRequest = createMockRequestWithFile(file);
String route = UrlConfig.MOCKS_PATH;
// Modify the MockRequest.QueryParams with longer value
mockRequest.setQueryParams(generateRandomAlphabeticString(2000));
// 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("queryParams", mockRequest.getQueryParams()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("QueryParams can be maximum of 1024 characters"))).andReturn();
}
use of com.arbindo.mimock.manage.mimocks.enums.Status in project mimock by arbindo.
the class MockManagementControllerTest method shouldReturnHttpOk_FilteredListMocksApi_ReturnsNull.
@Test
void shouldReturnHttpOk_FilteredListMocksApi_ReturnsNull() throws Exception {
// Arrange
String route = UrlConfig.MOCKS_PATH + "/" + UrlConfig.MOCKS_FILTER;
lenient().when(mockManagementService.getAllActiveMocks(any(Pageable.class), any(Status.class))).thenReturn(null);
// Act
MvcResult result = mockMvc.perform(get(route).param("status", "NONE")).andExpect(status().isOk()).andReturn();
// Assert
assertEquals("", result.getResponse().getContentAsString());
}
Aggregations