@Test public void shouldGetOneAccount() throws Exception { User bob = UserTestUtils.createBob(); Account savingsAccount = AccountTestUtils.createSavingsAccount(bob); when(accountServiceMock.get(savingsAccount.getId())).thenReturn(savingsAccount); final MockHttpServletRequestBuilder requestBuilder = get("/users/{userId}/accounts/{id}", bob.getId(), savingsAccount.getId()).accept(MediaType.APPLICATION_JSON); final MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn(); final MockHttpServletResponse response = mvcResult.getResponse(); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); final AccountResource userResource = JsonHelper.fromJson(response.getContentAsString(), AccountResource.class); assertThat(userResource.getDescription()).isEqualTo(savingsAccount.getDescription()); assertThat(userResource.getOnBudget()).isEqualTo(savingsAccount.isOnBudget()); }
@GetMapping("/{accountId}") public Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId) { Account account = accountService.get(accountId); final AccountResource accountResource = accountResourceAssembler.toResource(account); return new Resource<>(accountResource); }
AccountController { @GetMapping("/{accountId}") public Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId) { Account account = accountService.get(accountId); final AccountResource accountResource = accountResourceAssembler.toResource(account); return new Resource<>(accountResource); } }
AccountController { @GetMapping("/{accountId}") public Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId) { Account account = accountService.get(accountId); final AccountResource accountResource = accountResourceAssembler.toResource(account); return new Resource<>(accountResource); } @Autowired  AccountController(AccountService accountService, AccountResourceAssembler accountResourceAssembler); }
AccountController { @GetMapping("/{accountId}") public Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId) { Account account = accountService.get(accountId); final AccountResource accountResource = accountResourceAssembler.toResource(account); return new Resource<>(accountResource); } @Autowired  AccountController(AccountService accountService, AccountResourceAssembler accountResourceAssembler); @GetMapping Resources<AccountResource> list(@PathVariable("userId") long userId); @GetMapping("/{accountId}") Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId); @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<AccountResource> create(@PathVariable("userId") long userId, @RequestBody @Valid AccountResource accountResource); }
AccountController { @GetMapping("/{accountId}") public Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId) { Account account = accountService.get(accountId); final AccountResource accountResource = accountResourceAssembler.toResource(account); return new Resource<>(accountResource); } @Autowired  AccountController(AccountService accountService, AccountResourceAssembler accountResourceAssembler); @GetMapping Resources<AccountResource> list(@PathVariable("userId") long userId); @GetMapping("/{accountId}") Resource<AccountResource> get(@PathVariable("userId") long userId, @PathVariable("accountId") long accountId); @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<AccountResource> create(@PathVariable("userId") long userId, @RequestBody @Valid AccountResource accountResource);  }