PortfolioController { @RequestMapping(value = "/portfolio/{id}", method = RequestMethod.POST) public ResponseEntity<Order> addOrder(@PathVariable("id") final String accountId, @RequestBody final Order order, UriComponentsBuilder builder) { logger.debug("Adding Order: " + order); Order savedOrder = service.addOrder(order); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setLocation(builder.path("/portfolio/{id}") .buildAndExpand(accountId).toUri()); logger.debug("Order added: " + savedOrder); if (savedOrder != null && savedOrder.getOrderId() != null) { return new ResponseEntity<Order>(savedOrder, responseHeaders, HttpStatus.CREATED); } else { logger.warn("Order not saved: " + order); return new ResponseEntity<Order>(savedOrder, responseHeaders, HttpStatus.INTERNAL_SERVER_ERROR); } }  @RequestMapping(value = "/portfolio/{id}", method = RequestMethod.GET) ResponseEntity<Portfolio> getPortfolio(@PathVariable("id") final String accountId); @RequestMapping(value = "/portfolio/{id}", method = RequestMethod.POST) ResponseEntity<Order> addOrder(@PathVariable("id") final String accountId, @RequestBody final Order order, UriComponentsBuilder builder);  }
@Test public void addOrder() throws Exception { when(service.addOrder(ServiceTestConfiguration.order())) .thenReturn(ServiceTestConfiguration.order2()); mockMvc.perform( post("/portfolio/" + ServiceTestConfiguration.ACCOUNT_ID) .contentType(MediaType.APPLICATION_JSON) .content( convertObjectToJson(ServiceTestConfiguration.order()))) .andExpect(status().isCreated()).andDo(print()); }