You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2023/11/22 14:54:04 UTC

(plc4x) branch fix-discovered-event updated: Additional test for dynamic registration of connection state listener.

This is an automated email from the ASF dual-hosted git repository.

ldywicki pushed a commit to branch fix-discovered-event
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/fix-discovered-event by this push:
     new dc2050cbb5 Additional test for dynamic registration of connection state listener.
dc2050cbb5 is described below

commit dc2050cbb52289f37d542fcadd23eb4a76e49eba
Author: Łukasz Dywicki <lu...@code-house.org>
AuthorDate: Tue Nov 21 15:14:43 2023 +0100

    Additional test for dynamic registration of connection state listener.
    
    Signed-off-by: Łukasz Dywicki <lu...@code-house.org>
---
 .../SingleProtocolStackConfigurerTest.java         | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/SingleProtocolStackConfigurerTest.java b/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/SingleProtocolStackConfigurerTest.java
index 701c428d43..22c7733c9b 100644
--- a/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/SingleProtocolStackConfigurerTest.java
+++ b/plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/SingleProtocolStackConfigurerTest.java
@@ -21,6 +21,7 @@ package org.apache.plc4x.java.spi.connection;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import io.netty.buffer.ByteBuf;
@@ -61,6 +62,29 @@ class SingleProtocolStackConfigurerTest {
         verify(connectionListener).disconnected();
     }
 
+    @Test
+    void testConnectionStateListenerAppended() throws Exception {
+        TestChannelFactory channelFactory = new TestChannelFactory();
+
+        SingleProtocolStackConfigurer<TestMessage> stackConfigurer = SingleProtocolStackConfigurer.builder(TestMessage.class, TestMessage::staticParse)
+            .withProtocol(TestProtocol.class)
+            .build();
+
+        EventPlcConnection connection = new PlcConnectionFactory().create(channelFactory, stackConfigurer);
+        connection.addEventListener(connectionListener);
+
+        connection.connect();
+        verify(connectionListener).connected();
+
+        // append listener after connection been made
+        ConnectionStateListener dynamicListener = mock(ConnectionStateListener.class);
+        connection.addEventListener(dynamicListener);
+
+        connection.close();
+        verify(connectionListener).disconnected();
+        verify(dynamicListener).disconnected();
+    }
+
     @Test
     void testMessageExchangeListener() throws Exception {
         TestChannelFactory channelFactory = new TestChannelFactory();