From f686f8fcdd0542cbcb33356ad6c967007b96604a Mon Sep 17 00:00:00 2001 From: Eugen Date: Wed, 22 May 2019 09:48:00 +0300 Subject: [PATCH] minor formatting work --- .../baeldung/SpringDataRestApplication.java | 2 ++ .../controllers/UserController.java | 10 +++---- .../repositories/UserRepository.java | 3 +- .../test/UserControllerIntegrationTest.java | 28 ++++--------------- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java b/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java index 94eddc5b3e..702acb5b65 100644 --- a/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java +++ b/spring-data-rest/src/main/java/com/baeldung/SpringDataRestApplication.java @@ -5,7 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringDataRestApplication { + public static void main(String[] args) { SpringApplication.run(SpringDataRestApplication.class, args); } + } diff --git a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java index 8258c3b7aa..eb5d8d51d4 100644 --- a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java +++ b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/controllers/UserController.java @@ -1,8 +1,5 @@ package com.baeldung.springdatawebsupport.application.controllers; -import com.baeldung.springdatawebsupport.application.entities.User; -import com.baeldung.springdatawebsupport.application.repositories.UserRepository; -import com.querydsl.core.types.Predicate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -11,9 +8,12 @@ import org.springframework.data.domain.Sort; import org.springframework.data.querydsl.binding.QuerydslPredicate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.baeldung.springdatawebsupport.application.entities.User; +import com.baeldung.springdatawebsupport.application.repositories.UserRepository; +import com.querydsl.core.types.Predicate; + @RestController public class UserController { @@ -33,7 +33,7 @@ public class UserController { public Page findAllUsers(Pageable pageable) { return userRepository.findAll(pageable); } - + @GetMapping("/sortedusers") public Page findAllUsersSortedByName() { Pageable pageable = PageRequest.of(0, 5, Sort.by("name")); diff --git a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java index 41d7ed9d98..a20197dc8b 100644 --- a/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java +++ b/spring-data-rest/src/main/java/com/baeldung/springdatawebsupport/application/repositories/UserRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; @Repository -public interface UserRepository extends PagingAndSortingRepository, - QuerydslPredicateExecutor { +public interface UserRepository extends PagingAndSortingRepository, QuerydslPredicateExecutor { } diff --git a/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java index db522b1413..e1aff7e09d 100644 --- a/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/springdatawebsupport/application/test/UserControllerIntegrationTest.java @@ -31,44 +31,28 @@ public class UserControllerIntegrationTest { @Test public void whenGetRequestToUsersEndPointWithIdPathVariable_thenCorrectResponse() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/users/{id}", "1") - .contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.id").value("1")); + mockMvc.perform(MockMvcRequestBuilders.get("/users/{id}", "1").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$.id").value("1")); } @Test public void whenGetRequestToUsersEndPoint_thenCorrectResponse() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/users") - .contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$['pageable']['paged']").value("true")); + mockMvc.perform(MockMvcRequestBuilders.get("/users").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$['pageable']['paged']").value("true")); } @Test public void whenGetRequestToUserEndPointWithNameRequestParameter_thenCorrectResponse() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/user") - .param("name", "John") - .contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$['content'][0].['name']").value("John")); + mockMvc.perform(MockMvcRequestBuilders.get("/user").param("name", "John").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$['content'][0].['name']").value("John")); } @Test public void whenGetRequestToSorteredUsersEndPoint_thenCorrectResponse() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/sortedusers") - .contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$['sort']['sorted']").value("true")); + mockMvc.perform(MockMvcRequestBuilders.get("/sortedusers").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$['sort']['sorted']").value("true")); } @Test public void whenGetRequestToFilteredUsersEndPoint_thenCorrectResponse() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/filteredusers") - .param("name", "John") - .contentType(MediaType.APPLICATION_JSON_UTF8)) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("John")); + mockMvc.perform(MockMvcRequestBuilders.get("/filteredusers").param("name", "John").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("John")); } }