From e01f1619017734d896e1097d2c575f478e6b71ea Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 9 Jan 2025 19:54:02 +0100 Subject: [PATCH] Add unit test Signed-off-by: Florian Hotze --- .../core/io/websocket/EventWebSocketTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bundles/org.openhab.core.io.websocket/src/test/java/org/openhab/core/io/websocket/EventWebSocketTest.java b/bundles/org.openhab.core.io.websocket/src/test/java/org/openhab/core/io/websocket/EventWebSocketTest.java index c045a671237..d700ad279b4 100644 --- a/bundles/org.openhab.core.io.websocket/src/test/java/org/openhab/core/io/websocket/EventWebSocketTest.java +++ b/bundles/org.openhab.core.io.websocket/src/test/java/org/openhab/core/io/websocket/EventWebSocketTest.java @@ -240,6 +240,31 @@ public void eventFromBusFilterSource() throws IOException { verify(remoteEndpoint, times(2)).sendString(any()); } + @Test + public void eventFromBusFilterTopic() throws IOException { + EventDTO eventDTO = new EventDTO(WEBSOCKET_EVENT_TYPE, WEBSOCKET_TOPIC_PREFIX + "filter/topic", + "[\"openhab/items/*/command\", \"openhab/items/*/statechanged\"]", null, null); + EventDTO responseEventDTO = new EventDTO(WEBSOCKET_EVENT_TYPE, WEBSOCKET_TOPIC_PREFIX + "filter/topic", + eventDTO.payload, null, null); + eventWebSocket.onText(gson.toJson(eventDTO)); + verify(remoteEndpoint).sendString(gson.toJson(responseEventDTO)); + + // subscribed topics are sent + Event event = ItemEventFactory.createCommandEvent(TEST_ITEM_NAME, DecimalType.ZERO, + REMOTE_WEBSOCKET_IMPLEMENTATION); + eventWebSocket.processEvent(event); + verify(remoteEndpoint).sendString(gson.toJson(new EventDTO(event))); + + event = ItemEventFactory.createStateChangedEvent(TEST_ITEM_NAME, DecimalType.ZERO, DecimalType.ZERO); + eventWebSocket.processEvent(event); + verify(remoteEndpoint).sendString(gson.toJson(new EventDTO(event))); + + // not subscribed event not sent + event = ItemEventFactory.createStateEvent(TEST_ITEM_NAME, DecimalType.ZERO, REMOTE_WEBSOCKET_IMPLEMENTATION); + eventWebSocket.processEvent(event); + verify(remoteEndpoint, times(3)).sendString(any()); + } + private void assertEventProcessing(EventDTO incoming, @Nullable Event expectedEvent, @Nullable EventDTO expectedResponse) throws IOException { eventWebSocket.onText(gson.toJson(incoming));