org.springframework.messaging.simp.user.SimpUser Java Examples

The following examples show how to use org.springframework.messaging.simp.user.SimpUser. 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: DefaultSimpUserRegistryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void addMultipleSessionIds() {

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.CONNECT_ACK, "456");
	event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.CONNECT_ACK, "789");
	event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);

	assertEquals(3, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
	assertNotNull(simpUser.getSession("456"));
	assertNotNull(simpUser.getSession("789"));
}
 
Example #2
Source File: DefaultSimpUserRegistryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void addOneSessionId() {

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);

	assertEquals(1, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
}
 
Example #3
Source File: DefaultSimpUserRegistryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void addOneSessionId() {
	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);

	assertEquals(1, registry.getUserCount());
	assertEquals(1, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
}
 
Example #4
Source File: DefaultSimpUserRegistryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void addMultipleSessionIds() {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.CONNECT_ACK, "456");
	event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.CONNECT_ACK, "789");
	event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);

	assertEquals(1, registry.getUserCount());
	assertEquals(3, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
	assertNotNull(simpUser.getSession("456"));
	assertNotNull(simpUser.getSession("789"));
}
 
Example #5
Source File: DefaultSimpUserRegistryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void addOneSessionId() {
	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);

	assertEquals(1, registry.getUserCount());
	assertEquals(1, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
}
 
Example #6
Source File: DefaultSimpUserRegistryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void addMultipleSessionIds() {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.CONNECT_ACK, "456");
	event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	message = createMessage(SimpMessageType.CONNECT_ACK, "789");
	event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);

	assertEquals(1, registry.getUserCount());
	assertEquals(3, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
	assertNotNull(simpUser.getSession("456"));
	assertNotNull(simpUser.getSession("789"));
}
 
Example #7
Source File: DefaultSimpUserRegistryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void nullSessionId() throws Exception {

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNull(simpUser.getSession(null));
}
 
Example #8
Source File: DefaultSimpUserRegistryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void removeSessionIds() {

	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	message = createMessage(SimpMessageType.CONNECT_ACK, "456");
	connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	message = createMessage(SimpMessageType.CONNECT_ACK, "789");
	connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);
	assertEquals(3, simpUser.getSessions().size());


	CloseStatus status = CloseStatus.GOING_AWAY;
	message = createMessage(SimpMessageType.DISCONNECT, "456");
	SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, message, "456", status, user);
	registry.onApplicationEvent(disconnectEvent);

	message = createMessage(SimpMessageType.DISCONNECT, "789");
	disconnectEvent = new SessionDisconnectEvent(this, message, "789", status, user);
	registry.onApplicationEvent(disconnectEvent);

	assertEquals(1, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
}
 
Example #9
Source File: DefaultSimpUserRegistryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void removeSessionIds() {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	message = createMessage(SimpMessageType.CONNECT_ACK, "456");
	connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	message = createMessage(SimpMessageType.CONNECT_ACK, "789");
	connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);
	assertEquals(3, simpUser.getSessions().size());

	CloseStatus status = CloseStatus.GOING_AWAY;
	message = createMessage(SimpMessageType.DISCONNECT, "456");
	SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, message, "456", status, user);
	registry.onApplicationEvent(disconnectEvent);

	message = createMessage(SimpMessageType.DISCONNECT, "789");
	disconnectEvent = new SessionDisconnectEvent(this, message, "789", status, user);
	registry.onApplicationEvent(disconnectEvent);

	assertEquals(1, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
}
 
Example #10
Source File: DefaultSimpUserRegistryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void nullSessionId() throws Exception {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNull(simpUser.getSession(null));
}
 
Example #11
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object other) {
	if (this == other) {
		return true;
	}
	if (other == null || !(other instanceof SimpUser)) {
		return false;
	}
	return this.name.equals(((SimpUser) other).getName());
}
 
Example #12
Source File: DefaultSimpUserRegistryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void nullSessionId() throws Exception {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(event);

	SimpUser simpUser = registry.getUser("joe");
	assertNull(simpUser.getSession(null));
}
 
Example #13
Source File: DefaultSimpUserRegistryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void removeSessionIds() {
	DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();

	TestPrincipal user = new TestPrincipal("joe");
	Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
	SessionConnectedEvent connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	message = createMessage(SimpMessageType.CONNECT_ACK, "456");
	connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	message = createMessage(SimpMessageType.CONNECT_ACK, "789");
	connectedEvent = new SessionConnectedEvent(this, message, user);
	registry.onApplicationEvent(connectedEvent);

	SimpUser simpUser = registry.getUser("joe");
	assertNotNull(simpUser);
	assertEquals(3, simpUser.getSessions().size());

	CloseStatus status = CloseStatus.GOING_AWAY;
	message = createMessage(SimpMessageType.DISCONNECT, "456");
	SessionDisconnectEvent disconnectEvent = new SessionDisconnectEvent(this, message, "456", status, user);
	registry.onApplicationEvent(disconnectEvent);

	message = createMessage(SimpMessageType.DISCONNECT, "789");
	disconnectEvent = new SessionDisconnectEvent(this, message, "789", status, user);
	registry.onApplicationEvent(disconnectEvent);

	assertEquals(1, simpUser.getSessions().size());
	assertNotNull(simpUser.getSession("123"));
}
 
Example #14
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Set<SimpUser> getUsers() {
	return new HashSet<>(this.users.values());
}
 
Example #15
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Set<SimpUser> getUsers() {
	return new HashSet<SimpUser>(this.users.values());
}
 
Example #16
Source File: DefaultSimpUserRegistry.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public SimpUser getUser(String userName) {
	return this.users.get(userName);
}
 
Example #17
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean equals(Object other) {
	return (this == other ||
			(other instanceof SimpUser && getName().equals(((SimpUser) other).getName())));
}
 
Example #18
Source File: MessageBrokerConfigurationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public SimpUser getUser(String userName) { return null; }
 
Example #19
Source File: DefaultSimpUserRegistry.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Nullable
public SimpUser getUser(String userName) {
	return this.users.get(userName);
}
 
Example #20
Source File: MessageBrokerConfigurationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Set<SimpUser> getUsers() { return null; }
 
Example #21
Source File: MessageBrokerConfigurationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public SimpUser getUser(String userName) { return null; }
 
Example #22
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean equals(Object other) {
	return (this == other ||
			(other instanceof SimpUser && getName().equals(((SimpUser) other).getName())));
}
 
Example #23
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Set<SimpUser> getUsers() {
	return new HashSet<>(this.users.values());
}
 
Example #24
Source File: DefaultSimpUserRegistry.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
public SimpUser getUser(String userName) {
	return this.users.get(userName);
}
 
Example #25
Source File: MessageBrokerConfigurationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Set<SimpUser> getUsers() { return null; }