@Test public void getUserAccountResourceShouldReturnAccount() throws Exception { String content = "{\"userId\": 1, \"accountNumber\": \"123456789\", \"defaultAccount\": true}"; Account account = new Account(1L, "123456789", true); given(this.accountService.getAccount(1L)) .willReturn(account); this.mvc.perform(get("/v1/accounts/1").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andExpect(content().json(content)); }
@GetMapping(path = "/accounts/{id}") public ResponseEntity getAccount(@PathVariable Long id) { return Optional.ofNullable(getAccountResource(id)) .map(e -> new ResponseEntity<>(e, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
AccountController { @GetMapping(path = "/accounts/{id}") public ResponseEntity getAccount(@PathVariable Long id) { return Optional.ofNullable(getAccountResource(id)) .map(e -> new ResponseEntity<>(e, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); } }
AccountController { @GetMapping(path = "/accounts/{id}") public ResponseEntity getAccount(@PathVariable Long id) { return Optional.ofNullable(getAccountResource(id)) .map(e -> new ResponseEntity<>(e, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); } AccountController(AccountService accountService, EventService eventService); }
AccountController { @GetMapping(path = "/accounts/{id}") public ResponseEntity getAccount(@PathVariable Long id) { return Optional.ofNullable(getAccountResource(id)) .map(e -> new ResponseEntity<>(e, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); } AccountController(AccountService accountService, EventService eventService); @PostMapping(path = "/accounts") ResponseEntity createAccount(@RequestBody Account account); @PutMapping(path = "/accounts/{id}") ResponseEntity updateAccount(@RequestBody Account account, @PathVariable Long id); @GetMapping(path = "/accounts/{id}") ResponseEntity getAccount(@PathVariable Long id); @DeleteMapping(path = "/accounts/{id}") ResponseEntity deleteAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/events") ResponseEntity getAccountEvents(@PathVariable Long id); @PostMapping(path = "/accounts/{id}/events") ResponseEntity createAccount(@PathVariable Long id, @RequestBody AccountEvent event); @GetMapping(path = "/accounts/{id}/commands") ResponseEntity getAccountCommands(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/confirm") ResponseEntity confirmAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/activate") ResponseEntity activateAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/suspend") ResponseEntity suspendAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/archive") ResponseEntity archiveAccount(@PathVariable Long id); }
AccountController { @GetMapping(path = "/accounts/{id}") public ResponseEntity getAccount(@PathVariable Long id) { return Optional.ofNullable(getAccountResource(id)) .map(e -> new ResponseEntity<>(e, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); } AccountController(AccountService accountService, EventService eventService); @PostMapping(path = "/accounts") ResponseEntity createAccount(@RequestBody Account account); @PutMapping(path = "/accounts/{id}") ResponseEntity updateAccount(@RequestBody Account account, @PathVariable Long id); @GetMapping(path = "/accounts/{id}") ResponseEntity getAccount(@PathVariable Long id); @DeleteMapping(path = "/accounts/{id}") ResponseEntity deleteAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/events") ResponseEntity getAccountEvents(@PathVariable Long id); @PostMapping(path = "/accounts/{id}/events") ResponseEntity createAccount(@PathVariable Long id, @RequestBody AccountEvent event); @GetMapping(path = "/accounts/{id}/commands") ResponseEntity getAccountCommands(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/confirm") ResponseEntity confirmAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/activate") ResponseEntity activateAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/suspend") ResponseEntity suspendAccount(@PathVariable Long id); @GetMapping(path = "/accounts/{id}/commands/archive") ResponseEntity archiveAccount(@PathVariable Long id);  }