Migrate codec-http tests to JUnit 5 (#11316)
Motivation: JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel. Modifications: Use JUnit5 in tests Result: Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
parent
73bafaaf9b
commit
65e1f0e27c
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue;
|
import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -26,9 +26,10 @@ import static io.netty.handler.codec.http.HttpHeaderNames.SET_COOKIE;
|
|||||||
import static io.netty.util.AsciiString.contentEquals;
|
import static io.netty.util.AsciiString.contentEquals;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class CombinedHttpHeadersTest {
|
public class CombinedHttpHeadersTest {
|
||||||
private static final CharSequence HEADER_NAME = "testHeader";
|
private static final CharSequence HEADER_NAME = "testHeader";
|
||||||
@ -140,11 +141,11 @@ public class CombinedHttpHeadersTest {
|
|||||||
assertEquals(HeaderValue.EIGHT.subset(6), headers.getAll(HEADER_NAME));
|
assertEquals(HeaderValue.EIGHT.subset(6), headers.getAll(HEADER_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test (expected = NullPointerException.class)
|
@Test
|
||||||
public void addCharSequencesCsvNullValue() {
|
public void addCharSequencesCsvNullValue() {
|
||||||
final CombinedHttpHeaders headers = newCombinedHttpHeaders();
|
final CombinedHttpHeaders headers = newCombinedHttpHeaders();
|
||||||
final String value = null;
|
final String value = null;
|
||||||
headers.add(HEADER_NAME, value);
|
assertThrows(NullPointerException.class, () -> headers.add(HEADER_NAME, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.http;
|
|||||||
import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue;
|
import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue;
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -30,19 +30,25 @@ import static io.netty.util.AsciiString.contentEquals;
|
|||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class DefaultHttpHeadersTest {
|
public class DefaultHttpHeadersTest {
|
||||||
private static final CharSequence HEADER_NAME = "testHeader";
|
private static final CharSequence HEADER_NAME = "testHeader";
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void nullHeaderNameNotAllowed() {
|
public void nullHeaderNameNotAllowed() {
|
||||||
new DefaultHttpHeaders().add(null, "foo");
|
assertThrows(IllegalArgumentException.class, () -> new DefaultHttpHeaders().add(null, "foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void emptyHeaderNameNotAllowed() {
|
public void emptyHeaderNameNotAllowed() {
|
||||||
new DefaultHttpHeaders().add(StringUtil.EMPTY_STRING, "foo");
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> new DefaultHttpHeaders().add(StringUtil.EMPTY_STRING, "foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -146,16 +152,16 @@ public class DefaultHttpHeadersTest {
|
|||||||
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
|
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testSetNullHeaderValueValidate() {
|
public void testSetNullHeaderValueValidate() {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders(true);
|
HttpHeaders headers = new DefaultHttpHeaders(true);
|
||||||
headers.set(of("test"), (CharSequence) null);
|
assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testSetNullHeaderValueNotValidate() {
|
public void testSetNullHeaderValueNotValidate() {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders(false);
|
HttpHeaders headers = new DefaultHttpHeaders(false);
|
||||||
headers.set(of("test"), (CharSequence) null);
|
assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class DefaultHttpRequestTest {
|
public class DefaultHttpRequestTest {
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
public class DefaultHttpResponseTest {
|
public class DefaultHttpResponseTest {
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import io.netty.handler.stream.ChunkedNioStream;
|
|||||||
import io.netty.handler.stream.ChunkedStream;
|
import io.netty.handler.stream.ChunkedStream;
|
||||||
import io.netty.handler.stream.ChunkedWriteHandler;
|
import io.netty.handler.stream.ChunkedWriteHandler;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -34,7 +34,10 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpChunkedInputTest {
|
public class HttpChunkedInputTest {
|
||||||
private static final byte[] BYTES = new byte[1024 * 64];
|
private static final byte[] BYTES = new byte[1024 * 64];
|
||||||
@ -139,7 +142,7 @@ public class HttpChunkedInputTest {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (lastHttpContent != null) {
|
if (lastHttpContent != null) {
|
||||||
assertTrue("Chunk must be DefaultHttpContent", lastHttpContent instanceof DefaultHttpContent);
|
assertTrue(lastHttpContent instanceof DefaultHttpContent, "Chunk must be DefaultHttpContent");
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf buffer = httpContent.content();
|
ByteBuf buffer = httpContent.content();
|
||||||
@ -157,7 +160,7 @@ public class HttpChunkedInputTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(BYTES.length * inputs.length, read);
|
assertEquals(BYTES.length * inputs.length, read);
|
||||||
assertSame("Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT",
|
assertSame(LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent,
|
||||||
LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent);
|
"Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ import io.netty.handler.codec.PrematureChannelClosureException;
|
|||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.NetUtil;
|
import io.netty.util.NetUtil;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@ -47,7 +47,11 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
|||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpClientCodecTest {
|
public class HttpClientCodecTest {
|
||||||
|
|
||||||
@ -213,7 +217,7 @@ public class HttpClientCodecTest {
|
|||||||
|
|
||||||
Consumer connectResponseConsumer = new Consumer();
|
Consumer connectResponseConsumer = new Consumer();
|
||||||
sendRequestAndReadResponse(ch, HttpMethod.CONNECT, EMPTY_RESPONSE, connectResponseConsumer);
|
sendRequestAndReadResponse(ch, HttpMethod.CONNECT, EMPTY_RESPONSE, connectResponseConsumer);
|
||||||
assertTrue("No connect response messages received.", connectResponseConsumer.getReceivedCount() > 0);
|
assertTrue(connectResponseConsumer.getReceivedCount() > 0, "No connect response messages received.");
|
||||||
Consumer responseConsumer = new Consumer() {
|
Consumer responseConsumer = new Consumer() {
|
||||||
@Override
|
@Override
|
||||||
void accept(Object object) {
|
void accept(Object object) {
|
||||||
@ -225,8 +229,8 @@ public class HttpClientCodecTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
sendRequestAndReadResponse(ch, HttpMethod.GET, RESPONSE, responseConsumer);
|
sendRequestAndReadResponse(ch, HttpMethod.GET, RESPONSE, responseConsumer);
|
||||||
assertTrue("No response messages received.", responseConsumer.getReceivedCount() > 0);
|
assertTrue(responseConsumer.getReceivedCount() > 0, "No response messages received.");
|
||||||
assertFalse("Channel finish failed.", ch.finish());
|
assertFalse(ch.finish(), "Channel finish failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response) {
|
private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response) {
|
||||||
@ -235,10 +239,10 @@ public class HttpClientCodecTest {
|
|||||||
|
|
||||||
private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response,
|
private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response,
|
||||||
Consumer responseConsumer) {
|
Consumer responseConsumer) {
|
||||||
assertTrue("Channel outbound write failed.",
|
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "http://localhost/")),
|
||||||
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "http://localhost/")));
|
"Channel outbound write failed.");
|
||||||
assertTrue("Channel inbound write failed.",
|
assertTrue(ch.writeInbound(Unpooled.copiedBuffer(response, CharsetUtil.ISO_8859_1)),
|
||||||
ch.writeInbound(Unpooled.copiedBuffer(response, CharsetUtil.ISO_8859_1)));
|
"Channel inbound write failed.");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Object msg = ch.readOutbound();
|
Object msg = ch.readOutbound();
|
||||||
@ -287,22 +291,22 @@ public class HttpClientCodecTest {
|
|||||||
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/");
|
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/");
|
||||||
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
|
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
|
||||||
request.headers().set(HttpHeaderNames.UPGRADE, "TLS/1.2");
|
request.headers().set(HttpHeaderNames.UPGRADE, "TLS/1.2");
|
||||||
assertTrue("Channel outbound write failed.", ch.writeOutbound(request));
|
assertTrue(ch.writeOutbound(request), "Channel outbound write failed.");
|
||||||
|
|
||||||
assertTrue("Channel inbound write failed.",
|
assertTrue(ch.writeInbound(Unpooled.copiedBuffer(SWITCHING_PROTOCOLS_RESPONSE, CharsetUtil.ISO_8859_1)),
|
||||||
ch.writeInbound(Unpooled.copiedBuffer(SWITCHING_PROTOCOLS_RESPONSE, CharsetUtil.ISO_8859_1)));
|
"Channel inbound write failed.");
|
||||||
Object switchingProtocolsResponse = ch.readInbound();
|
Object switchingProtocolsResponse = ch.readInbound();
|
||||||
assertNotNull("No response received", switchingProtocolsResponse);
|
assertNotNull(switchingProtocolsResponse, "No response received");
|
||||||
assertThat("Response was not decoded", switchingProtocolsResponse, instanceOf(FullHttpResponse.class));
|
assertThat("Response was not decoded", switchingProtocolsResponse, instanceOf(FullHttpResponse.class));
|
||||||
((FullHttpResponse) switchingProtocolsResponse).release();
|
((FullHttpResponse) switchingProtocolsResponse).release();
|
||||||
|
|
||||||
assertTrue("Channel inbound write failed",
|
assertTrue(ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1)),
|
||||||
ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1)));
|
"Channel inbound write failed");
|
||||||
Object finalResponse = ch.readInbound();
|
Object finalResponse = ch.readInbound();
|
||||||
assertNotNull("No response received", finalResponse);
|
assertNotNull(finalResponse, "No response received");
|
||||||
assertThat("Response was not decoded", finalResponse, instanceOf(FullHttpResponse.class));
|
assertThat("Response was not decoded", finalResponse, instanceOf(FullHttpResponse.class));
|
||||||
((FullHttpResponse) finalResponse).release();
|
((FullHttpResponse) finalResponse).release();
|
||||||
assertTrue("Channel finish failed", ch.finishAndReleaseAll());
|
assertTrue(ch.finishAndReleaseAll(), "Channel finish failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -23,12 +23,12 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpClientUpgradeHandlerTest {
|
public class HttpClientUpgradeHandlerTest {
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import io.netty.handler.codec.EncoderException;
|
|||||||
import io.netty.handler.codec.compression.ZlibWrapper;
|
import io.netty.handler.codec.compression.ZlibWrapper;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
@ -32,11 +32,11 @@ import static org.hamcrest.CoreMatchers.is;
|
|||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpContentCompressorTest {
|
public class HttpContentCompressorTest {
|
||||||
|
|
||||||
|
@ -32,8 +32,7 @@ import io.netty.util.CharsetUtil;
|
|||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.junit.Assume;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -45,7 +44,13 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||||
|
|
||||||
public class HttpContentDecoderTest {
|
public class HttpContentDecoderTest {
|
||||||
private static final String HELLO_WORLD = "hello, world";
|
private static final String HELLO_WORLD = "hello, world";
|
||||||
@ -191,7 +196,7 @@ public class HttpContentDecoderTest {
|
|||||||
public void testResponseBrotliDecompression() throws Throwable {
|
public void testResponseBrotliDecompression() throws Throwable {
|
||||||
Brotli.ensureAvailability();
|
Brotli.ensureAvailability();
|
||||||
// Failing on windows atm
|
// Failing on windows atm
|
||||||
Assume.assumeFalse(PlatformDependent.isWindows());
|
assumeFalse(PlatformDependent.isWindows());
|
||||||
HttpResponseDecoder decoder = new HttpResponseDecoder();
|
HttpResponseDecoder decoder = new HttpResponseDecoder();
|
||||||
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE);
|
HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE);
|
||||||
@ -207,13 +212,12 @@ public class HttpContentDecoderTest {
|
|||||||
Object o = channel.readInbound();
|
Object o = channel.readInbound();
|
||||||
assertThat(o, is(instanceOf(FullHttpResponse.class)));
|
assertThat(o, is(instanceOf(FullHttpResponse.class)));
|
||||||
FullHttpResponse resp = (FullHttpResponse) o;
|
FullHttpResponse resp = (FullHttpResponse) o;
|
||||||
assertNull("Content-Encoding header should be removed", resp.headers().get(HttpHeaderNames.CONTENT_ENCODING));
|
assertNull(resp.headers().get(HttpHeaderNames.CONTENT_ENCODING), "Content-Encoding header should be removed");
|
||||||
assertEquals("Content-Length header should match uncompressed string's length",
|
assertEquals(SAMPLE_STRING.length(),
|
||||||
SAMPLE_STRING.length(),
|
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue(),
|
||||||
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue());
|
"Content-Length header should match uncompressed string's length");
|
||||||
assertEquals("Response body should match uncompressed string",
|
assertEquals(SAMPLE_STRING, resp.content().toString(CharsetUtil.UTF_8),
|
||||||
SAMPLE_STRING,
|
"Response body should match uncompressed string");
|
||||||
resp.content().toString(CharsetUtil.UTF_8));
|
|
||||||
resp.release();
|
resp.release();
|
||||||
|
|
||||||
assertHasInboundMessages(channel, false);
|
assertHasInboundMessages(channel, false);
|
||||||
@ -225,7 +229,7 @@ public class HttpContentDecoderTest {
|
|||||||
public void testResponseChunksBrotliDecompression() throws Throwable {
|
public void testResponseChunksBrotliDecompression() throws Throwable {
|
||||||
Brotli.ensureAvailability();
|
Brotli.ensureAvailability();
|
||||||
// Failing on windows atm
|
// Failing on windows atm
|
||||||
Assume.assumeFalse(PlatformDependent.isWindows());
|
assumeFalse(PlatformDependent.isWindows());
|
||||||
HttpResponseDecoder decoder = new HttpResponseDecoder();
|
HttpResponseDecoder decoder = new HttpResponseDecoder();
|
||||||
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
HttpContentDecoder decompressor = new HttpContentDecompressor();
|
||||||
HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE);
|
HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE);
|
||||||
@ -253,12 +257,11 @@ public class HttpContentDecoderTest {
|
|||||||
Object o = channel.readInbound();
|
Object o = channel.readInbound();
|
||||||
assertThat(o, is(instanceOf(FullHttpResponse.class)));
|
assertThat(o, is(instanceOf(FullHttpResponse.class)));
|
||||||
FullHttpResponse resp = (FullHttpResponse) o;
|
FullHttpResponse resp = (FullHttpResponse) o;
|
||||||
assertEquals("Content-Length header should match uncompressed string's length",
|
assertEquals(SAMPLE_STRING.length(),
|
||||||
SAMPLE_STRING.length(),
|
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue(),
|
||||||
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue());
|
"Content-Length header should match uncompressed string's length");
|
||||||
assertEquals("Response body should match uncompressed string",
|
assertEquals(SAMPLE_STRING, resp.content().toString(CharsetUtil.UTF_8),
|
||||||
SAMPLE_STRING,
|
"Response body should match uncompressed string");
|
||||||
resp.content().toString(CharsetUtil.UTF_8));
|
|
||||||
resp.release();
|
resp.release();
|
||||||
|
|
||||||
assertHasInboundMessages(channel, false);
|
assertHasInboundMessages(channel, false);
|
||||||
@ -511,11 +514,11 @@ public class HttpContentDecoderTest {
|
|||||||
assertThat(o, is(instanceOf(HttpResponse.class)));
|
assertThat(o, is(instanceOf(HttpResponse.class)));
|
||||||
HttpResponse r = (HttpResponse) o;
|
HttpResponse r = (HttpResponse) o;
|
||||||
|
|
||||||
assertFalse("Content-Length header not removed.", r.headers().contains(HttpHeaderNames.CONTENT_LENGTH));
|
assertFalse(r.headers().contains(HttpHeaderNames.CONTENT_LENGTH), "Content-Length header not removed.");
|
||||||
|
|
||||||
String transferEncoding = r.headers().get(HttpHeaderNames.TRANSFER_ENCODING);
|
String transferEncoding = r.headers().get(HttpHeaderNames.TRANSFER_ENCODING);
|
||||||
assertNotNull("Content-length as well as transfer-encoding not set.", transferEncoding);
|
assertNotNull(transferEncoding, "Content-length as well as transfer-encoding not set.");
|
||||||
assertEquals("Unexpected transfer-encoding value.", HttpHeaderValues.CHUNKED.toString(), transferEncoding);
|
assertEquals(HttpHeaderValues.CHUNKED.toString(), transferEncoding, "Unexpected transfer-encoding value.");
|
||||||
|
|
||||||
assertHasInboundMessages(channel, true);
|
assertHasInboundMessages(channel, true);
|
||||||
assertHasOutboundMessages(channel, false);
|
assertHasOutboundMessages(channel, false);
|
||||||
|
@ -18,13 +18,15 @@ package io.netty.handler.codec.http;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpContentDecompressorTest {
|
public class HttpContentDecompressorTest {
|
||||||
|
|
||||||
// See https://github.com/netty/netty/issues/8915.
|
// See https://github.com/netty/netty/issues/8915.
|
||||||
@ -53,18 +55,18 @@ public class HttpContentDecompressorTest {
|
|||||||
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8");
|
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8");
|
||||||
response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
|
response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
|
||||||
|
|
||||||
Assert.assertTrue(channel.writeInbound(response));
|
assertTrue(channel.writeInbound(response));
|
||||||
|
|
||||||
// we triggered read explicitly
|
// we triggered read explicitly
|
||||||
Assert.assertEquals(1, readCalled.get());
|
assertEquals(1, readCalled.get());
|
||||||
|
|
||||||
Assert.assertTrue(channel.readInbound() instanceof HttpResponse);
|
assertTrue(channel.readInbound() instanceof HttpResponse);
|
||||||
|
|
||||||
Assert.assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.EMPTY_BUFFER)));
|
assertFalse(channel.writeInbound(new DefaultHttpContent(Unpooled.EMPTY_BUFFER)));
|
||||||
|
|
||||||
// read was triggered by the HttpContentDecompressor itself as it did not produce any message to the next
|
// read was triggered by the HttpContentDecompressor itself as it did not produce any message to the next
|
||||||
// inbound handler.
|
// inbound handler.
|
||||||
Assert.assertEquals(2, readCalled.get());
|
assertEquals(2, readCalled.get());
|
||||||
Assert.assertFalse(channel.finishAndReleaseAll());
|
assertFalse(channel.finishAndReleaseAll());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,11 @@ import static org.hamcrest.CoreMatchers.is;
|
|||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpContentEncoderTest {
|
public class HttpContentEncoderTest {
|
||||||
|
|
||||||
|
@ -16,16 +16,17 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpHeadersTest {
|
public class HttpHeadersTest {
|
||||||
|
|
||||||
@ -61,22 +62,22 @@ public class HttpHeadersTest {
|
|||||||
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
|
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testSetNullHeaderValueValidate() {
|
public void testSetNullHeaderValueValidate() {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders(true);
|
HttpHeaders headers = new DefaultHttpHeaders(true);
|
||||||
headers.set(of("test"), (CharSequence) null);
|
assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testSetNullHeaderValueNotValidate() {
|
public void testSetNullHeaderValueNotValidate() {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders(false);
|
HttpHeaders headers = new DefaultHttpHeaders(false);
|
||||||
headers.set(of("test"), (CharSequence) null);
|
assertThrows(NullPointerException.class, () -> headers.set(of("test"), (CharSequence) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testAddSelf() {
|
public void testAddSelf() {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders(false);
|
HttpHeaders headers = new DefaultHttpHeaders(false);
|
||||||
headers.add(headers);
|
assertThrows(IllegalArgumentException.class, () -> headers.add(headers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -25,10 +25,10 @@ import org.junit.Test;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpInvalidMessageTest {
|
public class HttpInvalidMessageTest {
|
||||||
|
|
||||||
|
@ -37,14 +37,14 @@ import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
|||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpObjectAggregatorTest {
|
public class HttpObjectAggregatorTest {
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@ import static org.hamcrest.CoreMatchers.instanceOf;
|
|||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpRequestDecoderTest {
|
public class HttpRequestDecoderTest {
|
||||||
private static final byte[] CONTENT_CRLF_DELIMITERS = createContent("\r\n");
|
private static final byte[] CONTENT_CRLF_DELIMITERS = createContent("\r\n");
|
||||||
|
@ -31,7 +31,10 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import io.netty.handler.codec.PrematureChannelClosureException;
|
import io.netty.handler.codec.PrematureChannelClosureException;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,11 +33,11 @@ import static org.hamcrest.CoreMatchers.not;
|
|||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpResponseDecoderTest {
|
public class HttpResponseDecoderTest {
|
||||||
|
|
||||||
|
@ -20,14 +20,17 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.channel.FileRegion;
|
import io.netty.channel.FileRegion;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpResponseEncoderTest {
|
public class HttpResponseEncoderTest {
|
||||||
private static final long INTEGER_OVERFLOW = (long) Integer.MAX_VALUE + 1;
|
private static final long INTEGER_OVERFLOW = (long) Integer.MAX_VALUE + 1;
|
||||||
|
@ -16,11 +16,12 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.parseLine;
|
import static io.netty.handler.codec.http.HttpResponseStatus.parseLine;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
public class HttpResponseStatusTest {
|
public class HttpResponseStatusTest {
|
||||||
@Test
|
@Test
|
||||||
@ -46,14 +47,14 @@ public class HttpResponseStatusTest {
|
|||||||
assertEquals("FOO", customStatus.reasonPhrase());
|
assertEquals("FOO", customStatus.reasonPhrase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void parseLineStringMalformedCode() {
|
public void parseLineStringMalformedCode() {
|
||||||
parseLine("200a");
|
assertThrows(IllegalArgumentException.class, () -> parseLine("200a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void parseLineStringMalformedCodeWithPhrase() {
|
public void parseLineStringMalformedCodeWithPhrase() {
|
||||||
parseLine("200a foo");
|
assertThrows(IllegalArgumentException.class, () -> parseLine("200a foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -79,13 +80,13 @@ public class HttpResponseStatusTest {
|
|||||||
assertEquals("FOO", customStatus.reasonPhrase());
|
assertEquals("FOO", customStatus.reasonPhrase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void parseLineAsciiStringMalformedCode() {
|
public void parseLineAsciiStringMalformedCode() {
|
||||||
parseLine(new AsciiString("200a"));
|
assertThrows(IllegalArgumentException.class, () -> parseLine(new AsciiString("200a")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void parseLineAsciiStringMalformedCodeWithPhrase() {
|
public void parseLineAsciiStringMalformedCodeWithPhrase() {
|
||||||
parseLine(new AsciiString("200a foo"));
|
assertThrows(IllegalArgumentException.class, () -> parseLine(new AsciiString("200a foo")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,14 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpServerCodecTest {
|
public class HttpServerCodecTest {
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpServerExpectContinueHandlerTest {
|
public class HttpServerExpectContinueHandlerTest {
|
||||||
|
|
||||||
|
@ -37,9 +37,9 @@ import static io.netty.handler.codec.http.HttpUtil.isKeepAlive;
|
|||||||
import static io.netty.handler.codec.http.HttpUtil.setContentLength;
|
import static io.netty.handler.codec.http.HttpUtil.setContentLength;
|
||||||
import static io.netty.handler.codec.http.HttpUtil.setKeepAlive;
|
import static io.netty.handler.codec.http.HttpUtil.setKeepAlive;
|
||||||
import static io.netty.handler.codec.http.HttpUtil.setTransferEncodingChunked;
|
import static io.netty.handler.codec.http.HttpUtil.setTransferEncodingChunked;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class HttpServerKeepAliveHandlerTest {
|
public class HttpServerKeepAliveHandlerTest {
|
||||||
@ -111,8 +111,8 @@ public class HttpServerKeepAliveHandlerTest {
|
|||||||
channel.writeAndFlush(response);
|
channel.writeAndFlush(response);
|
||||||
HttpResponse writtenResponse = channel.readOutbound();
|
HttpResponse writtenResponse = channel.readOutbound();
|
||||||
|
|
||||||
assertEquals("channel.isOpen", isKeepAliveResponseExpected, channel.isOpen());
|
assertEquals(isKeepAliveResponseExpected, channel.isOpen(), "channel.isOpen");
|
||||||
assertEquals("response keep-alive", isKeepAliveResponseExpected, isKeepAlive(writtenResponse));
|
assertEquals(isKeepAliveResponseExpected, isKeepAlive(writtenResponse), "response keep-alive");
|
||||||
ReferenceCountUtil.release(writtenResponse);
|
ReferenceCountUtil.release(writtenResponse);
|
||||||
assertFalse(channel.finishAndReleaseAll());
|
assertFalse(channel.finishAndReleaseAll());
|
||||||
}
|
}
|
||||||
@ -167,8 +167,8 @@ public class HttpServerKeepAliveHandlerTest {
|
|||||||
|
|
||||||
channel.writeAndFlush(response.retainedDuplicate());
|
channel.writeAndFlush(response.retainedDuplicate());
|
||||||
HttpResponse firstResponse = channel.readOutbound();
|
HttpResponse firstResponse = channel.readOutbound();
|
||||||
assertTrue("channel.isOpen", channel.isOpen());
|
assertTrue(channel.isOpen(), "channel.isOpen");
|
||||||
assertTrue("response keep-alive", isKeepAlive(firstResponse));
|
assertTrue(isKeepAlive(firstResponse), "response keep-alive");
|
||||||
ReferenceCountUtil.release(firstResponse);
|
ReferenceCountUtil.release(firstResponse);
|
||||||
|
|
||||||
requestForwarded = channel.readInbound();
|
requestForwarded = channel.readInbound();
|
||||||
@ -177,8 +177,8 @@ public class HttpServerKeepAliveHandlerTest {
|
|||||||
|
|
||||||
channel.writeAndFlush(informationalResp);
|
channel.writeAndFlush(informationalResp);
|
||||||
HttpResponse writtenInfoResp = channel.readOutbound();
|
HttpResponse writtenInfoResp = channel.readOutbound();
|
||||||
assertTrue("channel.isOpen", channel.isOpen());
|
assertTrue(channel.isOpen(), "channel.isOpen");
|
||||||
assertTrue("response keep-alive", isKeepAlive(writtenInfoResp));
|
assertTrue(isKeepAlive(writtenInfoResp), "response keep-alive");
|
||||||
ReferenceCountUtil.release(writtenInfoResp);
|
ReferenceCountUtil.release(writtenInfoResp);
|
||||||
|
|
||||||
if (!StringUtil.isNullOrEmpty(setResponseConnection)) {
|
if (!StringUtil.isNullOrEmpty(setResponseConnection)) {
|
||||||
@ -189,8 +189,8 @@ public class HttpServerKeepAliveHandlerTest {
|
|||||||
setupMessageLength(response);
|
setupMessageLength(response);
|
||||||
channel.writeAndFlush(response.retainedDuplicate());
|
channel.writeAndFlush(response.retainedDuplicate());
|
||||||
HttpResponse secondResponse = channel.readOutbound();
|
HttpResponse secondResponse = channel.readOutbound();
|
||||||
assertEquals("channel.isOpen", isKeepAliveResponseExpected, channel.isOpen());
|
assertEquals(isKeepAliveResponseExpected, channel.isOpen(), "channel.isOpen");
|
||||||
assertEquals("response keep-alive", isKeepAliveResponseExpected, isKeepAlive(secondResponse));
|
assertEquals(isKeepAliveResponseExpected, isKeepAlive(secondResponse), "response keep-alive");
|
||||||
ReferenceCountUtil.release(secondResponse);
|
ReferenceCountUtil.release(secondResponse);
|
||||||
|
|
||||||
requestForwarded = channel.readInbound();
|
requestForwarded = channel.readInbound();
|
||||||
@ -200,8 +200,8 @@ public class HttpServerKeepAliveHandlerTest {
|
|||||||
if (isKeepAliveResponseExpected) {
|
if (isKeepAliveResponseExpected) {
|
||||||
channel.writeAndFlush(response);
|
channel.writeAndFlush(response);
|
||||||
HttpResponse finalResponse = channel.readOutbound();
|
HttpResponse finalResponse = channel.readOutbound();
|
||||||
assertFalse("channel.isOpen", channel.isOpen());
|
assertFalse(channel.isOpen(), "channel.isOpen");
|
||||||
assertFalse("response keep-alive", isKeepAlive(finalResponse));
|
assertFalse(isKeepAlive(finalResponse), "response keep-alive");
|
||||||
}
|
}
|
||||||
ReferenceCountUtil.release(response);
|
ReferenceCountUtil.release(response);
|
||||||
assertFalse(channel.finishAndReleaseAll());
|
assertFalse(channel.finishAndReleaseAll());
|
||||||
|
@ -31,7 +31,12 @@ import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodec;
|
|||||||
import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory;
|
import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpServerUpgradeHandlerTest {
|
public class HttpServerUpgradeHandlerTest {
|
||||||
|
|
||||||
|
@ -27,11 +27,11 @@ import io.netty.util.ReferenceCountUtil;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpUtilTest {
|
public class HttpUtilTest {
|
||||||
|
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
@ -26,12 +25,17 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class QueryStringDecoderTest {
|
public class QueryStringDecoderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicUris() throws URISyntaxException {
|
public void testBasicUris() throws URISyntaxException {
|
||||||
QueryStringDecoder d = new QueryStringDecoder(new URI("http://localhost/path"));
|
QueryStringDecoder d = new QueryStringDecoder(new URI("http://localhost/path"));
|
||||||
Assert.assertEquals(0, d.parameters().size());
|
assertEquals(0, d.parameters().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -39,68 +43,68 @@ public class QueryStringDecoderTest {
|
|||||||
QueryStringDecoder d;
|
QueryStringDecoder d;
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo");
|
d = new QueryStringDecoder("/foo");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(0, d.parameters().size());
|
assertEquals(0, d.parameters().size());
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo%20bar");
|
d = new QueryStringDecoder("/foo%20bar");
|
||||||
Assert.assertEquals("/foo bar", d.path());
|
assertEquals("/foo bar", d.path());
|
||||||
Assert.assertEquals(0, d.parameters().size());
|
assertEquals(0, d.parameters().size());
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?a=b=c");
|
d = new QueryStringDecoder("/foo?a=b=c");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(1, d.parameters().get("a").size());
|
assertEquals(1, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("b=c", d.parameters().get("a").get(0));
|
assertEquals("b=c", d.parameters().get("a").get(0));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?a=1&a=2");
|
d = new QueryStringDecoder("/foo?a=1&a=2");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(2, d.parameters().get("a").size());
|
assertEquals(2, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("1", d.parameters().get("a").get(0));
|
assertEquals("1", d.parameters().get("a").get(0));
|
||||||
Assert.assertEquals("2", d.parameters().get("a").get(1));
|
assertEquals("2", d.parameters().get("a").get(1));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo%20bar?a=1&a=2");
|
d = new QueryStringDecoder("/foo%20bar?a=1&a=2");
|
||||||
Assert.assertEquals("/foo bar", d.path());
|
assertEquals("/foo bar", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(2, d.parameters().get("a").size());
|
assertEquals(2, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("1", d.parameters().get("a").get(0));
|
assertEquals("1", d.parameters().get("a").get(0));
|
||||||
Assert.assertEquals("2", d.parameters().get("a").get(1));
|
assertEquals("2", d.parameters().get("a").get(1));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?a=&a=2");
|
d = new QueryStringDecoder("/foo?a=&a=2");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(2, d.parameters().get("a").size());
|
assertEquals(2, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("", d.parameters().get("a").get(0));
|
assertEquals("", d.parameters().get("a").get(0));
|
||||||
Assert.assertEquals("2", d.parameters().get("a").get(1));
|
assertEquals("2", d.parameters().get("a").get(1));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?a=1&a=");
|
d = new QueryStringDecoder("/foo?a=1&a=");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(2, d.parameters().get("a").size());
|
assertEquals(2, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("1", d.parameters().get("a").get(0));
|
assertEquals("1", d.parameters().get("a").get(0));
|
||||||
Assert.assertEquals("", d.parameters().get("a").get(1));
|
assertEquals("", d.parameters().get("a").get(1));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?a=1&a=&a=");
|
d = new QueryStringDecoder("/foo?a=1&a=&a=");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(3, d.parameters().get("a").size());
|
assertEquals(3, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("1", d.parameters().get("a").get(0));
|
assertEquals("1", d.parameters().get("a").get(0));
|
||||||
Assert.assertEquals("", d.parameters().get("a").get(1));
|
assertEquals("", d.parameters().get("a").get(1));
|
||||||
Assert.assertEquals("", d.parameters().get("a").get(2));
|
assertEquals("", d.parameters().get("a").get(2));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?a=1=&a==2");
|
d = new QueryStringDecoder("/foo?a=1=&a==2");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(2, d.parameters().get("a").size());
|
assertEquals(2, d.parameters().get("a").size());
|
||||||
Assert.assertEquals("1=", d.parameters().get("a").get(0));
|
assertEquals("1=", d.parameters().get("a").get(0));
|
||||||
Assert.assertEquals("=2", d.parameters().get("a").get(1));
|
assertEquals("=2", d.parameters().get("a").get(1));
|
||||||
|
|
||||||
d = new QueryStringDecoder("/foo?abc=1%2023&abc=124%20");
|
d = new QueryStringDecoder("/foo?abc=1%2023&abc=124%20");
|
||||||
Assert.assertEquals("/foo", d.path());
|
assertEquals("/foo", d.path());
|
||||||
Assert.assertEquals(1, d.parameters().size());
|
assertEquals(1, d.parameters().size());
|
||||||
Assert.assertEquals(2, d.parameters().get("abc").size());
|
assertEquals(2, d.parameters().get("abc").size());
|
||||||
Assert.assertEquals("1 23", d.parameters().get("abc").get(0));
|
assertEquals("1 23", d.parameters().get("abc").get(0));
|
||||||
Assert.assertEquals("124 ", d.parameters().get("abc").get(1));
|
assertEquals("124 ", d.parameters().get("abc").get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -139,32 +143,32 @@ public class QueryStringDecoderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testPathSpecific() {
|
public void testPathSpecific() {
|
||||||
// decode escaped characters
|
// decode escaped characters
|
||||||
Assert.assertEquals("/foo bar/", new QueryStringDecoder("/foo%20bar/?").path());
|
assertEquals("/foo bar/", new QueryStringDecoder("/foo%20bar/?").path());
|
||||||
Assert.assertEquals("/foo\r\n\\bar/", new QueryStringDecoder("/foo%0D%0A\\bar/?").path());
|
assertEquals("/foo\r\n\\bar/", new QueryStringDecoder("/foo%0D%0A\\bar/?").path());
|
||||||
|
|
||||||
// a 'fragment' after '#' should be cuted (see RFC 3986)
|
// a 'fragment' after '#' should be cuted (see RFC 3986)
|
||||||
Assert.assertEquals("", new QueryStringDecoder("#123").path());
|
assertEquals("", new QueryStringDecoder("#123").path());
|
||||||
Assert.assertEquals("foo", new QueryStringDecoder("foo?bar#anchor").path());
|
assertEquals("foo", new QueryStringDecoder("foo?bar#anchor").path());
|
||||||
Assert.assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#anchor").path());
|
assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#anchor").path());
|
||||||
Assert.assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#a#b?c=d").path());
|
assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#a#b?c=d").path());
|
||||||
|
|
||||||
// '+' is not escape ' ' for the path
|
// '+' is not escape ' ' for the path
|
||||||
Assert.assertEquals("+", new QueryStringDecoder("+").path());
|
assertEquals("+", new QueryStringDecoder("+").path());
|
||||||
Assert.assertEquals("/foo+bar/", new QueryStringDecoder("/foo+bar/?").path());
|
assertEquals("/foo+bar/", new QueryStringDecoder("/foo+bar/?").path());
|
||||||
Assert.assertEquals("/foo++", new QueryStringDecoder("/foo++?index.php").path());
|
assertEquals("/foo++", new QueryStringDecoder("/foo++?index.php").path());
|
||||||
Assert.assertEquals("/foo +", new QueryStringDecoder("/foo%20+?index.php").path());
|
assertEquals("/foo +", new QueryStringDecoder("/foo%20+?index.php").path());
|
||||||
Assert.assertEquals("/foo+ ", new QueryStringDecoder("/foo+%20").path());
|
assertEquals("/foo+ ", new QueryStringDecoder("/foo+%20").path());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExcludeFragment() {
|
public void testExcludeFragment() {
|
||||||
// a 'fragment' after '#' should be cuted (see RFC 3986)
|
// a 'fragment' after '#' should be cuted (see RFC 3986)
|
||||||
Assert.assertEquals("a", new QueryStringDecoder("?a#anchor").parameters().keySet().iterator().next());
|
assertEquals("a", new QueryStringDecoder("?a#anchor").parameters().keySet().iterator().next());
|
||||||
Assert.assertEquals("b", new QueryStringDecoder("?a=b#anchor").parameters().get("a").get(0));
|
assertEquals("b", new QueryStringDecoder("?a=b#anchor").parameters().get("a").get(0));
|
||||||
Assert.assertTrue(new QueryStringDecoder("?#").parameters().isEmpty());
|
assertTrue(new QueryStringDecoder("?#").parameters().isEmpty());
|
||||||
Assert.assertTrue(new QueryStringDecoder("?#anchor").parameters().isEmpty());
|
assertTrue(new QueryStringDecoder("?#anchor").parameters().isEmpty());
|
||||||
Assert.assertTrue(new QueryStringDecoder("#?a=b#anchor").parameters().isEmpty());
|
assertTrue(new QueryStringDecoder("#?a=b#anchor").parameters().isEmpty());
|
||||||
Assert.assertTrue(new QueryStringDecoder("?#a=b#anchor").parameters().isEmpty());
|
assertTrue(new QueryStringDecoder("?#a=b#anchor").parameters().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -178,20 +182,20 @@ public class QueryStringDecoderTest {
|
|||||||
buf.append(i);
|
buf.append(i);
|
||||||
buf.append('&');
|
buf.append('&');
|
||||||
}
|
}
|
||||||
Assert.assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size());
|
assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasPath() {
|
public void testHasPath() {
|
||||||
QueryStringDecoder decoder = new QueryStringDecoder("1=2", false);
|
QueryStringDecoder decoder = new QueryStringDecoder("1=2", false);
|
||||||
Assert.assertEquals("", decoder.path());
|
assertEquals("", decoder.path());
|
||||||
Map<String, List<String>> params = decoder.parameters();
|
Map<String, List<String>> params = decoder.parameters();
|
||||||
Assert.assertEquals(1, params.size());
|
assertEquals(1, params.size());
|
||||||
Assert.assertTrue(params.containsKey("1"));
|
assertTrue(params.containsKey("1"));
|
||||||
List<String> param = params.get("1");
|
List<String> param = params.get("1");
|
||||||
Assert.assertNotNull(param);
|
assertNotNull(param);
|
||||||
Assert.assertEquals(1, param.size());
|
assertEquals(1, param.size());
|
||||||
Assert.assertEquals("2", param.get(0));
|
assertEquals("2", param.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -224,9 +228,9 @@ public class QueryStringDecoderTest {
|
|||||||
final String expected = tests[i + 1];
|
final String expected = tests[i + 1];
|
||||||
try {
|
try {
|
||||||
final String decoded = QueryStringDecoder.decodeComponent(encoded);
|
final String decoded = QueryStringDecoder.decodeComponent(encoded);
|
||||||
Assert.assertEquals(expected, decoded);
|
assertEquals(expected, decoded);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Assert.assertEquals(expected, e.getMessage());
|
assertEquals(expected, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,8 +244,8 @@ public class QueryStringDecoderTest {
|
|||||||
1024, semicolonIsNormalChar);
|
1024, semicolonIsNormalChar);
|
||||||
QueryStringDecoder ad = new QueryStringDecoder(actual, CharsetUtil.UTF_8, true,
|
QueryStringDecoder ad = new QueryStringDecoder(actual, CharsetUtil.UTF_8, true,
|
||||||
1024, semicolonIsNormalChar);
|
1024, semicolonIsNormalChar);
|
||||||
Assert.assertEquals(ed.path(), ad.path());
|
assertEquals(ed.path(), ad.path());
|
||||||
Assert.assertEquals(ed.parameters(), ad.parameters());
|
assertEquals(ed.parameters(), ad.parameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
// See #189
|
// See #189
|
||||||
@ -249,29 +253,29 @@ public class QueryStringDecoderTest {
|
|||||||
public void testURI() {
|
public void testURI() {
|
||||||
URI uri = URI.create("http://localhost:8080/foo?param1=value1¶m2=value2¶m3=value3");
|
URI uri = URI.create("http://localhost:8080/foo?param1=value1¶m2=value2¶m3=value3");
|
||||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
Assert.assertEquals("/foo", decoder.path());
|
assertEquals("/foo", decoder.path());
|
||||||
Assert.assertEquals("/foo", decoder.rawPath());
|
assertEquals("/foo", decoder.rawPath());
|
||||||
Assert.assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery());
|
assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery());
|
||||||
Map<String, List<String>> params = decoder.parameters();
|
Map<String, List<String>> params = decoder.parameters();
|
||||||
Assert.assertEquals(3, params.size());
|
assertEquals(3, params.size());
|
||||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
Entry<String, List<String>> entry = entries.next();
|
Entry<String, List<String>> entry = entries.next();
|
||||||
Assert.assertEquals("param1", entry.getKey());
|
assertEquals("param1", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value1", entry.getValue().get(0));
|
assertEquals("value1", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("param2", entry.getKey());
|
assertEquals("param2", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value2", entry.getValue().get(0));
|
assertEquals("value2", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("param3", entry.getKey());
|
assertEquals("param3", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value3", entry.getValue().get(0));
|
assertEquals("value3", entry.getValue().get(0));
|
||||||
|
|
||||||
Assert.assertFalse(entries.hasNext());
|
assertFalse(entries.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
// See #189
|
// See #189
|
||||||
@ -279,30 +283,30 @@ public class QueryStringDecoderTest {
|
|||||||
public void testURISlashPath() {
|
public void testURISlashPath() {
|
||||||
URI uri = URI.create("http://localhost:8080/?param1=value1¶m2=value2¶m3=value3");
|
URI uri = URI.create("http://localhost:8080/?param1=value1¶m2=value2¶m3=value3");
|
||||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
Assert.assertEquals("/", decoder.path());
|
assertEquals("/", decoder.path());
|
||||||
Assert.assertEquals("/", decoder.rawPath());
|
assertEquals("/", decoder.rawPath());
|
||||||
Assert.assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery());
|
assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery());
|
||||||
|
|
||||||
Map<String, List<String>> params = decoder.parameters();
|
Map<String, List<String>> params = decoder.parameters();
|
||||||
Assert.assertEquals(3, params.size());
|
assertEquals(3, params.size());
|
||||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
Entry<String, List<String>> entry = entries.next();
|
Entry<String, List<String>> entry = entries.next();
|
||||||
Assert.assertEquals("param1", entry.getKey());
|
assertEquals("param1", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value1", entry.getValue().get(0));
|
assertEquals("value1", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("param2", entry.getKey());
|
assertEquals("param2", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value2", entry.getValue().get(0));
|
assertEquals("value2", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("param3", entry.getKey());
|
assertEquals("param3", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value3", entry.getValue().get(0));
|
assertEquals("value3", entry.getValue().get(0));
|
||||||
|
|
||||||
Assert.assertFalse(entries.hasNext());
|
assertFalse(entries.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
// See #189
|
// See #189
|
||||||
@ -310,30 +314,30 @@ public class QueryStringDecoderTest {
|
|||||||
public void testURINoPath() {
|
public void testURINoPath() {
|
||||||
URI uri = URI.create("http://localhost:8080?param1=value1¶m2=value2¶m3=value3");
|
URI uri = URI.create("http://localhost:8080?param1=value1¶m2=value2¶m3=value3");
|
||||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
Assert.assertEquals("", decoder.path());
|
assertEquals("", decoder.path());
|
||||||
Assert.assertEquals("", decoder.rawPath());
|
assertEquals("", decoder.rawPath());
|
||||||
Assert.assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery());
|
assertEquals("param1=value1¶m2=value2¶m3=value3", decoder.rawQuery());
|
||||||
|
|
||||||
Map<String, List<String>> params = decoder.parameters();
|
Map<String, List<String>> params = decoder.parameters();
|
||||||
Assert.assertEquals(3, params.size());
|
assertEquals(3, params.size());
|
||||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
Entry<String, List<String>> entry = entries.next();
|
Entry<String, List<String>> entry = entries.next();
|
||||||
Assert.assertEquals("param1", entry.getKey());
|
assertEquals("param1", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value1", entry.getValue().get(0));
|
assertEquals("value1", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("param2", entry.getKey());
|
assertEquals("param2", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value2", entry.getValue().get(0));
|
assertEquals("value2", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("param3", entry.getKey());
|
assertEquals("param3", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("value3", entry.getValue().get(0));
|
assertEquals("value3", entry.getValue().get(0));
|
||||||
|
|
||||||
Assert.assertFalse(entries.hasNext());
|
assertFalse(entries.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://github.com/netty/netty/issues/1833
|
// See https://github.com/netty/netty/issues/1833
|
||||||
@ -341,37 +345,37 @@ public class QueryStringDecoderTest {
|
|||||||
public void testURI2() {
|
public void testURI2() {
|
||||||
URI uri = URI.create("http://foo.com/images;num=10?query=name;value=123");
|
URI uri = URI.create("http://foo.com/images;num=10?query=name;value=123");
|
||||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||||
Assert.assertEquals("/images;num=10", decoder.path());
|
assertEquals("/images;num=10", decoder.path());
|
||||||
Assert.assertEquals("/images;num=10", decoder.rawPath());
|
assertEquals("/images;num=10", decoder.rawPath());
|
||||||
Assert.assertEquals("query=name;value=123", decoder.rawQuery());
|
assertEquals("query=name;value=123", decoder.rawQuery());
|
||||||
|
|
||||||
Map<String, List<String>> params = decoder.parameters();
|
Map<String, List<String>> params = decoder.parameters();
|
||||||
Assert.assertEquals(2, params.size());
|
assertEquals(2, params.size());
|
||||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||||
|
|
||||||
Entry<String, List<String>> entry = entries.next();
|
Entry<String, List<String>> entry = entries.next();
|
||||||
Assert.assertEquals("query", entry.getKey());
|
assertEquals("query", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("name", entry.getValue().get(0));
|
assertEquals("name", entry.getValue().get(0));
|
||||||
|
|
||||||
entry = entries.next();
|
entry = entries.next();
|
||||||
Assert.assertEquals("value", entry.getKey());
|
assertEquals("value", entry.getKey());
|
||||||
Assert.assertEquals(1, entry.getValue().size());
|
assertEquals(1, entry.getValue().size());
|
||||||
Assert.assertEquals("123", entry.getValue().get(0));
|
assertEquals("123", entry.getValue().get(0));
|
||||||
|
|
||||||
Assert.assertFalse(entries.hasNext());
|
assertFalse(entries.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyStrings() {
|
public void testEmptyStrings() {
|
||||||
QueryStringDecoder pathSlash = new QueryStringDecoder("path/");
|
QueryStringDecoder pathSlash = new QueryStringDecoder("path/");
|
||||||
Assert.assertEquals("path/", pathSlash.rawPath());
|
assertEquals("path/", pathSlash.rawPath());
|
||||||
Assert.assertEquals("", pathSlash.rawQuery());
|
assertEquals("", pathSlash.rawQuery());
|
||||||
QueryStringDecoder pathQuestion = new QueryStringDecoder("path?");
|
QueryStringDecoder pathQuestion = new QueryStringDecoder("path?");
|
||||||
Assert.assertEquals("path", pathQuestion.rawPath());
|
assertEquals("path", pathQuestion.rawPath());
|
||||||
Assert.assertEquals("", pathQuestion.rawQuery());
|
assertEquals("", pathQuestion.rawQuery());
|
||||||
QueryStringDecoder empty = new QueryStringDecoder("");
|
QueryStringDecoder empty = new QueryStringDecoder("");
|
||||||
Assert.assertEquals("", empty.rawPath());
|
assertEquals("", empty.rawPath());
|
||||||
Assert.assertEquals("", empty.rawQuery());
|
assertEquals("", empty.rawQuery());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class QueryStringEncoderTest {
|
public class QueryStringEncoderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -29,47 +30,47 @@ public class QueryStringEncoderTest {
|
|||||||
|
|
||||||
e = new QueryStringEncoder("/foo");
|
e = new QueryStringEncoder("/foo");
|
||||||
e.addParam("a", "b=c");
|
e.addParam("a", "b=c");
|
||||||
Assert.assertEquals("/foo?a=b%3Dc", e.toString());
|
assertEquals("/foo?a=b%3Dc", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo?a=b%3Dc"), e.toUri());
|
assertEquals(new URI("/foo?a=b%3Dc"), e.toUri());
|
||||||
|
|
||||||
e = new QueryStringEncoder("/foo/\u00A5");
|
e = new QueryStringEncoder("/foo/\u00A5");
|
||||||
e.addParam("a", "\u00A5");
|
e.addParam("a", "\u00A5");
|
||||||
Assert.assertEquals("/foo/\u00A5?a=%C2%A5", e.toString());
|
assertEquals("/foo/\u00A5?a=%C2%A5", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo/\u00A5?a=%C2%A5"), e.toUri());
|
assertEquals(new URI("/foo/\u00A5?a=%C2%A5"), e.toUri());
|
||||||
|
|
||||||
e = new QueryStringEncoder("/foo/\u00A5");
|
e = new QueryStringEncoder("/foo/\u00A5");
|
||||||
e.addParam("a", "abc\u00A5");
|
e.addParam("a", "abc\u00A5");
|
||||||
Assert.assertEquals("/foo/\u00A5?a=abc%C2%A5", e.toString());
|
assertEquals("/foo/\u00A5?a=abc%C2%A5", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo/\u00A5?a=abc%C2%A5"), e.toUri());
|
assertEquals(new URI("/foo/\u00A5?a=abc%C2%A5"), e.toUri());
|
||||||
|
|
||||||
e = new QueryStringEncoder("/foo");
|
e = new QueryStringEncoder("/foo");
|
||||||
e.addParam("a", "1");
|
e.addParam("a", "1");
|
||||||
e.addParam("b", "2");
|
e.addParam("b", "2");
|
||||||
Assert.assertEquals("/foo?a=1&b=2", e.toString());
|
assertEquals("/foo?a=1&b=2", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo?a=1&b=2"), e.toUri());
|
assertEquals(new URI("/foo?a=1&b=2"), e.toUri());
|
||||||
|
|
||||||
e = new QueryStringEncoder("/foo");
|
e = new QueryStringEncoder("/foo");
|
||||||
e.addParam("a", "1");
|
e.addParam("a", "1");
|
||||||
e.addParam("b", "");
|
e.addParam("b", "");
|
||||||
e.addParam("c", null);
|
e.addParam("c", null);
|
||||||
e.addParam("d", null);
|
e.addParam("d", null);
|
||||||
Assert.assertEquals("/foo?a=1&b=&c&d", e.toString());
|
assertEquals("/foo?a=1&b=&c&d", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri());
|
assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonDefaultEncoding() throws Exception {
|
public void testNonDefaultEncoding() throws Exception {
|
||||||
QueryStringEncoder e = new QueryStringEncoder("/foo/\u00A5", Charset.forName("UTF-16"));
|
QueryStringEncoder e = new QueryStringEncoder("/foo/\u00A5", Charset.forName("UTF-16"));
|
||||||
e.addParam("a", "\u00A5");
|
e.addParam("a", "\u00A5");
|
||||||
Assert.assertEquals("/foo/\u00A5?a=%FE%FF%00%A5", e.toString());
|
assertEquals("/foo/\u00A5?a=%FE%FF%00%A5", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo/\u00A5?a=%FE%FF%00%A5"), e.toUri());
|
assertEquals(new URI("/foo/\u00A5?a=%FE%FF%00%A5"), e.toUri());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhitespaceEncoding() throws Exception {
|
public void testWhitespaceEncoding() throws Exception {
|
||||||
QueryStringEncoder e = new QueryStringEncoder("/foo");
|
QueryStringEncoder e = new QueryStringEncoder("/foo");
|
||||||
e.addParam("a", "b c");
|
e.addParam("a", "b c");
|
||||||
Assert.assertEquals("/foo?a=b%20c", e.toString());
|
assertEquals("/foo?a=b%20c", e.toString());
|
||||||
Assert.assertEquals(new URI("/foo?a=b%20c"), e.toUri());
|
assertEquals(new URI("/foo?a=b%20c"), e.toUri());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,10 +30,11 @@ import static io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON;
|
|||||||
import static io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM;
|
import static io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE;
|
import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderValues.ZERO;
|
import static io.netty.handler.codec.http.HttpHeaderValues.ZERO;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ReadOnlyHttpHeadersTest {
|
public class ReadOnlyHttpHeadersTest {
|
||||||
@Test
|
@Test
|
||||||
@ -113,22 +114,22 @@ public class ReadOnlyHttpHeadersTest {
|
|||||||
assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(names.get(1)));
|
assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(names.get(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void validateNamesFail() {
|
public void validateNamesFail() {
|
||||||
new ReadOnlyHttpHeaders(true,
|
assertThrows(IllegalArgumentException.class, () -> new ReadOnlyHttpHeaders(true,
|
||||||
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "));
|
ACCEPT, APPLICATION_JSON, AsciiString.cached(" ")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void emptyHeaderName() {
|
public void emptyHeaderName() {
|
||||||
new ReadOnlyHttpHeaders(true,
|
assertThrows(IllegalArgumentException.class, () -> new ReadOnlyHttpHeaders(true,
|
||||||
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "), ZERO);
|
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "), ZERO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void headerWithoutValue() {
|
public void headerWithoutValue() {
|
||||||
new ReadOnlyHttpHeaders(false,
|
assertThrows(IllegalArgumentException.class, () -> new ReadOnlyHttpHeaders(false,
|
||||||
ACCEPT, APPLICATION_JSON, CONTENT_LENGTH);
|
ACCEPT, APPLICATION_JSON, CONTENT_LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assert3ParisEquals(Iterator<Entry<String, String>> itr) {
|
private static void assert3ParisEquals(Iterator<Entry<String, String>> itr) {
|
||||||
|
@ -17,7 +17,7 @@ package io.netty.handler.codec.http.cookie;
|
|||||||
|
|
||||||
import io.netty.handler.codec.DateFormatter;
|
import io.netty.handler.codec.DateFormatter;
|
||||||
import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite;
|
import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -29,7 +29,12 @@ import java.util.TimeZone;
|
|||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientCookieDecoderTest {
|
public class ClientCookieDecoderTest {
|
||||||
@Test
|
@Test
|
||||||
@ -42,10 +47,10 @@ public class ClientCookieDecoderTest {
|
|||||||
assertNotNull(cookie);
|
assertNotNull(cookie);
|
||||||
assertEquals("myValue", cookie.value());
|
assertEquals("myValue", cookie.value());
|
||||||
assertEquals(".adomainsomewhere", cookie.domain());
|
assertEquals(".adomainsomewhere", cookie.domain());
|
||||||
assertNotEquals("maxAge should be defined when parsing cookie " + cookieString,
|
assertNotEquals(Long.MIN_VALUE, cookie.maxAge(),
|
||||||
Long.MIN_VALUE, cookie.maxAge());
|
"maxAge should be defined when parsing cookie " + cookieString);
|
||||||
assertTrue("maxAge should be about 50ms when parsing cookie " + cookieString,
|
assertTrue(cookie.maxAge() >= 40 && cookie.maxAge() <= 60,
|
||||||
cookie.maxAge() >= 40 && cookie.maxAge() <= 60);
|
"maxAge should be about 50ms when parsing cookie " + cookieString);
|
||||||
assertEquals("/apathsomewhere", cookie.path());
|
assertEquals("/apathsomewhere", cookie.path());
|
||||||
assertTrue(cookie.isSecure());
|
assertTrue(cookie.isSecure());
|
||||||
|
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.cookie;
|
package io.netty.handler.codec.http.cookie;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ClientCookieEncoderTest {
|
public class ClientCookieEncoderTest {
|
||||||
|
|
||||||
@ -47,9 +48,10 @@ public class ClientCookieEncoderTest {
|
|||||||
ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "\"foo\""));
|
ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "\"foo\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testRejectCookieValueWithSemicolon() {
|
public void testRejectCookieValueWithSemicolon() {
|
||||||
ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "foo;bar"));
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "foo;bar")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -16,12 +16,15 @@
|
|||||||
package io.netty.handler.codec.http.cookie;
|
package io.netty.handler.codec.http.cookie;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerCookieDecoderTest {
|
public class ServerCookieDecoderTest {
|
||||||
@Test
|
@Test
|
||||||
|
@ -17,10 +17,10 @@ package io.netty.handler.codec.http.cookie;
|
|||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
import static org.hamcrest.CoreMatchers.containsString;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.netty.handler.codec.DateFormatter;
|
import io.netty.handler.codec.DateFormatter;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite;
|
import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ServerCookieEncoderTest {
|
public class ServerCookieEncoderTest {
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import io.netty.handler.codec.http.EmptyHttpHeaders;
|
|||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpMethod;
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
|
||||||
import static io.netty.handler.codec.http.cors.CorsConfigBuilder.forAnyOrigin;
|
import static io.netty.handler.codec.http.cors.CorsConfigBuilder.forAnyOrigin;
|
||||||
@ -30,6 +30,7 @@ import static org.hamcrest.CoreMatchers.hasItems;
|
|||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
public class CorsConfigTest {
|
public class CorsConfigTest {
|
||||||
|
|
||||||
@ -125,9 +126,10 @@ public class CorsConfigTest {
|
|||||||
assertThat(cors.preflightResponseHeaders(), equalTo((HttpHeaders) EmptyHttpHeaders.INSTANCE));
|
assertThat(cors.preflightResponseHeaders(), equalTo((HttpHeaders) EmptyHttpHeaders.INSTANCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test (expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void shouldThrowIfValueIsNull() {
|
public void shouldThrowIfValueIsNull() {
|
||||||
forOrigin("*").preflightResponseHeader("HeaderName", new Object[]{null}).build();
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> forOrigin("*").preflightResponseHeader("HeaderName", new Object[]{null}).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -27,7 +27,7 @@ import io.netty.handler.codec.http.HttpUtil;
|
|||||||
import io.netty.util.AsciiString;
|
import io.netty.util.AsciiString;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.hamcrest.core.IsEqual;
|
import org.hamcrest.core.IsEqual;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -18,7 +18,7 @@ package io.netty.handler.codec.http.multipart;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -28,8 +28,8 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static io.netty.util.CharsetUtil.UTF_8;
|
import static io.netty.util.CharsetUtil.UTF_8;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link AbstractDiskHttpData} test cases
|
* {@link AbstractDiskHttpData} test cases
|
||||||
@ -58,8 +58,8 @@ public class AbstractDiskHttpDataTest {
|
|||||||
ByteBuf buf2 = test.getChunk(1024);
|
ByteBuf buf2 = test.getChunk(1024);
|
||||||
assertEquals(buf2.readerIndex(), 0);
|
assertEquals(buf2.readerIndex(), 0);
|
||||||
assertEquals(buf2.writerIndex(), 1024);
|
assertEquals(buf2.writerIndex(), 1024);
|
||||||
assertFalse("Arrays should not be equal",
|
assertFalse(Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)),
|
||||||
Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)));
|
"Arrays should not be equal");
|
||||||
} finally {
|
} finally {
|
||||||
test.delete();
|
test.delete();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufUtil;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -35,7 +35,10 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static io.netty.util.CharsetUtil.*;
|
import static io.netty.util.CharsetUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/** {@link AbstractMemoryHttpData} test cases. */
|
/** {@link AbstractMemoryHttpData} test cases. */
|
||||||
public class AbstractMemoryHttpDataTest {
|
public class AbstractMemoryHttpDataTest {
|
||||||
|
@ -18,21 +18,21 @@ package io.netty.handler.codec.http.multipart;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaderValues.IDENTITY;
|
import static io.netty.handler.codec.http.HttpHeaderValues.IDENTITY;
|
||||||
import static io.netty.handler.codec.http.HttpMethod.POST;
|
import static io.netty.handler.codec.http.HttpMethod.POST;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE;
|
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE;
|
||||||
import static io.netty.util.CharsetUtil.UTF_8;
|
import static io.netty.util.CharsetUtil.UTF_8;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class DefaultHttpDataFactoryTest {
|
public class DefaultHttpDataFactoryTest {
|
||||||
// req1 equals req2
|
// req1 equals req2
|
||||||
@ -41,19 +41,19 @@ public class DefaultHttpDataFactoryTest {
|
|||||||
|
|
||||||
private DefaultHttpDataFactory factory;
|
private DefaultHttpDataFactory factory;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void assertReq1EqualsReq2() {
|
public static void assertReq1EqualsReq2() {
|
||||||
// Before doing anything, assert that the requests are equal
|
// Before doing anything, assert that the requests are equal
|
||||||
assertEquals(req1.hashCode(), req2.hashCode());
|
assertEquals(req1.hashCode(), req2.hashCode());
|
||||||
assertTrue(req1.equals(req2));
|
assertTrue(req1.equals(req2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setupFactory() {
|
public void setupFactory() {
|
||||||
factory = new DefaultHttpDataFactory();
|
factory = new DefaultHttpDataFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void cleanupFactory() {
|
public void cleanupFactory() {
|
||||||
factory.cleanAllHttpData();
|
factory.cleanAllHttpData();
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ package io.netty.handler.codec.http.multipart;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@ -27,7 +27,9 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpMethod.POST;
|
import static io.netty.handler.codec.http.HttpMethod.POST;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test DeleteFileOnExitHook
|
* Test DeleteFileOnExitHook
|
||||||
@ -37,7 +39,7 @@ public class DeleteFileOnExitHookTest {
|
|||||||
private static final String HOOK_TEST_TMP = "target/DeleteFileOnExitHookTest/tmp";
|
private static final String HOOK_TEST_TMP = "target/DeleteFileOnExitHookTest/tmp";
|
||||||
private FileUpload fu;
|
private FileUpload fu;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
DefaultHttpDataFactory defaultHttpDataFactory = new DefaultHttpDataFactory(true);
|
DefaultHttpDataFactory defaultHttpDataFactory = new DefaultHttpDataFactory(true);
|
||||||
defaultHttpDataFactory.setBaseDir(HOOK_TEST_TMP);
|
defaultHttpDataFactory.setBaseDir(HOOK_TEST_TMP);
|
||||||
|
@ -22,7 +22,7 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -32,13 +32,13 @@ import java.io.InputStream;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class DiskFileUploadTest {
|
public class DiskFileUploadTest {
|
||||||
@Test
|
@Test
|
||||||
|
@ -28,17 +28,17 @@ import io.netty.handler.codec.http.HttpMethod;
|
|||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HttpPostMultiPartRequestDecoderTest {
|
public class HttpPostMultiPartRequestDecoderTest {
|
||||||
|
|
||||||
@ -173,22 +173,22 @@ public class HttpPostMultiPartRequestDecoderTest {
|
|||||||
assertEquals(inMemory, data.isInMemory());
|
assertEquals(inMemory, data.isInMemory());
|
||||||
if (data.isInMemory()) {
|
if (data.isInMemory()) {
|
||||||
// To be done only if not inMemory: assertEquals(data.get().length, fileSize);
|
// To be done only if not inMemory: assertEquals(data.get().length, fileSize);
|
||||||
assertFalse("Capacity should be higher than 1M", data.getByteBuf().capacity()
|
assertFalse(data.getByteBuf().capacity() < 1024 * 1024,
|
||||||
< 1024 * 1024);
|
"Capacity should be higher than 1M");
|
||||||
}
|
}
|
||||||
assertTrue("Capacity should be less than 1M", decoder.getCurrentAllocatedCapacity()
|
assertTrue(decoder.getCurrentAllocatedCapacity() < 1024 * 1024,
|
||||||
< 1024 * 1024);
|
"Capacity should be less than 1M");
|
||||||
InterfaceHttpData[] httpDatas = decoder.getBodyHttpDatas().toArray(new InterfaceHttpData[0]);
|
InterfaceHttpData[] httpDatas = decoder.getBodyHttpDatas().toArray(new InterfaceHttpData[0]);
|
||||||
for (InterfaceHttpData httpData : httpDatas) {
|
for (InterfaceHttpData httpData : httpDatas) {
|
||||||
assertEquals("Before cleanAllHttpData should be 1", 1, httpData.refCnt());
|
assertEquals(1, httpData.refCnt(), "Before cleanAllHttpData should be 1");
|
||||||
}
|
}
|
||||||
factory.cleanAllHttpData();
|
factory.cleanAllHttpData();
|
||||||
for (InterfaceHttpData httpData : httpDatas) {
|
for (InterfaceHttpData httpData : httpDatas) {
|
||||||
assertEquals("Before cleanAllHttpData should be 1 if in Memory", inMemory? 1 : 0, httpData.refCnt());
|
assertEquals(inMemory? 1 : 0, httpData.refCnt(), "Before cleanAllHttpData should be 1 if in Memory");
|
||||||
}
|
}
|
||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
for (InterfaceHttpData httpData : httpDatas) {
|
for (InterfaceHttpData httpData : httpDatas) {
|
||||||
assertEquals("RefCnt should be 0", 0, httpData.refCnt());
|
assertEquals(0, httpData.refCnt(), "RefCnt should be 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,13 +32,18 @@ import io.netty.handler.codec.http.HttpRequest;
|
|||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.netty.handler.codec.http.LastHttpContent;
|
import io.netty.handler.codec.http.LastHttpContent;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link HttpPostRequestDecoder} test case.
|
* {@link HttpPostRequestDecoder} test case.
|
||||||
@ -97,8 +102,8 @@ public class HttpPostRequestDecoderTest {
|
|||||||
MemoryFileUpload upload = (MemoryFileUpload) decoder.next();
|
MemoryFileUpload upload = (MemoryFileUpload) decoder.next();
|
||||||
|
|
||||||
// Validate data has been parsed correctly as it was passed into request.
|
// Validate data has been parsed correctly as it was passed into request.
|
||||||
assertEquals("Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']',
|
assertEquals(data, upload.getString(CharsetUtil.UTF_8),
|
||||||
data, upload.getString(CharsetUtil.UTF_8));
|
"Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']');
|
||||||
upload.release();
|
upload.release();
|
||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
buf.release();
|
buf.release();
|
||||||
@ -266,7 +271,7 @@ public class HttpPostRequestDecoderTest {
|
|||||||
|
|
||||||
aDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);
|
aDecoder.offer(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
|
|
||||||
assertTrue("Should have a piece of data", aDecoder.hasNext());
|
assertTrue(aDecoder.hasNext(), "Should have a piece of data");
|
||||||
|
|
||||||
InterfaceHttpData aDecodedData = aDecoder.next();
|
InterfaceHttpData aDecodedData = aDecoder.next();
|
||||||
assertEquals(InterfaceHttpData.HttpDataType.Attribute, aDecodedData.getHttpDataType());
|
assertEquals(InterfaceHttpData.HttpDataType.Attribute, aDecodedData.getHttpDataType());
|
||||||
@ -465,10 +470,10 @@ public class HttpPostRequestDecoderTest {
|
|||||||
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||||
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
||||||
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
||||||
assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
|
assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload");
|
||||||
FileUpload fileUpload = (FileUpload) part1;
|
FileUpload fileUpload = (FileUpload) part1;
|
||||||
byte[] fileBytes = fileUpload.get();
|
byte[] fileBytes = fileUpload.get();
|
||||||
assertTrue("the filecontent should not be decoded", filecontent.equals(new String(fileBytes)));
|
assertTrue(filecontent.equals(new String(fileBytes)), "the filecontent should not be decoded");
|
||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
assertTrue(req.release());
|
assertTrue(req.release());
|
||||||
}
|
}
|
||||||
@ -580,9 +585,9 @@ public class HttpPostRequestDecoderTest {
|
|||||||
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||||
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
||||||
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
||||||
assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
|
assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload");
|
||||||
FileUpload fileUpload = (FileUpload) part1;
|
FileUpload fileUpload = (FileUpload) part1;
|
||||||
assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
|
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
|
||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
assertTrue(req.release());
|
assertTrue(req.release());
|
||||||
}
|
}
|
||||||
@ -616,9 +621,9 @@ public class HttpPostRequestDecoderTest {
|
|||||||
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||||
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
||||||
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
||||||
assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
|
assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload");
|
||||||
FileUpload fileUpload = (FileUpload) part1;
|
FileUpload fileUpload = (FileUpload) part1;
|
||||||
assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
|
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
|
||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
assertTrue(req.release());
|
assertTrue(req.release());
|
||||||
}
|
}
|
||||||
@ -758,25 +763,28 @@ public class HttpPostRequestDecoderTest {
|
|||||||
assertTrue(req.release());
|
assertTrue(req.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
|
@Test
|
||||||
public void testNotLeak() {
|
public void testNotLeak() {
|
||||||
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/",
|
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/",
|
||||||
Unpooled.copiedBuffer("a=1&&b=2", CharsetUtil.US_ASCII));
|
Unpooled.copiedBuffer("a=1&&b=2", CharsetUtil.US_ASCII));
|
||||||
try {
|
try {
|
||||||
new HttpPostStandardRequestDecoder(request).destroy();
|
assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class,
|
||||||
|
() -> new HttpPostStandardRequestDecoder(request).destroy());
|
||||||
} finally {
|
} finally {
|
||||||
assertTrue(request.release());
|
assertTrue(request.release());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
|
@Test
|
||||||
public void testNotLeakDirectBufferWhenWrapIllegalArgumentException() {
|
public void testNotLeakDirectBufferWhenWrapIllegalArgumentException() {
|
||||||
testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer());
|
assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class,
|
||||||
|
() -> testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
|
@Test
|
||||||
public void testNotLeakHeapBufferWhenWrapIllegalArgumentException() {
|
public void testNotLeakHeapBufferWhenWrapIllegalArgumentException() {
|
||||||
testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer());
|
assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class,
|
||||||
|
() -> testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testNotLeakWhenWrapIllegalArgumentException(ByteBuf buf) {
|
private static void testNotLeakWhenWrapIllegalArgumentException(ByteBuf buf) {
|
||||||
@ -830,9 +838,9 @@ public class HttpPostRequestDecoderTest {
|
|||||||
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||||
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
||||||
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
||||||
assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
|
assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload");
|
||||||
FileUpload fileUpload = (FileUpload) part1;
|
FileUpload fileUpload = (FileUpload) part1;
|
||||||
assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
|
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
|
||||||
|
|
||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
assertTrue(req.release());
|
assertTrue(req.release());
|
||||||
|
@ -30,7 +30,7 @@ import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.EncoderMode;
|
|||||||
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
|
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -41,10 +41,10 @@ import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_DISPOSITION;
|
|||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TRANSFER_ENCODING;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TRANSFER_ENCODING;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
/** {@link HttpPostRequestEncoder} test case. */
|
/** {@link HttpPostRequestEncoder} test case. */
|
||||||
public class HttpPostRequestEncoderTest {
|
public class HttpPostRequestEncoderTest {
|
||||||
@ -345,9 +345,9 @@ public class HttpPostRequestEncoderTest {
|
|||||||
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
|
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
|
||||||
ByteBuf content = httpContent.content();
|
ByteBuf content = httpContent.content();
|
||||||
int refCnt = content.refCnt();
|
int refCnt = content.refCnt();
|
||||||
assertTrue("content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt,
|
assertTrue((content.unwrap() == content || content.unwrap() == null) && refCnt == 1 ||
|
||||||
(content.unwrap() == content || content.unwrap() == null) && refCnt == 1 ||
|
content.unwrap() != content && refCnt == 2,
|
||||||
content.unwrap() != content && refCnt == 2);
|
"content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt);
|
||||||
httpContent.release();
|
httpContent.release();
|
||||||
}
|
}
|
||||||
encoder.cleanFiles();
|
encoder.cleanFiles();
|
||||||
@ -401,10 +401,10 @@ public class HttpPostRequestEncoderTest {
|
|||||||
checkNextChunkSize(encoder, 8080);
|
checkNextChunkSize(encoder, 8080);
|
||||||
|
|
||||||
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
|
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
|
||||||
assertTrue("Expected LastHttpContent is not received", httpContent instanceof LastHttpContent);
|
assertTrue(httpContent instanceof LastHttpContent, "Expected LastHttpContent is not received");
|
||||||
httpContent.release();
|
httpContent.release();
|
||||||
|
|
||||||
assertTrue("Expected end of input is not receive", encoder.isEndOfInput());
|
assertTrue(encoder.isEndOfInput(), "Expected end of input is not receive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -423,10 +423,10 @@ public class HttpPostRequestEncoderTest {
|
|||||||
checkNextChunkSize(encoder, 8080);
|
checkNextChunkSize(encoder, 8080);
|
||||||
|
|
||||||
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
|
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
|
||||||
assertTrue("Expected LastHttpContent is not received", httpContent instanceof LastHttpContent);
|
assertTrue(httpContent instanceof LastHttpContent, "Expected LastHttpContent is not received");
|
||||||
httpContent.release();
|
httpContent.release();
|
||||||
|
|
||||||
assertTrue("Expected end of input is not receive", encoder.isEndOfInput());
|
assertTrue(encoder.isEndOfInput(), "Expected end of input is not receive");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkNextChunkSize(HttpPostRequestEncoder encoder, int sizeWithoutDelimiter) throws Exception {
|
private static void checkNextChunkSize(HttpPostRequestEncoder encoder, int sizeWithoutDelimiter) throws Exception {
|
||||||
@ -441,8 +441,8 @@ public class HttpPostRequestEncoderTest {
|
|||||||
|
|
||||||
int readable = httpContent.content().readableBytes();
|
int readable = httpContent.content().readableBytes();
|
||||||
boolean expectedSize = readable >= expectedSizeMin && readable <= expectedSizeMax;
|
boolean expectedSize = readable >= expectedSizeMin && readable <= expectedSizeMax;
|
||||||
assertTrue("Chunk size is not in expected range (" + expectedSizeMin + " - " + expectedSizeMax + "), was: "
|
assertTrue(expectedSize, "Chunk size is not in expected range (" + expectedSizeMin + " - "
|
||||||
+ readable, expectedSize);
|
+ expectedSizeMax + "), was: " + readable);
|
||||||
httpContent.release();
|
httpContent.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.multipart;
|
package io.netty.handler.codec.http.multipart;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class MemoryFileUploadTest {
|
public class MemoryFileUploadTest {
|
||||||
|
|
||||||
@ -24,6 +25,6 @@ public class MemoryFileUploadTest {
|
|||||||
public final void testMemoryFileUploadEquals() {
|
public final void testMemoryFileUploadEquals() {
|
||||||
MemoryFileUpload f1 =
|
MemoryFileUpload f1 =
|
||||||
new MemoryFileUpload("m1", "m1", "application/json", null, null, 100);
|
new MemoryFileUpload("m1", "m1", "application/json", null, null, 100);
|
||||||
Assert.assertEquals(f1, f1);
|
assertEquals(f1, f1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,11 @@ package io.netty.handler.codec.http.websocketx;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocket00FrameEncoderTest {
|
public class WebSocket00FrameEncoderTest {
|
||||||
|
|
||||||
@ -26,19 +29,19 @@ public class WebSocket00FrameEncoderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testMultipleWebSocketCloseFrames() {
|
public void testMultipleWebSocketCloseFrames() {
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new WebSocket00FrameEncoder());
|
EmbeddedChannel channel = new EmbeddedChannel(new WebSocket00FrameEncoder());
|
||||||
Assert.assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
|
assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
|
||||||
Assert.assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
|
assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
|
||||||
Assert.assertTrue(channel.finish());
|
assertTrue(channel.finish());
|
||||||
assertCloseWebSocketFrame(channel);
|
assertCloseWebSocketFrame(channel);
|
||||||
assertCloseWebSocketFrame(channel);
|
assertCloseWebSocketFrame(channel);
|
||||||
Assert.assertNull(channel.readOutbound());
|
assertNull(channel.readOutbound());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertCloseWebSocketFrame(EmbeddedChannel channel) {
|
private static void assertCloseWebSocketFrame(EmbeddedChannel channel) {
|
||||||
ByteBuf buf = channel.readOutbound();
|
ByteBuf buf = channel.readOutbound();
|
||||||
Assert.assertEquals(2, buf.readableBytes());
|
assertEquals(2, buf.readableBytes());
|
||||||
Assert.assertEquals((byte) 0xFF, buf.readByte());
|
assertEquals((byte) 0xFF, buf.readByte());
|
||||||
Assert.assertEquals((byte) 0x00, buf.readByte());
|
assertEquals((byte) 0x00, buf.readByte());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,13 @@ package io.netty.handler.codec.http.websocketx;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the WebSocket08FrameEncoder and Decoder implementation.<br>
|
* Tests the WebSocket08FrameEncoder and Decoder implementation.<br>
|
||||||
@ -73,13 +78,13 @@ public class WebSocket08EncoderDecoderTest {
|
|||||||
executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage);
|
executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage);
|
||||||
|
|
||||||
CloseWebSocketFrame response = inChannel.readOutbound();
|
CloseWebSocketFrame response = inChannel.readOutbound();
|
||||||
Assert.assertNotNull(response);
|
assertNotNull(response);
|
||||||
Assert.assertEquals(expectedStatus.code(), response.statusCode());
|
assertEquals(expectedStatus.code(), response.statusCode());
|
||||||
Assert.assertEquals(errorMessage, response.reasonText());
|
assertEquals(errorMessage, response.reasonText());
|
||||||
response.release();
|
response.release();
|
||||||
|
|
||||||
Assert.assertFalse(inChannel.finish());
|
assertFalse(inChannel.finish());
|
||||||
Assert.assertFalse(outChannel.finish());
|
assertFalse(outChannel.finish());
|
||||||
|
|
||||||
// Without auto-close
|
// Without auto-close
|
||||||
config = WebSocketDecoderConfig.newBuilder()
|
config = WebSocketDecoderConfig.newBuilder()
|
||||||
@ -92,10 +97,10 @@ public class WebSocket08EncoderDecoderTest {
|
|||||||
executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage);
|
executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage);
|
||||||
|
|
||||||
response = inChannel.readOutbound();
|
response = inChannel.readOutbound();
|
||||||
Assert.assertNull(response);
|
assertNull(response);
|
||||||
|
|
||||||
Assert.assertFalse(inChannel.finish());
|
assertFalse(inChannel.finish());
|
||||||
Assert.assertFalse(outChannel.finish());
|
assertFalse(outChannel.finish());
|
||||||
|
|
||||||
// Release test data
|
// Release test data
|
||||||
binTestData.release();
|
binTestData.release();
|
||||||
@ -112,11 +117,11 @@ public class WebSocket08EncoderDecoderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BinaryWebSocketFrame exceedingFrame = inChannel.readInbound();
|
BinaryWebSocketFrame exceedingFrame = inChannel.readInbound();
|
||||||
Assert.assertNull(exceedingFrame);
|
assertNull(exceedingFrame);
|
||||||
|
|
||||||
Assert.assertNotNull(corrupted);
|
assertNotNull(corrupted);
|
||||||
Assert.assertEquals(expectedStatus, corrupted.closeStatus());
|
assertEquals(expectedStatus, corrupted.closeStatus());
|
||||||
Assert.assertEquals(errorMessage, corrupted.getMessage());
|
assertEquals(errorMessage, corrupted.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -177,10 +182,10 @@ public class WebSocket08EncoderDecoderTest {
|
|||||||
transfer(outChannel, inChannel);
|
transfer(outChannel, inChannel);
|
||||||
|
|
||||||
Object decoded = inChannel.readInbound();
|
Object decoded = inChannel.readInbound();
|
||||||
Assert.assertNotNull(decoded);
|
assertNotNull(decoded);
|
||||||
Assert.assertTrue(decoded instanceof TextWebSocketFrame);
|
assertTrue(decoded instanceof TextWebSocketFrame);
|
||||||
TextWebSocketFrame txt = (TextWebSocketFrame) decoded;
|
TextWebSocketFrame txt = (TextWebSocketFrame) decoded;
|
||||||
Assert.assertEquals(txt.text(), testStr);
|
assertEquals(txt.text(), testStr);
|
||||||
txt.release();
|
txt.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,13 +197,13 @@ public class WebSocket08EncoderDecoderTest {
|
|||||||
transfer(outChannel, inChannel);
|
transfer(outChannel, inChannel);
|
||||||
|
|
||||||
Object decoded = inChannel.readInbound();
|
Object decoded = inChannel.readInbound();
|
||||||
Assert.assertNotNull(decoded);
|
assertNotNull(decoded);
|
||||||
Assert.assertTrue(decoded instanceof BinaryWebSocketFrame);
|
assertTrue(decoded instanceof BinaryWebSocketFrame);
|
||||||
BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) decoded;
|
BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) decoded;
|
||||||
int readable = binFrame.content().readableBytes();
|
int readable = binFrame.content().readableBytes();
|
||||||
Assert.assertEquals(readable, testDataLength);
|
assertEquals(readable, testDataLength);
|
||||||
for (int i = 0; i < testDataLength; i++) {
|
for (int i = 0; i < testDataLength; i++) {
|
||||||
Assert.assertEquals(binTestData.getByte(i), binFrame.content().getByte(i));
|
assertEquals(binTestData.getByte(i), binFrame.content().getByte(i));
|
||||||
}
|
}
|
||||||
binFrame.release();
|
binFrame.release();
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,14 @@ package io.netty.handler.codec.http.websocketx;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ import io.netty.handler.codec.http.DefaultHttpHeaders;
|
|||||||
import io.netty.handler.codec.http.FullHttpRequest;
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class WebSocketClientHandshaker07Test extends WebSocketClientHandshakerTest {
|
public class WebSocketClientHandshaker07Test extends WebSocketClientHandshakerTest {
|
||||||
|
|
||||||
|
@ -35,12 +35,15 @@ import io.netty.handler.codec.http.HttpResponseDecoder;
|
|||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public abstract class WebSocketClientHandshakerTest {
|
public abstract class WebSocketClientHandshakerTest {
|
||||||
protected abstract WebSocketClientHandshaker newHandshaker(URI uri, String subprotocol, HttpHeaders headers,
|
protected abstract WebSocketClientHandshaker newHandshaker(URI uri, String subprotocol, HttpHeaders headers,
|
||||||
@ -256,12 +259,14 @@ public abstract class WebSocketClientHandshakerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 3000)
|
@Test
|
||||||
|
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testHttpResponseAndFrameInSameBuffer() {
|
public void testHttpResponseAndFrameInSameBuffer() {
|
||||||
testHttpResponseAndFrameInSameBuffer(false);
|
testHttpResponseAndFrameInSameBuffer(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 3000)
|
@Test
|
||||||
|
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testHttpResponseAndFrameInSameBufferCodec() {
|
public void testHttpResponseAndFrameInSameBufferCodec() {
|
||||||
testHttpResponseAndFrameInSameBuffer(true);
|
testHttpResponseAndFrameInSameBuffer(true);
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,13 @@ import java.util.TreeSet;
|
|||||||
|
|
||||||
import org.assertj.core.api.ThrowableAssert;
|
import org.assertj.core.api.ThrowableAssert;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.WebSocketCloseStatus.*;
|
import static io.netty.handler.codec.http.websocketx.WebSocketCloseStatus.*;
|
||||||
|
|
||||||
|
@ -21,8 +21,13 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
|
||||||
public class WebSocketFrameAggregatorTest {
|
public class WebSocketFrameAggregatorTest {
|
||||||
@ -46,29 +51,29 @@ public class WebSocketFrameAggregatorTest {
|
|||||||
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
||||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
|
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
|
||||||
|
|
||||||
Assert.assertTrue(channel.finish());
|
assertTrue(channel.finish());
|
||||||
|
|
||||||
BinaryWebSocketFrame frame = channel.readInbound();
|
BinaryWebSocketFrame frame = channel.readInbound();
|
||||||
Assert.assertTrue(frame.isFinalFragment());
|
assertTrue(frame.isFinalFragment());
|
||||||
Assert.assertEquals(1, frame.rsv());
|
assertEquals(1, frame.rsv());
|
||||||
Assert.assertArrayEquals(content1, toBytes(frame.content()));
|
assertArrayEquals(content1, toBytes(frame.content()));
|
||||||
|
|
||||||
PingWebSocketFrame frame2 = channel.readInbound();
|
PingWebSocketFrame frame2 = channel.readInbound();
|
||||||
Assert.assertTrue(frame2.isFinalFragment());
|
assertTrue(frame2.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame2.rsv());
|
assertEquals(0, frame2.rsv());
|
||||||
Assert.assertArrayEquals(content1, toBytes(frame2.content()));
|
assertArrayEquals(content1, toBytes(frame2.content()));
|
||||||
|
|
||||||
PongWebSocketFrame frame3 = channel.readInbound();
|
PongWebSocketFrame frame3 = channel.readInbound();
|
||||||
Assert.assertTrue(frame3.isFinalFragment());
|
assertTrue(frame3.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame3.rsv());
|
assertEquals(0, frame3.rsv());
|
||||||
Assert.assertArrayEquals(content1, toBytes(frame3.content()));
|
assertArrayEquals(content1, toBytes(frame3.content()));
|
||||||
|
|
||||||
BinaryWebSocketFrame frame4 = channel.readInbound();
|
BinaryWebSocketFrame frame4 = channel.readInbound();
|
||||||
Assert.assertTrue(frame4.isFinalFragment());
|
assertTrue(frame4.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame4.rsv());
|
assertEquals(0, frame4.rsv());
|
||||||
Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
|
assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
|
||||||
|
|
||||||
Assert.assertNull(channel.readInbound());
|
assertNull(channel.readInbound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -81,29 +86,29 @@ public class WebSocketFrameAggregatorTest {
|
|||||||
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
|
||||||
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
|
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
|
||||||
|
|
||||||
Assert.assertTrue(channel.finish());
|
assertTrue(channel.finish());
|
||||||
|
|
||||||
TextWebSocketFrame frame = channel.readInbound();
|
TextWebSocketFrame frame = channel.readInbound();
|
||||||
Assert.assertTrue(frame.isFinalFragment());
|
assertTrue(frame.isFinalFragment());
|
||||||
Assert.assertEquals(1, frame.rsv());
|
assertEquals(1, frame.rsv());
|
||||||
Assert.assertArrayEquals(content1, toBytes(frame.content()));
|
assertArrayEquals(content1, toBytes(frame.content()));
|
||||||
|
|
||||||
PingWebSocketFrame frame2 = channel.readInbound();
|
PingWebSocketFrame frame2 = channel.readInbound();
|
||||||
Assert.assertTrue(frame2.isFinalFragment());
|
assertTrue(frame2.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame2.rsv());
|
assertEquals(0, frame2.rsv());
|
||||||
Assert.assertArrayEquals(content1, toBytes(frame2.content()));
|
assertArrayEquals(content1, toBytes(frame2.content()));
|
||||||
|
|
||||||
PongWebSocketFrame frame3 = channel.readInbound();
|
PongWebSocketFrame frame3 = channel.readInbound();
|
||||||
Assert.assertTrue(frame3.isFinalFragment());
|
assertTrue(frame3.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame3.rsv());
|
assertEquals(0, frame3.rsv());
|
||||||
Assert.assertArrayEquals(content1, toBytes(frame3.content()));
|
assertArrayEquals(content1, toBytes(frame3.content()));
|
||||||
|
|
||||||
TextWebSocketFrame frame4 = channel.readInbound();
|
TextWebSocketFrame frame4 = channel.readInbound();
|
||||||
Assert.assertTrue(frame4.isFinalFragment());
|
assertTrue(frame4.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame4.rsv());
|
assertEquals(0, frame4.rsv());
|
||||||
Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
|
assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
|
||||||
|
|
||||||
Assert.assertNull(channel.readInbound());
|
assertNull(channel.readInbound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -113,7 +118,7 @@ public class WebSocketFrameAggregatorTest {
|
|||||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
||||||
try {
|
try {
|
||||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (TooLongFrameException e) {
|
} catch (TooLongFrameException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
@ -124,7 +129,7 @@ public class WebSocketFrameAggregatorTest {
|
|||||||
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
|
||||||
try {
|
try {
|
||||||
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (TooLongFrameException e) {
|
} catch (TooLongFrameException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,11 @@ import io.netty.handler.codec.http.HttpRequest;
|
|||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class WebSocketHandshakeExceptionTest {
|
public class WebSocketHandshakeExceptionTest {
|
||||||
|
|
||||||
|
@ -29,13 +29,19 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
|||||||
import io.netty.handler.codec.http.HttpServerCodec;
|
import io.netty.handler.codec.http.HttpServerCodec;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.ClientHandshakeStateEvent;
|
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.ClientHandshakeStateEvent;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler.ServerHandshakeStateEvent;
|
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler.ServerHandshakeStateEvent;
|
||||||
import org.junit.Before;
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocketHandshakeHandOverTest {
|
public class WebSocketHandshakeHandOverTest {
|
||||||
|
|
||||||
@ -66,7 +72,7 @@ public class WebSocketHandshakeHandOverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serverReceivedHandshake = false;
|
serverReceivedHandshake = false;
|
||||||
serverHandshakeComplete = null;
|
serverHandshakeComplete = null;
|
||||||
@ -124,7 +130,7 @@ public class WebSocketHandshakeHandOverTest {
|
|||||||
assertTrue(clientReceivedMessage);
|
assertTrue(clientReceivedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = WebSocketHandshakeException.class)
|
@Test
|
||||||
public void testClientHandshakeTimeout() throws Throwable {
|
public void testClientHandshakeTimeout() throws Throwable {
|
||||||
EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler<Object>() {
|
EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler<Object>() {
|
||||||
@Override
|
@Override
|
||||||
@ -178,9 +184,9 @@ public class WebSocketHandshakeHandOverTest {
|
|||||||
assertFalse(clientReceivedMessage);
|
assertFalse(clientReceivedMessage);
|
||||||
// Should throw WebSocketHandshakeException
|
// Should throw WebSocketHandshakeException
|
||||||
try {
|
try {
|
||||||
handshakeHandler.getHandshakeFuture().syncUninterruptibly();
|
assertTrue(assertThrows(CompletionException.class,
|
||||||
} catch (CompletionException e) {
|
() -> handshakeHandler.getHandshakeFuture().syncUninterruptibly())
|
||||||
throw e.getCause();
|
.getCause() instanceof WebSocketHandshakeException);
|
||||||
} finally {
|
} finally {
|
||||||
serverChannel.finishAndReleaseAll();
|
serverChannel.finishAndReleaseAll();
|
||||||
}
|
}
|
||||||
@ -220,7 +226,8 @@ public class WebSocketHandshakeHandOverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 10000)
|
@Test
|
||||||
|
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
|
||||||
public void testClientHandshakerForceClose() throws Exception {
|
public void testClientHandshakerForceClose() throws Exception {
|
||||||
final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
|
final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
|
||||||
new URI("ws://localhost:1234/test"), WebSocketVersion.V13, null, true,
|
new URI("ws://localhost:1234/test"), WebSocketVersion.V13, null, true,
|
||||||
|
@ -26,13 +26,16 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import io.netty.handler.flow.FlowControlHandler;
|
import io.netty.handler.flow.FlowControlHandler;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static io.netty.util.CharsetUtil.UTF_8;
|
import static io.netty.util.CharsetUtil.UTF_8;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests common, abstract class functionality in {@link WebSocketClientProtocolHandler}.
|
* Tests common, abstract class functionality in {@link WebSocketClientProtocolHandler}.
|
||||||
|
@ -30,12 +30,12 @@ import io.netty.handler.codec.http.HttpResponseDecoder;
|
|||||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||||
import io.netty.handler.codec.http.LastHttpContent;
|
import io.netty.handler.codec.http.LastHttpContent;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTest {
|
public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTest {
|
||||||
|
|
||||||
@ -115,16 +115,16 @@ public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTe
|
|||||||
ch2.writeInbound((ByteBuf) ch.readOutbound());
|
ch2.writeInbound((ByteBuf) ch.readOutbound());
|
||||||
HttpResponse res = ch2.readInbound();
|
HttpResponse res = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals("ws://example.com/chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_LOCATION));
|
assertEquals("ws://example.com/chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_LOCATION));
|
||||||
|
|
||||||
if (subProtocol) {
|
if (subProtocol) {
|
||||||
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
||||||
} else {
|
} else {
|
||||||
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
||||||
}
|
}
|
||||||
LastHttpContent content = ch2.readInbound();
|
LastHttpContent content = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII));
|
assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII));
|
||||||
content.release();
|
content.release();
|
||||||
req.release();
|
req.release();
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,11 @@ import io.netty.handler.codec.http.HttpResponse;
|
|||||||
import io.netty.handler.codec.http.HttpResponseDecoder;
|
import io.netty.handler.codec.http.HttpResponseDecoder;
|
||||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class WebSocketServerHandshaker08Test extends WebSocketServerHandshakerTest {
|
public class WebSocketServerHandshaker08Test extends WebSocketServerHandshakerTest {
|
||||||
|
|
||||||
@ -83,12 +84,12 @@ public class WebSocketServerHandshaker08Test extends WebSocketServerHandshakerTe
|
|||||||
ch2.writeInbound(resBuf);
|
ch2.writeInbound(resBuf);
|
||||||
HttpResponse res = ch2.readInbound();
|
HttpResponse res = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals(
|
assertEquals(
|
||||||
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
|
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
|
||||||
if (subProtocol) {
|
if (subProtocol) {
|
||||||
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
||||||
} else {
|
} else {
|
||||||
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
|
||||||
}
|
}
|
||||||
ReferenceCountUtil.release(res);
|
ReferenceCountUtil.release(res);
|
||||||
req.release();
|
req.release();
|
||||||
|
@ -33,16 +33,16 @@ import io.netty.handler.codec.http.HttpServerCodec;
|
|||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.ReferenceCounted;
|
import io.netty.util.ReferenceCounted;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class WebSocketServerHandshaker13Test extends WebSocketServerHandshakerTest {
|
public class WebSocketServerHandshaker13Test extends WebSocketServerHandshakerTest {
|
||||||
|
|
||||||
|
@ -22,9 +22,12 @@ import io.netty.handler.codec.http.HttpHeaderNames;
|
|||||||
import io.netty.handler.codec.http.HttpUtil;
|
import io.netty.handler.codec.http.HttpUtil;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class WebSocketServerHandshakerFactoryTest {
|
public class WebSocketServerHandshakerFactoryTest {
|
||||||
|
|
||||||
|
@ -24,9 +24,12 @@ import io.netty.handler.codec.http.HttpHeaderValues;
|
|||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import io.netty.handler.codec.http.HttpMethod;
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public abstract class WebSocketServerHandshakerTest {
|
public abstract class WebSocketServerHandshakerTest {
|
||||||
|
|
||||||
|
@ -34,21 +34,25 @@ import io.netty.handler.codec.http.HttpServerCodec;
|
|||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
import static io.netty.handler.codec.http.HttpResponseStatus.*;
|
||||||
import static io.netty.handler.codec.http.HttpVersion.*;
|
import static io.netty.handler.codec.http.HttpVersion.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocketServerProtocolHandlerTest {
|
public class WebSocketServerProtocolHandlerTest {
|
||||||
|
|
||||||
private final Queue<FullHttpResponse> responses = new ArrayDeque<>();
|
private final Queue<FullHttpResponse> responses = new ArrayDeque<>();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
responses.clear();
|
responses.clear();
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,14 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.handler.codec.CorruptedFrameException;
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class WebSocketUtf8FrameValidatorTest {
|
public class WebSocketUtf8FrameValidatorTest {
|
||||||
|
|
||||||
@ -39,19 +45,19 @@ public class WebSocketUtf8FrameValidatorTest {
|
|||||||
TextWebSocketFrame frame = new TextWebSocketFrame(Unpooled.copiedBuffer(data));
|
TextWebSocketFrame frame = new TextWebSocketFrame(Unpooled.copiedBuffer(data));
|
||||||
try {
|
try {
|
||||||
channel.writeInbound(frame);
|
channel.writeInbound(frame);
|
||||||
Assert.fail();
|
fail();
|
||||||
} catch (CorruptedFrameException e) {
|
} catch (CorruptedFrameException e) {
|
||||||
// expected exception
|
// expected exception
|
||||||
}
|
}
|
||||||
Assert.assertTrue(channel.finish());
|
assertTrue(channel.finish());
|
||||||
ByteBuf buf = channel.readOutbound();
|
ByteBuf buf = channel.readOutbound();
|
||||||
Assert.assertNotNull(buf);
|
assertNotNull(buf);
|
||||||
try {
|
try {
|
||||||
Assert.assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
} finally {
|
} finally {
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
Assert.assertNull(channel.readOutbound());
|
assertNull(channel.readOutbound());
|
||||||
Assert.assertEquals(0, frame.refCnt());
|
assertEquals(0, frame.refCnt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.websocketx;
|
package io.netty.handler.codec.http.websocketx;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocketUtilTest {
|
public class WebSocketUtilTest {
|
||||||
|
|
||||||
|
@ -24,10 +24,13 @@ import io.netty.handler.codec.http.HttpResponse;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@ -218,7 +221,7 @@ public class WebSocketClientExtensionHandlerTest {
|
|||||||
verify(fallbackExtensionMock).newExtensionDecoder();
|
verify(fallbackExtensionMock).newExtensionDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = CodecException.class)
|
@Test
|
||||||
public void testIfMainAndFallbackUseRSV1WillFail() {
|
public void testIfMainAndFallbackUseRSV1WillFail() {
|
||||||
// initialize
|
// initialize
|
||||||
when(mainHandshakerMock.newRequestData()).
|
when(mainHandshakerMock.newRequestData()).
|
||||||
@ -248,7 +251,12 @@ public class WebSocketClientExtensionHandlerTest {
|
|||||||
req2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
req2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
HttpResponse res = newUpgradeResponse("main, fallback");
|
HttpResponse res = newUpgradeResponse("main, fallback");
|
||||||
|
try {
|
||||||
ch.writeInbound(res);
|
ch.writeInbound(res);
|
||||||
|
} catch (CodecException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fail("Expected to encounter a CodecException");
|
||||||
|
|
||||||
// test
|
// test
|
||||||
assertEquals(2, reqExts.size());
|
assertEquals(2, reqExts.size());
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.websocketx.extensions;
|
package io.netty.handler.codec.http.websocketx.extensions;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
public class WebSocketExtensionFilterProviderTest {
|
public class WebSocketExtensionFilterProviderTest {
|
||||||
|
|
||||||
|
@ -21,9 +21,10 @@ import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame;
|
|||||||
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocketExtensionFilterTest {
|
public class WebSocketExtensionFilterTest {
|
||||||
|
|
||||||
|
@ -19,12 +19,14 @@ import io.netty.handler.codec.http.DefaultHttpHeaders;
|
|||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||||
import io.netty.handler.codec.http.HttpHeaderValues;
|
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||||
import io.netty.handler.codec.http.HttpHeaders;
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionUtil.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionUtil.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocketExtensionUtilTest {
|
public class WebSocketExtensionUtilTest {
|
||||||
|
|
||||||
|
@ -25,10 +25,14 @@ import java.io.IOException;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class WebSocketServerExtensionHandlerTest {
|
public class WebSocketServerExtensionHandlerTest {
|
||||||
|
@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
DeflateFrameServerExtensionHandshaker.*;
|
DeflateFrameServerExtensionHandshaker.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
||||||
|
|
||||||
@ -25,7 +29,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class DeflateFrameClientExtensionHandshakerTest {
|
public class DeflateFrameClientExtensionHandshakerTest {
|
||||||
|
|
||||||
|
@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
DeflateFrameServerExtensionHandshaker.*;
|
DeflateFrameServerExtensionHandshaker.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
||||||
|
|
||||||
@ -25,7 +29,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class DeflateFrameServerExtensionHandshakerTest {
|
public class DeflateFrameServerExtensionHandshakerTest {
|
||||||
|
|
||||||
|
@ -22,13 +22,17 @@ import io.netty.handler.codec.compression.ZlibCodecFactory;
|
|||||||
import io.netty.handler.codec.compression.ZlibWrapper;
|
import io.netty.handler.codec.compression.ZlibWrapper;
|
||||||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.*;
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class PerFrameDeflateDecoderTest {
|
public class PerFrameDeflateDecoderTest {
|
||||||
|
|
||||||
|
@ -24,12 +24,16 @@ import io.netty.handler.codec.compression.ZlibWrapper;
|
|||||||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class PerFrameDeflateEncoderTest {
|
public class PerFrameDeflateEncoderTest {
|
||||||
|
|
||||||
|
@ -18,7 +18,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
|
|||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.RSV1;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.RSV1;
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
PerMessageDeflateServerExtensionHandshaker.*;
|
PerMessageDeflateServerExtensionHandshaker.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
@ -31,7 +35,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class PerMessageDeflateClientExtensionHandshakerTest {
|
public class PerMessageDeflateClientExtensionHandshakerTest {
|
||||||
|
|
||||||
|
@ -28,14 +28,19 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.*;
|
||||||
import static io.netty.util.CharsetUtil.*;
|
import static io.netty.util.CharsetUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class PerMessageDeflateDecoderTest {
|
public class PerMessageDeflateDecoderTest {
|
||||||
|
|
||||||
@ -260,7 +265,7 @@ public class PerMessageDeflateDecoderTest {
|
|||||||
assertFalse(decoderChannel.finish());
|
assertFalse(decoderChannel.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DecoderException.class)
|
@Test
|
||||||
public void testIllegalStateWhenDecompressionInProgress() {
|
public void testIllegalStateWhenDecompressionInProgress() {
|
||||||
WebSocketExtensionFilter selectivityDecompressionFilter = frame -> frame.content().readableBytes() < 100;
|
WebSocketExtensionFilter selectivityDecompressionFilter = frame -> frame.content().readableBytes() < 100;
|
||||||
|
|
||||||
@ -295,7 +300,7 @@ public class PerMessageDeflateDecoderTest {
|
|||||||
|
|
||||||
//final part throwing exception
|
//final part throwing exception
|
||||||
try {
|
try {
|
||||||
decoderChannel.writeInbound(finalPart);
|
assertThrows(DecoderException.class, () -> decoderChannel.writeInbound(finalPart));
|
||||||
} finally {
|
} finally {
|
||||||
assertTrue(finalPart.release());
|
assertTrue(finalPart.release());
|
||||||
assertFalse(encoderChannel.finishAndReleaseAll());
|
assertFalse(encoderChannel.finishAndReleaseAll());
|
||||||
|
@ -28,7 +28,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -36,7 +36,12 @@ import java.util.Random;
|
|||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter.*;
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder.*;
|
||||||
import static io.netty.util.CharsetUtil.*;
|
import static io.netty.util.CharsetUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class PerMessageDeflateEncoderTest {
|
public class PerMessageDeflateEncoderTest {
|
||||||
|
|
||||||
@ -232,7 +237,7 @@ public class PerMessageDeflateEncoderTest {
|
|||||||
assertFalse(decoderChannel.finish());
|
assertFalse(decoderChannel.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EncoderException.class)
|
@Test
|
||||||
public void testIllegalStateWhenCompressionInProgress() {
|
public void testIllegalStateWhenCompressionInProgress() {
|
||||||
WebSocketExtensionFilter selectivityCompressionFilter = frame -> frame.content().readableBytes() < 100;
|
WebSocketExtensionFilter selectivityCompressionFilter = frame -> frame.content().readableBytes() < 100;
|
||||||
EmbeddedChannel encoderChannel = new EmbeddedChannel(
|
EmbeddedChannel encoderChannel = new EmbeddedChannel(
|
||||||
@ -257,7 +262,7 @@ public class PerMessageDeflateEncoderTest {
|
|||||||
|
|
||||||
//final part throwing exception
|
//final part throwing exception
|
||||||
try {
|
try {
|
||||||
encoderChannel.writeOutbound(finalPart);
|
assertThrows(EncoderException.class, () -> encoderChannel.writeOutbound(finalPart));
|
||||||
} finally {
|
} finally {
|
||||||
assertTrue(finalPart.release());
|
assertTrue(finalPart.release());
|
||||||
assertFalse(encoderChannel.finishAndReleaseAll());
|
assertFalse(encoderChannel.finishAndReleaseAll());
|
||||||
@ -281,14 +286,14 @@ public class PerMessageDeflateEncoderTest {
|
|||||||
assertFalse(encoderChannel.finish());
|
assertFalse(encoderChannel.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EncoderException.class)
|
@Test
|
||||||
public void testCodecExceptionForNotFinEmptyFrame() {
|
public void testCodecExceptionForNotFinEmptyFrame() {
|
||||||
EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false));
|
EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false));
|
||||||
|
|
||||||
TextWebSocketFrame emptyNotFinFrame = new TextWebSocketFrame(false, 0, "");
|
TextWebSocketFrame emptyNotFinFrame = new TextWebSocketFrame(false, 0, "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
encoderChannel.writeOutbound(emptyNotFinFrame);
|
assertThrows(EncoderException.class, () -> encoderChannel.writeOutbound(emptyNotFinFrame));
|
||||||
} finally {
|
} finally {
|
||||||
// EmptyByteBuf buffer
|
// EmptyByteBuf buffer
|
||||||
assertFalse(emptyNotFinFrame.release());
|
assertFalse(emptyNotFinFrame.release());
|
||||||
|
@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
PerMessageDeflateServerExtensionHandshaker.*;
|
PerMessageDeflateServerExtensionHandshaker.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
||||||
|
|
||||||
@ -25,7 +29,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class PerMessageDeflateServerExtensionHandshakerTest {
|
public class PerMessageDeflateServerExtensionHandshakerTest {
|
||||||
|
|
||||||
|
@ -25,12 +25,16 @@ import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensio
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
PerMessageDeflateServerExtensionHandshaker.*;
|
PerMessageDeflateServerExtensionHandshaker.*;
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class WebSocketServerCompressionHandlerTest {
|
public class WebSocketServerCompressionHandlerTest {
|
||||||
|
|
||||||
@ -48,10 +52,10 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
||||||
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
||||||
Assert.assertTrue(exts.get(0).parameters().isEmpty());
|
assertTrue(exts.get(0).parameters().isEmpty());
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -69,10 +73,10 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
||||||
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
||||||
Assert.assertEquals("10", exts.get(0).parameters().get(CLIENT_MAX_WINDOW));
|
assertEquals("10", exts.get(0).parameters().get(CLIENT_MAX_WINDOW));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -90,10 +94,10 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
||||||
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
||||||
Assert.assertTrue(exts.get(0).parameters().isEmpty());
|
assertTrue(exts.get(0).parameters().isEmpty());
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -111,10 +115,10 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
||||||
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
||||||
Assert.assertEquals("10", exts.get(0).parameters().get(SERVER_MAX_WINDOW));
|
assertEquals("10", exts.get(0).parameters().get(SERVER_MAX_WINDOW));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -130,9 +134,9 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
|
|
||||||
HttpResponse res2 = ch.readOutbound();
|
HttpResponse res2 = ch.readOutbound();
|
||||||
|
|
||||||
Assert.assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
Assert.assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -147,9 +151,9 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
|
|
||||||
HttpResponse res2 = ch.readOutbound();
|
HttpResponse res2 = ch.readOutbound();
|
||||||
|
|
||||||
Assert.assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
Assert.assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -166,10 +170,10 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
||||||
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
||||||
Assert.assertTrue(exts.get(0).parameters().isEmpty());
|
assertTrue(exts.get(0).parameters().isEmpty());
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -188,10 +192,10 @@ public class WebSocketServerCompressionHandlerTest {
|
|||||||
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
|
||||||
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
|
|
||||||
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
|
||||||
Assert.assertTrue(exts.get(0).parameters().isEmpty());
|
assertTrue(exts.get(0).parameters().isEmpty());
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
|
||||||
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user