minor formatting work
This commit is contained in:
		
							parent
							
								
									49304324ad
								
							
						
					
					
						commit
						f686f8fcdd
					
				| @ -5,7 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||||
| 
 | 
 | ||||||
| @SpringBootApplication | @SpringBootApplication | ||||||
| public class SpringDataRestApplication { | public class SpringDataRestApplication { | ||||||
|  | 
 | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|         SpringApplication.run(SpringDataRestApplication.class, args); |         SpringApplication.run(SpringDataRestApplication.class, args); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,8 +1,5 @@ | |||||||
| package com.baeldung.springdatawebsupport.application.controllers; | 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.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.data.domain.Page; | import org.springframework.data.domain.Page; | ||||||
| import org.springframework.data.domain.PageRequest; | 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.data.querydsl.binding.QuerydslPredicate; | ||||||
| import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||||
| import org.springframework.web.bind.annotation.PathVariable; | import org.springframework.web.bind.annotation.PathVariable; | ||||||
| import org.springframework.web.bind.annotation.RequestParam; |  | ||||||
| import org.springframework.web.bind.annotation.RestController; | 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 | @RestController | ||||||
| public class UserController { | public class UserController { | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -8,7 +8,6 @@ import org.springframework.data.repository.PagingAndSortingRepository; | |||||||
| import org.springframework.stereotype.Repository; | import org.springframework.stereotype.Repository; | ||||||
| 
 | 
 | ||||||
| @Repository | @Repository | ||||||
| public interface UserRepository extends PagingAndSortingRepository<User, Long>,  | public interface UserRepository extends PagingAndSortingRepository<User, Long>, QuerydslPredicateExecutor<User> { | ||||||
|   QuerydslPredicateExecutor<User> { |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -31,44 +31,28 @@ public class UserControllerIntegrationTest { | |||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenGetRequestToUsersEndPointWithIdPathVariable_thenCorrectResponse() throws Exception { |     public void whenGetRequestToUsersEndPointWithIdPathVariable_thenCorrectResponse() throws Exception { | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/users/{id}", "1") |         mockMvc.perform(MockMvcRequestBuilders.get("/users/{id}", "1").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$.id").value("1")); | ||||||
|           .contentType(MediaType.APPLICATION_JSON_UTF8)) |  | ||||||
|           .andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
|           .andExpect(MockMvcResultMatchers.jsonPath("$.id").value("1")); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenGetRequestToUsersEndPoint_thenCorrectResponse() throws Exception { |     public void whenGetRequestToUsersEndPoint_thenCorrectResponse() throws Exception { | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/users") |         mockMvc.perform(MockMvcRequestBuilders.get("/users").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$['pageable']['paged']").value("true")); | ||||||
|           .contentType(MediaType.APPLICATION_JSON_UTF8)) |  | ||||||
|           .andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
|           .andExpect(MockMvcResultMatchers.jsonPath("$['pageable']['paged']").value("true")); |  | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenGetRequestToUserEndPointWithNameRequestParameter_thenCorrectResponse() throws Exception { |     public void whenGetRequestToUserEndPointWithNameRequestParameter_thenCorrectResponse() throws Exception { | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/user") |         mockMvc.perform(MockMvcRequestBuilders.get("/user").param("name", "John").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()) | ||||||
|           .param("name", "John") |  | ||||||
|           .contentType(MediaType.APPLICATION_JSON_UTF8)) |  | ||||||
|           .andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
|                 .andExpect(MockMvcResultMatchers.jsonPath("$['content'][0].['name']").value("John")); |                 .andExpect(MockMvcResultMatchers.jsonPath("$['content'][0].['name']").value("John")); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenGetRequestToSorteredUsersEndPoint_thenCorrectResponse() throws Exception { |     public void whenGetRequestToSorteredUsersEndPoint_thenCorrectResponse() throws Exception { | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/sortedusers") |         mockMvc.perform(MockMvcRequestBuilders.get("/sortedusers").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$['sort']['sorted']").value("true")); | ||||||
|           .contentType(MediaType.APPLICATION_JSON_UTF8)) |  | ||||||
|           .andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
|           .andExpect(MockMvcResultMatchers.jsonPath("$['sort']['sorted']").value("true")); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     public void whenGetRequestToFilteredUsersEndPoint_thenCorrectResponse() throws Exception { |     public void whenGetRequestToFilteredUsersEndPoint_thenCorrectResponse() throws Exception { | ||||||
|         mockMvc.perform(MockMvcRequestBuilders.get("/filteredusers") |         mockMvc.perform(MockMvcRequestBuilders.get("/filteredusers").param("name", "John").contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("John")); | ||||||
|           .param("name", "John") |  | ||||||
|           .contentType(MediaType.APPLICATION_JSON_UTF8)) |  | ||||||
|           .andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
|           .andExpect(MockMvcResultMatchers.jsonPath("$[0].name").value("John")); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user