Skip to content
This repository has been archived by the owner on Nov 18, 2018. It is now read-only.

AGSMPLPUSH-49 "Greeting message is only returned once." #71

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public static boolean matches(final String path) {
}

public static FullHttpResponse response(final HttpRequest request) {
final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), OK, CONTENT);
final FullHttpResponse response = new DefaultFullHttpResponse(
request.getProtocolVersion(),
OK,
CONTENT.duplicate());
response.headers().set(CONTENT_TYPE, Transports.CONTENT_TYPE_PLAIN);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,43 @@
*/
package org.jboss.aerogear.io.netty.handler.codec.sockjs.handler;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.CharsetUtil;

import org.jboss.aerogear.io.netty.handler.codec.sockjs.handler.Greeting;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;

public class GreetingTest {

@Test
public void greeting() throws Exception {
final FullHttpResponse response = Greeting.response(createHttpRequest("/simplepush"));
final FullHttpResponse response = sendGreetingRequest();
assertWelcomeMessage(response);
}

@Test
public void greetingThroughDecoder() throws Exception {
final EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseEncoder());
final FullHttpResponse response = sendGreetingRequest();
assertWelcomeMessage(response);
// send response through HttpResponseEncoder
ch.writeOutbound(response);
final FullHttpResponse response2 = sendGreetingRequest();
assertWelcomeMessage(response2);
}

private FullHttpResponse sendGreetingRequest() {
return Greeting.response(createHttpRequest("/simplepush"));
}

private void assertWelcomeMessage(final FullHttpResponse response) {
assertThat(response.content().toString(CharsetUtil.UTF_8), equalTo("Welcome to SockJS!\n"));
response.release();
}
Expand Down