mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
WIP
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.commafeed.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -8,6 +9,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.glassfish.jersey.client.JerseyClientBuilder;
|
||||
@@ -17,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.commafeed.frontend.model.request.FeedModificationRequest;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.websocket.ClientEndpointConfig;
|
||||
import jakarta.websocket.CloseReason;
|
||||
import jakarta.websocket.ContainerProvider;
|
||||
@@ -25,8 +28,10 @@ import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.EndpointConfig;
|
||||
import jakarta.websocket.Session;
|
||||
import jakarta.ws.rs.client.Entity;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@QuarkusTest
|
||||
@Slf4j
|
||||
class WebSocketIT extends BaseIT {
|
||||
|
||||
@@ -49,18 +54,17 @@ class WebSocketIT extends BaseIT {
|
||||
public void onClose(Session session, CloseReason closeReason) {
|
||||
closeReasonRef.set(closeReason);
|
||||
}
|
||||
}, buildConfig("fake-session-id"), URI.create(getWebSocketUrl()))) {
|
||||
}, buildConfig(List.of()), URI.create(getWebSocketUrl()))) {
|
||||
Awaitility.await().atMost(15, TimeUnit.SECONDS).untilTrue(connected);
|
||||
log.info("connected to {}", session.getRequestURI());
|
||||
|
||||
Awaitility.await().atMost(15, TimeUnit.SECONDS).until(() -> closeReasonRef.get() != null);
|
||||
Assertions.assertEquals(CloseReason.CloseCodes.VIOLATED_POLICY, closeReasonRef.get().getCloseCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void subscribeAndGetsNotified() throws DeploymentException, IOException {
|
||||
String sessionId = login();
|
||||
List<HttpCookie> cookies = login();
|
||||
|
||||
AtomicBoolean connected = new AtomicBoolean();
|
||||
AtomicReference<String> messageRef = new AtomicReference<>();
|
||||
@@ -70,7 +74,7 @@ class WebSocketIT extends BaseIT {
|
||||
session.addMessageHandler(String.class, messageRef::set);
|
||||
connected.set(true);
|
||||
}
|
||||
}, buildConfig(sessionId), URI.create(getWebSocketUrl()))) {
|
||||
}, buildConfig(cookies), URI.create(getWebSocketUrl()))) {
|
||||
Awaitility.await().atMost(15, TimeUnit.SECONDS).untilTrue(connected);
|
||||
log.info("connected to {}", session.getRequestURI());
|
||||
|
||||
@@ -83,7 +87,7 @@ class WebSocketIT extends BaseIT {
|
||||
|
||||
@Test
|
||||
void notNotifiedForFilteredEntries() throws DeploymentException, IOException {
|
||||
String sessionId = login();
|
||||
List<HttpCookie> cookies = login();
|
||||
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
|
||||
FeedModificationRequest req = new FeedModificationRequest();
|
||||
@@ -100,7 +104,7 @@ class WebSocketIT extends BaseIT {
|
||||
session.addMessageHandler(String.class, messageRef::set);
|
||||
connected.set(true);
|
||||
}
|
||||
}, buildConfig(sessionId), URI.create(getWebSocketUrl()))) {
|
||||
}, buildConfig(cookies), URI.create(getWebSocketUrl()))) {
|
||||
Awaitility.await().atMost(15, TimeUnit.SECONDS).untilTrue(connected);
|
||||
log.info("connected to {}", session.getRequestURI());
|
||||
|
||||
@@ -115,7 +119,7 @@ class WebSocketIT extends BaseIT {
|
||||
|
||||
@Test
|
||||
void pingPong() throws DeploymentException, IOException {
|
||||
String sessionId = login();
|
||||
List<HttpCookie> cookies = login();
|
||||
|
||||
AtomicBoolean connected = new AtomicBoolean();
|
||||
AtomicReference<String> messageRef = new AtomicReference<>();
|
||||
@@ -125,7 +129,7 @@ class WebSocketIT extends BaseIT {
|
||||
session.addMessageHandler(String.class, messageRef::set);
|
||||
connected.set(true);
|
||||
}
|
||||
}, buildConfig(sessionId), URI.create(getWebSocketUrl()))) {
|
||||
}, buildConfig(cookies), URI.create(getWebSocketUrl()))) {
|
||||
Awaitility.await().atMost(15, TimeUnit.SECONDS).untilTrue(connected);
|
||||
log.info("connected to {}", session.getRequestURI());
|
||||
|
||||
@@ -136,11 +140,12 @@ class WebSocketIT extends BaseIT {
|
||||
}
|
||||
}
|
||||
|
||||
private ClientEndpointConfig buildConfig(String sessionId) {
|
||||
private ClientEndpointConfig buildConfig(List<HttpCookie> cookies) {
|
||||
return ClientEndpointConfig.Builder.create().configurator(new ClientEndpointConfig.Configurator() {
|
||||
@Override
|
||||
public void beforeRequest(Map<String, List<String>> headers) {
|
||||
headers.put("Cookie", Collections.singletonList("JSESSIONID=" + sessionId));
|
||||
headers.put(HttpHeaders.COOKIE,
|
||||
Collections.singletonList(cookies.stream().map(HttpCookie::toString).collect(Collectors.joining(";"))));
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user