diff --git a/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResource.java b/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResource.java index ba026ca..70bcd67 100644 --- a/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResource.java +++ b/support-portal-backend/src/main/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResource.java @@ -16,6 +16,7 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.List; import static org.springframework.http.HttpStatus.OK; @@ -74,6 +75,11 @@ public class UserResource { return userService.findByUsername(username); } + @GetMapping + public List getAllUsers() { + return userService.findAll(); + } + private void authenticate(String username, String password) { Authentication auth = new UsernamePasswordAuthenticationToken(username, password); authenticationManager.authenticate(auth); diff --git a/support-portal-backend/src/test/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResourceUnSecureTest.java b/support-portal-backend/src/test/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResourceUnSecureTest.java index a02564a..db31280 100644 --- a/support-portal-backend/src/test/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResourceUnSecureTest.java +++ b/support-portal-backend/src/test/java/net/shyshkin/study/fullstack/supportportal/backend/controller/UserResourceUnSecureTest.java @@ -12,10 +12,12 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.test.context.TestPropertySource; +import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -467,4 +469,24 @@ class UserResourceUnSecureTest extends BaseUserTest { .hasFieldOrPropertyWithValue("message", String.format("User with username `%s` not found", username).toUpperCase()); } } + + @Nested + class GetAllUsersTests { + + @Test + void getAllUsers() { + + //when + var responseEntity = restTemplate.exchange("/user", HttpMethod.GET, null, new ParameterizedTypeReference>() { + }); + + //then + log.debug("Response Entity: {}", responseEntity); + assertThat(responseEntity.getStatusCode()).isEqualTo(OK); + assertThat(responseEntity.getBody()) + .isNotNull() + .hasSizeGreaterThan(2); + } + } + } \ No newline at end of file