@Test @Order(4) public void testRegister() { int maxId = given() .contentType(ContentType.JSON) .when().get("/all").as(new TypeRef<List<Employee>>() {}).size(); int createdId = maxId + 1; given() .queryParam("name", "test-user") .when().post("/") .then() .statusCode(201); testFindById(createdId, "test-user"); }
@PostMapping @ResponseStatus(HttpStatus.CREATED) public void register(@RequestParam("name") String name) { Employee employee = new Employee(); employee.setName(name); employeeRepository.save(employee); }
EmployeeController { @PostMapping @ResponseStatus(HttpStatus.CREATED) public void register(@RequestParam("name") String name) { Employee employee = new Employee(); employee.setName(name); employeeRepository.save(employee); } }
EmployeeController { @PostMapping @ResponseStatus(HttpStatus.CREATED) public void register(@RequestParam("name") String name) { Employee employee = new Employee(); employee.setName(name); employeeRepository.save(employee); } EmployeeController(EmployeeRepository employeeRepository); }
EmployeeController { @PostMapping @ResponseStatus(HttpStatus.CREATED) public void register(@RequestParam("name") String name) { Employee employee = new Employee(); employee.setName(name); employeeRepository.save(employee); } EmployeeController(EmployeeRepository employeeRepository); @GetMapping(value = "/all", produces = "application/json") Iterable<Employee> getAll(); @GetMapping("/{id}") Employee get(@PathVariable long id); @PostMapping @ResponseStatus(HttpStatus.CREATED) void register(@RequestParam("name") String name); @DeleteMapping("/{id}") ResponseEntity<Void> resign(@PathVariable long id); }
EmployeeController { @PostMapping @ResponseStatus(HttpStatus.CREATED) public void register(@RequestParam("name") String name) { Employee employee = new Employee(); employee.setName(name); employeeRepository.save(employee); } EmployeeController(EmployeeRepository employeeRepository); @GetMapping(value = "/all", produces = "application/json") Iterable<Employee> getAll(); @GetMapping("/{id}") Employee get(@PathVariable long id); @PostMapping @ResponseStatus(HttpStatus.CREATED) void register(@RequestParam("name") String name); @DeleteMapping("/{id}") ResponseEntity<Void> resign(@PathVariable long id);  }