Skip to content

Commit

Permalink
INT-3515: IllegalStateException for the `WebSocketInboundChannelAdapt…
Browse files Browse the repository at this point in the history
…er`, when `useBroker = true`, but there is no Broker Relay in the Context
  • Loading branch information
artembilan committed Sep 25, 2014
1 parent 13a43b1 commit a845295
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 0 additions & 1 deletion build.gradle
Expand Up @@ -600,7 +600,6 @@ project('spring-integration-websocket') {

compile ("org.springframework:spring-webmvc:$springVersion", optional)

// testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
testCompile "org.apache.tomcat.embed:tomcat-embed-websocket:$tomcatVersion"
testCompile("org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}")
}
Expand Down
Expand Up @@ -189,10 +189,9 @@ protected void onInit() {
break;
}
}
if (this.brokerHandler == null) {
logger.warn("'AbstractBrokerMessageHandler' isn't present in the application context. " +
"The non-MESSAGE WebSocketMessages will be ignored.");
}
Assert.state(this.brokerHandler != null,
"WebSocket Broker Relay isn't present in the application context. \n" +
"Or provide it or don't use 'useBroker = true' for this Adapter.");
}
}

Expand Down
Expand Up @@ -16,22 +16,27 @@

package org.springframework.integration.websocket.server;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
Expand Down Expand Up @@ -130,6 +135,24 @@ public void testWebSocketOutboundMessageHandler() throws Exception {
assertEquals("subs1", subscription.get(0));
}

@Test
public void testBrokerIsNotPresented() throws Exception {
WebSocketInboundChannelAdapter webSocketInboundChannelAdapter =
new WebSocketInboundChannelAdapter(Mockito.mock(ServerWebSocketContainer.class));
webSocketInboundChannelAdapter.setOutputChannel(new DirectChannel());
webSocketInboundChannelAdapter.setUseBroker(true);
webSocketInboundChannelAdapter.setBeanFactory(Mockito.mock(BeanFactory.class));
webSocketInboundChannelAdapter.setApplicationContext(Mockito.mock(ApplicationContext.class));
try {
webSocketInboundChannelAdapter.afterPropertiesSet();
fail("IllegalStateException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("WebSocket Broker Relay isn't present in the application context."));
}

}

@Configuration
@EnableIntegration
Expand Down

0 comments on commit a845295

Please sign in to comment.