Skip to content

Commit

Permalink
fix WebSocketClientFactoryContextTest
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Hernán Carle <pablo.carle@broadcom.com>
  • Loading branch information
Pablo Hernán Carle committed Aug 23, 2024
1 parent 7221a3f commit 09acdcf
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = {
Expand All @@ -44,14 +51,19 @@ public class WebSocketClientFactoryContextTest {
@Autowired
private WebSocketClientFactory webSocketClientFactory;

@BeforeEach
void setUp() {
webSocketClientFactory.getClientInstance("key");
}

@Nested
class GivenWebSocketClientParametrization {

@Test
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();
Expand All @@ -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<String, JettyWebSocketClient> clients = new ConcurrentHashMap<>();
clients.put("key", client);
ReflectionTestUtils.setField(factory, "clientsMap", clients);
}

@Test
void whenIsRunning_thenStop() {
doReturn(true).when(client).isRunning();
Expand Down

0 comments on commit 09acdcf

Please sign in to comment.