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