From 09acdcf688c8f23a2b92001da165532533fcca2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Hern=C3=A1n=20Carle?= Date: Fri, 23 Aug 2024 10:31:57 +0200 Subject: [PATCH] fix WebSocketClientFactoryContextTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pablo HernĂ¡n Carle --- .../ws/WebSocketClientFactoryContextTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gateway-service/src/test/java/org/zowe/apiml/gateway/ws/WebSocketClientFactoryContextTest.java b/gateway-service/src/test/java/org/zowe/apiml/gateway/ws/WebSocketClientFactoryContextTest.java index 1f0f6c9bdf..5b5e43da13 100644 --- a/gateway-service/src/test/java/org/zowe/apiml/gateway/ws/WebSocketClientFactoryContextTest.java +++ b/gateway-service/src/test/java/org/zowe/apiml/gateway/ws/WebSocketClientFactoryContextTest.java @@ -14,6 +14,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -23,9 +24,15 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.socket.client.jetty.JettyWebSocketClient; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; @SpringBootTest( properties = { @@ -44,6 +51,11 @@ public class WebSocketClientFactoryContextTest { @Autowired private WebSocketClientFactory webSocketClientFactory; + @BeforeEach + void setUp() { + webSocketClientFactory.getClientInstance("key"); + } + @Nested class GivenWebSocketClientParametrization { @@ -51,7 +63,7 @@ class GivenWebSocketClientParametrization { void thenBeanIsInitialized() { assertNotNull(webSocketClientFactory); - JettyWebSocketClient jettyWebSocketClient = (JettyWebSocketClient) ReflectionTestUtils.getField(webSocketClientFactory, "client"); + JettyWebSocketClient jettyWebSocketClient = webSocketClientFactory.getClientInstance("key"); WebSocketClient webSocketClient = (WebSocketClient) ReflectionTestUtils.getField(jettyWebSocketClient, "client"); WebSocketPolicy policy = webSocketClient.getPolicy(); @@ -72,6 +84,13 @@ class GivenFactory { private JettyWebSocketClient client = mock(JettyWebSocketClient.class); private WebSocketClientFactory factory = new WebSocketClientFactory(null, 0, 0, 0, 0, 0); + @BeforeEach + void setUp() { + ConcurrentMap clients = new ConcurrentHashMap<>(); + clients.put("key", client); + ReflectionTestUtils.setField(factory, "clientsMap", clients); + } + @Test void whenIsRunning_thenStop() { doReturn(true).when(client).isRunning();