Bael 3557 : renamed package name to more unique name - springwithgroovy (#9172)
* BAEL-3557: Completed a simple web application in spring boot and groovy * BAEL-3557: renamed packagename from com.baeldung.app to more unique name - com.baeldung.springwithgroovy Co-authored-by: Vikas Ramsingh Rajput <vikas.rajput@crownconsult.com>
This commit is contained in:
		
							parent
							
								
									9efd76c261
								
							
						
					
					
						commit
						b8d41e5613
					
				| @ -0,0 +1,13 @@ | ||||
| package com.baeldung.springwithgroovy | ||||
| 
 | ||||
| import org.springframework.boot.SpringApplication | ||||
| import org.springframework.boot.autoconfigure.SpringBootApplication | ||||
| 
 | ||||
| import com.baeldung.springwithgroovy.SpringBootGroovyApplication | ||||
| 
 | ||||
| @SpringBootApplication | ||||
| class SpringBootGroovyApplication { | ||||
|     static void main(String[] args) { | ||||
|         SpringApplication.run SpringBootGroovyApplication, args | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,48 @@ | ||||
| package com.baeldung.springwithgroovy.controller | ||||
| 
 | ||||
| import org.springframework.beans.factory.annotation.Autowired | ||||
| import org.springframework.web.bind.annotation.DeleteMapping | ||||
| import org.springframework.web.bind.annotation.GetMapping | ||||
| import org.springframework.web.bind.annotation.PathVariable | ||||
| import org.springframework.web.bind.annotation.PostMapping | ||||
| import org.springframework.web.bind.annotation.PutMapping | ||||
| import org.springframework.web.bind.annotation.RequestBody | ||||
| import org.springframework.web.bind.annotation.RequestMapping | ||||
| import org.springframework.web.bind.annotation.RequestMethod | ||||
| import org.springframework.web.bind.annotation.RestController | ||||
| 
 | ||||
| import com.baeldung.springwithgroovy.entity.Todo | ||||
| import com.baeldung.springwithgroovy.service.TodoService | ||||
| 
 | ||||
| @RestController | ||||
| @RequestMapping('todo') | ||||
| public class TodoController { | ||||
| 
 | ||||
|     @Autowired | ||||
|     TodoService todoService | ||||
| 
 | ||||
|     @GetMapping | ||||
|     List<Todo> getAllTodoList(){ | ||||
|         todoService.findAll() | ||||
|     } | ||||
| 
 | ||||
|     @PostMapping | ||||
|     Todo saveTodo(@RequestBody Todo todo){ | ||||
|         todoService.saveTodo todo | ||||
|     } | ||||
| 
 | ||||
|     @PutMapping | ||||
|     Todo updateTodo(@RequestBody Todo todo){ | ||||
|         todoService.updateTodo todo | ||||
|     } | ||||
| 
 | ||||
|     @DeleteMapping('/{todoId}') | ||||
|     deleteTodo(@PathVariable Integer todoId){ | ||||
|         todoService.deleteTodo todoId | ||||
|     } | ||||
| 
 | ||||
|     @GetMapping('/{todoId}') | ||||
|     Todo getTodoById(@PathVariable Integer todoId){ | ||||
|         todoService.findById todoId | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,23 @@ | ||||
| package com.baeldung.springwithgroovy.entity | ||||
| 
 | ||||
| import javax.persistence.Column | ||||
| import javax.persistence.Entity | ||||
| import javax.persistence.GeneratedValue | ||||
| import javax.persistence.GenerationType | ||||
| import javax.persistence.Id | ||||
| import javax.persistence.Table | ||||
| 
 | ||||
| @Entity | ||||
| @Table(name = 'todo') | ||||
| class Todo { | ||||
|     @Id | ||||
|     @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||
|     Integer id | ||||
|      | ||||
|     @Column | ||||
|     String task | ||||
|      | ||||
|     @Column | ||||
|     Boolean isCompleted | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,9 @@ | ||||
| package com.baeldung.springwithgroovy.repository | ||||
| 
 | ||||
| import org.springframework.data.jpa.repository.JpaRepository | ||||
| import org.springframework.stereotype.Repository | ||||
| 
 | ||||
| import com.baeldung.springwithgroovy.entity.Todo | ||||
| 
 | ||||
| @Repository | ||||
| interface TodoRepository extends JpaRepository<Todo, Integer> {} | ||||
| @ -0,0 +1,16 @@ | ||||
| package com.baeldung.springwithgroovy.service | ||||
| 
 | ||||
| import com.baeldung.springwithgroovy.entity.Todo | ||||
| 
 | ||||
| interface TodoService { | ||||
| 
 | ||||
|     List<Todo> findAll() | ||||
| 
 | ||||
|     Todo findById(Integer todoId) | ||||
| 
 | ||||
|     Todo saveTodo(Todo todo) | ||||
| 
 | ||||
|     Todo updateTodo(Todo todo) | ||||
| 
 | ||||
|     Todo deleteTodo(Integer todoId) | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| package com.baeldung.springwithgroovy.service.impl | ||||
| 
 | ||||
| import org.springframework.beans.factory.annotation.Autowired | ||||
| import org.springframework.stereotype.Service | ||||
| 
 | ||||
| import com.baeldung.springwithgroovy.entity.Todo | ||||
| import com.baeldung.springwithgroovy.repository.TodoRepository | ||||
| import com.baeldung.springwithgroovy.service.TodoService | ||||
| 
 | ||||
| @Service | ||||
| class TodoServiceImpl implements TodoService { | ||||
| 
 | ||||
|     @Autowired | ||||
|     TodoRepository todoRepository | ||||
| 
 | ||||
|     @Override | ||||
|     List<Todo> findAll() { | ||||
|         todoRepository.findAll() | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     Todo findById(Integer todoId) { | ||||
|         todoRepository.findById todoId get() | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     Todo saveTodo(Todo todo){ | ||||
|         todoRepository.save todo | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     Todo updateTodo(Todo todo){ | ||||
|         todoRepository.save todo | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     Todo deleteTodo(Integer todoId){ | ||||
|         todoRepository.deleteById todoId | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,97 @@ | ||||
| package com.baeldung.springwithgroovy | ||||
| 
 | ||||
| import static org.junit.jupiter.api.Assertions.assertEquals | ||||
| import static org.junit.jupiter.api.Assertions.assertTrue | ||||
| 
 | ||||
| import org.junit.BeforeClass | ||||
| import org.junit.Test | ||||
| import org.junit.runner.RunWith | ||||
| import org.springframework.boot.test.context.SpringBootTest | ||||
| import org.springframework.http.HttpStatus | ||||
| import org.springframework.http.MediaType | ||||
| import org.springframework.test.context.event.annotation.BeforeTestClass | ||||
| import org.springframework.test.context.junit4.SpringRunner | ||||
| 
 | ||||
| import com.baeldung.springwithgroovy.entity.Todo | ||||
| 
 | ||||
| import io.restassured.RestAssured | ||||
| import io.restassured.response.Response | ||||
| 
 | ||||
| class TodoAppUnitTest { | ||||
|     static API_ROOT = 'http://localhost:8081/todo' | ||||
|     static readingTodoId | ||||
|     static writingTodoId | ||||
| 
 | ||||
|     @BeforeClass | ||||
|     static void populateDummyData() { | ||||
|         Todo readingTodo = new Todo(task: 'Reading', isCompleted: false) | ||||
|         Todo writingTodo = new Todo(task: 'Writing', isCompleted: false) | ||||
| 
 | ||||
|         final Response readingResponse =  | ||||
|           RestAssured.given() | ||||
|             .contentType(MediaType.APPLICATION_JSON_VALUE) | ||||
|               .body(readingTodo).post(API_ROOT) | ||||
|                | ||||
|         Todo cookingTodoResponse = readingResponse.as Todo.class | ||||
|         readingTodoId = cookingTodoResponse.getId() | ||||
| 
 | ||||
|         final Response writingResponse =  | ||||
|           RestAssured.given() | ||||
|             .contentType(MediaType.APPLICATION_JSON_VALUE) | ||||
|               .body(writingTodo).post(API_ROOT) | ||||
|                | ||||
|         Todo writingTodoResponse = writingResponse.as Todo.class | ||||
|         writingTodoId = writingTodoResponse.getId() | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void whenGetAllTodoList_thenOk(){ | ||||
|         final Response response = RestAssured.get(API_ROOT) | ||||
|          | ||||
|         assertEquals HttpStatus.OK.value(),response.getStatusCode() | ||||
|         assertTrue response.as(List.class).size() > 0 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void whenGetTodoById_thenOk(){ | ||||
|         final Response response =  | ||||
|           RestAssured.get("$API_ROOT/$readingTodoId") | ||||
|          | ||||
|         assertEquals HttpStatus.OK.value(),response.getStatusCode() | ||||
|         Todo todoResponse = response.as Todo.class | ||||
|         assertEquals readingTodoId,todoResponse.getId() | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void whenUpdateTodoById_thenOk(){ | ||||
|         Todo todo = new Todo(id:readingTodoId, isCompleted: true) | ||||
|         final Response response =  | ||||
|           RestAssured.given() | ||||
|             .contentType(MediaType.APPLICATION_JSON_VALUE) | ||||
|               .body(todo).put(API_ROOT) | ||||
|                | ||||
|         assertEquals HttpStatus.OK.value(),response.getStatusCode() | ||||
|         Todo todoResponse = response.as Todo.class | ||||
|         assertTrue todoResponse.getIsCompleted() | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void whenDeleteTodoById_thenOk(){ | ||||
|         final Response response =  | ||||
|           RestAssured.given() | ||||
|             .delete("$API_ROOT/$writingTodoId") | ||||
|          | ||||
|         assertEquals HttpStatus.OK.value(),response.getStatusCode() | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void whenSaveTodo_thenOk(){ | ||||
|         Todo todo = new Todo(task: 'Blogging', isCompleted: false) | ||||
|         final Response response =  | ||||
|           RestAssured.given() | ||||
|             .contentType(MediaType.APPLICATION_JSON_VALUE) | ||||
|               .body(todo).post(API_ROOT) | ||||
|                | ||||
|         assertEquals HttpStatus.OK.value(),response.getStatusCode() | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user