@Test(expected = LoopThroughIllegalStateException.class) public void closeOrCancelAnAlreadyClosedOrCanceledOrderShouldFail() throws CommunicationException { when(pendingOrderMapper.has(EXAMPLE_PENDING_ORDER_ID)).thenReturn(false); final OrderManagement orderManagement = cut.sendOrder(EXAMPLE_PENDING_ORDER, exampleOrderEventListener); orderManagement.closeOrCancelOrder(); }
@Override public OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener) { try { clientConnection.sendMessage(new PlacePendingOrderMessage(order)); final ResponsePlacePendingOrderMessage idMessage = clientConnection .readMessage(ResponsePlacePendingOrderMessage.class); if (idMessage.isSuccess()) { orderMapper.put(idMessage.getId().get(), eventListener); return new RemoteOrderManagement(idMessage.getId().get()); } else { eventListener.orderRejected(new MetaTraderFailure(idMessage.getErrorCode().get())); return NO_OP_ORDER_MANAGEMENT; } } catch (final CommunicationException e) { throw new LoopThroughCommunicationException(e); } }
RemoteBroker implements Broker<PendingOrder> { @Override public OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener) { try { clientConnection.sendMessage(new PlacePendingOrderMessage(order)); final ResponsePlacePendingOrderMessage idMessage = clientConnection .readMessage(ResponsePlacePendingOrderMessage.class); if (idMessage.isSuccess()) { orderMapper.put(idMessage.getId().get(), eventListener); return new RemoteOrderManagement(idMessage.getId().get()); } else { eventListener.orderRejected(new MetaTraderFailure(idMessage.getErrorCode().get())); return NO_OP_ORDER_MANAGEMENT; } } catch (final CommunicationException e) { throw new LoopThroughCommunicationException(e); } } }
RemoteBroker implements Broker<PendingOrder> { @Override public OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener) { try { clientConnection.sendMessage(new PlacePendingOrderMessage(order)); final ResponsePlacePendingOrderMessage idMessage = clientConnection .readMessage(ResponsePlacePendingOrderMessage.class); if (idMessage.isSuccess()) { orderMapper.put(idMessage.getId().get(), eventListener); return new RemoteOrderManagement(idMessage.getId().get()); } else { eventListener.orderRejected(new MetaTraderFailure(idMessage.getErrorCode().get())); return NO_OP_ORDER_MANAGEMENT; } } catch (final CommunicationException e) { throw new LoopThroughCommunicationException(e); } } RemoteBroker(final MessageBasedClientConnection clientConnection, final PendingOrderMapper orderMapper); }
RemoteBroker implements Broker<PendingOrder> { @Override public OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener) { try { clientConnection.sendMessage(new PlacePendingOrderMessage(order)); final ResponsePlacePendingOrderMessage idMessage = clientConnection .readMessage(ResponsePlacePendingOrderMessage.class); if (idMessage.isSuccess()) { orderMapper.put(idMessage.getId().get(), eventListener); return new RemoteOrderManagement(idMessage.getId().get()); } else { eventListener.orderRejected(new MetaTraderFailure(idMessage.getErrorCode().get())); return NO_OP_ORDER_MANAGEMENT; } } catch (final CommunicationException e) { throw new LoopThroughCommunicationException(e); } } RemoteBroker(final MessageBasedClientConnection clientConnection, final PendingOrderMapper orderMapper); @Override OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener); }
RemoteBroker implements Broker<PendingOrder> { @Override public OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener) { try { clientConnection.sendMessage(new PlacePendingOrderMessage(order)); final ResponsePlacePendingOrderMessage idMessage = clientConnection .readMessage(ResponsePlacePendingOrderMessage.class); if (idMessage.isSuccess()) { orderMapper.put(idMessage.getId().get(), eventListener); return new RemoteOrderManagement(idMessage.getId().get()); } else { eventListener.orderRejected(new MetaTraderFailure(idMessage.getErrorCode().get())); return NO_OP_ORDER_MANAGEMENT; } } catch (final CommunicationException e) { throw new LoopThroughCommunicationException(e); } } RemoteBroker(final MessageBasedClientConnection clientConnection, final PendingOrderMapper orderMapper); @Override OrderManagement sendOrder(final PendingOrder order, final OrderEventListener eventListener);  }