Skip to content

Commit

Permalink
Migrate tests to JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Oct 10, 2024
1 parent 474b123 commit 2cba14c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 42 deletions.
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,6 @@
</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.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus.bundles</groupId>
<artifactId>tyrus-standalone-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Test;
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 @@ -27,23 +27,24 @@
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

/**
* @author Chamseddine Benhamed <chamseddine.benhamed at rte-france.com>
* @author Jon Harper <jon.harper at rte-france.com>
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
public class MergeNotificationWebSocketHandlerTest {
class MergeNotificationWebSocketHandlerTest {

private ObjectMapper objectMapper;
private WebSocketSession ws;
Expand All @@ -53,8 +54,8 @@ public class MergeNotificationWebSocketHandlerTest {
private static final String SWE_UUID = "11111111-f60e-4766-bc5c-8f312c1984e4";
private static final String CORE_UUID = "21111111-f60e-4766-bc5c-8f312c1984e4";

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

Expand Down Expand Up @@ -135,17 +136,17 @@ private void withFilters(String processUuid, String businessProcess) {
}

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

@Test
public void testProcessFilter() {
void testProcessFilter() {
withFilters(SWE_UUID, "1D");
}

@Test
public void testHeartbeat() {
void testHeartbeat() {
var notificationWebSocketHandler = new MergeNotificationWebSocketHandler(null, 1);

when(handshakeinfo.getUri()).thenReturn(uriComponentBuilder.build().toUri());
Expand All @@ -160,7 +161,7 @@ public void testHeartbeat() {
}

@Test
public void testDiscard() {
void testDiscard() {
var notificationWebSocketHandler = new MergeNotificationWebSocketHandler(objectMapper, Integer.MAX_VALUE);

UriComponentsBuilder uriComponentBuilder = UriComponentsBuilder.fromUriString("http://localhost:1234/notify");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,37 @@
*/
package org.gridsuite.merge.notification.server;

import java.net.URI;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
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.WebSocketSession;
import org.springframework.web.reactive.socket.client.StandardWebSocketClient;
import org.springframework.web.reactive.socket.client.WebSocketClient;

import static org.junit.Assert.*;
import java.net.URI;

import static org.junit.jupiter.api.Assertions.assertNotNull;

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

@LocalServerPort
private String port;

@Test
public void echo() {
void echo() {
WebSocketClient client = new StandardWebSocketClient();
assertNotNull(client);
client.execute(getUrl("/notify"), WebSocketSession::close).block();
}

protected URI getUrl(String path) {
private URI getUrl(String path) {
return URI.create("ws://localhost:" + this.port + path);
}
}

0 comments on commit 2cba14c

Please sign in to comment.