parent
dc561548b3
commit
553c368b5b
|
@ -5,9 +5,10 @@ import java.util.List;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
|
@ -15,16 +16,16 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
public class EmployeeRestController {
|
||||
|
||||
@Autowired
|
||||
EmployeeService employeeService;
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@RequestMapping(value = "/employees", method = RequestMethod.POST)
|
||||
@PostMapping("/employees")
|
||||
public ResponseEntity<Employee> createEmployee(@RequestBody Employee employee) {
|
||||
HttpStatus status = HttpStatus.CREATED;
|
||||
Employee saved = employeeService.save(employee);
|
||||
return new ResponseEntity<>(saved, status);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/employees", method = RequestMethod.GET)
|
||||
@GetMapping("/employees")
|
||||
public List<Employee> getAllEmployees() {
|
||||
return employeeService.getAllEmployees();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.stereotype.Service;
|
|||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@Autowired
|
||||
EmployeeRepository employeeRepository;
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Override
|
||||
public Optional<Employee> getEmployeeById(Long id) {
|
||||
|
|
|
@ -20,10 +20,10 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
public class EmployeeRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
TestEntityManager entityManager;
|
||||
private TestEntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
EmployeeRepository employeeRepository;
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Test
|
||||
public void whenFindByName_thenReturnEmployee() {
|
||||
|
|
|
@ -34,10 +34,10 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
public class EmployeeRestControllerIntTest {
|
||||
|
||||
@Autowired
|
||||
MockMvc mvc;
|
||||
private MockMvc mvc;
|
||||
|
||||
@Autowired
|
||||
EmployeeRepository repository;
|
||||
private EmployeeRepository repository;
|
||||
|
||||
@After
|
||||
public void resetDb() {
|
||||
|
|
|
@ -33,10 +33,10 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
public class EmployeeRestControllerTest {
|
||||
|
||||
@Autowired
|
||||
MockMvc mvc;
|
||||
private MockMvc mvc;
|
||||
|
||||
@MockBean
|
||||
EmployeeService service;
|
||||
private EmployeeService service;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
|
|
@ -34,10 +34,10 @@ public class EmployeeServiceImplTest {
|
|||
}
|
||||
|
||||
@Autowired
|
||||
EmployeeService employeeService;
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@MockBean
|
||||
EmployeeRepository employeeRepository;
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
|
Loading…
Reference in New Issue