OandaOrderManagementProvider implements OrderManagementProvider<Long, String, Long> { @Override public boolean modifyOrder(Order<String, Long> order, Long accountId) { CloseableHttpClient httpClient = getHttpClient(); try { HttpPatch httpPatch = createPatchCommand(order, accountId); LOG.info(TradingUtils.executingRequestMsg(httpPatch)); HttpResponse resp = httpClient.execute(httpPatch); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK && resp.getEntity() != null) { LOG.info("Order Modified->" + TradingUtils.responseToString(resp)); return true; } LOG.warn(String.format("order %s could not be modified.", order.toString())); } catch (Exception e) { LOG.error(String.format("error encountered whilst modifying order %d for account %d", order, accountId), e); } finally { TradingUtils.closeSilently(httpClient); } return false; } OandaOrderManagementProvider(String url, String accessToken, AccountDataProvider<Long> accountDataProvider); @Override boolean closeOrder(Long orderId, Long accountId); @Override Long placeOrder(Order<String, Long> order, Long accountId); @Override Order<String, Long> pendingOrderForAccount(Long orderId, Long accountId); @Override Collection<Order<String, Long>> pendingOrdersForInstrument(TradeableInstrument<String> instrument); @Override Collection<Order<String, Long>> allPendingOrders(); @Override Collection<Order<String, Long>> pendingOrdersForAccount(Long accountId); @Override boolean modifyOrder(Order<String, Long> order, Long accountId);  }
@Test @SuppressWarnings("unchecked") public void modifyOrderTest() throws Exception { OandaOrderManagementProvider service = new OandaOrderManagementProvider(OandaTestConstants.url, OandaTestConstants.accessToken, null); OandaOrderManagementProvider spy = doMockStuff("src/test/resources/orderForAccount123456.txt", service); Order<String, Long> order = mock(Order.class); when(order.getTakeProfit()).thenReturn(119.45); when(order.getStopLoss()).thenReturn(124.75); when(order.getUnits()).thenReturn(1000l); when(order.getPrice()).thenReturn(122.0); when(order.getOrderId()).thenReturn(OandaTestConstants.orderId); spy.modifyOrder(order, OandaTestConstants.accountId); verify(spy, times(1)).createPatchCommand(order, OandaTestConstants.accountId); verify(order, times(1)).getOrderId(); verify(order, times(1)).getTakeProfit(); verify(order, times(1)).getStopLoss(); verify(order, times(1)).getPrice(); }