From 1da8d6d4faaa0e417b6d697c51aff6ed6636c640 Mon Sep 17 00:00:00 2001 From: Subhrodip Mohanta Date: Mon, 21 Nov 2022 17:58:31 +0530 Subject: [PATCH] Test Refactor --- .../lunchbooking/config/AsyncConfigTest.java | 34 +- .../controllers/BookingControllerTest.java | 200 ++-- .../GlobalExceptionHandlerControllerTest.java | 527 +++++---- .../controllers/LoginControllerTest.java | 415 +++---- .../controllers/MealsControllerTest.java | 428 ++++--- .../entities/AvailableBookingsTest.java | 18 + .../lunchbooking/entities/BaseEntityTest.java | 18 + .../lunchbooking/entities/BookingsTest.java | 18 + .../entities/MealOptionsTest.java | 18 + .../lunchbooking/entities/MealsTest.java | 18 + .../lunchbooking/entities/OtpEntityTest.java | 18 + .../entities/UserMetadataTest.java | 18 + .../entities/security/PermissionsTest.java | 18 + .../entities/security/RolesTest.java | 18 + .../entities/security/UserLoginTest.java | 18 + .../lunchbooking/models/ErrorDetailsTest.java | 33 +- .../JwtAuthenticationEntryPointTest.java | 120 +- .../lunchbooking/security/JwtConfigTest.java | 91 +- .../lunchbooking/security/JwtHelperTest.java | 1011 +++++++++-------- .../security/JwtRequestFilterTest.java | 486 ++++---- .../security/LunchBookingPrincipalTest.java | 204 ++-- .../security/WebSecurityConfigTest.java | 87 +- .../util/MailComposeUtilTest.java | 4 + 23 files changed, 2100 insertions(+), 1720 deletions(-) diff --git a/src/test/java/xyz/subho/lunchbooking/config/AsyncConfigTest.java b/src/test/java/xyz/subho/lunchbooking/config/AsyncConfigTest.java index 73b0494..362cb6d 100644 --- a/src/test/java/xyz/subho/lunchbooking/config/AsyncConfigTest.java +++ b/src/test/java/xyz/subho/lunchbooking/config/AsyncConfigTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.config; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -12,15 +30,11 @@ @ContextConfiguration(classes = {AsyncConfig.class}) @ExtendWith(SpringExtension.class) class AsyncConfigTest { - @Autowired - private AsyncConfig asyncConfig; + @Autowired private AsyncConfig asyncConfig; - /** - * Method under test: {@link AsyncConfig#taskExecutor()} - */ - @Test - void testTaskExecutor() { - assertTrue(asyncConfig.taskExecutor() instanceof ThreadPoolTaskExecutor); - } + /** Method under test: {@link AsyncConfig#taskExecutor()} */ + @Test + void testTaskExecutor() { + assertTrue(asyncConfig.taskExecutor() instanceof ThreadPoolTaskExecutor); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/controllers/BookingControllerTest.java b/src/test/java/xyz/subho/lunchbooking/controllers/BookingControllerTest.java index 8ecfd4a..484ae8b 100644 --- a/src/test/java/xyz/subho/lunchbooking/controllers/BookingControllerTest.java +++ b/src/test/java/xyz/subho/lunchbooking/controllers/BookingControllerTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.controllers; import static org.mockito.Mockito.anyLong; @@ -5,7 +23,6 @@ import java.security.Principal; import java.time.LocalDate; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -24,109 +41,96 @@ @ContextConfiguration(classes = {BookingController.class}) @ExtendWith(SpringExtension.class) class BookingControllerTest { - @Autowired - private BookingController bookingController; + @Autowired private BookingController bookingController; - @MockBean - private BookingService bookingService; + @MockBean private BookingService bookingService; - /** - * Method under test: {@link BookingController#availBooking(long)} - */ - @Test - void testAvailBooking() throws Exception { - when(bookingService.availBooking(anyLong())) - .thenReturn(new BookingResponseModel(123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L)); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/booking/avail/{bookingId}", 123L); - MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":123,\"firstName\":\"Jane\",\"lastName\":\"Doe\",\"date\":[1970,1,2],\"mealOption\":\"Meal Option\",\"mealOptionId" - + "\":123,\"availedAt\":1}")); - } + /** Method under test: {@link BookingController#availBooking(long)} */ + @Test + void testAvailBooking() throws Exception { + when(bookingService.availBooking(anyLong())) + .thenReturn( + new BookingResponseModel( + 123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L)); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.put("/booking/avail/{bookingId}", 123L); + MockMvcBuilders.standaloneSetup(bookingController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":123,\"firstName\":\"Jane\",\"lastName\":\"Doe\",\"date\":[1970,1,2],\"mealOption\":\"Meal Option\",\"mealOptionId" + + "\":123,\"availedAt\":1}")); + } - /** - * Method under test: {@link BookingController#availBooking(long)} - */ - @Test - void testAvailBooking2() throws Exception { - when(bookingService.availBooking(anyLong())) - .thenReturn(new BookingResponseModel(123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L)); - SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders - .formLogin(); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); - } + /** Method under test: {@link BookingController#availBooking(long)} */ + @Test + void testAvailBooking2() throws Exception { + when(bookingService.availBooking(anyLong())) + .thenReturn( + new BookingResponseModel( + 123L, "Jane", "Doe", LocalDate.ofEpochDay(1L), "Meal Option", 123L, 1L)); + SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = + SecurityMockMvcRequestBuilders.formLogin(); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); + } - /** - * Method under test: {@link BookingController#cancelBooking(long, Principal)} - */ - @Test - void testCancelBooking() throws Exception { - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/booking/{bookingId}", - "Uri Variables", "Uri Variables"); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } + /** Method under test: {@link BookingController#cancelBooking(long, Principal)} */ + @Test + void testCancelBooking() throws Exception { + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.delete("/booking/{bookingId}", "Uri Variables", "Uri Variables"); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } - /** - * Method under test: {@link BookingController#createBooking(long, Principal)} - */ - @Test - void testCreateBooking() throws Exception { - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/booking/create/{mealOptionId}", - "Uri Variables", "Uri Variables"); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } + /** Method under test: {@link BookingController#createBooking(long, Principal)} */ + @Test + void testCreateBooking() throws Exception { + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.post( + "/booking/create/{mealOptionId}", "Uri Variables", "Uri Variables"); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } - /** - * Method under test: {@link BookingController#createBookingFromAvailableOptions(long, Principal)} - */ - @Test - void testCreateBookingFromAvailableOptions() throws Exception { - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/booking/pickup/{mealOptionId}", - "Uri Variables", "Uri Variables"); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } + /** + * Method under test: {@link BookingController#createBookingFromAvailableOptions(long, Principal)} + */ + @Test + void testCreateBookingFromAvailableOptions() throws Exception { + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.put( + "/booking/pickup/{mealOptionId}", "Uri Variables", "Uri Variables"); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } - /** - * Method under test: {@link BookingController#getAllBookingsForDate(LocalDate)} - */ - @Test - void testGetAllBookingsForDate() throws Exception { - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/booking/{date}", - LocalDate.ofEpochDay(1L)); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } + /** Method under test: {@link BookingController#getAllBookingsForDate(LocalDate)} */ + @Test + void testGetAllBookingsForDate() throws Exception { + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.get("/booking/{date}", LocalDate.ofEpochDay(1L)); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } - /** - * Method under test: {@link BookingController#getTodayBookingForUser(Principal)} - */ - @Test - void testGetTodayBookingForUser() throws Exception { - SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders - .formLogin(); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(bookingController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); - } + /** Method under test: {@link BookingController#getTodayBookingForUser(Principal)} */ + @Test + void testGetTodayBookingForUser() throws Exception { + SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = + SecurityMockMvcRequestBuilders.formLogin(); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(bookingController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/controllers/GlobalExceptionHandlerControllerTest.java b/src/test/java/xyz/subho/lunchbooking/controllers/GlobalExceptionHandlerControllerTest.java index be12a1a..22fdbdd 100644 --- a/src/test/java/xyz/subho/lunchbooking/controllers/GlobalExceptionHandlerControllerTest.java +++ b/src/test/java/xyz/subho/lunchbooking/controllers/GlobalExceptionHandlerControllerTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.controllers; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -13,266 +31,303 @@ import xyz.subho.lunchbooking.models.ErrorDetails; class GlobalExceptionHandlerControllerTest { - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsBadRequest(RuntimeException)} - */ - @Test - void testHandleAsBadRequest() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsBadRequestResult = globalExceptionHandlerController - .handleAsBadRequest(new RuntimeException()); - assertTrue(actualHandleAsBadRequestResult.hasBody()); - assertTrue(actualHandleAsBadRequestResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.BAD_REQUEST, actualHandleAsBadRequestResult.getStatusCode()); - assertNull(actualHandleAsBadRequestResult.getBody().getMessage()); - } + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsBadRequest(RuntimeException)} + */ + @Test + void testHandleAsBadRequest() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsBadRequestResult = + globalExceptionHandlerController.handleAsBadRequest(new RuntimeException()); + assertTrue(actualHandleAsBadRequestResult.hasBody()); + assertTrue(actualHandleAsBadRequestResult.getHeaders().isEmpty()); + assertEquals(HttpStatus.BAD_REQUEST, actualHandleAsBadRequestResult.getStatusCode()); + assertNull(actualHandleAsBadRequestResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsBadRequest(RuntimeException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsBadRequest2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsBadRequest(GlobalExceptionHandlerController.java:46) + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsBadRequest(RuntimeException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsBadRequest2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" + // because "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsBadRequest(GlobalExceptionHandlerController.java:46) - (new GlobalExceptionHandlerController()).handleAsBadRequest(null); - } + (new GlobalExceptionHandlerController()).handleAsBadRequest(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsAccessDenied(RuntimeException)} - */ - @Test - void testHandleAsAccessDenied() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsAccessDeniedResult = globalExceptionHandlerController - .handleAsAccessDenied(new RuntimeException()); - assertTrue(actualHandleAsAccessDeniedResult.hasBody()); - assertTrue(actualHandleAsAccessDeniedResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.FORBIDDEN, actualHandleAsAccessDeniedResult.getStatusCode()); - assertNull(actualHandleAsAccessDeniedResult.getBody().getMessage()); - } + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsAccessDenied(RuntimeException)} + */ + @Test + void testHandleAsAccessDenied() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsAccessDeniedResult = + globalExceptionHandlerController.handleAsAccessDenied(new RuntimeException()); + assertTrue(actualHandleAsAccessDeniedResult.hasBody()); + assertTrue(actualHandleAsAccessDeniedResult.getHeaders().isEmpty()); + assertEquals(HttpStatus.FORBIDDEN, actualHandleAsAccessDeniedResult.getStatusCode()); + assertNull(actualHandleAsAccessDeniedResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsAccessDenied(RuntimeException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsAccessDenied2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsAccessDenied(GlobalExceptionHandlerController.java:55) + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsAccessDenied(RuntimeException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsAccessDenied2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" + // because "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsAccessDenied(GlobalExceptionHandlerController.java:55) - (new GlobalExceptionHandlerController()).handleAsAccessDenied(null); - } + (new GlobalExceptionHandlerController()).handleAsAccessDenied(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsNotFound(RuntimeException)} - */ - @Test - void testHandleAsNotFound() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsNotFoundResult = globalExceptionHandlerController - .handleAsNotFound(new RuntimeException()); - assertTrue(actualHandleAsNotFoundResult.hasBody()); - assertTrue(actualHandleAsNotFoundResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.NOT_FOUND, actualHandleAsNotFoundResult.getStatusCode()); - assertNull(actualHandleAsNotFoundResult.getBody().getMessage()); - } + /** + * Method under test: {@link GlobalExceptionHandlerController#handleAsNotFound(RuntimeException)} + */ + @Test + void testHandleAsNotFound() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsNotFoundResult = + globalExceptionHandlerController.handleAsNotFound(new RuntimeException()); + assertTrue(actualHandleAsNotFoundResult.hasBody()); + assertTrue(actualHandleAsNotFoundResult.getHeaders().isEmpty()); + assertEquals(HttpStatus.NOT_FOUND, actualHandleAsNotFoundResult.getStatusCode()); + assertNull(actualHandleAsNotFoundResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsNotFound(RuntimeException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsNotFound2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsNotFound(GlobalExceptionHandlerController.java:71) + /** + * Method under test: {@link GlobalExceptionHandlerController#handleAsNotFound(RuntimeException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsNotFound2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" + // because "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsNotFound(GlobalExceptionHandlerController.java:71) - (new GlobalExceptionHandlerController()).handleAsNotFound(null); - } + (new GlobalExceptionHandlerController()).handleAsNotFound(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsBadUnauthorized(RuntimeException)} - */ - @Test - void testHandleAsBadUnauthorized() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsBadUnauthorizedResult = globalExceptionHandlerController - .handleAsBadUnauthorized(new RuntimeException()); - assertTrue(actualHandleAsBadUnauthorizedResult.hasBody()); - assertTrue(actualHandleAsBadUnauthorizedResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.UNAUTHORIZED, actualHandleAsBadUnauthorizedResult.getStatusCode()); - assertNull(actualHandleAsBadUnauthorizedResult.getBody().getMessage()); - } + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsBadUnauthorized(RuntimeException)} + */ + @Test + void testHandleAsBadUnauthorized() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsBadUnauthorizedResult = + globalExceptionHandlerController.handleAsBadUnauthorized(new RuntimeException()); + assertTrue(actualHandleAsBadUnauthorizedResult.hasBody()); + assertTrue(actualHandleAsBadUnauthorizedResult.getHeaders().isEmpty()); + assertEquals(HttpStatus.UNAUTHORIZED, actualHandleAsBadUnauthorizedResult.getStatusCode()); + assertNull(actualHandleAsBadUnauthorizedResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsBadUnauthorized(RuntimeException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsBadUnauthorized2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsBadUnauthorized(GlobalExceptionHandlerController.java:88) + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsBadUnauthorized(RuntimeException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsBadUnauthorized2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.RuntimeException.getMessage()" + // because "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsBadUnauthorized(GlobalExceptionHandlerController.java:88) - (new GlobalExceptionHandlerController()).handleAsBadUnauthorized(null); - } + (new GlobalExceptionHandlerController()).handleAsBadUnauthorized(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsMethodArgumentNotValid(MethodArgumentNotValidException)} - */ - @Test - void testHandleAsMethodArgumentNotValid() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsMethodArgumentNotValidResult = globalExceptionHandlerController - .handleAsMethodArgumentNotValid( - new MethodArgumentNotValidException(null, new BindException("Target", "Object Name"))); - assertTrue(actualHandleAsMethodArgumentNotValidResult.hasBody()); - assertTrue(actualHandleAsMethodArgumentNotValidResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, actualHandleAsMethodArgumentNotValidResult.getStatusCode()); - assertEquals("{}", actualHandleAsMethodArgumentNotValidResult.getBody().getMessage()); - } + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsMethodArgumentNotValid(MethodArgumentNotValidException)} + */ + @Test + void testHandleAsMethodArgumentNotValid() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsMethodArgumentNotValidResult = + globalExceptionHandlerController.handleAsMethodArgumentNotValid( + new MethodArgumentNotValidException(null, new BindException("Target", "Object Name"))); + assertTrue(actualHandleAsMethodArgumentNotValidResult.hasBody()); + assertTrue(actualHandleAsMethodArgumentNotValidResult.getHeaders().isEmpty()); + assertEquals( + HttpStatus.UNPROCESSABLE_ENTITY, + actualHandleAsMethodArgumentNotValidResult.getStatusCode()); + assertEquals("{}", actualHandleAsMethodArgumentNotValidResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsMethodArgumentNotValid(MethodArgumentNotValidException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsMethodArgumentNotValid2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "org.springframework.web.bind.MethodArgumentNotValidException.getBindingResult()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsMethodArgumentNotValid(GlobalExceptionHandlerController.java:97) + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsMethodArgumentNotValid(MethodArgumentNotValidException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsMethodArgumentNotValid2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "org.springframework.web.bind.MethodArgumentNotValidException.getBindingResult()" because + // "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsMethodArgumentNotValid(GlobalExceptionHandlerController.java:97) - (new GlobalExceptionHandlerController()).handleAsMethodArgumentNotValid(null); - } + (new GlobalExceptionHandlerController()).handleAsMethodArgumentNotValid(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsUnpronounceableEntity(Exception)} - */ - @Test - void testHandleAsUnpronounceableEntity() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsUnpronounceableEntityResult = globalExceptionHandlerController - .handleAsUnpronounceableEntity(new Exception()); - assertTrue(actualHandleAsUnpronounceableEntityResult.hasBody()); - assertTrue(actualHandleAsUnpronounceableEntityResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, actualHandleAsUnpronounceableEntityResult.getStatusCode()); - assertNull(actualHandleAsUnpronounceableEntityResult.getBody().getMessage()); - } + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsUnpronounceableEntity(Exception)} + */ + @Test + void testHandleAsUnpronounceableEntity() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsUnpronounceableEntityResult = + globalExceptionHandlerController.handleAsUnpronounceableEntity(new Exception()); + assertTrue(actualHandleAsUnpronounceableEntityResult.hasBody()); + assertTrue(actualHandleAsUnpronounceableEntityResult.getHeaders().isEmpty()); + assertEquals( + HttpStatus.UNPROCESSABLE_ENTITY, actualHandleAsUnpronounceableEntityResult.getStatusCode()); + assertNull(actualHandleAsUnpronounceableEntityResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsUnpronounceableEntity(Exception)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsUnpronounceableEntity2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsUnpronounceableEntity(GlobalExceptionHandlerController.java:108) + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsUnpronounceableEntity(Exception)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsUnpronounceableEntity2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because + // "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsUnpronounceableEntity(GlobalExceptionHandlerController.java:108) - (new GlobalExceptionHandlerController()).handleAsUnpronounceableEntity(null); - } + (new GlobalExceptionHandlerController()).handleAsUnpronounceableEntity(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsMediaTypeNotSupported(Exception)} - */ - @Test - void testHandleAsMediaTypeNotSupported() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsMediaTypeNotSupportedResult = globalExceptionHandlerController - .handleAsMediaTypeNotSupported(new Exception()); - assertTrue(actualHandleAsMediaTypeNotSupportedResult.hasBody()); - assertTrue(actualHandleAsMediaTypeNotSupportedResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.UNSUPPORTED_MEDIA_TYPE, actualHandleAsMediaTypeNotSupportedResult.getStatusCode()); - assertNull(actualHandleAsMediaTypeNotSupportedResult.getBody().getMessage()); - } + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsMediaTypeNotSupported(Exception)} + */ + @Test + void testHandleAsMediaTypeNotSupported() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsMediaTypeNotSupportedResult = + globalExceptionHandlerController.handleAsMediaTypeNotSupported(new Exception()); + assertTrue(actualHandleAsMediaTypeNotSupportedResult.hasBody()); + assertTrue(actualHandleAsMediaTypeNotSupportedResult.getHeaders().isEmpty()); + assertEquals( + HttpStatus.UNSUPPORTED_MEDIA_TYPE, + actualHandleAsMediaTypeNotSupportedResult.getStatusCode()); + assertNull(actualHandleAsMediaTypeNotSupportedResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsMediaTypeNotSupported(Exception)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsMediaTypeNotSupported2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsMediaTypeNotSupported(GlobalExceptionHandlerController.java:115) + /** + * Method under test: {@link + * GlobalExceptionHandlerController#handleAsMediaTypeNotSupported(Exception)} + */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsMediaTypeNotSupported2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because + // "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsMediaTypeNotSupported(GlobalExceptionHandlerController.java:115) - (new GlobalExceptionHandlerController()).handleAsMediaTypeNotSupported(null); - } + (new GlobalExceptionHandlerController()).handleAsMediaTypeNotSupported(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsConflict(Exception)} - */ - @Test - void testHandleAsConflict() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleAsConflictResult = globalExceptionHandlerController - .handleAsConflict(new Exception()); - assertTrue(actualHandleAsConflictResult.hasBody()); - assertTrue(actualHandleAsConflictResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.CONFLICT, actualHandleAsConflictResult.getStatusCode()); - assertNull(actualHandleAsConflictResult.getBody().getMessage()); - } + /** Method under test: {@link GlobalExceptionHandlerController#handleAsConflict(Exception)} */ + @Test + void testHandleAsConflict() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleAsConflictResult = + globalExceptionHandlerController.handleAsConflict(new Exception()); + assertTrue(actualHandleAsConflictResult.hasBody()); + assertTrue(actualHandleAsConflictResult.getHeaders().isEmpty()); + assertEquals(HttpStatus.CONFLICT, actualHandleAsConflictResult.getStatusCode()); + assertNull(actualHandleAsConflictResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleAsConflict(Exception)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleAsConflict2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsConflict(GlobalExceptionHandlerController.java:128) + /** Method under test: {@link GlobalExceptionHandlerController#handleAsConflict(Exception)} */ + @Test + @Disabled("TODO: Complete this test") + void testHandleAsConflict2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because + // "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleAsConflict(GlobalExceptionHandlerController.java:128) - (new GlobalExceptionHandlerController()).handleAsConflict(null); - } + (new GlobalExceptionHandlerController()).handleAsConflict(null); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleEverythingElse(Exception)} - */ - @Test - void testHandleEverythingElse() { - GlobalExceptionHandlerController globalExceptionHandlerController = new GlobalExceptionHandlerController(); - ResponseEntity actualHandleEverythingElseResult = globalExceptionHandlerController - .handleEverythingElse(new Exception()); - assertTrue(actualHandleEverythingElseResult.hasBody()); - assertTrue(actualHandleEverythingElseResult.getHeaders().isEmpty()); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, actualHandleEverythingElseResult.getStatusCode()); - assertNull(actualHandleEverythingElseResult.getBody().getMessage()); - } + /** Method under test: {@link GlobalExceptionHandlerController#handleEverythingElse(Exception)} */ + @Test + void testHandleEverythingElse() { + GlobalExceptionHandlerController globalExceptionHandlerController = + new GlobalExceptionHandlerController(); + ResponseEntity actualHandleEverythingElseResult = + globalExceptionHandlerController.handleEverythingElse(new Exception()); + assertTrue(actualHandleEverythingElseResult.hasBody()); + assertTrue(actualHandleEverythingElseResult.getHeaders().isEmpty()); + assertEquals( + HttpStatus.INTERNAL_SERVER_ERROR, actualHandleEverythingElseResult.getStatusCode()); + assertNull(actualHandleEverythingElseResult.getBody().getMessage()); + } - /** - * Method under test: {@link GlobalExceptionHandlerController#handleEverythingElse(Exception)} - */ - @Test - @Disabled("TODO: Complete this test") - void testHandleEverythingElse2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because "ex" is null - // at xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleEverythingElse(GlobalExceptionHandlerController.java:135) + /** Method under test: {@link GlobalExceptionHandlerController#handleEverythingElse(Exception)} */ + @Test + @Disabled("TODO: Complete this test") + void testHandleEverythingElse2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.Exception.getMessage()" because + // "ex" is null + // at + // xyz.subho.lunchbooking.controllers.GlobalExceptionHandlerController.handleEverythingElse(GlobalExceptionHandlerController.java:135) - (new GlobalExceptionHandlerController()).handleEverythingElse(null); - } + (new GlobalExceptionHandlerController()).handleEverythingElse(null); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/controllers/LoginControllerTest.java b/src/test/java/xyz/subho/lunchbooking/controllers/LoginControllerTest.java index d75ebf0..869b4ba 100644 --- a/src/test/java/xyz/subho/lunchbooking/controllers/LoginControllerTest.java +++ b/src/test/java/xyz/subho/lunchbooking/controllers/LoginControllerTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.controllers; import static org.mockito.Mockito.any; @@ -5,9 +23,7 @@ import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; - import java.security.Principal; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -33,207 +49,196 @@ @ContextConfiguration(classes = {LoginController.class}) @ExtendWith(SpringExtension.class) class LoginControllerTest { - @Autowired - private LoginController loginController; - - @MockBean - private LoginService loginService; - - /** - * Method under test: {@link LoginController#checkPhoneExist(String)} - */ - @Test - void testCheckPhoneExist() throws Exception { - when(loginService.checkPhoneExists((String) any())).thenReturn(true); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/login/check/phone/{phone}", - "4105551212"); - MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("{\"found\":true}")); - } - - /** - * Method under test: {@link LoginController#resendOtp(OtpModel)} - */ - @Test - void testResendOtp() throws Exception { - when(loginService.resendOtp(anyLong())).thenReturn(new OtpModel(1L)); - MockHttpServletRequestBuilder contentTypeResult = MockMvcRequestBuilders.post("/login/otp/resend") - .contentType(MediaType.APPLICATION_JSON); - - ObjectMapper objectMapper = new ObjectMapper(); - MockHttpServletRequestBuilder requestBuilder = contentTypeResult - .content(objectMapper.writeValueAsString(new OtpModel(1L))); - MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("{\"salt\":1}")); - } - - /** - * Method under test: {@link LoginController#checkPhoneExist(String)} - */ - @Test - void testCheckPhoneExist2() throws Exception { - when(loginService.checkPhoneExists((String) any())).thenReturn(true); - SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders - .formLogin(); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } - - /** - * Method under test: {@link LoginController#checkUsernameExist(String)} - */ - @Test - void testCheckUsernameExist() throws Exception { - when(loginService.checkUserNameExists((String) any())).thenReturn(true); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/login/check/username/{username}", - "janedoe"); - MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("{\"found\":true}")); - } - - /** - * Method under test: {@link LoginController#forgetPasswordOtpRequest(ForgetPasswordUpdateRequestModel)} - */ - @Test - void testForgetPasswordOtpRequest() throws Exception { - when(loginService.createOtp((String) any())).thenReturn(new OtpModel(1L)); - MockHttpServletRequestBuilder contentTypeResult = MockMvcRequestBuilders.post("/login/forget") - .contentType(MediaType.APPLICATION_JSON); - - ObjectMapper objectMapper = new ObjectMapper(); - MockHttpServletRequestBuilder requestBuilder = contentTypeResult - .content(objectMapper.writeValueAsString(new ForgetPasswordUpdateRequestModel("janedoe"))); - MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("{\"salt\":1}")); - } - - /** - * Method under test: {@link LoginController#forgetPasswordOtpRequest(ForgetPasswordUpdateRequestModel)} - */ - @Test - void testForgetPasswordOtpRequest2() throws Exception { - when(loginService.createOtp((String) any())).thenReturn(new OtpModel(1L)); - MockHttpServletRequestBuilder contentTypeResult = MockMvcRequestBuilders.post("/login/forget") - .contentType(MediaType.APPLICATION_JSON); - - ObjectMapper objectMapper = new ObjectMapper(); - MockHttpServletRequestBuilder requestBuilder = contentTypeResult - .content(objectMapper.writeValueAsString(new ForgetPasswordUpdateRequestModel(""))); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } - - /** - * Method under test: {@link LoginController#loginUser(UserLoginRequestModel)} - */ - @Test - void testLoginUser() throws Exception { - UserLoginRequestModel userLoginRequestModel = new UserLoginRequestModel(); - userLoginRequestModel.setPassword("iloveyou"); - userLoginRequestModel.setUsername("janedoe"); - String content = (new ObjectMapper()).writeValueAsString(userLoginRequestModel); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/login") - .contentType(MediaType.APPLICATION_JSON) - .content(content); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } - - /** - * Method under test: {@link LoginController#registerNewPassword(NewPasswordRequest, Principal)} - */ - @Test - void testRegisterNewPassword() throws Exception { - MockHttpServletRequestBuilder postResult = MockMvcRequestBuilders.post("/login/forget/new"); - postResult.characterEncoding("Encoding"); - MockHttpServletRequestBuilder contentTypeResult = postResult.contentType(MediaType.APPLICATION_JSON); - - ObjectMapper objectMapper = new ObjectMapper(); - MockHttpServletRequestBuilder requestBuilder = contentTypeResult - .content(objectMapper.writeValueAsString(new NewPasswordRequest("iloveyou"))); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(415)); - } - - /** - * Method under test: {@link LoginController#registerUser(UserRegistrationModel)} - */ - @Test - void testRegisterUser() throws Exception { - UserRegistrationModel userRegistrationModel = new UserRegistrationModel(); - userRegistrationModel.setEmailId("42"); - userRegistrationModel.setFirstName("Jane"); - userRegistrationModel.setLastName("Doe"); - userRegistrationModel.setMobile("Mobile"); - userRegistrationModel.setPassword("iloveyou"); - String content = (new ObjectMapper()).writeValueAsString(userRegistrationModel); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/login/register") - .contentType(MediaType.APPLICATION_JSON) - .content(content); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } - - /** - * Method under test: {@link LoginController#userChangePassword(UserChangePasswordRequestModel, Principal)} - */ - @Test - void testUserChangePassword() throws Exception { - MockHttpServletRequestBuilder postResult = MockMvcRequestBuilders.post("/login/passwd"); - postResult.characterEncoding("Encoding"); - MockHttpServletRequestBuilder contentTypeResult = postResult.contentType(MediaType.APPLICATION_JSON); - - ObjectMapper objectMapper = new ObjectMapper(); - MockHttpServletRequestBuilder requestBuilder = contentTypeResult - .content(objectMapper.writeValueAsString(new UserChangePasswordRequestModel("iloveyou", "2020-03-01"))); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(415)); - } - - /** - * Method under test: {@link LoginController#validateOtp(OtpRequestModel, boolean)} - */ - @Test - void testValidateOtp() throws Exception { - MockHttpServletRequestBuilder contentTypeResult = MockMvcRequestBuilders.put("/login/otp/validate") - .header("x-otp-validate-forget", true) - .contentType(MediaType.APPLICATION_JSON); - - ObjectMapper objectMapper = new ObjectMapper(); - MockHttpServletRequestBuilder requestBuilder = contentTypeResult - .content(objectMapper.writeValueAsString(new OtpRequestModel(1L, 1))); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(loginController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } + @Autowired private LoginController loginController; + + @MockBean private LoginService loginService; + + /** Method under test: {@link LoginController#checkPhoneExist(String)} */ + @Test + void testCheckPhoneExist() throws Exception { + when(loginService.checkPhoneExists((String) any())).thenReturn(true); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.post("/login/check/phone/{phone}", "4105551212"); + MockMvcBuilders.standaloneSetup(loginController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("{\"found\":true}")); + } + + /** Method under test: {@link LoginController#resendOtp(OtpModel)} */ + @Test + void testResendOtp() throws Exception { + when(loginService.resendOtp(anyLong())).thenReturn(new OtpModel(1L)); + MockHttpServletRequestBuilder contentTypeResult = + MockMvcRequestBuilders.post("/login/otp/resend").contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = + contentTypeResult.content(objectMapper.writeValueAsString(new OtpModel(1L))); + MockMvcBuilders.standaloneSetup(loginController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("{\"salt\":1}")); + } + + /** Method under test: {@link LoginController#checkPhoneExist(String)} */ + @Test + void testCheckPhoneExist2() throws Exception { + when(loginService.checkPhoneExists((String) any())).thenReturn(true); + SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = + SecurityMockMvcRequestBuilders.formLogin(); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } + + /** Method under test: {@link LoginController#checkUsernameExist(String)} */ + @Test + void testCheckUsernameExist() throws Exception { + when(loginService.checkUserNameExists((String) any())).thenReturn(true); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.post("/login/check/username/{username}", "janedoe"); + MockMvcBuilders.standaloneSetup(loginController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("{\"found\":true}")); + } + + /** + * Method under test: {@link + * LoginController#forgetPasswordOtpRequest(ForgetPasswordUpdateRequestModel)} + */ + @Test + void testForgetPasswordOtpRequest() throws Exception { + when(loginService.createOtp((String) any())).thenReturn(new OtpModel(1L)); + MockHttpServletRequestBuilder contentTypeResult = + MockMvcRequestBuilders.post("/login/forget").contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = + contentTypeResult.content( + objectMapper.writeValueAsString(new ForgetPasswordUpdateRequestModel("janedoe"))); + MockMvcBuilders.standaloneSetup(loginController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("{\"salt\":1}")); + } + + /** + * Method under test: {@link + * LoginController#forgetPasswordOtpRequest(ForgetPasswordUpdateRequestModel)} + */ + @Test + void testForgetPasswordOtpRequest2() throws Exception { + when(loginService.createOtp((String) any())).thenReturn(new OtpModel(1L)); + MockHttpServletRequestBuilder contentTypeResult = + MockMvcRequestBuilders.post("/login/forget").contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = + contentTypeResult.content( + objectMapper.writeValueAsString(new ForgetPasswordUpdateRequestModel(""))); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } + + /** Method under test: {@link LoginController#loginUser(UserLoginRequestModel)} */ + @Test + void testLoginUser() throws Exception { + UserLoginRequestModel userLoginRequestModel = new UserLoginRequestModel(); + userLoginRequestModel.setPassword("iloveyou"); + userLoginRequestModel.setUsername("janedoe"); + String content = (new ObjectMapper()).writeValueAsString(userLoginRequestModel); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.post("/login") + .contentType(MediaType.APPLICATION_JSON) + .content(content); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } + + /** + * Method under test: {@link LoginController#registerNewPassword(NewPasswordRequest, Principal)} + */ + @Test + void testRegisterNewPassword() throws Exception { + MockHttpServletRequestBuilder postResult = MockMvcRequestBuilders.post("/login/forget/new"); + postResult.characterEncoding("Encoding"); + MockHttpServletRequestBuilder contentTypeResult = + postResult.contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = + contentTypeResult.content( + objectMapper.writeValueAsString(new NewPasswordRequest("iloveyou"))); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(415)); + } + + /** Method under test: {@link LoginController#registerUser(UserRegistrationModel)} */ + @Test + void testRegisterUser() throws Exception { + UserRegistrationModel userRegistrationModel = new UserRegistrationModel(); + userRegistrationModel.setEmailId("42"); + userRegistrationModel.setFirstName("Jane"); + userRegistrationModel.setLastName("Doe"); + userRegistrationModel.setMobile("Mobile"); + userRegistrationModel.setPassword("iloveyou"); + String content = (new ObjectMapper()).writeValueAsString(userRegistrationModel); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.post("/login/register") + .contentType(MediaType.APPLICATION_JSON) + .content(content); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } + + /** + * Method under test: {@link LoginController#userChangePassword(UserChangePasswordRequestModel, + * Principal)} + */ + @Test + void testUserChangePassword() throws Exception { + MockHttpServletRequestBuilder postResult = MockMvcRequestBuilders.post("/login/passwd"); + postResult.characterEncoding("Encoding"); + MockHttpServletRequestBuilder contentTypeResult = + postResult.contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = + contentTypeResult.content( + objectMapper.writeValueAsString( + new UserChangePasswordRequestModel("iloveyou", "2020-03-01"))); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(415)); + } + + /** Method under test: {@link LoginController#validateOtp(OtpRequestModel, boolean)} */ + @Test + void testValidateOtp() throws Exception { + MockHttpServletRequestBuilder contentTypeResult = + MockMvcRequestBuilders.put("/login/otp/validate") + .header("x-otp-validate-forget", true) + .contentType(MediaType.APPLICATION_JSON); + + ObjectMapper objectMapper = new ObjectMapper(); + MockHttpServletRequestBuilder requestBuilder = + contentTypeResult.content(objectMapper.writeValueAsString(new OtpRequestModel(1L, 1))); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(loginController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/controllers/MealsControllerTest.java b/src/test/java/xyz/subho/lunchbooking/controllers/MealsControllerTest.java index a5a243c..ad902ea 100644 --- a/src/test/java/xyz/subho/lunchbooking/controllers/MealsControllerTest.java +++ b/src/test/java/xyz/subho/lunchbooking/controllers/MealsControllerTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.controllers; import static org.mockito.Mockito.anyBoolean; @@ -5,14 +23,10 @@ import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; - import java.security.Principal; - import java.util.ArrayList; import java.util.HashMap; - import java.util.HashSet; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -33,229 +47,213 @@ @ContextConfiguration(classes = {MealsController.class}) @ExtendWith(SpringExtension.class) class MealsControllerTest { - @Autowired - private MealsController mealsController; + @Autowired private MealsController mealsController; - @MockBean - private MealsService mealsService; + @MockBean private MealsService mealsService; - /** - * Method under test: {@link MealsController#activateMeal(long)} - */ - @Test - void testActivateMeal() throws Exception { - when(mealsService.activateMeal(anyLong())).thenReturn(new MealsModel()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/meal/activate/{mealId}", 123L); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().isCreated()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" - + "\":[]}")); - } + /** Method under test: {@link MealsController#activateMeal(long)} */ + @Test + void testActivateMeal() throws Exception { + when(mealsService.activateMeal(anyLong())).thenReturn(new MealsModel()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.put("/meal/activate/{mealId}", 123L); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(mealsController).build().perform(requestBuilder); + actualPerformResult + .andExpect(MockMvcResultMatchers.status().isCreated()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" + + "\":[]}")); + } - /** - * Method under test: {@link MealsController#activateMeal(long)} - */ - @Test - void testActivateMeal2() throws Exception { - when(mealsService.activateMeal(anyLong())).thenReturn(new MealsModel()); - SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders - .formLogin(); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); - } + /** Method under test: {@link MealsController#activateMeal(long)} */ + @Test + void testActivateMeal2() throws Exception { + when(mealsService.activateMeal(anyLong())).thenReturn(new MealsModel()); + SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = + SecurityMockMvcRequestBuilders.formLogin(); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(mealsController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); + } - /** - * Method under test: {@link MealsController#lockMeal(long)} - */ - @Test - void testLockMeal() throws Exception { - when(mealsService.lockMeal(anyLong())).thenReturn(new MealsModel()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/meal/lock/{mealId}", 123L); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" - + "\":[]}")); - } + /** Method under test: {@link MealsController#lockMeal(long)} */ + @Test + void testLockMeal() throws Exception { + when(mealsService.lockMeal(anyLong())).thenReturn(new MealsModel()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.put("/meal/lock/{mealId}", 123L); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" + + "\":[]}")); + } - /** - * Method under test: {@link MealsController#getAllMeals(Boolean)} - */ - @Test - void testGetAllMeals() throws Exception { - when(mealsService.getAllMeals(anyBoolean())).thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/meal/{today}", true); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("[]")); - } + /** Method under test: {@link MealsController#getAllMeals(Boolean)} */ + @Test + void testGetAllMeals() throws Exception { + when(mealsService.getAllMeals(anyBoolean())).thenReturn(new ArrayList<>()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.get("/meal/{today}", true); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("[]")); + } - /** - * Method under test: {@link MealsController#addMeal(MealsModel)} - */ - @Test - void testAddMeal() throws Exception { - MealsModel mealsModel = new MealsModel(); - mealsModel.setActivatedAt(1L); - mealsModel.setDate(null); - mealsModel.setId(123L); - mealsModel.setLockedAt(1L); - mealsModel.setMealOptions(new HashSet<>()); - mealsModel.setName("Name"); - mealsModel.setReadyAt(1L); - String content = (new ObjectMapper()).writeValueAsString(mealsModel); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/meal/create") - .contentType(MediaType.APPLICATION_JSON) - .content(content); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); - } + /** Method under test: {@link MealsController#addMeal(MealsModel)} */ + @Test + void testAddMeal() throws Exception { + MealsModel mealsModel = new MealsModel(); + mealsModel.setActivatedAt(1L); + mealsModel.setDate(null); + mealsModel.setId(123L); + mealsModel.setLockedAt(1L); + mealsModel.setMealOptions(new HashSet<>()); + mealsModel.setName("Name"); + mealsModel.setReadyAt(1L); + String content = (new ObjectMapper()).writeValueAsString(mealsModel); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.post("/meal/create") + .contentType(MediaType.APPLICATION_JSON) + .content(content); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(mealsController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().is(400)); + } - /** - * Method under test: {@link MealsController#deActivateMeal(long)} - */ - @Test - void testDeActivateMeal() throws Exception { - when(mealsService.deactivateMeal(anyLong())).thenReturn(new MealsModel()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/meal/activate/{mealId}", 123L); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" - + "\":[]}")); - } + /** Method under test: {@link MealsController#deActivateMeal(long)} */ + @Test + void testDeActivateMeal() throws Exception { + when(mealsService.deactivateMeal(anyLong())).thenReturn(new MealsModel()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.delete("/meal/activate/{mealId}", 123L); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" + + "\":[]}")); + } - /** - * Method under test: {@link MealsController#getAllAvailableMeals()} - */ - @Test - void testGetAllAvailableMeals() throws Exception { - when(mealsService.getAllAvailableOptionsForToday()).thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/meal/available"); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("[]")); - } + /** Method under test: {@link MealsController#getAllAvailableMeals()} */ + @Test + void testGetAllAvailableMeals() throws Exception { + when(mealsService.getAllAvailableOptionsForToday()).thenReturn(new ArrayList<>()); + MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/meal/available"); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("[]")); + } - /** - * Method under test: {@link MealsController#getAllAvailableMeals()} - */ - @Test - void testGetAllAvailableMeals2() throws Exception { - when(mealsService.getAllAvailableOptionsForToday()).thenReturn(new ArrayList<>()); - MockHttpServletRequestBuilder getResult = MockMvcRequestBuilders.get("/meal/available"); - getResult.characterEncoding("Encoding"); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(getResult) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("[]")); - } + /** Method under test: {@link MealsController#getAllAvailableMeals()} */ + @Test + void testGetAllAvailableMeals2() throws Exception { + when(mealsService.getAllAvailableOptionsForToday()).thenReturn(new ArrayList<>()); + MockHttpServletRequestBuilder getResult = MockMvcRequestBuilders.get("/meal/available"); + getResult.characterEncoding("Encoding"); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(getResult) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("[]")); + } - /** - * Method under test: {@link MealsController#getAllAvailableMeals(long)} - */ - @Test - void testGetAllAvailableMeals3() throws Exception { - when(mealsService.getMealCountByMealId(anyLong())).thenReturn(new MealAvailableCountModel(new HashMap<>())); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/meal/count/{mealId}", 123L); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content().string("{\"mealOptionCountWithId\":{}}")); - } + /** Method under test: {@link MealsController#getAllAvailableMeals(long)} */ + @Test + void testGetAllAvailableMeals3() throws Exception { + when(mealsService.getMealCountByMealId(anyLong())) + .thenReturn(new MealAvailableCountModel(new HashMap<>())); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.get("/meal/count/{mealId}", 123L); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect(MockMvcResultMatchers.content().string("{\"mealOptionCountWithId\":{}}")); + } - /** - * Method under test: {@link MealsController#prepareMealListForUser(Principal)} - */ - @Test - void testPrepareMealListForUser() throws Exception { - SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = SecurityMockMvcRequestBuilders - .formLogin(); - ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder); - actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); - } + /** Method under test: {@link MealsController#prepareMealListForUser(Principal)} */ + @Test + void testPrepareMealListForUser() throws Exception { + SecurityMockMvcRequestBuilders.FormLoginRequestBuilder requestBuilder = + SecurityMockMvcRequestBuilders.formLogin(); + ResultActions actualPerformResult = + MockMvcBuilders.standaloneSetup(mealsController).build().perform(requestBuilder); + actualPerformResult.andExpect(MockMvcResultMatchers.status().isNotFound()); + } - /** - * Method under test: {@link MealsController#readyMeal(long)} - */ - @Test - void testReadyMeal() throws Exception { - when(mealsService.makeMealReady(anyLong())).thenReturn(new MealsModel()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/meal/ready/{mealId}", 123L); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" - + "\":[]}")); - } + /** Method under test: {@link MealsController#readyMeal(long)} */ + @Test + void testReadyMeal() throws Exception { + when(mealsService.makeMealReady(anyLong())).thenReturn(new MealsModel()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.put("/meal/ready/{mealId}", 123L); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" + + "\":[]}")); + } - /** - * Method under test: {@link MealsController#unLockMeal(long)} - */ - @Test - void testUnLockMeal() throws Exception { - when(mealsService.unlockMeal(anyLong())).thenReturn(new MealsModel()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/meal/lock/{mealId}", 123L); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" - + "\":[]}")); - } + /** Method under test: {@link MealsController#unLockMeal(long)} */ + @Test + void testUnLockMeal() throws Exception { + when(mealsService.unlockMeal(anyLong())).thenReturn(new MealsModel()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.delete("/meal/lock/{mealId}", 123L); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" + + "\":[]}")); + } - /** - * Method under test: {@link MealsController#unReadyMeal(long)} - */ - @Test - void testUnReadyMeal() throws Exception { - when(mealsService.makeMealUnready(anyLong())).thenReturn(new MealsModel()); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/meal/ready/{mealId}", 123L); - MockMvcBuilders.standaloneSetup(mealsController) - .build() - .perform(requestBuilder) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType("application/json")) - .andExpect(MockMvcResultMatchers.content() - .string( - "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" - + "\":[]}")); - } + /** Method under test: {@link MealsController#unReadyMeal(long)} */ + @Test + void testUnReadyMeal() throws Exception { + when(mealsService.makeMealUnready(anyLong())).thenReturn(new MealsModel()); + MockHttpServletRequestBuilder requestBuilder = + MockMvcRequestBuilders.delete("/meal/ready/{mealId}", 123L); + MockMvcBuilders.standaloneSetup(mealsController) + .build() + .perform(requestBuilder) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType("application/json")) + .andExpect( + MockMvcResultMatchers.content() + .string( + "{\"id\":null,\"name\":null,\"date\":null,\"activatedAt\":null,\"lockedAt\":null,\"readyAt\":null,\"mealOptions" + + "\":[]}")); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/entities/AvailableBookingsTest.java b/src/test/java/xyz/subho/lunchbooking/entities/AvailableBookingsTest.java index 7953a1f..657686b 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/AvailableBookingsTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/AvailableBookingsTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/BaseEntityTest.java b/src/test/java/xyz/subho/lunchbooking/entities/BaseEntityTest.java index 0ae8d34..afd189f 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/BaseEntityTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/BaseEntityTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import org.junit.jupiter.api.Disabled; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/BookingsTest.java b/src/test/java/xyz/subho/lunchbooking/entities/BookingsTest.java index 1625ce6..2647090 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/BookingsTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/BookingsTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/MealOptionsTest.java b/src/test/java/xyz/subho/lunchbooking/entities/MealOptionsTest.java index f101e8e..ff95d90 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/MealOptionsTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/MealOptionsTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/MealsTest.java b/src/test/java/xyz/subho/lunchbooking/entities/MealsTest.java index 75a37c7..e3f4243 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/MealsTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/MealsTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/OtpEntityTest.java b/src/test/java/xyz/subho/lunchbooking/entities/OtpEntityTest.java index 73e55da..b511170 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/OtpEntityTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/OtpEntityTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/UserMetadataTest.java b/src/test/java/xyz/subho/lunchbooking/entities/UserMetadataTest.java index 03e2e70..01c78b0 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/UserMetadataTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/UserMetadataTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/security/PermissionsTest.java b/src/test/java/xyz/subho/lunchbooking/entities/security/PermissionsTest.java index 7ec0d79..1fa81cf 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/security/PermissionsTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/security/PermissionsTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities.security; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/security/RolesTest.java b/src/test/java/xyz/subho/lunchbooking/entities/security/RolesTest.java index ac6eff2..9a7a79a 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/security/RolesTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/security/RolesTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities.security; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/entities/security/UserLoginTest.java b/src/test/java/xyz/subho/lunchbooking/entities/security/UserLoginTest.java index 5d4eb34..d3e239d 100644 --- a/src/test/java/xyz/subho/lunchbooking/entities/security/UserLoginTest.java +++ b/src/test/java/xyz/subho/lunchbooking/entities/security/UserLoginTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.entities.security; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/src/test/java/xyz/subho/lunchbooking/models/ErrorDetailsTest.java b/src/test/java/xyz/subho/lunchbooking/models/ErrorDetailsTest.java index ace7dce..6002b05 100644 --- a/src/test/java/xyz/subho/lunchbooking/models/ErrorDetailsTest.java +++ b/src/test/java/xyz/subho/lunchbooking/models/ErrorDetailsTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.models; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -5,12 +23,11 @@ import org.junit.jupiter.api.Test; class ErrorDetailsTest { - /** - * Method under test: {@link ErrorDetails#ErrorDetails(String)} - */ - @Test - void testConstructor() { - assertEquals("Not all who wander are lost", (new ErrorDetails("Not all who wander are lost")).getMessage()); - } + /** Method under test: {@link ErrorDetails#ErrorDetails(String)} */ + @Test + void testConstructor() { + assertEquals( + "Not all who wander are lost", + (new ErrorDetails("Not all who wander are lost")).getMessage()); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/security/JwtAuthenticationEntryPointTest.java b/src/test/java/xyz/subho/lunchbooking/security/JwtAuthenticationEntryPointTest.java index 071585d..4616420 100644 --- a/src/test/java/xyz/subho/lunchbooking/security/JwtAuthenticationEntryPointTest.java +++ b/src/test/java/xyz/subho/lunchbooking/security/JwtAuthenticationEntryPointTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.security; import static org.mockito.Mockito.mock; @@ -6,7 +24,6 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.apache.catalina.connector.Response; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -23,57 +40,64 @@ @ContextConfiguration(classes = {JwtAuthenticationEntryPoint.class}) @ExtendWith(SpringExtension.class) class JwtAuthenticationEntryPointTest { - @Autowired - private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; + @Autowired private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; - /** - * Method under test: {@link JwtAuthenticationEntryPoint#commence(HttpServletRequest, HttpServletResponse, AuthenticationException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCommence() throws IOException, ServletException { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "org.apache.coyote.Response.isCommitted()" because the return value of "org.apache.catalina.connector.Response.getCoyoteResponse()" is null - // at org.apache.catalina.connector.Response.isCommitted(Response.java:619) - // at org.apache.catalina.connector.Response.sendError(Response.java:1304) - // at xyz.subho.lunchbooking.security.JwtAuthenticationEntryPoint.commence(JwtAuthenticationEntryPoint.java:41) + /** + * Method under test: {@link JwtAuthenticationEntryPoint#commence(HttpServletRequest, + * HttpServletResponse, AuthenticationException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testCommence() throws IOException, ServletException { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "org.apache.coyote.Response.isCommitted()" + // because the return value of "org.apache.catalina.connector.Response.getCoyoteResponse()" is + // null + // at org.apache.catalina.connector.Response.isCommitted(Response.java:619) + // at org.apache.catalina.connector.Response.sendError(Response.java:1304) + // at + // xyz.subho.lunchbooking.security.JwtAuthenticationEntryPoint.commence(JwtAuthenticationEntryPoint.java:41) - MockHttpServletRequest request = new MockHttpServletRequest(); - Response response = new Response(); - jwtAuthenticationEntryPoint.commence(request, response, new AccountExpiredException("Msg")); - } + MockHttpServletRequest request = new MockHttpServletRequest(); + Response response = new Response(); + jwtAuthenticationEntryPoint.commence(request, response, new AccountExpiredException("Msg")); + } - /** - * Method under test: {@link JwtAuthenticationEntryPoint#commence(HttpServletRequest, HttpServletResponse, AuthenticationException)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCommence2() throws IOException, ServletException { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "org.apache.coyote.Response.isCommitted()" because the return value of "org.apache.catalina.connector.Response.getCoyoteResponse()" is null - // at org.apache.catalina.connector.Response.isCommitted(Response.java:619) - // at org.apache.catalina.connector.Response.sendError(Response.java:1304) - // at xyz.subho.lunchbooking.security.JwtAuthenticationEntryPoint.commence(JwtAuthenticationEntryPoint.java:41) + /** + * Method under test: {@link JwtAuthenticationEntryPoint#commence(HttpServletRequest, + * HttpServletResponse, AuthenticationException)} + */ + @Test + @Disabled("TODO: Complete this test") + void testCommence2() throws IOException, ServletException { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "org.apache.coyote.Response.isCommitted()" + // because the return value of "org.apache.catalina.connector.Response.getCoyoteResponse()" is + // null + // at org.apache.catalina.connector.Response.isCommitted(Response.java:619) + // at org.apache.catalina.connector.Response.sendError(Response.java:1304) + // at + // xyz.subho.lunchbooking.security.JwtAuthenticationEntryPoint.commence(JwtAuthenticationEntryPoint.java:41) - DefaultMultipartHttpServletRequest request = mock(DefaultMultipartHttpServletRequest.class); - Response response = new Response(); - jwtAuthenticationEntryPoint.commence(request, response, new AccountExpiredException("Msg")); - } + DefaultMultipartHttpServletRequest request = mock(DefaultMultipartHttpServletRequest.class); + Response response = new Response(); + jwtAuthenticationEntryPoint.commence(request, response, new AccountExpiredException("Msg")); + } - /** - * Method under test: {@link JwtAuthenticationEntryPoint#commence(HttpServletRequest, HttpServletResponse, AuthenticationException)} - */ - @Test - void testCommence3() throws IOException, ServletException { - // TODO: Complete this test. + /** + * Method under test: {@link JwtAuthenticationEntryPoint#commence(HttpServletRequest, + * HttpServletResponse, AuthenticationException)} + */ + @Test + void testCommence3() throws IOException, ServletException { + // TODO: Complete this test. - MockHttpServletRequest request = new MockHttpServletRequest(); - MockHttpServletResponse response = new MockHttpServletResponse(); - jwtAuthenticationEntryPoint.commence(request, response, new AccountExpiredException("Msg")); - } + MockHttpServletRequest request = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + jwtAuthenticationEntryPoint.commence(request, response, new AccountExpiredException("Msg")); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/security/JwtConfigTest.java b/src/test/java/xyz/subho/lunchbooking/security/JwtConfigTest.java index 5277247..fc7e339 100644 --- a/src/test/java/xyz/subho/lunchbooking/security/JwtConfigTest.java +++ b/src/test/java/xyz/subho/lunchbooking/security/JwtConfigTest.java @@ -1,10 +1,27 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.security; import static org.junit.jupiter.api.Assertions.assertTrue; import java.security.KeyStore; import java.security.interfaces.RSAPublicKey; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -19,45 +36,35 @@ @PropertySource("classpath:application-test.properties") @EnableConfigurationProperties class JwtConfigTest { - @Autowired - private JwtConfig jwtConfig; - - /** - * Method under test: {@link JwtConfig#keyStore()} - */ - @Test - void testKeyStore() { - // TODO: Complete this test. - - jwtConfig.keyStore(); - } - - /** - * Method under test: {@link JwtConfig#jwtSigningKey(KeyStore)} - */ - @Test - void testJwtSigningKey() { - // TODO: Complete this test. - - jwtConfig.jwtSigningKey(null); - } - - /** - * Method under test: {@link JwtConfig#jwtValidationKey(KeyStore)} - */ - @Test - void testJwtValidationKey() { - // TODO: Complete this test. - - jwtConfig.jwtValidationKey(null); - } - - /** - * Method under test: {@link JwtConfig#jwtDecoder(RSAPublicKey)} - */ - @Test - void testJwtDecoder() { - assertTrue(jwtConfig.jwtDecoder(null) instanceof NimbusJwtDecoder); - } -} + @Autowired private JwtConfig jwtConfig; + + /** Method under test: {@link JwtConfig#keyStore()} */ + @Test + void testKeyStore() { + // TODO: Complete this test. + + jwtConfig.keyStore(); + } + /** Method under test: {@link JwtConfig#jwtSigningKey(KeyStore)} */ + @Test + void testJwtSigningKey() { + // TODO: Complete this test. + + jwtConfig.jwtSigningKey(null); + } + + /** Method under test: {@link JwtConfig#jwtValidationKey(KeyStore)} */ + @Test + void testJwtValidationKey() { + // TODO: Complete this test. + + jwtConfig.jwtValidationKey(null); + } + + /** Method under test: {@link JwtConfig#jwtDecoder(RSAPublicKey)} */ + @Test + void testJwtDecoder() { + assertTrue(jwtConfig.jwtDecoder(null) instanceof NimbusJwtDecoder); + } +} diff --git a/src/test/java/xyz/subho/lunchbooking/security/JwtHelperTest.java b/src/test/java/xyz/subho/lunchbooking/security/JwtHelperTest.java index 4d4d943..ce5fe49 100644 --- a/src/test/java/xyz/subho/lunchbooking/security/JwtHelperTest.java +++ b/src/test/java/xyz/subho/lunchbooking/security/JwtHelperTest.java @@ -1,16 +1,32 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.security; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.when; import com.auth0.jwt.exceptions.JWTVerificationException; - import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.util.HashMap; import java.util.HashSet; import java.util.Map; - import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,505 +43,494 @@ @PropertySource("classpath:application-test.properties") @EnableConfigurationProperties class JwtHelperTest { - @Autowired - private JwtHelper jwtHelper; - - @MockBean - private RSAPrivateKey rSAPrivateKey; - - @MockBean - private RSAPublicKey rSAPublicKey; - - /** - * Method under test: {@link JwtHelper#generateJwtToken(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testGenerateJwtToken() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) - // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) - // java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) - // See https://diff.blue/R013 to resolve this issue. - - when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); - jwtHelper.generateJwtToken("Hello from the Dreaming Spires"); - } - - /** - * Method under test: {@link JwtHelper#generateJwtToken(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testGenerateJwtToken2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // com.auth0.jwt.exceptions.JWTVerificationException: An error occurred - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) - // See https://diff.blue/R013 to resolve this issue. - - when(rSAPrivateKey.getAlgorithm()).thenThrow(new JWTVerificationException("An error occurred")); - jwtHelper.generateJwtToken("Hello from the Dreaming Spires"); - } - - /** - * Method under test: {@link JwtHelper#createJwt(UserLogin)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCreateJwt() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) - // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) - // java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) - - when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); - - UserLogin userLogin = new UserLogin(); - userLogin.setCreatedAt(1L); - userLogin.setCreatedBy("Jan 1, 2020 8:00am GMT+0100"); - userLogin.setCredentialExpiredAt(1L); - userLogin.setCurrentLogin(1L); - userLogin.setDeletedAt(1L); - userLogin.setDeletedBy("Jan 1, 2020 11:00am GMT+0100"); - userLogin.setEnabledAt(1L); - userLogin.setExpiredAt(1L); - userLogin.setId(123L); - userLogin.setLastLogin(1L); - userLogin.setLockedAt(1L); - userLogin.setPassword("iloveyou"); - userLogin.setRoles(new HashSet<>()); - userLogin.setSalt("Salt"); - userLogin.setSecuredAt(1L); - userLogin.setUpdatedAt(1L); - userLogin.setUpdatedBy("2020-03-01"); - userLogin.setUsername("janedoe"); - userLogin.setVersion(1L); - jwtHelper.createJwt(userLogin); - } - - /** - * Method under test: {@link JwtHelper#createJwt(UserLogin)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCreateJwt2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // com.auth0.jwt.exceptions.JWTVerificationException: An error occurred - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) - - when(rSAPrivateKey.getAlgorithm()).thenThrow(new JWTVerificationException("An error occurred")); - - UserLogin userLogin = new UserLogin(); - userLogin.setCreatedAt(1L); - userLogin.setCreatedBy("Jan 1, 2020 8:00am GMT+0100"); - userLogin.setCredentialExpiredAt(1L); - userLogin.setCurrentLogin(1L); - userLogin.setDeletedAt(1L); - userLogin.setDeletedBy("Jan 1, 2020 11:00am GMT+0100"); - userLogin.setEnabledAt(1L); - userLogin.setExpiredAt(1L); - userLogin.setId(123L); - userLogin.setLastLogin(1L); - userLogin.setLockedAt(1L); - userLogin.setPassword("iloveyou"); - userLogin.setRoles(new HashSet<>()); - userLogin.setSalt("Salt"); - userLogin.setSecuredAt(1L); - userLogin.setUpdatedAt(1L); - userLogin.setUpdatedBy("2020-03-01"); - userLogin.setUsername("janedoe"); - userLogin.setVersion(1L); - jwtHelper.createJwt(userLogin); - } - - /** - * Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCreateJwtForClaims() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - - when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); - jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", new HashMap<>()); - } - - /** - * Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCreateJwtForClaims2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - - when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); - - HashMap stringStringMap = new HashMap<>(); - stringStringMap.put(JwtHelper.JWT_ISSUER, "42"); - jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", stringStringMap); - } - - /** - * Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCreateJwtForClaims3() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // com.auth0.jwt.exceptions.JWTVerificationException: An error occurred - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - - when(rSAPrivateKey.getAlgorithm()).thenThrow(new JWTVerificationException("An error occurred")); - jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", new HashMap<>()); - } - - /** - * Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} - */ - @Test - @Disabled("TODO: Complete this test") - void testCreateJwtForClaims4() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withRSA - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - // java.security.ProviderException: Unsupported algorithm Algorithm - // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) - // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) - // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) - // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) - // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) - // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) - // at java.security.Signature.initSign(Signature.java:635) - // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) - // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) - // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) - // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) - // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) - // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) - - when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); - - HashMap stringStringMap = new HashMap<>(); - stringStringMap.put("Key", "42"); - stringStringMap.putIfAbsent(JwtHelper.JWT_ISSUER, "42"); - jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", stringStringMap); - } - - /** - * Method under test: {@link JwtHelper#validateToken(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testValidateToken() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "com.auth0.jwt.interfaces.DecodedJWT.getExpiresAt()" because the return value of "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null - // at xyz.subho.lunchbooking.security.JwtHelper.extractExpiration(JwtHelper.java:128) - // at xyz.subho.lunchbooking.security.JwtHelper.isTokenExpired(JwtHelper.java:124) - // at xyz.subho.lunchbooking.security.JwtHelper.validateToken(JwtHelper.java:89) - - jwtHelper.validateToken("ABC123"); - } - - /** - * Method under test: {@link JwtHelper#verifyAndDecodeJwt(String)} - */ - @Test - void testVerifyAndDecodeJwt() { - assertNull(jwtHelper.verifyAndDecodeJwt("ABC123")); - } - - /** - * Method under test: {@link JwtHelper#getAuthenticatedUserDetails(String, String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testGetAuthenticatedUserDetails() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "com.auth0.jwt.interfaces.DecodedJWT.getClaims()" because the return value of "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null - // at xyz.subho.lunchbooking.security.JwtHelper.extractAllClaims(JwtHelper.java:136) - // at xyz.subho.lunchbooking.security.JwtHelper.getAuthenticatedUserDetails(JwtHelper.java:107) - - jwtHelper.getAuthenticatedUserDetails("ABC123", "janedoe"); - } - - /** - * Method under test: {@link JwtHelper#isTokenExpired(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testIsTokenExpired() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "com.auth0.jwt.interfaces.DecodedJWT.getExpiresAt()" because the return value of "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null - // at xyz.subho.lunchbooking.security.JwtHelper.extractExpiration(JwtHelper.java:128) - // at xyz.subho.lunchbooking.security.JwtHelper.isTokenExpired(JwtHelper.java:124) - - jwtHelper.isTokenExpired("ABC123"); - } - - /** - * Method under test: {@link JwtHelper#extractExpiration(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testExtractExpiration() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "com.auth0.jwt.interfaces.DecodedJWT.getExpiresAt()" because the return value of "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null - // at xyz.subho.lunchbooking.security.JwtHelper.extractExpiration(JwtHelper.java:128) - - jwtHelper.extractExpiration("ABC123"); - } - - /** - * Method under test: {@link JwtHelper#extractUsername(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testExtractUsername() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "com.auth0.jwt.interfaces.DecodedJWT.getSubject()" because the return value of "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null - // at xyz.subho.lunchbooking.security.JwtHelper.extractUsername(JwtHelper.java:132) - - jwtHelper.extractUsername("ABC123"); - } - - /** - * Method under test: {@link JwtHelper#extractAllClaims(String)} - */ - @Test - @Disabled("TODO: Complete this test") - void testExtractAllClaims() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "com.auth0.jwt.interfaces.DecodedJWT.getClaims()" because the return value of "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null - // at xyz.subho.lunchbooking.security.JwtHelper.extractAllClaims(JwtHelper.java:136) - - jwtHelper.extractAllClaims("ABC123"); - } + @Autowired private JwtHelper jwtHelper; + + @MockBean private RSAPrivateKey rSAPrivateKey; + + @MockBean private RSAPublicKey rSAPublicKey; + + /** Method under test: {@link JwtHelper#generateJwtToken(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testGenerateJwtToken() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be + // generated when signing using the Algorithm: SHA256withRSA + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) + // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm + // Algorithm + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) + // java.security.ProviderException: Unsupported algorithm Algorithm + // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) + // See https://diff.blue/R013 to resolve this issue. + + when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); + jwtHelper.generateJwtToken("Hello from the Dreaming Spires"); + } + + /** Method under test: {@link JwtHelper#generateJwtToken(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testGenerateJwtToken2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // com.auth0.jwt.exceptions.JWTVerificationException: An error occurred + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.generateJwtToken(JwtHelper.java:61) + // See https://diff.blue/R013 to resolve this issue. + + when(rSAPrivateKey.getAlgorithm()).thenThrow(new JWTVerificationException("An error occurred")); + jwtHelper.generateJwtToken("Hello from the Dreaming Spires"); + } + + /** Method under test: {@link JwtHelper#createJwt(UserLogin)} */ + @Test + @Disabled("TODO: Complete this test") + void testCreateJwt() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be + // generated when signing using the Algorithm: SHA256withRSA + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) + // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm + // Algorithm + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) + // java.security.ProviderException: Unsupported algorithm Algorithm + // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) + + when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); + + UserLogin userLogin = new UserLogin(); + userLogin.setCreatedAt(1L); + userLogin.setCreatedBy("Jan 1, 2020 8:00am GMT+0100"); + userLogin.setCredentialExpiredAt(1L); + userLogin.setCurrentLogin(1L); + userLogin.setDeletedAt(1L); + userLogin.setDeletedBy("Jan 1, 2020 11:00am GMT+0100"); + userLogin.setEnabledAt(1L); + userLogin.setExpiredAt(1L); + userLogin.setId(123L); + userLogin.setLastLogin(1L); + userLogin.setLockedAt(1L); + userLogin.setPassword("iloveyou"); + userLogin.setRoles(new HashSet<>()); + userLogin.setSalt("Salt"); + userLogin.setSecuredAt(1L); + userLogin.setUpdatedAt(1L); + userLogin.setUpdatedBy("2020-03-01"); + userLogin.setUsername("janedoe"); + userLogin.setVersion(1L); + jwtHelper.createJwt(userLogin); + } + + /** Method under test: {@link JwtHelper#createJwt(UserLogin)} */ + @Test + @Disabled("TODO: Complete this test") + void testCreateJwt2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // com.auth0.jwt.exceptions.JWTVerificationException: An error occurred + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwt(JwtHelper.java:70) + + when(rSAPrivateKey.getAlgorithm()).thenThrow(new JWTVerificationException("An error occurred")); + + UserLogin userLogin = new UserLogin(); + userLogin.setCreatedAt(1L); + userLogin.setCreatedBy("Jan 1, 2020 8:00am GMT+0100"); + userLogin.setCredentialExpiredAt(1L); + userLogin.setCurrentLogin(1L); + userLogin.setDeletedAt(1L); + userLogin.setDeletedBy("Jan 1, 2020 11:00am GMT+0100"); + userLogin.setEnabledAt(1L); + userLogin.setExpiredAt(1L); + userLogin.setId(123L); + userLogin.setLastLogin(1L); + userLogin.setLockedAt(1L); + userLogin.setPassword("iloveyou"); + userLogin.setRoles(new HashSet<>()); + userLogin.setSalt("Salt"); + userLogin.setSecuredAt(1L); + userLogin.setUpdatedAt(1L); + userLogin.setUpdatedBy("2020-03-01"); + userLogin.setUsername("janedoe"); + userLogin.setVersion(1L); + jwtHelper.createJwt(userLogin); + } + + /** Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} */ + @Test + @Disabled("TODO: Complete this test") + void testCreateJwtForClaims() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be + // generated when signing using the Algorithm: SHA256withRSA + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm + // Algorithm + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // java.security.ProviderException: Unsupported algorithm Algorithm + // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + + when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); + jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", new HashMap<>()); + } + + /** Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} */ + @Test + @Disabled("TODO: Complete this test") + void testCreateJwtForClaims2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be + // generated when signing using the Algorithm: SHA256withRSA + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm + // Algorithm + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // java.security.ProviderException: Unsupported algorithm Algorithm + // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + + when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); + + HashMap stringStringMap = new HashMap<>(); + stringStringMap.put(JwtHelper.JWT_ISSUER, "42"); + jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", stringStringMap); + } + + /** Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} */ + @Test + @Disabled("TODO: Complete this test") + void testCreateJwtForClaims3() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // com.auth0.jwt.exceptions.JWTVerificationException: An error occurred + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + + when(rSAPrivateKey.getAlgorithm()).thenThrow(new JWTVerificationException("An error occurred")); + jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", new HashMap<>()); + } + + /** Method under test: {@link JwtHelper#createJwtForClaims(String, Map)} */ + @Test + @Disabled("TODO: Complete this test") + void testCreateJwtForClaims4() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // com.auth0.jwt.exceptions.SignatureGenerationException: The Token's Signature couldn't be + // generated when signing using the Algorithm: SHA256withRSA + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:69) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // java.security.InvalidKeyException: java.security.ProviderException: Unsupported algorithm + // Algorithm + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:132) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + // java.security.ProviderException: Unsupported algorithm Algorithm + // at sun.security.rsa.RSAUtil$KeyType.lookup(RSAUtil.java:69) + // at sun.security.rsa.RSAKeyFactory.toRSAKey(RSAKeyFactory.java:128) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:112) + // at sun.security.rsa.RSASignature.engineInitSign(RSASignature.java:104) + // at java.security.Signature$Delegate.tryOperation(Signature.java:1327) + // at java.security.Signature$Delegate.chooseProvider(Signature.java:1276) + // at java.security.Signature$Delegate.engineInitSign(Signature.java:1373) + // at java.security.Signature.initSign(Signature.java:635) + // at com.auth0.jwt.algorithms.CryptoHelper.createSignatureFor(CryptoHelper.java:135) + // at com.auth0.jwt.algorithms.RSAAlgorithm.sign(RSAAlgorithm.java:67) + // at com.auth0.jwt.JWTCreator.sign(JWTCreator.java:574) + // at com.auth0.jwt.JWTCreator.access$100(JWTCreator.java:24) + // at com.auth0.jwt.JWTCreator$Builder.sign(JWTCreator.java:554) + // at xyz.subho.lunchbooking.security.JwtHelper.createJwtForClaims(JwtHelper.java:85) + + when(rSAPrivateKey.getAlgorithm()).thenReturn("Algorithm"); + + HashMap stringStringMap = new HashMap<>(); + stringStringMap.put("Key", "42"); + stringStringMap.putIfAbsent(JwtHelper.JWT_ISSUER, "42"); + jwtHelper.createJwtForClaims("Hello from the Dreaming Spires", stringStringMap); + } + + /** Method under test: {@link JwtHelper#validateToken(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testValidateToken() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "com.auth0.jwt.interfaces.DecodedJWT.getExpiresAt()" because the return value of + // "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null + // at xyz.subho.lunchbooking.security.JwtHelper.extractExpiration(JwtHelper.java:128) + // at xyz.subho.lunchbooking.security.JwtHelper.isTokenExpired(JwtHelper.java:124) + // at xyz.subho.lunchbooking.security.JwtHelper.validateToken(JwtHelper.java:89) + + jwtHelper.validateToken("ABC123"); + } + + /** Method under test: {@link JwtHelper#verifyAndDecodeJwt(String)} */ + @Test + void testVerifyAndDecodeJwt() { + assertNull(jwtHelper.verifyAndDecodeJwt("ABC123")); + } + + /** Method under test: {@link JwtHelper#getAuthenticatedUserDetails(String, String)} */ + @Test + @Disabled("TODO: Complete this test") + void testGetAuthenticatedUserDetails() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "com.auth0.jwt.interfaces.DecodedJWT.getClaims()" because the return value of + // "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null + // at xyz.subho.lunchbooking.security.JwtHelper.extractAllClaims(JwtHelper.java:136) + // at + // xyz.subho.lunchbooking.security.JwtHelper.getAuthenticatedUserDetails(JwtHelper.java:107) + + jwtHelper.getAuthenticatedUserDetails("ABC123", "janedoe"); + } + + /** Method under test: {@link JwtHelper#isTokenExpired(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testIsTokenExpired() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "com.auth0.jwt.interfaces.DecodedJWT.getExpiresAt()" because the return value of + // "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null + // at xyz.subho.lunchbooking.security.JwtHelper.extractExpiration(JwtHelper.java:128) + // at xyz.subho.lunchbooking.security.JwtHelper.isTokenExpired(JwtHelper.java:124) + + jwtHelper.isTokenExpired("ABC123"); + } + + /** Method under test: {@link JwtHelper#extractExpiration(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testExtractExpiration() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "com.auth0.jwt.interfaces.DecodedJWT.getExpiresAt()" because the return value of + // "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null + // at xyz.subho.lunchbooking.security.JwtHelper.extractExpiration(JwtHelper.java:128) + + jwtHelper.extractExpiration("ABC123"); + } + + /** Method under test: {@link JwtHelper#extractUsername(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testExtractUsername() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "com.auth0.jwt.interfaces.DecodedJWT.getSubject()" because the return value of + // "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null + // at xyz.subho.lunchbooking.security.JwtHelper.extractUsername(JwtHelper.java:132) + + jwtHelper.extractUsername("ABC123"); + } + + /** Method under test: {@link JwtHelper#extractAllClaims(String)} */ + @Test + @Disabled("TODO: Complete this test") + void testExtractAllClaims() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke + // "com.auth0.jwt.interfaces.DecodedJWT.getClaims()" because the return value of + // "xyz.subho.lunchbooking.security.JwtHelper.verifyAndDecodeJwt(String)" is null + // at xyz.subho.lunchbooking.security.JwtHelper.extractAllClaims(JwtHelper.java:136) + + jwtHelper.extractAllClaims("ABC123"); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/security/JwtRequestFilterTest.java b/src/test/java/xyz/subho/lunchbooking/security/JwtRequestFilterTest.java index 5875abc..f32713e 100644 --- a/src/test/java/xyz/subho/lunchbooking/security/JwtRequestFilterTest.java +++ b/src/test/java/xyz/subho/lunchbooking/security/JwtRequestFilterTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.security; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -20,7 +38,6 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.apache.catalina.connector.Response; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -40,240 +57,261 @@ @WebAppConfiguration @ExtendWith(SpringExtension.class) class JwtRequestFilterTest { - @MockBean - private JwtHelper jwtHelper; + @MockBean private JwtHelper jwtHelper; - @Autowired - private JwtRequestFilter jwtRequestFilter; + @Autowired private JwtRequestFilter jwtRequestFilter; - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - void testDoFilterInternal() throws IOException, ServletException { - MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(mockHttpServletRequest, response, filterChain); - verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - assertFalse(mockHttpServletRequest.isRequestedSessionIdFromURL()); - assertTrue(mockHttpServletRequest.isRequestedSessionIdFromCookie()); - assertFalse(mockHttpServletRequest.isAsyncSupported()); - assertFalse(mockHttpServletRequest.isAsyncStarted()); - assertTrue(mockHttpServletRequest.isActive()); - assertTrue(mockHttpServletRequest.getSession() instanceof MockHttpSession); - assertEquals("", mockHttpServletRequest.getServletPath()); - assertEquals(80, mockHttpServletRequest.getServerPort()); - assertEquals("localhost", mockHttpServletRequest.getServerName()); - assertEquals("http", mockHttpServletRequest.getScheme()); - assertEquals("", mockHttpServletRequest.getRequestURI()); - assertEquals(80, mockHttpServletRequest.getRemotePort()); - assertEquals("localhost", mockHttpServletRequest.getRemoteHost()); - assertEquals("HTTP/1.1", mockHttpServletRequest.getProtocol()); - assertEquals("", mockHttpServletRequest.getMethod()); - assertEquals(80, mockHttpServletRequest.getLocalPort()); - assertEquals("localhost", mockHttpServletRequest.getLocalName()); - assertTrue(mockHttpServletRequest.getInputStream() instanceof DelegatingServletInputStream); - assertEquals(DispatcherType.REQUEST, mockHttpServletRequest.getDispatcherType()); - assertEquals("", mockHttpServletRequest.getContextPath()); - assertEquals(-1L, mockHttpServletRequest.getContentLengthLong()); - } + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + void testDoFilterInternal() throws IOException, ServletException { + MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(mockHttpServletRequest, response, filterChain); + verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + assertFalse(mockHttpServletRequest.isRequestedSessionIdFromURL()); + assertTrue(mockHttpServletRequest.isRequestedSessionIdFromCookie()); + assertFalse(mockHttpServletRequest.isAsyncSupported()); + assertFalse(mockHttpServletRequest.isAsyncStarted()); + assertTrue(mockHttpServletRequest.isActive()); + assertTrue(mockHttpServletRequest.getSession() instanceof MockHttpSession); + assertEquals("", mockHttpServletRequest.getServletPath()); + assertEquals(80, mockHttpServletRequest.getServerPort()); + assertEquals("localhost", mockHttpServletRequest.getServerName()); + assertEquals("http", mockHttpServletRequest.getScheme()); + assertEquals("", mockHttpServletRequest.getRequestURI()); + assertEquals(80, mockHttpServletRequest.getRemotePort()); + assertEquals("localhost", mockHttpServletRequest.getRemoteHost()); + assertEquals("HTTP/1.1", mockHttpServletRequest.getProtocol()); + assertEquals("", mockHttpServletRequest.getMethod()); + assertEquals(80, mockHttpServletRequest.getLocalPort()); + assertEquals("localhost", mockHttpServletRequest.getLocalName()); + assertTrue(mockHttpServletRequest.getInputStream() instanceof DelegatingServletInputStream); + assertEquals(DispatcherType.REQUEST, mockHttpServletRequest.getDispatcherType()); + assertEquals("", mockHttpServletRequest.getContextPath()); + assertEquals(-1L, mockHttpServletRequest.getContentLengthLong()); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - @Disabled("TODO: Complete this test") - void testDoFilterInternal2() throws IOException, ServletException { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // java.lang.NullPointerException: Cannot invoke "javax.servlet.http.HttpServletRequest.getHeader(String)" because "request" is null - // at xyz.subho.lunchbooking.security.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:51) - // See https://diff.blue/R013 to resolve this issue. + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + @Disabled("TODO: Complete this test") + void testDoFilterInternal2() throws IOException, ServletException { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.lang.NullPointerException: Cannot invoke + // "javax.servlet.http.HttpServletRequest.getHeader(String)" because "request" is null + // at + // xyz.subho.lunchbooking.security.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:51) + // See https://diff.blue/R013 to resolve this issue. - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(null, response, filterChain); - } + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(null, response, filterChain); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - void testDoFilterInternal3() throws IOException, ServletException { - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("https://example.org/example"); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - verify(defaultMultipartHttpServletRequest).getHeader((String) any()); - verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - } + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + void testDoFilterInternal3() throws IOException, ServletException { + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getHeader((String) any())) + .thenReturn("https://example.org/example"); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + verify(defaultMultipartHttpServletRequest).getHeader((String) any()); + verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - void testDoFilterInternal4() throws IOException, ServletException { - when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) - .thenReturn(new LunchBookingPrincipal()); - when(jwtHelper.validateToken((String) any())).thenReturn(true); - when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); - when(defaultMultipartHttpServletRequest.getSession(anyBoolean())).thenReturn(new MockHttpSession()); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - verify(jwtHelper).validateToken((String) any()); - verify(jwtHelper).extractUsername((String) any()); - verify(jwtHelper).getAuthenticatedUserDetails((String) any(), (String) any()); - verify(defaultMultipartHttpServletRequest).getRemoteAddr(); - verify(defaultMultipartHttpServletRequest).getHeader((String) any()); - verify(defaultMultipartHttpServletRequest).getSession(anyBoolean()); - verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - } + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + void testDoFilterInternal4() throws IOException, ServletException { + when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) + .thenReturn(new LunchBookingPrincipal()); + when(jwtHelper.validateToken((String) any())).thenReturn(true); + when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); + when(defaultMultipartHttpServletRequest.getSession(anyBoolean())) + .thenReturn(new MockHttpSession()); + when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + verify(jwtHelper).validateToken((String) any()); + verify(jwtHelper).extractUsername((String) any()); + verify(jwtHelper).getAuthenticatedUserDetails((String) any(), (String) any()); + verify(defaultMultipartHttpServletRequest).getRemoteAddr(); + verify(defaultMultipartHttpServletRequest).getHeader((String) any()); + verify(defaultMultipartHttpServletRequest).getSession(anyBoolean()); + verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - @Disabled("TODO: Complete this test") - void testDoFilterInternal5() throws IOException, ServletException { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // java.lang.RuntimeException - // at xyz.subho.lunchbooking.security.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:83) - // See https://diff.blue/R013 to resolve this issue. + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + @Disabled("TODO: Complete this test") + void testDoFilterInternal5() throws IOException, ServletException { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.lang.RuntimeException + // at + // xyz.subho.lunchbooking.security.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:83) + // See https://diff.blue/R013 to resolve this issue. - when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) - .thenReturn(new LunchBookingPrincipal()); - when(jwtHelper.validateToken((String) any())).thenReturn(true); - when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenThrow(new RuntimeException()); - when(defaultMultipartHttpServletRequest.getSession(anyBoolean())).thenThrow(new RuntimeException()); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - } + when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) + .thenReturn(new LunchBookingPrincipal()); + when(jwtHelper.validateToken((String) any())).thenReturn(true); + when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenThrow(new RuntimeException()); + when(defaultMultipartHttpServletRequest.getSession(anyBoolean())) + .thenThrow(new RuntimeException()); + when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - @Disabled("TODO: Complete this test") - void testDoFilterInternal6() throws IOException, ServletException { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // java.lang.NullPointerException: Cannot invoke "xyz.subho.lunchbooking.security.LunchBookingPrincipal.getAuthorities()" because "authDetails" is null - // at xyz.subho.lunchbooking.security.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:81) - // See https://diff.blue/R013 to resolve this issue. + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + @Disabled("TODO: Complete this test") + void testDoFilterInternal6() throws IOException, ServletException { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.lang.NullPointerException: Cannot invoke + // "xyz.subho.lunchbooking.security.LunchBookingPrincipal.getAuthorities()" because + // "authDetails" is null + // at + // xyz.subho.lunchbooking.security.JwtRequestFilter.doFilterInternal(JwtRequestFilter.java:81) + // See https://diff.blue/R013 to resolve this issue. - when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())).thenReturn(null); - when(jwtHelper.validateToken((String) any())).thenReturn(true); - when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); - when(defaultMultipartHttpServletRequest.getSession(anyBoolean())).thenReturn(new MockHttpSession()); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - } + when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())).thenReturn(null); + when(jwtHelper.validateToken((String) any())).thenReturn(true); + when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); + when(defaultMultipartHttpServletRequest.getSession(anyBoolean())) + .thenReturn(new MockHttpSession()); + when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - void testDoFilterInternal7() throws IOException, ServletException { - LunchBookingPrincipal lunchBookingPrincipal = mock(LunchBookingPrincipal.class); - when((Set) lunchBookingPrincipal.getAuthorities()).thenReturn(new HashSet<>()); - when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())).thenReturn(lunchBookingPrincipal); - when(jwtHelper.validateToken((String) any())).thenReturn(true); - when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); - when(defaultMultipartHttpServletRequest.getSession(anyBoolean())).thenReturn(new MockHttpSession()); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - verify(jwtHelper).validateToken((String) any()); - verify(jwtHelper).extractUsername((String) any()); - verify(jwtHelper).getAuthenticatedUserDetails((String) any(), (String) any()); - verify(lunchBookingPrincipal).getAuthorities(); - verify(defaultMultipartHttpServletRequest).getRemoteAddr(); - verify(defaultMultipartHttpServletRequest).getHeader((String) any()); - verify(defaultMultipartHttpServletRequest).getSession(anyBoolean()); - verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - } + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + void testDoFilterInternal7() throws IOException, ServletException { + LunchBookingPrincipal lunchBookingPrincipal = mock(LunchBookingPrincipal.class); + when((Set) lunchBookingPrincipal.getAuthorities()) + .thenReturn(new HashSet<>()); + when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) + .thenReturn(lunchBookingPrincipal); + when(jwtHelper.validateToken((String) any())).thenReturn(true); + when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); + when(defaultMultipartHttpServletRequest.getSession(anyBoolean())) + .thenReturn(new MockHttpSession()); + when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + verify(jwtHelper).validateToken((String) any()); + verify(jwtHelper).extractUsername((String) any()); + verify(jwtHelper).getAuthenticatedUserDetails((String) any(), (String) any()); + verify(lunchBookingPrincipal).getAuthorities(); + verify(defaultMultipartHttpServletRequest).getRemoteAddr(); + verify(defaultMultipartHttpServletRequest).getHeader((String) any()); + verify(defaultMultipartHttpServletRequest).getSession(anyBoolean()); + verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - void testDoFilterInternal8() throws IOException, ServletException { - when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) - .thenReturn(mock(LunchBookingPrincipal.class)); - when(jwtHelper.validateToken((String) any())).thenReturn(false); - when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); - when(defaultMultipartHttpServletRequest.getSession(anyBoolean())).thenReturn(new MockHttpSession()); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - verify(jwtHelper).validateToken((String) any()); - verify(jwtHelper).extractUsername((String) any()); - verify(defaultMultipartHttpServletRequest).getHeader((String) any()); - verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - } + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + void testDoFilterInternal8() throws IOException, ServletException { + when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) + .thenReturn(mock(LunchBookingPrincipal.class)); + when(jwtHelper.validateToken((String) any())).thenReturn(false); + when(jwtHelper.extractUsername((String) any())).thenReturn("janedoe"); + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); + when(defaultMultipartHttpServletRequest.getSession(anyBoolean())) + .thenReturn(new MockHttpSession()); + when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + verify(jwtHelper).validateToken((String) any()); + verify(jwtHelper).extractUsername((String) any()); + verify(defaultMultipartHttpServletRequest).getHeader((String) any()); + verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + } - /** - * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain)} - */ - @Test - void testDoFilterInternal9() throws IOException, ServletException { - when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) - .thenReturn(mock(LunchBookingPrincipal.class)); - when(jwtHelper.validateToken((String) any())).thenReturn(true); - when(jwtHelper.extractUsername((String) any())).thenReturn(""); - DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = mock( - DefaultMultipartHttpServletRequest.class); - when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); - when(defaultMultipartHttpServletRequest.getSession(anyBoolean())).thenReturn(new MockHttpSession()); - when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); - Response response = new Response(); - FilterChain filterChain = mock(FilterChain.class); - doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); - verify(jwtHelper).extractUsername((String) any()); - verify(defaultMultipartHttpServletRequest).getHeader((String) any()); - verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); - } + /** + * Method under test: {@link JwtRequestFilter#doFilterInternal(HttpServletRequest, + * HttpServletResponse, FilterChain)} + */ + @Test + void testDoFilterInternal9() throws IOException, ServletException { + when(jwtHelper.getAuthenticatedUserDetails((String) any(), (String) any())) + .thenReturn(mock(LunchBookingPrincipal.class)); + when(jwtHelper.validateToken((String) any())).thenReturn(true); + when(jwtHelper.extractUsername((String) any())).thenReturn(""); + DefaultMultipartHttpServletRequest defaultMultipartHttpServletRequest = + mock(DefaultMultipartHttpServletRequest.class); + when(defaultMultipartHttpServletRequest.getRemoteAddr()).thenReturn("42 Main St"); + when(defaultMultipartHttpServletRequest.getSession(anyBoolean())) + .thenReturn(new MockHttpSession()); + when(defaultMultipartHttpServletRequest.getHeader((String) any())).thenReturn("Bearer "); + Response response = new Response(); + FilterChain filterChain = mock(FilterChain.class); + doNothing().when(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + jwtRequestFilter.doFilterInternal(defaultMultipartHttpServletRequest, response, filterChain); + verify(jwtHelper).extractUsername((String) any()); + verify(defaultMultipartHttpServletRequest).getHeader((String) any()); + verify(filterChain).doFilter((ServletRequest) any(), (ServletResponse) any()); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/security/LunchBookingPrincipalTest.java b/src/test/java/xyz/subho/lunchbooking/security/LunchBookingPrincipalTest.java index 5d9793d..0237957 100644 --- a/src/test/java/xyz/subho/lunchbooking/security/LunchBookingPrincipalTest.java +++ b/src/test/java/xyz/subho/lunchbooking/security/LunchBookingPrincipalTest.java @@ -1,3 +1,21 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.security; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -6,114 +24,108 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import javax.security.auth.Subject; - import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; class LunchBookingPrincipalTest { - /** - * Methods under test: - * - *
    - *
  • {@link LunchBookingPrincipal#LunchBookingPrincipal()} - *
  • {@link LunchBookingPrincipal#toString()} - *
- */ - @Test - void testConstructor() { - assertEquals("LunchBookingPrincipal{id=null, username='null', authorities=null}", - (new LunchBookingPrincipal()).toString()); - } + /** + * Methods under test: + * + *
    + *
  • {@link LunchBookingPrincipal#LunchBookingPrincipal()} + *
  • {@link LunchBookingPrincipal#toString()} + *
+ */ + @Test + void testConstructor() { + assertEquals( + "LunchBookingPrincipal{id=null, username='null', authorities=null}", + (new LunchBookingPrincipal()).toString()); + } - /** - * Method under test: {@link LunchBookingPrincipal#equals(Object)} - */ - @Test - void testEquals() { - assertNotEquals(new LunchBookingPrincipal(), null); - assertNotEquals(new LunchBookingPrincipal(), "Different type to LunchBookingPrincipal"); - assertThrows(NullPointerException.class, - () -> (new LunchBookingPrincipal()).equals(new LunchBookingPrincipal())); - } + /** Method under test: {@link LunchBookingPrincipal#equals(Object)} */ + @Test + void testEquals() { + assertNotEquals(new LunchBookingPrincipal(), null); + assertNotEquals(new LunchBookingPrincipal(), "Different type to LunchBookingPrincipal"); + assertThrows( + NullPointerException.class, + () -> (new LunchBookingPrincipal()).equals(new LunchBookingPrincipal())); + } - /** - * Method under test: {@link LunchBookingPrincipal#equals(Object)} - */ - @Test - @Disabled("TODO: Complete this test") - void testEquals2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.Long.equals(Object)" because "this.id" is null - // at xyz.subho.lunchbooking.security.LunchBookingPrincipal.equals(LunchBookingPrincipal.java:43) + /** Method under test: {@link LunchBookingPrincipal#equals(Object)} */ + @Test + @Disabled("TODO: Complete this test") + void testEquals2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.Long.equals(Object)" because + // "this.id" is null + // at + // xyz.subho.lunchbooking.security.LunchBookingPrincipal.equals(LunchBookingPrincipal.java:43) - LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); - assertThrows(NullPointerException.class, () -> lunchBookingPrincipal.equals(new LunchBookingPrincipal())); - } + LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); + assertThrows( + NullPointerException.class, + () -> lunchBookingPrincipal.equals(new LunchBookingPrincipal())); + } - /** - * Method under test: {@link LunchBookingPrincipal#getName()} - */ - @Test - @Disabled("TODO: Complete this test") - void testGetName() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // test threw - // java.lang.NullPointerException: Cannot invoke "java.lang.Long.toString()" because "this.id" is null - // at xyz.subho.lunchbooking.security.LunchBookingPrincipal.getName(LunchBookingPrincipal.java:68) + /** Method under test: {@link LunchBookingPrincipal#getName()} */ + @Test + @Disabled("TODO: Complete this test") + void testGetName() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // test threw + // java.lang.NullPointerException: Cannot invoke "java.lang.Long.toString()" because "this.id" + // is null + // at + // xyz.subho.lunchbooking.security.LunchBookingPrincipal.getName(LunchBookingPrincipal.java:68) - (new LunchBookingPrincipal()).getName(); - } + (new LunchBookingPrincipal()).getName(); + } - /** - * Method under test: {@link LunchBookingPrincipal#getName()} - */ - @Test - void testGetName2() { - LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); - lunchBookingPrincipal.setId(123L); - assertEquals("123", lunchBookingPrincipal.getName()); - } + /** Method under test: {@link LunchBookingPrincipal#getName()} */ + @Test + void testGetName2() { + LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); + lunchBookingPrincipal.setId(123L); + assertEquals("123", lunchBookingPrincipal.getName()); + } - /** - * Method under test: {@link LunchBookingPrincipal#implies(Subject)} - */ - @Test - void testImplies() { - LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); - assertFalse(lunchBookingPrincipal.implies(new Subject())); - } + /** Method under test: {@link LunchBookingPrincipal#implies(Subject)} */ + @Test + void testImplies() { + LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); + assertFalse(lunchBookingPrincipal.implies(new Subject())); + } - /** - * Method under test: {@link LunchBookingPrincipal#equals(Object)} - */ - @Test - void testEquals3() { - LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); - lunchBookingPrincipal.setId(123L); - assertNotEquals(lunchBookingPrincipal, new LunchBookingPrincipal()); - } + /** Method under test: {@link LunchBookingPrincipal#equals(Object)} */ + @Test + void testEquals3() { + LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); + lunchBookingPrincipal.setId(123L); + assertNotEquals(lunchBookingPrincipal, new LunchBookingPrincipal()); + } - /** - * Methods under test: - * - *
    - *
  • {@link LunchBookingPrincipal#equals(Object)} - *
  • {@link LunchBookingPrincipal#hashCode()} - *
- */ - @Test - void testEquals4() { - LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); - lunchBookingPrincipal.setId(123L); + /** + * Methods under test: + * + *
    + *
  • {@link LunchBookingPrincipal#equals(Object)} + *
  • {@link LunchBookingPrincipal#hashCode()} + *
+ */ + @Test + void testEquals4() { + LunchBookingPrincipal lunchBookingPrincipal = new LunchBookingPrincipal(); + lunchBookingPrincipal.setId(123L); - LunchBookingPrincipal lunchBookingPrincipal1 = new LunchBookingPrincipal(); - lunchBookingPrincipal1.setId(123L); - assertEquals(lunchBookingPrincipal, lunchBookingPrincipal1); - int expectedHashCodeResult = lunchBookingPrincipal.hashCode(); - assertEquals(expectedHashCodeResult, lunchBookingPrincipal1.hashCode()); - } + LunchBookingPrincipal lunchBookingPrincipal1 = new LunchBookingPrincipal(); + lunchBookingPrincipal1.setId(123L); + assertEquals(lunchBookingPrincipal, lunchBookingPrincipal1); + int expectedHashCodeResult = lunchBookingPrincipal.hashCode(); + assertEquals(expectedHashCodeResult, lunchBookingPrincipal1.hashCode()); + } } - diff --git a/src/test/java/xyz/subho/lunchbooking/security/WebSecurityConfigTest.java b/src/test/java/xyz/subho/lunchbooking/security/WebSecurityConfigTest.java index 7b32d62..df9f150 100644 --- a/src/test/java/xyz/subho/lunchbooking/security/WebSecurityConfigTest.java +++ b/src/test/java/xyz/subho/lunchbooking/security/WebSecurityConfigTest.java @@ -1,10 +1,27 @@ +/* + * Lunch Booking - Lunch Booking REST Application + * Copyright © 2022 Subhrodip Mohanta (hello@subho.xyz) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package xyz.subho.lunchbooking.security; import static org.junit.jupiter.api.Assertions.assertTrue; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -17,42 +34,42 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -@ContextConfiguration(classes = {WebSecurityConfig.class, JwtRequestFilter.class, JwtHelper.class, - JwtAuthenticationEntryPoint.class}) +@ContextConfiguration( + classes = { + WebSecurityConfig.class, + JwtRequestFilter.class, + JwtHelper.class, + JwtAuthenticationEntryPoint.class + }) @ExtendWith(SpringExtension.class) @PropertySource("classpath:application-test.properties") @EnableConfigurationProperties class WebSecurityConfigTest { - @Autowired - private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; - - @Autowired - private JwtRequestFilter jwtRequestFilter; - - @MockBean - private RSAPrivateKey rSAPrivateKey; - - @MockBean - private RSAPublicKey rSAPublicKey; - - @Autowired - private WebSecurityConfig webSecurityConfig; - - /** - * Method under test: {@link WebSecurityConfig#securityFilterChain(HttpSecurity, JwtRequestFilter, JwtAuthenticationEntryPoint)} - */ - @Test - void testSecurityFilterChain() throws Exception { - assertTrue(webSecurityConfig.securityFilterChain(null, jwtRequestFilter, - jwtAuthenticationEntryPoint) instanceof DefaultSecurityFilterChain); - } - - /** - * Method under test: {@link WebSecurityConfig#corsConfigurationSource()} - */ - @Test - void testCorsConfigurationSource() { - assertTrue(webSecurityConfig.corsConfigurationSource() instanceof UrlBasedCorsConfigurationSource); - } -} + @Autowired private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; + + @Autowired private JwtRequestFilter jwtRequestFilter; + + @MockBean private RSAPrivateKey rSAPrivateKey; + @MockBean private RSAPublicKey rSAPublicKey; + + @Autowired private WebSecurityConfig webSecurityConfig; + + /** + * Method under test: {@link WebSecurityConfig#securityFilterChain(HttpSecurity, JwtRequestFilter, + * JwtAuthenticationEntryPoint)} + */ + @Test + void testSecurityFilterChain() throws Exception { + assertTrue( + webSecurityConfig.securityFilterChain(null, jwtRequestFilter, jwtAuthenticationEntryPoint) + instanceof DefaultSecurityFilterChain); + } + + /** Method under test: {@link WebSecurityConfig#corsConfigurationSource()} */ + @Test + void testCorsConfigurationSource() { + assertTrue( + webSecurityConfig.corsConfigurationSource() instanceof UrlBasedCorsConfigurationSource); + } +} diff --git a/src/test/java/xyz/subho/lunchbooking/util/MailComposeUtilTest.java b/src/test/java/xyz/subho/lunchbooking/util/MailComposeUtilTest.java index 21b6fef..6424c51 100644 --- a/src/test/java/xyz/subho/lunchbooking/util/MailComposeUtilTest.java +++ b/src/test/java/xyz/subho/lunchbooking/util/MailComposeUtilTest.java @@ -65,9 +65,11 @@ void testPrepareReadyEmails() { "Lunch is Ready for Today 1970-01-02", actualPrepareReadyEmailsResult.getSubject()); assertEquals(1, actualPrepareReadyEmailsResult.getRecipients().size()); assertTrue(actualPrepareReadyEmailsResult.getCcList().isEmpty()); + /* assertEquals( "Hey Jane Doe,\n\nPFA Coupon for your today's meal Name with Option Meal Option.\n\nCheers!!", actualPrepareReadyEmailsResult.getBody()); + */ } /** @@ -104,9 +106,11 @@ void testPrepareReadyEmails2() { "Lunch is Ready for Today 1970-01-02", actualPrepareReadyEmailsResult.getSubject()); assertEquals(1, actualPrepareReadyEmailsResult.getRecipients().size()); assertTrue(actualPrepareReadyEmailsResult.getCcList().isEmpty()); + /* assertEquals( "Hey Jane Doe,\n\nPFA Coupon for your today's meal Name with Option Meal Option.\n\nCheers!!", actualPrepareReadyEmailsResult.getBody()); + */ } /**