@Test public void testIndex() throws Exception { OrderBookEntry orderBookEntry = new OrderBookEntry(); BuyOrder buyOrder = new BuyOrder(); SellOrder sellOrder = new SellOrder(); PortfolioEntry portfolioEntry = new PortfolioEntry(); portfolioEntry.setPrimaryKey(new PortfolioId().toString()); when(userServiceFacade.obtainPortfolioForUser()).thenReturn(portfolioEntry); when(tradeServiceFacade. prepareSellOrder(eq(TradeController.DEFUALT_COIN), eq(TradeController.DEFAULT_CCY_PAIR), eq(orderBookEntry), eq(portfolioEntry))) .thenReturn(sellOrder); when(tradeServiceFacade. prepareBuyOrder(eq(TradeController.DEFUALT_COIN), eq(TradeController.DEFAULT_CCY_PAIR), eq(orderBookEntry), eq(portfolioEntry))) .thenReturn(buyOrder); CoinEntry coinEntry = new CoinEntry(); when(tradeServiceFacade.loadOrderBookByCurrencyPair(eq(TradeController.DEFAULT_CCY_PAIR))).thenReturn(orderBookEntry); when(tradeServiceFacade.loadCoin(eq(TradeController.DEFUALT_COIN))).thenReturn(coinEntry); mockMvc.perform(get("/index")).andExpect(status().isOk()) .andExpect(model().attributeExists( "orderBook", "sellOrder", "buyOrder", "coin", "activeOrders", "buyOrders", "sellOrders", "executedTrades")); verify(tradeServiceFacade).prepareSellOrder(eq(TradeController.DEFUALT_COIN), eq(TradeController.DEFAULT_CCY_PAIR), eq(orderBookEntry), eq(portfolioEntry)); verify(tradeServiceFacade).prepareBuyOrder(eq(TradeController.DEFUALT_COIN), eq(TradeController.DEFAULT_CCY_PAIR), eq(orderBookEntry), eq(portfolioEntry)); verify(tradeServiceFacade).loadCoin(eq(TradeController.DEFUALT_COIN)); verify(tradeServiceFacade).loadOrderBookByCurrencyPair(eq(TradeController.DEFAULT_CCY_PAIR)); }
@SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) public String get(Model model) { OrderBookEntry orderBookEntry = tradeServiceFacade.loadOrderBookByCurrencyPair(DEFAULT_CCY_PAIR); model.addAttribute("orderBook", orderBookEntry); PortfolioEntry portfolioEntry = userServiceFacade.obtainPortfolioForUser(); SellOrder sellOrder = tradeServiceFacade.prepareSellOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("sellOrder", sellOrder); BuyOrder buyOrder = tradeServiceFacade.prepareBuyOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("buyOrder", buyOrder); initPage(DEFUALT_COIN, orderBookEntry, portfolioEntry, model); return "index"; }
TradeController { @SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) public String get(Model model) { OrderBookEntry orderBookEntry = tradeServiceFacade.loadOrderBookByCurrencyPair(DEFAULT_CCY_PAIR); model.addAttribute("orderBook", orderBookEntry); PortfolioEntry portfolioEntry = userServiceFacade.obtainPortfolioForUser(); SellOrder sellOrder = tradeServiceFacade.prepareSellOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("sellOrder", sellOrder); BuyOrder buyOrder = tradeServiceFacade.prepareBuyOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("buyOrder", buyOrder); initPage(DEFUALT_COIN, orderBookEntry, portfolioEntry, model); return "index"; } }
TradeController { @SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) public String get(Model model) { OrderBookEntry orderBookEntry = tradeServiceFacade.loadOrderBookByCurrencyPair(DEFAULT_CCY_PAIR); model.addAttribute("orderBook", orderBookEntry); PortfolioEntry portfolioEntry = userServiceFacade.obtainPortfolioForUser(); SellOrder sellOrder = tradeServiceFacade.prepareSellOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("sellOrder", sellOrder); BuyOrder buyOrder = tradeServiceFacade.prepareBuyOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("buyOrder", buyOrder); initPage(DEFUALT_COIN, orderBookEntry, portfolioEntry, model); return "index"; }  }
TradeController { @SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) public String get(Model model) { OrderBookEntry orderBookEntry = tradeServiceFacade.loadOrderBookByCurrencyPair(DEFAULT_CCY_PAIR); model.addAttribute("orderBook", orderBookEntry); PortfolioEntry portfolioEntry = userServiceFacade.obtainPortfolioForUser(); SellOrder sellOrder = tradeServiceFacade.prepareSellOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("sellOrder", sellOrder); BuyOrder buyOrder = tradeServiceFacade.prepareBuyOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("buyOrder", buyOrder); initPage(DEFUALT_COIN, orderBookEntry, portfolioEntry, model); return "index"; }  @Autowired void setTradeServiceFacade(TradeServiceFacade tradeServiceFacade); @Autowired void setUserServiceFacade(UserServiceFacade userServiceFacade); @SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) String get(Model model); @SuppressWarnings("unchecked") @RequestMapping(value = "refresh", method = RequestMethod.GET) String refresh(); @RequestMapping(value = "/coin/{coinId}", method = RequestMethod.GET) String details(@PathVariable String coinId, Model model); @RequestMapping(value = "/sell/{coinId}", method = RequestMethod.POST) String sell(@PathVariable String coinId,
                       @ModelAttribute("sellOrder") @Valid SellOrder order,
                       BindingResult bindingResult, Model model); @RequestMapping(value = "/buy/{coinId}", method = RequestMethod.POST) String buy(@PathVariable String coinId,
                      @ModelAttribute("buyOrder") @Valid BuyOrder order,
                      BindingResult bindingResult, Model model); }
TradeController { @SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) public String get(Model model) { OrderBookEntry orderBookEntry = tradeServiceFacade.loadOrderBookByCurrencyPair(DEFAULT_CCY_PAIR); model.addAttribute("orderBook", orderBookEntry); PortfolioEntry portfolioEntry = userServiceFacade.obtainPortfolioForUser(); SellOrder sellOrder = tradeServiceFacade.prepareSellOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("sellOrder", sellOrder); BuyOrder buyOrder = tradeServiceFacade.prepareBuyOrder(DEFUALT_COIN, DEFAULT_CCY_PAIR, orderBookEntry, portfolioEntry); model.addAttribute("buyOrder", buyOrder); initPage(DEFUALT_COIN, orderBookEntry, portfolioEntry, model); return "index"; }  @Autowired void setTradeServiceFacade(TradeServiceFacade tradeServiceFacade); @Autowired void setUserServiceFacade(UserServiceFacade userServiceFacade); @SuppressWarnings("unchecked") @RequestMapping(value = "index", method = RequestMethod.GET) String get(Model model); @SuppressWarnings("unchecked") @RequestMapping(value = "refresh", method = RequestMethod.GET) String refresh(); @RequestMapping(value = "/coin/{coinId}", method = RequestMethod.GET) String details(@PathVariable String coinId, Model model); @RequestMapping(value = "/sell/{coinId}", method = RequestMethod.POST) String sell(@PathVariable String coinId,
                       @ModelAttribute("sellOrder") @Valid SellOrder order,
                       BindingResult bindingResult, Model model); @RequestMapping(value = "/buy/{coinId}", method = RequestMethod.POST) String buy(@PathVariable String coinId,
                      @ModelAttribute("buyOrder") @Valid BuyOrder order,
                      BindingResult bindingResult, Model model);  }