org.springframework.web.socket.handler.TestPrincipal Java Examples

The following examples show how to use org.springframework.web.socket.handler.TestPrincipal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyWebSocketSessionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);

	assertSame(user, session.getPrincipal());
	verifyNoMoreInteractions(nativeSession);
}
 
Example #2
Source File: DefaultSockJsServiceTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void handleTransportRequestXhrSendWithDifferentUser() throws Exception {
	String sockJsPath = sessionUrlPrefix + "xhr";
	setRequest("POST", sockJsPrefix + sockJsPath);
	this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

	assertEquals(200, this.servletResponse.getStatus()); // session created
	verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);

	this.session.setPrincipal(new TestPrincipal("little red riding hood"));
	this.servletRequest.setUserPrincipal(new TestPrincipal("wolf"));

	resetResponse();
	reset(this.xhrSendHandler);
	sockJsPath = sessionUrlPrefix + "xhr_send";
	setRequest("POST", sockJsPrefix + sockJsPath);
	this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

	assertEquals(404, this.servletResponse.getStatus());
	verifyNoMoreInteractions(this.xhrSendHandler);
}
 
Example #3
Source File: JettyWebSocketSessionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);

	assertSame(user, session.getPrincipal());
	verifyNoMoreInteractions(nativeSession);
}
 
Example #4
Source File: DefaultSockJsServiceTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void handleTransportRequestXhrSendWithDifferentUser() throws Exception {
	String sockJsPath = sessionUrlPrefix + "xhr";
	setRequest("POST", sockJsPrefix + sockJsPath);
	this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

	assertEquals(200, this.servletResponse.getStatus()); // session created
	verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);

	this.session.setPrincipal(new TestPrincipal("little red riding hood"));
	this.servletRequest.setUserPrincipal(new TestPrincipal("wolf"));

	resetResponse();
	reset(this.xhrSendHandler);
	sockJsPath = sessionUrlPrefix + "xhr_send";
	setRequest("POST", sockJsPrefix + sockJsPath);
	this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

	assertEquals(404, this.servletResponse.getStatus());
	verifyNoMoreInteractions(this.xhrSendHandler);
}
 
Example #5
Source File: JettyWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
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);

	assertSame(user, session.getPrincipal());
	verifyNoMoreInteractions(nativeSession);
}
 
Example #6
Source File: DefaultSockJsServiceTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void handleTransportRequestXhrSendWithDifferentUser() throws Exception {
	String sockJsPath = sessionUrlPrefix + "xhr";
	setRequest("POST", sockJsPrefix + sockJsPath);
	this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

	assertEquals(200, this.servletResponse.getStatus()); // session created
	verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);

	this.session.setPrincipal(new TestPrincipal("little red riding hood"));
	this.servletRequest.setUserPrincipal(new TestPrincipal("wolf"));

	resetResponse();
	reset(this.xhrSendHandler);
	sockJsPath = sessionUrlPrefix + "xhr_send";
	setRequest("POST", sockJsPrefix + sockJsPath);
	this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

	assertEquals(404, this.servletResponse.getStatus());
	verifyNoMoreInteractions(this.xhrSendHandler);
}
 
Example #7
Source File: StandardWebSocketSessionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() {
	TestPrincipal user = new TestPrincipal("joe");
	StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null, user);

	assertSame(user, session.getPrincipal());
}
 
Example #8
Source File: StandardWebSocketSessionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void getPrincipalWithNativeSession() {
	TestPrincipal user = new TestPrincipal("joe");

	Session nativeSession = Mockito.mock(Session.class);
	given(nativeSession.getUserPrincipal()).willReturn(user);

	StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
	session.initializeNativeSession(nativeSession);

	assertSame(user, session.getPrincipal());
}
 
Example #9
Source File: JettyWebSocketSessionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() {
	TestPrincipal user = new TestPrincipal("joe");
	JettyWebSocketSession session = new JettyWebSocketSession(attributes, user);

	assertSame(user, session.getPrincipal());
}
 
Example #10
Source File: StandardWebSocketSessionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() {
	TestPrincipal user = new TestPrincipal("joe");
	StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null, user);

	assertSame(user, session.getPrincipal());
}
 
Example #11
Source File: StandardWebSocketSessionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void getPrincipalWithNativeSession() {
	TestPrincipal user = new TestPrincipal("joe");

	Session nativeSession = Mockito.mock(Session.class);
	given(nativeSession.getUserPrincipal()).willReturn(user);

	StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
	session.initializeNativeSession(nativeSession);

	assertSame(user, session.getPrincipal());
}
 
Example #12
Source File: JettyWebSocketSessionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void getPrincipalWithConstructorArg() {
	TestPrincipal user = new TestPrincipal("joe");
	JettyWebSocketSession session = new JettyWebSocketSession(attributes, user);

	assertSame(user, session.getPrincipal());
}
 
Example #13
Source File: StandardWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void getPrincipalWithConstructorArg() {
	TestPrincipal user = new TestPrincipal("joe");
	StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null, user);

	assertSame(user, session.getPrincipal());
}
 
Example #14
Source File: JettyWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void getPrincipalWithConstructorArg() {
	TestPrincipal user = new TestPrincipal("joe");
	JettyWebSocketSession session = new JettyWebSocketSession(attributes, user);

	assertSame(user, session.getPrincipal());
}
 
Example #15
Source File: StandardWebSocketSessionTests.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
@Test
public void getPrincipalWithNativeSession() {

	TestPrincipal user = new TestPrincipal("joe");

	Session nativeSession = Mockito.mock(Session.class);
	given(nativeSession.getUserPrincipal()).willReturn(user);

	StandardWebSocketSession session = new StandardWebSocketSession(this.headers, this.attributes, null, null);
	session.initializeNativeSession(nativeSession);

	assertSame(user, session.getPrincipal());
}