use of org.eclipse.jetty.websocket.api.UpgradeRequest in project spring-framework by spring-projects.
the class JettyWebSocketSessionTests method getAcceptedProtocol.
@Test
@SuppressWarnings("resource")
public void getAcceptedProtocol() {
String protocol = "foo";
UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
given(request.getUserPrincipal()).willReturn(null);
UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
given(response.getAcceptedSubProtocol()).willReturn(protocol);
Session nativeSession = Mockito.mock(Session.class);
given(nativeSession.getUpgradeRequest()).willReturn(request);
given(nativeSession.getUpgradeResponse()).willReturn(response);
JettyWebSocketSession session = new JettyWebSocketSession(attributes);
session.initializeNativeSession(nativeSession);
reset(nativeSession);
assertThat(session.getAcceptedProtocol()).isSameAs(protocol);
verifyNoMoreInteractions(nativeSession);
}
use of org.eclipse.jetty.websocket.api.UpgradeRequest in project jetty.project by eclipse.
the class WebSocketClientTest method testParameterMap.
@Test
public void testParameterMap() throws Exception {
JettyTrackingSocket wsocket = new JettyTrackingSocket();
URI wsUri = server.getWsUri().resolve("/test?snack=cashews&amount=handful&brand=off");
Future<Session> future = client.connect(wsocket, wsUri);
IBlockheadServerConnection ssocket = server.accept();
ssocket.upgrade();
future.get(30, TimeUnit.SECONDS);
Assert.assertTrue(wsocket.openLatch.await(1, TimeUnit.SECONDS));
Session session = wsocket.getSession();
UpgradeRequest req = session.getUpgradeRequest();
Assert.assertThat("Upgrade Request", req, notNullValue());
Map<String, List<String>> parameterMap = req.getParameterMap();
Assert.assertThat("Parameter Map", parameterMap, notNullValue());
Assert.assertThat("Parameter[snack]", parameterMap.get("snack"), is(Arrays.asList(new String[] { "cashews" })));
Assert.assertThat("Parameter[amount]", parameterMap.get("amount"), is(Arrays.asList(new String[] { "handful" })));
Assert.assertThat("Parameter[brand]", parameterMap.get("brand"), is(Arrays.asList(new String[] { "off" })));
Assert.assertThat("Parameter[cost]", parameterMap.get("cost"), nullValue());
}
use of org.eclipse.jetty.websocket.api.UpgradeRequest in project jetty.project by eclipse.
the class RequestHeadersTest method testAccessRequestCookies.
@Test
public void testAccessRequestCookies() throws Exception {
BlockheadClient client = new BlockheadClient(server.getServerUri());
client.setTimeout(1, TimeUnit.SECONDS);
try {
client.connect();
client.addHeader("Cookie: fruit=Pear; type=Anjou\r\n");
client.sendStandardRequest();
client.expectUpgradeResponse();
UpgradeRequest req = echoCreator.getLastRequest();
Assert.assertThat("Last Request", req, notNullValue());
List<HttpCookie> cookies = req.getCookies();
Assert.assertThat("Request cookies", cookies, notNullValue());
Assert.assertThat("Request cookies.size", cookies.size(), is(2));
for (HttpCookie cookie : cookies) {
Assert.assertThat("Cookie name", cookie.getName(), anyOf(is("fruit"), is("type")));
Assert.assertThat("Cookie value", cookie.getValue(), anyOf(is("Pear"), is("Anjou")));
}
} finally {
client.close();
}
}
use of org.eclipse.jetty.websocket.api.UpgradeRequest in project spring-framework by spring-projects.
the class JettyWebSocketSessionTests method getPrincipalNotAvailable.
@Test
@SuppressWarnings("resource")
public void getPrincipalNotAvailable() {
UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
given(request.getUserPrincipal()).willReturn(null);
UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
given(response.getAcceptedSubProtocol()).willReturn(null);
Session nativeSession = Mockito.mock(Session.class);
given(nativeSession.getUpgradeRequest()).willReturn(request);
given(nativeSession.getUpgradeResponse()).willReturn(response);
JettyWebSocketSession session = new JettyWebSocketSession(attributes);
session.initializeNativeSession(nativeSession);
reset(nativeSession);
assertThat(session.getPrincipal()).isNull();
verifyNoMoreInteractions(nativeSession);
}
use of org.eclipse.jetty.websocket.api.UpgradeRequest in project spring-framework by spring-projects.
the class JettyWebSocketSessionTests method getPrincipalFromNativeSession.
@Test
@SuppressWarnings("resource")
public void getPrincipalFromNativeSession() {
TestPrincipal user = new TestPrincipal("joe");
UpgradeRequest request = Mockito.mock(UpgradeRequest.class);
given(request.getUserPrincipal()).willReturn(user);
UpgradeResponse response = Mockito.mock(UpgradeResponse.class);
given(response.getAcceptedSubProtocol()).willReturn(null);
Session nativeSession = Mockito.mock(Session.class);
given(nativeSession.getUpgradeRequest()).willReturn(request);
given(nativeSession.getUpgradeResponse()).willReturn(response);
JettyWebSocketSession session = new JettyWebSocketSession(attributes);
session.initializeNativeSession(nativeSession);
reset(nativeSession);
assertThat(session.getPrincipal()).isSameAs(user);
verifyNoMoreInteractions(nativeSession);
}
Aggregations