Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,11 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus.bundles</groupId>
<artifactId>tyrus-standalone-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@
*/
package org.gridsuite.study.notification.server;

import java.time.Duration;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.gridsuite.study.notification.server.dto.*;
import org.junit.Before;
import org.junit.Test;
import org.gridsuite.study.notification.server.dto.Filters;
import org.gridsuite.study.notification.server.dto.FiltersToAdd;
import org.gridsuite.study.notification.server.dto.FiltersToRemove;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.core.io.buffer.DataBuffer;
Expand All @@ -40,15 +33,23 @@
import reactor.core.publisher.FluxSink;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.gridsuite.study.notification.server.NotificationWebSocketHandler.*;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

/**
* @author Jon Harper <jon.harper at rte-france.com>
*/
public class NotificationWebSocketHandlerTest {
class NotificationWebSocketHandlerTest {

private ObjectMapper objectMapper;
private WebSocketSession ws;
Expand All @@ -57,8 +58,8 @@ public class NotificationWebSocketHandlerTest {

private final MeterRegistry meterRegistry = new SimpleMeterRegistry();

@Before
public void setup() {
@BeforeEach
void setup() {
objectMapper = new ObjectMapper();
var dataBufferFactory = new DefaultDataBufferFactory();

Expand Down Expand Up @@ -193,7 +194,7 @@ private void withFilters(String filterStudyUuid, String filterUpdateType, boolea
return (filterStudyUuid == null || filterStudyUuid.equals(studyUuid)) && (filterUpdateType == null || filterUpdateType.equals(updateType));
})
.map(GenericMessage::getHeaders)
.map(this::toResultHeader)
.map(NotificationWebSocketHandlerTest::toResultHeader)
.collect(Collectors.toList());

List<Map<String, Object>> actual = messages.stream().map(t -> {
Expand All @@ -207,7 +208,7 @@ private void withFilters(String filterStudyUuid, String filterUpdateType, boolea
assertNotEquals(0, actual.size());
}

private Map<String, Object> toResultHeader(Map<String, Object> messageHeader) {
private static Map<String, Object> toResultHeader(Map<String, Object> messageHeader) {
var resHeader = new HashMap<String, Object>();
resHeader.put(HEADER_TIMESTAMP, messageHeader.get(HEADER_TIMESTAMP));
resHeader.put(HEADER_UPDATE_TYPE, messageHeader.get(HEADER_UPDATE_TYPE));
Expand All @@ -228,64 +229,64 @@ private Map<String, Object> toResultHeader(Map<String, Object> messageHeader) {
return resHeader;
}

private void passHeaderRef(Map<String, Object> messageHeader, HashMap<String, Object> resHeader, String headerName) {
private static void passHeaderRef(Map<String, Object> messageHeader, HashMap<String, Object> resHeader, String headerName) {
if (messageHeader.get(headerName) != null) {
resHeader.put(headerName, messageHeader.get(headerName));
}
}

@Test
public void testWithoutFilterInBody() {
void testWithoutFilterInBody() {
withFilters(null, null, false);
}

@Test
public void testWithoutFilterInUrl() {
void testWithoutFilterInUrl() {
withFilters(null, null, true);
}

@Test
public void testStudyFilterInBody() {
void testStudyFilterInBody() {
withFilters("bar", null, false);
}

@Test
public void testStudyFilterInUrl() {
void testStudyFilterInUrl() {
withFilters("bar", null, true);
}

@Test
public void testTypeFilterInBody() {
void testTypeFilterInBody() {
withFilters(null, "rab", false);
}

@Test
public void testTypeFilterInUrl() {
void testTypeFilterInUrl() {
withFilters(null, "rab", true);
}

@Test
public void testStudyAndTypeFilterInBody() {
void testStudyAndTypeFilterInBody() {
withFilters("bar", "rab", false);
}

@Test
public void testStudyAndTypeFilterInUrl() {
void testStudyAndTypeFilterInUrl() {
withFilters("bar", "rab", true);
}

@Test
public void testEncodingCharactersInBody() {
void testEncodingCharactersInBody() {
withFilters("foo bar/bar", "foobar", false);
}

@Test
public void testEncodingCharactersInUrl() {
void testEncodingCharactersInUrl() {
withFilters("foo bar/bar", "foobar", true);
}

@Test
public void testWsReceiveFilters() throws JsonProcessingException {
void testWsReceiveFilters() throws Exception {
setUpUriComponentBuilder("userId");
var dataBufferFactory = new DefaultDataBufferFactory();

Expand All @@ -308,7 +309,7 @@ public void testWsReceiveFilters() throws JsonProcessingException {
}

@Test
public void testWsRemoveFilters() throws JsonProcessingException {
void testWsRemoveFilters() throws Exception {
setUpUriComponentBuilder("userId");
var dataBufferFactory = new DefaultDataBufferFactory();

Expand All @@ -335,7 +336,7 @@ public void testWsRemoveFilters() throws JsonProcessingException {
}

@Test
public void testWsReceiveEmptyFilters() throws JsonProcessingException {
void testWsReceiveEmptyFilters() throws Exception {
setUpUriComponentBuilder("userId");
var dataBufferFactory = new DefaultDataBufferFactory();

Expand All @@ -356,7 +357,7 @@ public void testWsReceiveEmptyFilters() throws JsonProcessingException {
}

@Test
public void testWsReceiveUnprocessableFilter() {
void testWsReceiveUnprocessableFilter() {
setUpUriComponentBuilder("userId");
var dataBufferFactory = new DefaultDataBufferFactory();

Expand All @@ -374,7 +375,7 @@ public void testWsReceiveUnprocessableFilter() {
}

@Test
public void testHeartbeat() {
void testHeartbeat() {
setUpUriComponentBuilder("userId");

var notificationWebSocketHandler = new NotificationWebSocketHandler(null, meterRegistry, 1);
Expand All @@ -389,7 +390,7 @@ public void testHeartbeat() {
}

@Test
public void testDiscard() {
void testDiscard() {
setUpUriComponentBuilder("userId");

var notificationWebSocketHandler = new NotificationWebSocketHandler(objectMapper, meterRegistry, Integer.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
package org.gridsuite.study.notification.server;

import io.micrometer.core.instrument.MeterRegistry;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpHeaders;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.reactive.socket.client.StandardWebSocketClient;
import org.springframework.web.reactive.socket.client.WebSocketClient;
import reactor.core.publisher.Mono;
Expand All @@ -28,16 +25,14 @@
import java.util.concurrent.CountDownLatch;

import static org.gridsuite.study.notification.server.NotificationWebSocketHandler.*;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Jon Harper <jon.harper at rte-france.com>
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = { NotificationApplication.class })
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {NotificationApplication.class})
@DirtiesContext
public class NotificationWebSocketIT {
class NotificationWebSocketIT {

@LocalServerPort
private String port;
Expand All @@ -46,7 +41,7 @@ public class NotificationWebSocketIT {
private MeterRegistry meterRegistry;

@Test
public void echo() {
void echo() {
WebSocketClient client = new StandardWebSocketClient();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HEADER_USER_ID, "test");
Expand All @@ -58,8 +53,8 @@ protected URI getUrl(String path) {
}

@Test
@Ignore("This test case is not stable due to unexpected behavior of meterRegistry in asynchronous test context")
public void metricsMapOneUserTwoConnections() {
@Disabled("This test case is not stable due to unexpected behavior of meterRegistry in asynchronous test context")
void metricsMapOneUserTwoConnections() {
WebSocketClient client1 = new StandardWebSocketClient();
HttpHeaders httpHeaders1 = new HttpHeaders();
String user = "test";
Expand All @@ -77,8 +72,8 @@ public void metricsMapOneUserTwoConnections() {
}

@Test
@Ignore("This test case is not stable due to unexpected behavior of meterRegistry in asynchronous test context")
public void metricsMapTwoUsers() {
@Disabled("This test case is not stable due to unexpected behavior of meterRegistry in asynchronous test context")
void metricsMapTwoUsers() {
// First WebSocketClient for connections related to 'test' user
WebSocketClient client1 = new StandardWebSocketClient();
HttpHeaders httpHeaders1 = new HttpHeaders();
Expand All @@ -102,7 +97,7 @@ public void metricsMapTwoUsers() {
evaluationFuture.join(); // Throw assertion errors
}

private void handleLatches(CountDownLatch connectionLatch, CountDownLatch assertLatch) {
private static void handleLatches(CountDownLatch connectionLatch, CountDownLatch assertLatch) {
try {
connectionLatch.countDown();
assertLatch.await(); // Wait for assertion to be evaluated before closing the connection
Expand Down
Loading