@Test(expected = ChargePointCommunicationException.class) public void ioExceptionShouldResultInCommunicationExceptionOnSendMessage() throws IOException, ChargePointCommunicationException { WebSocket mockWebSocket = getMockWebSocket(); WebSocketWrapper wrapper = new WebSocketWrapper(CHARGING_STATION_ID, mockWebSocket, mock(WampMessageHandler.class), gson); WampMessage wampMessage = new WampMessage(WampMessage.CALL, "1", MessageProcUri.CANCEL_RESERVATION, "dummy payload"); when(mockWebSocket.write(anyString())).thenThrow(new IOException("dummy exception")); wrapper.sendMessage(wampMessage); }
public void sendMessage(WampMessage wampMessage) throws ChargePointCommunicationException { String wampMessageRaw = wampMessage.toJson(gson); try { writeToSocket(wampMessageRaw); if (wampMessageHandler != null) { wampMessageHandler.handleWampCall( chargingStationId.getId(), wampMessageRaw, wampMessage.getCallId() ); } } catch (IOException e) { LOG.error("IOException while writing to web socket [{}] message [{}]. Closing websocket", chargingStationId, wampMessageRaw, e); throw new ChargePointCommunicationException("Error during writing to web socket [" + chargingStationId + "] message [" + wampMessageRaw + "]", e, webSocket); } }
WebSocketWrapper { public void sendMessage(WampMessage wampMessage) throws ChargePointCommunicationException { String wampMessageRaw = wampMessage.toJson(gson); try { writeToSocket(wampMessageRaw); if (wampMessageHandler != null) { wampMessageHandler.handleWampCall( chargingStationId.getId(), wampMessageRaw, wampMessage.getCallId() ); } } catch (IOException e) { LOG.error("IOException while writing to web socket [{}] message [{}]. Closing websocket", chargingStationId, wampMessageRaw, e); throw new ChargePointCommunicationException("Error during writing to web socket [" + chargingStationId + "] message [" + wampMessageRaw + "]", e, webSocket); } } }
WebSocketWrapper { public void sendMessage(WampMessage wampMessage) throws ChargePointCommunicationException { String wampMessageRaw = wampMessage.toJson(gson); try { writeToSocket(wampMessageRaw); if (wampMessageHandler != null) { wampMessageHandler.handleWampCall( chargingStationId.getId(), wampMessageRaw, wampMessage.getCallId() ); } } catch (IOException e) { LOG.error("IOException while writing to web socket [{}] message [{}]. Closing websocket", chargingStationId, wampMessageRaw, e); throw new ChargePointCommunicationException("Error during writing to web socket [" + chargingStationId + "] message [" + wampMessageRaw + "]", e, webSocket); } } WebSocketWrapper(ChargingStationId chargingStationId, WebSocket webSocket, WampMessageHandler wampMessageHandler,
                            Gson gson); }
WebSocketWrapper { public void sendMessage(WampMessage wampMessage) throws ChargePointCommunicationException { String wampMessageRaw = wampMessage.toJson(gson); try { writeToSocket(wampMessageRaw); if (wampMessageHandler != null) { wampMessageHandler.handleWampCall( chargingStationId.getId(), wampMessageRaw, wampMessage.getCallId() ); } } catch (IOException e) { LOG.error("IOException while writing to web socket [{}] message [{}]. Closing websocket", chargingStationId, wampMessageRaw, e); throw new ChargePointCommunicationException("Error during writing to web socket [" + chargingStationId + "] message [" + wampMessageRaw + "]", e, webSocket); } } WebSocketWrapper(ChargingStationId chargingStationId, WebSocket webSocket, WampMessageHandler wampMessageHandler,
                            Gson gson); WebSocket getWebSocket(); boolean isOpen(); void close(); void sendMessage(WampMessage wampMessage); void sendResultMessage(WampMessage wampMessage); }
WebSocketWrapper { public void sendMessage(WampMessage wampMessage) throws ChargePointCommunicationException { String wampMessageRaw = wampMessage.toJson(gson); try { writeToSocket(wampMessageRaw); if (wampMessageHandler != null) { wampMessageHandler.handleWampCall( chargingStationId.getId(), wampMessageRaw, wampMessage.getCallId() ); } } catch (IOException e) { LOG.error("IOException while writing to web socket [{}] message [{}]. Closing websocket", chargingStationId, wampMessageRaw, e); throw new ChargePointCommunicationException("Error during writing to web socket [" + chargingStationId + "] message [" + wampMessageRaw + "]", e, webSocket); } } WebSocketWrapper(ChargingStationId chargingStationId, WebSocket webSocket, WampMessageHandler wampMessageHandler,
                            Gson gson); WebSocket getWebSocket(); boolean isOpen(); void close(); void sendMessage(WampMessage wampMessage); void sendResultMessage(WampMessage wampMessage);  }