@Test public void shouldSentCloseConditionChangesOfPendingOrdersCorrectly() throws CommunicationException { when(client.readMessage(ResponseChangeCloseConditionsMessage.class)).thenReturn( new ResponseChangeCloseConditionsMessage()); final OrderManagement orderManagement = cut.sendOrder(EXAMPLE_PENDING_ORDER, exampleOrderEventListener); final Optional<Failed> result = orderManagement.changeCloseConditionsOfOrder(EXAMPLE_NEW_CLOSE_CONDITIONS); verify(client, times(2)).sendMessage(sentMessage.capture()); assertThat(sentMessage.getAllValues().get(1)).isInstanceOf(ChangeCloseConditionsMessage.class); final ChangeCloseConditionsMessage changeCloseConditionsMessage = (ChangeCloseConditionsMessage) sentMessage .getAllValues().get(1); assertThat(changeCloseConditionsMessage.getId()).isEqualTo(EXAMPLE_PENDING_ORDER_ID); assertThat(changeCloseConditionsMessage.getNewCloseConditions()).isEqualTo(EXAMPLE_NEW_CLOSE_CONDITIONS); assertThat(result).isEmpty(); }
@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);  }