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:
Riley Park 2021-05-27 00:06:23 -07:00 committed by Norman Maurer
parent b646a2670a
commit ac3f823cce
74 changed files with 928 additions and 628 deletions

View File

@ -16,7 +16,8 @@
package io.netty.handler.codec.http;
import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Arrays;
import java.util.Collections;
@ -26,9 +27,10 @@ import static io.netty.handler.codec.http.HttpHeaderNames.SET_COOKIE;
import static io.netty.util.AsciiString.contentEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CombinedHttpHeadersTest {
private static final CharSequence HEADER_NAME = "testHeader";
@ -140,11 +142,16 @@ public class CombinedHttpHeadersTest {
assertEquals(HeaderValue.EIGHT.subset(6), headers.getAll(HEADER_NAME));
}
@Test (expected = NullPointerException.class)
@Test
public void addCharSequencesCsvNullValue() {
final CombinedHttpHeaders headers = newCombinedHttpHeaders();
final String value = null;
headers.add(HEADER_NAME, value);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
headers.add(HEADER_NAME, value);
}
});
}
@Test

View File

@ -18,7 +18,8 @@ package io.netty.handler.codec.http;
import io.netty.handler.codec.http.HttpHeadersTestUtils.HeaderValue;
import io.netty.util.AsciiString;
import io.netty.util.internal.StringUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Arrays;
import java.util.Iterator;
@ -30,19 +31,34 @@ import static io.netty.util.AsciiString.contentEquals;
import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.is;
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 {
private static final CharSequence HEADER_NAME = "testHeader";
@Test(expected = IllegalArgumentException.class)
@Test
public void nullHeaderNameNotAllowed() {
new DefaultHttpHeaders().add(null, "foo");
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new DefaultHttpHeaders().add(null, "foo");
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void emptyHeaderNameNotAllowed() {
new DefaultHttpHeaders().add(StringUtil.EMPTY_STRING, "foo");
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new DefaultHttpHeaders().add(StringUtil.EMPTY_STRING, "foo");
}
});
}
@Test
@ -146,16 +162,26 @@ public class DefaultHttpHeadersTest {
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
}
@Test(expected = NullPointerException.class)
@Test
public void testSetNullHeaderValueValidate() {
HttpHeaders headers = new DefaultHttpHeaders(true);
headers.set(of("test"), (CharSequence) null);
final HttpHeaders headers = new DefaultHttpHeaders(true);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
headers.set(of("test"), (CharSequence) null);
}
});
}
@Test(expected = NullPointerException.class)
@Test
public void testSetNullHeaderValueNotValidate() {
HttpHeaders headers = new DefaultHttpHeaders(false);
headers.set(of("test"), (CharSequence) null);
final HttpHeaders headers = new DefaultHttpHeaders(false);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
headers.set(of("test"), (CharSequence) null);
}
});
}
@Test

View File

@ -16,11 +16,11 @@
package io.netty.handler.codec.http;
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 org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class DefaultHttpRequestTest {

View File

@ -15,10 +15,10 @@
*/
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.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class DefaultHttpResponseTest {

View File

@ -26,7 +26,7 @@ import io.netty.handler.stream.ChunkedNioStream;
import io.netty.handler.stream.ChunkedStream;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -34,7 +34,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
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 {
private static final byte[] BYTES = new byte[1024 * 64];
@ -139,7 +142,7 @@ public class HttpChunkedInputTest {
break;
}
if (lastHttpContent != null) {
assertTrue("Chunk must be DefaultHttpContent", lastHttpContent instanceof DefaultHttpContent);
assertTrue(lastHttpContent instanceof DefaultHttpContent, "Chunk must be DefaultHttpContent");
}
ByteBuf buffer = httpContent.content();
@ -157,7 +160,7 @@ public class HttpChunkedInputTest {
}
assertEquals(BYTES.length * inputs.length, read);
assertSame("Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT",
LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent);
assertSame(LastHttpContent.EMPTY_LAST_CONTENT, lastHttpContent,
"Last chunk must be LastHttpContent.EMPTY_LAST_CONTENT");
}
}

View File

@ -36,7 +36,7 @@ import io.netty.handler.codec.PrematureChannelClosureException;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
@ -46,7 +46,11 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
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 {
@ -218,7 +222,7 @@ public class HttpClientCodecTest {
Consumer connectResponseConsumer = new Consumer();
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() {
@Override
void accept(Object object) {
@ -230,8 +234,8 @@ public class HttpClientCodecTest {
}
};
sendRequestAndReadResponse(ch, HttpMethod.GET, RESPONSE, responseConsumer);
assertTrue("No response messages received.", responseConsumer.getReceivedCount() > 0);
assertFalse("Channel finish failed.", ch.finish());
assertTrue(responseConsumer.getReceivedCount() > 0, "No response messages received.");
assertFalse(ch.finish(), "Channel finish failed.");
}
private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response) {
@ -240,10 +244,10 @@ public class HttpClientCodecTest {
private static void sendRequestAndReadResponse(EmbeddedChannel ch, HttpMethod httpMethod, String response,
Consumer responseConsumer) {
assertTrue("Channel outbound write failed.",
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "http://localhost/")));
assertTrue("Channel inbound write failed.",
ch.writeInbound(Unpooled.copiedBuffer(response, CharsetUtil.ISO_8859_1)));
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, httpMethod, "http://localhost/")),
"Channel outbound write failed.");
assertTrue(ch.writeInbound(Unpooled.copiedBuffer(response, CharsetUtil.ISO_8859_1)),
"Channel inbound write failed.");
for (;;) {
Object msg = ch.readOutbound();
@ -292,22 +296,22 @@ public class HttpClientCodecTest {
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/");
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE);
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.",
ch.writeInbound(Unpooled.copiedBuffer(SWITCHING_PROTOCOLS_RESPONSE, CharsetUtil.ISO_8859_1)));
assertTrue(ch.writeInbound(Unpooled.copiedBuffer(SWITCHING_PROTOCOLS_RESPONSE, CharsetUtil.ISO_8859_1)),
"Channel inbound write failed.");
Object switchingProtocolsResponse = ch.readInbound();
assertNotNull("No response received", switchingProtocolsResponse);
assertNotNull(switchingProtocolsResponse, "No response received");
assertThat("Response was not decoded", switchingProtocolsResponse, instanceOf(FullHttpResponse.class));
((FullHttpResponse) switchingProtocolsResponse).release();
assertTrue("Channel inbound write failed",
ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1)));
assertTrue(ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1)),
"Channel inbound write failed");
Object finalResponse = ch.readInbound();
assertNotNull("No response received", finalResponse);
assertNotNull(finalResponse, "No response received");
assertThat("Response was not decoded", finalResponse, instanceOf(FullHttpResponse.class));
((FullHttpResponse) finalResponse).release();
assertTrue("Channel finish failed", ch.finishAndReleaseAll());
assertTrue(ch.finishAndReleaseAll(), "Channel finish failed");
}
@Test

View File

@ -23,12 +23,12 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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;
public class HttpClientUpgradeHandlerTest {

View File

@ -41,7 +41,8 @@ import java.util.UUID;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
import static org.hamcrest.CoreMatchers.instanceOf;
@ -49,13 +50,13 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class HttpContentCompressorTest {

View File

@ -32,8 +32,7 @@ import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.PlatformDependent;
import org.apache.commons.io.IOUtils;
import org.junit.Assume;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
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.is;
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 {
private static final String HELLO_WORLD = "hello, world";
@ -191,7 +196,7 @@ public class HttpContentDecoderTest {
public void testResponseBrotliDecompression() throws Throwable {
Brotli.ensureAvailability();
// Failing on windows atm
Assume.assumeFalse(PlatformDependent.isWindows());
assumeFalse(PlatformDependent.isWindows());
HttpResponseDecoder decoder = new HttpResponseDecoder();
HttpContentDecoder decompressor = new HttpContentDecompressor();
HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE);
@ -207,13 +212,12 @@ public class HttpContentDecoderTest {
Object o = channel.readInbound();
assertThat(o, is(instanceOf(FullHttpResponse.class)));
FullHttpResponse resp = (FullHttpResponse) o;
assertNull("Content-Encoding header should be removed", resp.headers().get(HttpHeaderNames.CONTENT_ENCODING));
assertEquals("Content-Length header should match uncompressed string's length",
SAMPLE_STRING.length(),
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue());
assertEquals("Response body should match uncompressed string",
SAMPLE_STRING,
resp.content().toString(CharsetUtil.UTF_8));
assertNull(resp.headers().get(HttpHeaderNames.CONTENT_ENCODING), "Content-Encoding header should be removed");
assertEquals(SAMPLE_STRING.length(),
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue(),
"Content-Length header should match uncompressed string's length");
assertEquals(SAMPLE_STRING, resp.content().toString(CharsetUtil.UTF_8),
"Response body should match uncompressed string");
resp.release();
assertHasInboundMessages(channel, false);
@ -225,7 +229,7 @@ public class HttpContentDecoderTest {
public void testResponseChunksBrotliDecompression() throws Throwable {
Brotli.ensureAvailability();
// Failing on windows atm
Assume.assumeFalse(PlatformDependent.isWindows());
assumeFalse(PlatformDependent.isWindows());
HttpResponseDecoder decoder = new HttpResponseDecoder();
HttpContentDecoder decompressor = new HttpContentDecompressor();
HttpObjectAggregator aggregator = new HttpObjectAggregator(Integer.MAX_VALUE);
@ -253,12 +257,11 @@ public class HttpContentDecoderTest {
Object o = channel.readInbound();
assertThat(o, is(instanceOf(FullHttpResponse.class)));
FullHttpResponse resp = (FullHttpResponse) o;
assertEquals("Content-Length header should match uncompressed string's length",
SAMPLE_STRING.length(),
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue());
assertEquals("Response body should match uncompressed string",
SAMPLE_STRING,
resp.content().toString(CharsetUtil.UTF_8));
assertEquals(SAMPLE_STRING.length(),
resp.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).intValue(),
"Content-Length header should match uncompressed string's length");
assertEquals(SAMPLE_STRING, resp.content().toString(CharsetUtil.UTF_8),
"Response body should match uncompressed string");
resp.release();
assertHasInboundMessages(channel, false);
@ -511,11 +514,11 @@ public class HttpContentDecoderTest {
assertThat(o, is(instanceOf(HttpResponse.class)));
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);
assertNotNull("Content-length as well as transfer-encoding not set.", transferEncoding);
assertEquals("Unexpected transfer-encoding value.", HttpHeaderValues.CHUNKED.toString(), transferEncoding);
assertNotNull(transferEncoding, "Content-length as well as transfer-encoding not set.");
assertEquals(HttpHeaderValues.CHUNKED.toString(), transferEncoding, "Unexpected transfer-encoding value.");
assertHasInboundMessages(channel, true);
assertHasOutboundMessages(channel, false);

View File

@ -20,11 +20,14 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
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 {
// See https://github.com/netty/netty/issues/8915.
@ -53,18 +56,18 @@ public class HttpContentDecompressorTest {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json;charset=UTF-8");
response.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
Assert.assertTrue(channel.writeInbound(response));
assertTrue(channel.writeInbound(response));
// 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
// inbound handler.
Assert.assertEquals(2, readCalled.get());
Assert.assertFalse(channel.finishAndReleaseAll());
assertEquals(2, readCalled.get());
assertFalse(channel.finishAndReleaseAll());
}
}

View File

@ -36,7 +36,11 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
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 {

View File

@ -16,16 +16,18 @@
package io.netty.handler.codec.http;
import io.netty.util.AsciiString;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.List;
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class HttpHeadersTest {
@ -61,22 +63,37 @@ public class HttpHeadersTest {
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
}
@Test(expected = NullPointerException.class)
@Test
public void testSetNullHeaderValueValidate() {
HttpHeaders headers = new DefaultHttpHeaders(true);
headers.set(of("test"), (CharSequence) null);
final HttpHeaders headers = new DefaultHttpHeaders(true);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
headers.set(of("test"), (CharSequence) null);
}
});
}
@Test(expected = NullPointerException.class)
@Test
public void testSetNullHeaderValueNotValidate() {
HttpHeaders headers = new DefaultHttpHeaders(false);
headers.set(of("test"), (CharSequence) null);
final HttpHeaders headers = new DefaultHttpHeaders(false);
assertThrows(NullPointerException.class, new Executable() {
@Override
public void execute() {
headers.set(of("test"), (CharSequence) null);
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testAddSelf() {
HttpHeaders headers = new DefaultHttpHeaders(false);
headers.add(headers);
final HttpHeaders headers = new DefaultHttpHeaders(false);
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
headers.add(headers);
}
});
}
@Test

View File

@ -25,10 +25,10 @@ import org.junit.Test;
import java.util.Random;
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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;
public class HttpInvalidMessageTest {

View File

@ -37,14 +37,14 @@ import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertSame;
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.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 HttpObjectAggregatorTest {

View File

@ -31,11 +31,11 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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 HttpRequestDecoderTest {
private static final byte[] CONTENT_CRLF_DELIMITERS = createContent("\r\n");

View File

@ -31,7 +31,10 @@ import java.util.concurrent.ExecutionException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
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;
/**
*/

View File

@ -21,7 +21,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.PrematureChannelClosureException;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
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.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class HttpResponseDecoderTest {

View File

@ -20,14 +20,17 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.FileRegion;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.channels.WritableByteChannel;
import static org.hamcrest.MatcherAssert.assertThat;
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 {
private static final long INTEGER_OVERFLOW = (long) Integer.MAX_VALUE + 1;

View File

@ -16,11 +16,13 @@
package io.netty.handler.codec.http;
import io.netty.util.AsciiString;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static io.netty.handler.codec.http.HttpResponseStatus.parseLine;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class HttpResponseStatusTest {
@Test
@ -46,14 +48,24 @@ public class HttpResponseStatusTest {
assertEquals("FOO", customStatus.reasonPhrase());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseLineStringMalformedCode() {
parseLine("200a");
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
parseLine("200a");
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseLineStringMalformedCodeWithPhrase() {
parseLine("200a foo");
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
parseLine("200a foo");
}
});
}
@Test
@ -79,13 +91,23 @@ public class HttpResponseStatusTest {
assertEquals("FOO", customStatus.reasonPhrase());
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseLineAsciiStringMalformedCode() {
parseLine(new AsciiString("200a"));
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
parseLine(new AsciiString("200a"));
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void parseLineAsciiStringMalformedCodeWithPhrase() {
parseLine(new AsciiString("200a foo"));
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
parseLine(new AsciiString("200a foo"));
}
});
}
}

View File

@ -19,11 +19,14 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.*;
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 {

View File

@ -21,7 +21,8 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
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 {

View File

@ -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.setKeepAlive;
import static io.netty.handler.codec.http.HttpUtil.setTransferEncodingChunked;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@RunWith(Parameterized.class)
public class HttpServerKeepAliveHandlerTest {
@ -111,8 +111,8 @@ public class HttpServerKeepAliveHandlerTest {
channel.writeAndFlush(response);
HttpResponse writtenResponse = channel.readOutbound();
assertEquals("channel.isOpen", isKeepAliveResponseExpected, channel.isOpen());
assertEquals("response keep-alive", isKeepAliveResponseExpected, isKeepAlive(writtenResponse));
assertEquals(isKeepAliveResponseExpected, channel.isOpen(), "channel.isOpen");
assertEquals(isKeepAliveResponseExpected, isKeepAlive(writtenResponse), "response keep-alive");
ReferenceCountUtil.release(writtenResponse);
assertFalse(channel.finishAndReleaseAll());
}
@ -167,8 +167,8 @@ public class HttpServerKeepAliveHandlerTest {
channel.writeAndFlush(response.retainedDuplicate());
HttpResponse firstResponse = channel.readOutbound();
assertTrue("channel.isOpen", channel.isOpen());
assertTrue("response keep-alive", isKeepAlive(firstResponse));
assertTrue(channel.isOpen(), "channel.isOpen");
assertTrue(isKeepAlive(firstResponse), "response keep-alive");
ReferenceCountUtil.release(firstResponse);
requestForwarded = channel.readInbound();
@ -177,8 +177,8 @@ public class HttpServerKeepAliveHandlerTest {
channel.writeAndFlush(informationalResp);
HttpResponse writtenInfoResp = channel.readOutbound();
assertTrue("channel.isOpen", channel.isOpen());
assertTrue("response keep-alive", isKeepAlive(writtenInfoResp));
assertTrue(channel.isOpen(), "channel.isOpen");
assertTrue(isKeepAlive(writtenInfoResp), "response keep-alive");
ReferenceCountUtil.release(writtenInfoResp);
if (!StringUtil.isNullOrEmpty(setResponseConnection)) {
@ -189,8 +189,8 @@ public class HttpServerKeepAliveHandlerTest {
setupMessageLength(response);
channel.writeAndFlush(response.retainedDuplicate());
HttpResponse secondResponse = channel.readOutbound();
assertEquals("channel.isOpen", isKeepAliveResponseExpected, channel.isOpen());
assertEquals("response keep-alive", isKeepAliveResponseExpected, isKeepAlive(secondResponse));
assertEquals(isKeepAliveResponseExpected, channel.isOpen(), "channel.isOpen");
assertEquals(isKeepAliveResponseExpected, isKeepAlive(secondResponse), "response keep-alive");
ReferenceCountUtil.release(secondResponse);
requestForwarded = channel.readInbound();
@ -200,8 +200,8 @@ public class HttpServerKeepAliveHandlerTest {
if (isKeepAliveResponseExpected) {
channel.writeAndFlush(response);
HttpResponse finalResponse = channel.readOutbound();
assertFalse("channel.isOpen", channel.isOpen());
assertFalse("response keep-alive", isKeepAlive(finalResponse));
assertFalse(channel.isOpen(), "channel.isOpen");
assertFalse(isKeepAlive(finalResponse), "response keep-alive");
}
ReferenceCountUtil.release(response);
assertFalse(channel.finishAndReleaseAll());

View File

@ -34,7 +34,12 @@ import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodec;
import io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory;
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 {

View File

@ -27,11 +27,11 @@ import io.netty.util.ReferenceCountUtil;
import org.junit.Test;
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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;
import static org.junit.jupiter.api.Assertions.fail;
public class HttpUtilTest {

View File

@ -16,8 +16,7 @@
package io.netty.handler.codec.http;
import io.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.net.URISyntaxException;
@ -26,12 +25,17 @@ import java.util.List;
import java.util.Map;
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 {
@Test
public void testBasicUris() throws URISyntaxException {
QueryStringDecoder d = new QueryStringDecoder(new URI("http://localhost/path"));
Assert.assertEquals(0, d.parameters().size());
assertEquals(0, d.parameters().size());
}
@Test
@ -39,68 +43,68 @@ public class QueryStringDecoderTest {
QueryStringDecoder d;
d = new QueryStringDecoder("/foo");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(0, d.parameters().size());
assertEquals("/foo", d.path());
assertEquals(0, d.parameters().size());
d = new QueryStringDecoder("/foo%20bar");
Assert.assertEquals("/foo bar", d.path());
Assert.assertEquals(0, d.parameters().size());
assertEquals("/foo bar", d.path());
assertEquals(0, d.parameters().size());
d = new QueryStringDecoder("/foo?a=b=c");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(1, d.parameters().get("a").size());
Assert.assertEquals("b=c", d.parameters().get("a").get(0));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(1, d.parameters().get("a").size());
assertEquals("b=c", d.parameters().get("a").get(0));
d = new QueryStringDecoder("/foo?a=1&a=2");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("2", d.parameters().get("a").get(1));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(2, d.parameters().get("a").size());
assertEquals("1", d.parameters().get("a").get(0));
assertEquals("2", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo%20bar?a=1&a=2");
Assert.assertEquals("/foo bar", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("2", d.parameters().get("a").get(1));
assertEquals("/foo bar", d.path());
assertEquals(1, d.parameters().size());
assertEquals(2, d.parameters().get("a").size());
assertEquals("1", d.parameters().get("a").get(0));
assertEquals("2", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?a=&a=2");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("", d.parameters().get("a").get(0));
Assert.assertEquals("2", d.parameters().get("a").get(1));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(2, d.parameters().get("a").size());
assertEquals("", d.parameters().get("a").get(0));
assertEquals("2", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?a=1&a=");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("", d.parameters().get("a").get(1));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(2, d.parameters().get("a").size());
assertEquals("1", d.parameters().get("a").get(0));
assertEquals("", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?a=1&a=&a=");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(3, d.parameters().get("a").size());
Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("", d.parameters().get("a").get(1));
Assert.assertEquals("", d.parameters().get("a").get(2));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(3, d.parameters().get("a").size());
assertEquals("1", d.parameters().get("a").get(0));
assertEquals("", d.parameters().get("a").get(1));
assertEquals("", d.parameters().get("a").get(2));
d = new QueryStringDecoder("/foo?a=1=&a==2");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1=", d.parameters().get("a").get(0));
Assert.assertEquals("=2", d.parameters().get("a").get(1));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(2, d.parameters().get("a").size());
assertEquals("1=", d.parameters().get("a").get(0));
assertEquals("=2", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?abc=1%2023&abc=124%20");
Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.parameters().get("abc").size());
Assert.assertEquals("1 23", d.parameters().get("abc").get(0));
Assert.assertEquals("124 ", d.parameters().get("abc").get(1));
assertEquals("/foo", d.path());
assertEquals(1, d.parameters().size());
assertEquals(2, d.parameters().get("abc").size());
assertEquals("1 23", d.parameters().get("abc").get(0));
assertEquals("124 ", d.parameters().get("abc").get(1));
}
@Test
@ -139,32 +143,32 @@ public class QueryStringDecoderTest {
@Test
public void testPathSpecific() {
// decode escaped characters
Assert.assertEquals("/foo bar/", new QueryStringDecoder("/foo%20bar/?").path());
Assert.assertEquals("/foo\r\n\\bar/", new QueryStringDecoder("/foo%0D%0A\\bar/?").path());
assertEquals("/foo bar/", new QueryStringDecoder("/foo%20bar/?").path());
assertEquals("/foo\r\n\\bar/", new QueryStringDecoder("/foo%0D%0A\\bar/?").path());
// a 'fragment' after '#' should be cuted (see RFC 3986)
Assert.assertEquals("", new QueryStringDecoder("#123").path());
Assert.assertEquals("foo", new QueryStringDecoder("foo?bar#anchor").path());
Assert.assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#anchor").path());
Assert.assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#a#b?c=d").path());
assertEquals("", new QueryStringDecoder("#123").path());
assertEquals("foo", new QueryStringDecoder("foo?bar#anchor").path());
assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#anchor").path());
assertEquals("/foo-bar", new QueryStringDecoder("/foo-bar#a#b?c=d").path());
// '+' is not escape ' ' for the path
Assert.assertEquals("+", new QueryStringDecoder("+").path());
Assert.assertEquals("/foo+bar/", new QueryStringDecoder("/foo+bar/?").path());
Assert.assertEquals("/foo++", new QueryStringDecoder("/foo++?index.php").path());
Assert.assertEquals("/foo +", new QueryStringDecoder("/foo%20+?index.php").path());
Assert.assertEquals("/foo+ ", new QueryStringDecoder("/foo+%20").path());
assertEquals("+", new QueryStringDecoder("+").path());
assertEquals("/foo+bar/", new QueryStringDecoder("/foo+bar/?").path());
assertEquals("/foo++", new QueryStringDecoder("/foo++?index.php").path());
assertEquals("/foo +", new QueryStringDecoder("/foo%20+?index.php").path());
assertEquals("/foo+ ", new QueryStringDecoder("/foo+%20").path());
}
@Test
public void testExcludeFragment() {
// a 'fragment' after '#' should be cuted (see RFC 3986)
Assert.assertEquals("a", new QueryStringDecoder("?a#anchor").parameters().keySet().iterator().next());
Assert.assertEquals("b", new QueryStringDecoder("?a=b#anchor").parameters().get("a").get(0));
Assert.assertTrue(new QueryStringDecoder("?#").parameters().isEmpty());
Assert.assertTrue(new QueryStringDecoder("?#anchor").parameters().isEmpty());
Assert.assertTrue(new QueryStringDecoder("#?a=b#anchor").parameters().isEmpty());
Assert.assertTrue(new QueryStringDecoder("?#a=b#anchor").parameters().isEmpty());
assertEquals("a", new QueryStringDecoder("?a#anchor").parameters().keySet().iterator().next());
assertEquals("b", new QueryStringDecoder("?a=b#anchor").parameters().get("a").get(0));
assertTrue(new QueryStringDecoder("?#").parameters().isEmpty());
assertTrue(new QueryStringDecoder("?#anchor").parameters().isEmpty());
assertTrue(new QueryStringDecoder("#?a=b#anchor").parameters().isEmpty());
assertTrue(new QueryStringDecoder("?#a=b#anchor").parameters().isEmpty());
}
@Test
@ -178,20 +182,20 @@ public class QueryStringDecoderTest {
buf.append(i);
buf.append('&');
}
Assert.assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size());
assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size());
}
@Test
public void testHasPath() {
QueryStringDecoder decoder = new QueryStringDecoder("1=2", false);
Assert.assertEquals("", decoder.path());
assertEquals("", decoder.path());
Map<String, List<String>> params = decoder.parameters();
Assert.assertEquals(1, params.size());
Assert.assertTrue(params.containsKey("1"));
assertEquals(1, params.size());
assertTrue(params.containsKey("1"));
List<String> param = params.get("1");
Assert.assertNotNull(param);
Assert.assertEquals(1, param.size());
Assert.assertEquals("2", param.get(0));
assertNotNull(param);
assertEquals(1, param.size());
assertEquals("2", param.get(0));
}
@Test
@ -224,9 +228,9 @@ public class QueryStringDecoderTest {
final String expected = tests[i + 1];
try {
final String decoded = QueryStringDecoder.decodeComponent(encoded);
Assert.assertEquals(expected, decoded);
assertEquals(expected, decoded);
} catch (IllegalArgumentException e) {
Assert.assertEquals(expected, e.getMessage());
assertEquals(expected, e.getMessage());
}
}
}
@ -240,8 +244,8 @@ public class QueryStringDecoderTest {
1024, semicolonIsNormalChar);
QueryStringDecoder ad = new QueryStringDecoder(actual, CharsetUtil.UTF_8, true,
1024, semicolonIsNormalChar);
Assert.assertEquals(ed.path(), ad.path());
Assert.assertEquals(ed.parameters(), ad.parameters());
assertEquals(ed.path(), ad.path());
assertEquals(ed.parameters(), ad.parameters());
}
// See #189
@ -249,29 +253,29 @@ public class QueryStringDecoderTest {
public void testURI() {
URI uri = URI.create("http://localhost:8080/foo?param1=value1&param2=value2&param3=value3");
QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("/foo", decoder.path());
Assert.assertEquals("/foo", decoder.rawPath());
Assert.assertEquals("param1=value1&param2=value2&param3=value3", decoder.rawQuery());
assertEquals("/foo", decoder.path());
assertEquals("/foo", decoder.rawPath());
assertEquals("param1=value1&param2=value2&param3=value3", decoder.rawQuery());
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();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("param1", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value1", entry.getValue().get(0));
assertEquals("param1", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value1", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param2", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value2", entry.getValue().get(0));
assertEquals("param2", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value2", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param3", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value3", entry.getValue().get(0));
assertEquals("param3", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value3", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
assertFalse(entries.hasNext());
}
// See #189
@ -279,30 +283,30 @@ public class QueryStringDecoderTest {
public void testURISlashPath() {
URI uri = URI.create("http://localhost:8080/?param1=value1&param2=value2&param3=value3");
QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("/", decoder.path());
Assert.assertEquals("/", decoder.rawPath());
Assert.assertEquals("param1=value1&param2=value2&param3=value3", decoder.rawQuery());
assertEquals("/", decoder.path());
assertEquals("/", decoder.rawPath());
assertEquals("param1=value1&param2=value2&param3=value3", decoder.rawQuery());
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();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("param1", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value1", entry.getValue().get(0));
assertEquals("param1", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value1", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param2", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value2", entry.getValue().get(0));
assertEquals("param2", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value2", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param3", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value3", entry.getValue().get(0));
assertEquals("param3", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value3", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
assertFalse(entries.hasNext());
}
// See #189
@ -310,30 +314,30 @@ public class QueryStringDecoderTest {
public void testURINoPath() {
URI uri = URI.create("http://localhost:8080?param1=value1&param2=value2&param3=value3");
QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("", decoder.path());
Assert.assertEquals("", decoder.rawPath());
Assert.assertEquals("param1=value1&param2=value2&param3=value3", decoder.rawQuery());
assertEquals("", decoder.path());
assertEquals("", decoder.rawPath());
assertEquals("param1=value1&param2=value2&param3=value3", decoder.rawQuery());
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();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("param1", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value1", entry.getValue().get(0));
assertEquals("param1", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value1", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param2", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value2", entry.getValue().get(0));
assertEquals("param2", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value2", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("param3", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("value3", entry.getValue().get(0));
assertEquals("param3", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("value3", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
assertFalse(entries.hasNext());
}
// See https://github.com/netty/netty/issues/1833
@ -341,37 +345,37 @@ public class QueryStringDecoderTest {
public void testURI2() {
URI uri = URI.create("http://foo.com/images;num=10?query=name;value=123");
QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("/images;num=10", decoder.path());
Assert.assertEquals("/images;num=10", decoder.rawPath());
Assert.assertEquals("query=name;value=123", decoder.rawQuery());
assertEquals("/images;num=10", decoder.path());
assertEquals("/images;num=10", decoder.rawPath());
assertEquals("query=name;value=123", decoder.rawQuery());
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();
Entry<String, List<String>> entry = entries.next();
Assert.assertEquals("query", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("name", entry.getValue().get(0));
assertEquals("query", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("name", entry.getValue().get(0));
entry = entries.next();
Assert.assertEquals("value", entry.getKey());
Assert.assertEquals(1, entry.getValue().size());
Assert.assertEquals("123", entry.getValue().get(0));
assertEquals("value", entry.getKey());
assertEquals(1, entry.getValue().size());
assertEquals("123", entry.getValue().get(0));
Assert.assertFalse(entries.hasNext());
assertFalse(entries.hasNext());
}
@Test
public void testEmptyStrings() {
QueryStringDecoder pathSlash = new QueryStringDecoder("path/");
Assert.assertEquals("path/", pathSlash.rawPath());
Assert.assertEquals("", pathSlash.rawQuery());
assertEquals("path/", pathSlash.rawPath());
assertEquals("", pathSlash.rawQuery());
QueryStringDecoder pathQuestion = new QueryStringDecoder("path?");
Assert.assertEquals("path", pathQuestion.rawPath());
Assert.assertEquals("", pathQuestion.rawQuery());
assertEquals("path", pathQuestion.rawPath());
assertEquals("", pathQuestion.rawQuery());
QueryStringDecoder empty = new QueryStringDecoder("");
Assert.assertEquals("", empty.rawPath());
Assert.assertEquals("", empty.rawQuery());
assertEquals("", empty.rawPath());
assertEquals("", empty.rawQuery());
}
}

View File

@ -15,12 +15,13 @@
*/
package io.netty.handler.codec.http;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.nio.charset.Charset;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class QueryStringEncoderTest {
@Test
@ -29,47 +30,47 @@ public class QueryStringEncoderTest {
e = new QueryStringEncoder("/foo");
e.addParam("a", "b=c");
Assert.assertEquals("/foo?a=b%3Dc", e.toString());
Assert.assertEquals(new URI("/foo?a=b%3Dc"), e.toUri());
assertEquals("/foo?a=b%3Dc", e.toString());
assertEquals(new URI("/foo?a=b%3Dc"), e.toUri());
e = new QueryStringEncoder("/foo/\u00A5");
e.addParam("a", "\u00A5");
Assert.assertEquals("/foo/\u00A5?a=%C2%A5", e.toString());
Assert.assertEquals(new URI("/foo/\u00A5?a=%C2%A5"), e.toUri());
assertEquals("/foo/\u00A5?a=%C2%A5", e.toString());
assertEquals(new URI("/foo/\u00A5?a=%C2%A5"), e.toUri());
e = new QueryStringEncoder("/foo/\u00A5");
e.addParam("a", "abc\u00A5");
Assert.assertEquals("/foo/\u00A5?a=abc%C2%A5", e.toString());
Assert.assertEquals(new URI("/foo/\u00A5?a=abc%C2%A5"), e.toUri());
assertEquals("/foo/\u00A5?a=abc%C2%A5", e.toString());
assertEquals(new URI("/foo/\u00A5?a=abc%C2%A5"), e.toUri());
e = new QueryStringEncoder("/foo");
e.addParam("a", "1");
e.addParam("b", "2");
Assert.assertEquals("/foo?a=1&b=2", e.toString());
Assert.assertEquals(new URI("/foo?a=1&b=2"), e.toUri());
assertEquals("/foo?a=1&b=2", e.toString());
assertEquals(new URI("/foo?a=1&b=2"), e.toUri());
e = new QueryStringEncoder("/foo");
e.addParam("a", "1");
e.addParam("b", "");
e.addParam("c", null);
e.addParam("d", null);
Assert.assertEquals("/foo?a=1&b=&c&d", e.toString());
Assert.assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri());
assertEquals("/foo?a=1&b=&c&d", e.toString());
assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri());
}
@Test
public void testNonDefaultEncoding() throws Exception {
QueryStringEncoder e = new QueryStringEncoder("/foo/\u00A5", Charset.forName("UTF-16"));
e.addParam("a", "\u00A5");
Assert.assertEquals("/foo/\u00A5?a=%FE%FF%00%A5", e.toString());
Assert.assertEquals(new URI("/foo/\u00A5?a=%FE%FF%00%A5"), e.toUri());
assertEquals("/foo/\u00A5?a=%FE%FF%00%A5", e.toString());
assertEquals(new URI("/foo/\u00A5?a=%FE%FF%00%A5"), e.toUri());
}
@Test
public void testWhitespaceEncoding() throws Exception {
QueryStringEncoder e = new QueryStringEncoder("/foo");
e.addParam("a", "b c");
Assert.assertEquals("/foo?a=b%20c", e.toString());
Assert.assertEquals(new URI("/foo?a=b%20c"), e.toUri());
assertEquals("/foo?a=b%20c", e.toString());
assertEquals(new URI("/foo?a=b%20c"), e.toUri());
}
}

View File

@ -16,7 +16,8 @@
package io.netty.handler.codec.http;
import io.netty.util.AsciiString;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Iterator;
import java.util.List;
@ -30,10 +31,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.CLOSE;
import static io.netty.handler.codec.http.HttpHeaderValues.ZERO;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ReadOnlyHttpHeadersTest {
@Test
@ -113,22 +115,37 @@ public class ReadOnlyHttpHeadersTest {
assertTrue(APPLICATION_OCTET_STREAM.contentEqualsIgnoreCase(names.get(1)));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void validateNamesFail() {
new ReadOnlyHttpHeaders(true,
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "));
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new ReadOnlyHttpHeaders(true,
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "));
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void emptyHeaderName() {
new ReadOnlyHttpHeaders(true,
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "), ZERO);
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new ReadOnlyHttpHeaders(true,
ACCEPT, APPLICATION_JSON, AsciiString.cached(" "), ZERO);
}
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void headerWithoutValue() {
new ReadOnlyHttpHeaders(false,
ACCEPT, APPLICATION_JSON, CONTENT_LENGTH);
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
new ReadOnlyHttpHeaders(false,
ACCEPT, APPLICATION_JSON, CONTENT_LENGTH);
}
});
}
private static void assert3ParisEquals(Iterator<Entry<String, String>> itr) {

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.http.cookie;
import io.netty.handler.codec.DateFormatter;
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.Calendar;
@ -29,7 +29,12 @@ import java.util.TimeZone;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
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 {
@Test
@ -42,10 +47,10 @@ public class ClientCookieDecoderTest {
assertNotNull(cookie);
assertEquals("myValue", cookie.value());
assertEquals(".adomainsomewhere", cookie.domain());
assertNotEquals("maxAge should be defined when parsing cookie " + cookieString,
Long.MIN_VALUE, cookie.maxAge());
assertTrue("maxAge should be about 50ms when parsing cookie " + cookieString,
cookie.maxAge() >= 40 && cookie.maxAge() <= 60);
assertNotEquals(Long.MIN_VALUE, cookie.maxAge(),
"maxAge should be defined when parsing cookie " + cookieString);
assertTrue(cookie.maxAge() >= 40 && cookie.maxAge() <= 60,
"maxAge should be about 50ms when parsing cookie " + cookieString);
assertEquals("/apathsomewhere", cookie.path());
assertTrue(cookie.isSecure());

View File

@ -15,9 +15,11 @@
*/
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;
import org.junit.jupiter.api.function.Executable;
public class ClientCookieEncoderTest {
@ -47,9 +49,14 @@ public class ClientCookieEncoderTest {
ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "\"foo\""));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testRejectCookieValueWithSemicolon() {
ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "foo;bar"));
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
ClientCookieEncoder.STRICT.encode(new DefaultCookie("myCookie", "foo;bar"));
}
});
}
@Test

View File

@ -16,12 +16,15 @@
package io.netty.handler.codec.http.cookie;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Iterator;
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 {
@Test

View File

@ -17,10 +17,10 @@ package io.netty.handler.codec.http.cookie;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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.DateFormatter;
@ -34,7 +34,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.netty.handler.codec.http.cookie.CookieHeaderNames.SameSite;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ServerCookieEncoderTest {

View File

@ -19,7 +19,8 @@ import io.netty.handler.codec.http.EmptyHttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
import static io.netty.handler.codec.http.cors.CorsConfigBuilder.forAnyOrigin;
@ -30,6 +31,7 @@ import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class CorsConfigTest {
@ -125,9 +127,14 @@ public class CorsConfigTest {
assertThat(cors.preflightResponseHeaders(), equalTo((HttpHeaders) EmptyHttpHeaders.INSTANCE));
}
@Test (expected = IllegalArgumentException.class)
@Test
public void shouldThrowIfValueIsNull() {
forOrigin("*").preflightResponseHeader("HeaderName", new Object[]{null}).build();
assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() {
forOrigin("*").preflightResponseHeader("HeaderName", new Object[]{null}).build();
}
});
}
@Test

View File

@ -27,7 +27,7 @@ import io.netty.handler.codec.http.HttpUtil;
import io.netty.util.AsciiString;
import io.netty.util.ReferenceCountUtil;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileOutputStream;
@ -27,8 +27,8 @@ import java.util.Arrays;
import java.util.UUID;
import static io.netty.util.CharsetUtil.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* {@link AbstractDiskHttpData} test cases
@ -57,8 +57,8 @@ public class AbstractDiskHttpDataTest {
ByteBuf buf2 = test.getChunk(1024);
assertEquals(buf2.readerIndex(), 0);
assertEquals(buf2.writerIndex(), 1024);
assertFalse("Arrays should not be equal",
Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)));
assertFalse(Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)),
"Arrays should not be equal");
} finally {
test.delete();
}

View File

@ -21,7 +21,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -34,7 +34,10 @@ import java.util.Random;
import java.util.UUID;
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. */
public class AbstractMemoryHttpDataTest {

View File

@ -18,21 +18,21 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
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.HttpVersion.HTTP_1_1;
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE;
import static io.netty.util.CharsetUtil.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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 DefaultHttpDataFactoryTest {
// req1 equals req2
@ -41,19 +41,19 @@ public class DefaultHttpDataFactoryTest {
private DefaultHttpDataFactory factory;
@BeforeClass
@BeforeAll
public static void assertReq1EqualsReq2() {
// Before doing anything, assert that the requests are equal
assertEquals(req1.hashCode(), req2.hashCode());
assertTrue(req1.equals(req2));
}
@Before
@BeforeEach
public void setupFactory() {
factory = new DefaultHttpDataFactory();
}
@After
@AfterEach
public void cleanupFactory() {
factory.cleanAllHttpData();
}

View File

@ -18,8 +18,8 @@ package io.netty.handler.codec.http.multipart;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
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.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
@ -37,7 +39,7 @@ public class DeleteFileOnExitHookTest {
private static final String HOOK_TEST_TMP = "target/DeleteFileOnExitHookTest/tmp";
private FileUpload fu;
@Before
@BeforeEach
public void setUp() throws IOException {
DefaultHttpDataFactory defaultHttpDataFactory = new DefaultHttpDataFactory(true);
defaultHttpDataFactory.setBaseDir(HOOK_TEST_TMP);

View File

@ -22,7 +22,7 @@ import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileInputStream;
@ -31,13 +31,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class DiskFileUploadTest {
@Test

View File

@ -28,17 +28,17 @@ import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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 HttpPostMultiPartRequestDecoderTest {
@ -173,22 +173,22 @@ public class HttpPostMultiPartRequestDecoderTest {
assertEquals(inMemory, data.isInMemory());
if (data.isInMemory()) {
// To be done only if not inMemory: assertEquals(data.get().length, fileSize);
assertFalse("Capacity should be higher than 1M", data.getByteBuf().capacity()
< 1024 * 1024);
assertFalse(data.getByteBuf().capacity() < 1024 * 1024,
"Capacity should be higher than 1M");
}
assertTrue("Capacity should be less than 1M", decoder.getCurrentAllocatedCapacity()
< 1024 * 1024);
assertTrue(decoder.getCurrentAllocatedCapacity() < 1024 * 1024,
"Capacity should be less than 1M");
InterfaceHttpData[] httpDatas = decoder.getBodyHttpDatas().toArray(new InterfaceHttpData[0]);
for (InterfaceHttpData httpData : httpDatas) {
assertEquals("Before cleanAllHttpData should be 1", 1, httpData.refCnt());
assertEquals(1, httpData.refCnt(), "Before cleanAllHttpData should be 1");
}
factory.cleanAllHttpData();
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();
for (InterfaceHttpData httpData : httpDatas) {
assertEquals("RefCnt should be 0", 0, httpData.refCnt());
assertEquals(0, httpData.refCnt(), "RefCnt should be 0");
}
}

View File

@ -32,13 +32,19 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.net.URLEncoder;
import java.nio.charset.UnsupportedCharsetException;
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.
@ -97,8 +103,8 @@ public class HttpPostRequestDecoderTest {
MemoryFileUpload upload = (MemoryFileUpload) decoder.next();
// Validate data has been parsed correctly as it was passed into request.
assertEquals("Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']',
data, upload.getString(CharsetUtil.UTF_8));
assertEquals(data, upload.getString(CharsetUtil.UTF_8),
"Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']');
upload.release();
decoder.destroy();
buf.release();
@ -266,7 +272,7 @@ public class HttpPostRequestDecoderTest {
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();
assertEquals(InterfaceHttpData.HttpDataType.Attribute, aDecodedData.getHttpDataType());
@ -465,10 +471,10 @@ public class HttpPostRequestDecoderTest {
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
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;
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();
assertTrue(req.release());
}
@ -580,9 +586,9 @@ public class HttpPostRequestDecoderTest {
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
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;
assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
decoder.destroy();
assertTrue(req.release());
}
@ -616,9 +622,9 @@ public class HttpPostRequestDecoderTest {
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
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;
assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
decoder.destroy();
assertTrue(req.release());
}
@ -758,25 +764,40 @@ public class HttpPostRequestDecoderTest {
assertTrue(req.release());
}
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
@Test
public void testNotLeak() {
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/",
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/",
Unpooled.copiedBuffer("a=1&&b=2", CharsetUtil.US_ASCII));
try {
new HttpPostStandardRequestDecoder(request).destroy();
assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class, new Executable() {
@Override
public void execute() {
new HttpPostStandardRequestDecoder(request).destroy();
}
});
} finally {
assertTrue(request.release());
}
}
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
@Test
public void testNotLeakDirectBufferWhenWrapIllegalArgumentException() {
testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer());
assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class, new Executable() {
@Override
public void execute() {
testNotLeakWhenWrapIllegalArgumentException(Unpooled.directBuffer());
}
});
}
@Test(expected = HttpPostRequestDecoder.ErrorDataDecoderException.class)
@Test
public void testNotLeakHeapBufferWhenWrapIllegalArgumentException() {
testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer());
assertThrows(HttpPostRequestDecoder.ErrorDataDecoderException.class, new Executable() {
@Override
public void execute() throws Throwable {
testNotLeakWhenWrapIllegalArgumentException(Unpooled.buffer());
}
});
}
private static void testNotLeakWhenWrapIllegalArgumentException(ByteBuf buf) {
@ -830,9 +851,9 @@ public class HttpPostRequestDecoderTest {
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
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;
assertEquals("the filename should be decoded", filename, fileUpload.getFilename());
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
decoder.destroy();
assertTrue(req.release());

View File

@ -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.util.CharsetUtil;
import io.netty.util.internal.StringUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
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_TRANSFER_ENCODING;
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
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;
/** {@link HttpPostRequestEncoder} test case. */
public class HttpPostRequestEncoderTest {
@ -345,9 +345,9 @@ public class HttpPostRequestEncoderTest {
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
ByteBuf content = httpContent.content();
int refCnt = content.refCnt();
assertTrue("content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt,
(content.unwrap() == content || content.unwrap() == null) && refCnt == 1 ||
content.unwrap() != content && refCnt == 2);
assertTrue((content.unwrap() == content || content.unwrap() == null) && refCnt == 1 ||
content.unwrap() != content && refCnt == 2,
"content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt);
httpContent.release();
}
encoder.cleanFiles();
@ -401,10 +401,10 @@ public class HttpPostRequestEncoderTest {
checkNextChunkSize(encoder, 8080);
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();
assertTrue("Expected end of input is not receive", encoder.isEndOfInput());
assertTrue(encoder.isEndOfInput(), "Expected end of input is not receive");
}
@Test
@ -423,10 +423,10 @@ public class HttpPostRequestEncoderTest {
checkNextChunkSize(encoder, 8080);
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();
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 {
@ -441,8 +441,8 @@ public class HttpPostRequestEncoderTest {
int readable = httpContent.content().readableBytes();
boolean expectedSize = readable >= expectedSizeMin && readable <= expectedSizeMax;
assertTrue("Chunk size is not in expected range (" + expectedSizeMin + " - " + expectedSizeMax + "), was: "
+ readable, expectedSize);
assertTrue(expectedSize, "Chunk size is not in expected range (" + expectedSizeMin + " - "
+ expectedSizeMax + "), was: " + readable);
httpContent.release();
}

View File

@ -15,8 +15,9 @@
*/
package io.netty.handler.codec.http.multipart;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class MemoryFileUploadTest {
@ -24,6 +25,6 @@ public class MemoryFileUploadTest {
public final void testMemoryFileUploadEquals() {
MemoryFileUpload f1 =
new MemoryFileUpload("m1", "m1", "application/json", null, null, 100);
Assert.assertEquals(f1, f1);
assertEquals(f1, f1);
}
}

View File

@ -17,8 +17,11 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.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 {
@ -26,19 +29,19 @@ public class WebSocket00FrameEncoderTest {
@Test
public void testMultipleWebSocketCloseFrames() {
EmbeddedChannel channel = new EmbeddedChannel(new WebSocket00FrameEncoder());
Assert.assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
Assert.assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
Assert.assertTrue(channel.finish());
assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
assertTrue(channel.writeOutbound(new CloseWebSocketFrame()));
assertTrue(channel.finish());
assertCloseWebSocketFrame(channel);
assertCloseWebSocketFrame(channel);
Assert.assertNull(channel.readOutbound());
assertNull(channel.readOutbound());
}
private static void assertCloseWebSocketFrame(EmbeddedChannel channel) {
ByteBuf buf = channel.readOutbound();
Assert.assertEquals(2, buf.readableBytes());
Assert.assertEquals((byte) 0xFF, buf.readByte());
Assert.assertEquals((byte) 0x00, buf.readByte());
assertEquals(2, buf.readableBytes());
assertEquals((byte) 0xFF, buf.readByte());
assertEquals((byte) 0x00, buf.readByte());
buf.release();
}
}

View File

@ -18,8 +18,13 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.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>
@ -73,13 +78,13 @@ public class WebSocket08EncoderDecoderTest {
executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage);
CloseWebSocketFrame response = inChannel.readOutbound();
Assert.assertNotNull(response);
Assert.assertEquals(expectedStatus.code(), response.statusCode());
Assert.assertEquals(errorMessage, response.reasonText());
assertNotNull(response);
assertEquals(expectedStatus.code(), response.statusCode());
assertEquals(errorMessage, response.reasonText());
response.release();
Assert.assertFalse(inChannel.finish());
Assert.assertFalse(outChannel.finish());
assertFalse(inChannel.finish());
assertFalse(outChannel.finish());
// Without auto-close
config = WebSocketDecoderConfig.newBuilder()
@ -92,10 +97,10 @@ public class WebSocket08EncoderDecoderTest {
executeProtocolViolationTest(outChannel, inChannel, maxPayloadLength + 1, expectedStatus, errorMessage);
response = inChannel.readOutbound();
Assert.assertNull(response);
assertNull(response);
Assert.assertFalse(inChannel.finish());
Assert.assertFalse(outChannel.finish());
assertFalse(inChannel.finish());
assertFalse(outChannel.finish());
// Release test data
binTestData.release();
@ -112,11 +117,11 @@ public class WebSocket08EncoderDecoderTest {
}
BinaryWebSocketFrame exceedingFrame = inChannel.readInbound();
Assert.assertNull(exceedingFrame);
assertNull(exceedingFrame);
Assert.assertNotNull(corrupted);
Assert.assertEquals(expectedStatus, corrupted.closeStatus());
Assert.assertEquals(errorMessage, corrupted.getMessage());
assertNotNull(corrupted);
assertEquals(expectedStatus, corrupted.closeStatus());
assertEquals(errorMessage, corrupted.getMessage());
}
@Test
@ -177,10 +182,10 @@ public class WebSocket08EncoderDecoderTest {
transfer(outChannel, inChannel);
Object decoded = inChannel.readInbound();
Assert.assertNotNull(decoded);
Assert.assertTrue(decoded instanceof TextWebSocketFrame);
assertNotNull(decoded);
assertTrue(decoded instanceof TextWebSocketFrame);
TextWebSocketFrame txt = (TextWebSocketFrame) decoded;
Assert.assertEquals(txt.text(), testStr);
assertEquals(txt.text(), testStr);
txt.release();
}
@ -192,13 +197,13 @@ public class WebSocket08EncoderDecoderTest {
transfer(outChannel, inChannel);
Object decoded = inChannel.readInbound();
Assert.assertNotNull(decoded);
Assert.assertTrue(decoded instanceof BinaryWebSocketFrame);
assertNotNull(decoded);
assertTrue(decoded instanceof BinaryWebSocketFrame);
BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) decoded;
int readable = binFrame.content().readableBytes();
Assert.assertEquals(readable, testDataLength);
assertEquals(readable, testDataLength);
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();
}

View File

@ -15,14 +15,14 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
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.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

View File

@ -19,11 +19,11 @@ import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.net.URI;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class WebSocketClientHandshaker07Test extends WebSocketClientHandshakerTest {

View File

@ -35,12 +35,15 @@ import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
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 {
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() {
testHttpResponseAndFrameInSameBuffer(false);
}
@Test(timeout = 3000)
@Test
@Timeout(value = 3000, unit = TimeUnit.MILLISECONDS)
public void testHttpResponseAndFrameInSameBufferCodec() {
testHttpResponseAndFrameInSameBuffer(true);
}

View File

@ -20,13 +20,13 @@ import java.util.TreeSet;
import org.assertj.core.api.ThrowableAssert;
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.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static io.netty.handler.codec.http.websocketx.WebSocketCloseStatus.*;

View File

@ -21,8 +21,13 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.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 {
@ -46,29 +51,29 @@ public class WebSocketFrameAggregatorTest {
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
Assert.assertTrue(channel.finish());
assertTrue(channel.finish());
BinaryWebSocketFrame frame = channel.readInbound();
Assert.assertTrue(frame.isFinalFragment());
Assert.assertEquals(1, frame.rsv());
Assert.assertArrayEquals(content1, toBytes(frame.content()));
assertTrue(frame.isFinalFragment());
assertEquals(1, frame.rsv());
assertArrayEquals(content1, toBytes(frame.content()));
PingWebSocketFrame frame2 = channel.readInbound();
Assert.assertTrue(frame2.isFinalFragment());
Assert.assertEquals(0, frame2.rsv());
Assert.assertArrayEquals(content1, toBytes(frame2.content()));
assertTrue(frame2.isFinalFragment());
assertEquals(0, frame2.rsv());
assertArrayEquals(content1, toBytes(frame2.content()));
PongWebSocketFrame frame3 = channel.readInbound();
Assert.assertTrue(frame3.isFinalFragment());
Assert.assertEquals(0, frame3.rsv());
Assert.assertArrayEquals(content1, toBytes(frame3.content()));
assertTrue(frame3.isFinalFragment());
assertEquals(0, frame3.rsv());
assertArrayEquals(content1, toBytes(frame3.content()));
BinaryWebSocketFrame frame4 = channel.readInbound();
Assert.assertTrue(frame4.isFinalFragment());
Assert.assertEquals(0, frame4.rsv());
Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
assertTrue(frame4.isFinalFragment());
assertEquals(0, frame4.rsv());
assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
Assert.assertNull(channel.readInbound());
assertNull(channel.readInbound());
}
@Test
@ -81,29 +86,29 @@ public class WebSocketFrameAggregatorTest {
channel.writeInbound(new PongWebSocketFrame(Unpooled.wrappedBuffer(content1)));
channel.writeInbound(new ContinuationWebSocketFrame(true, 0, Unpooled.wrappedBuffer(content3)));
Assert.assertTrue(channel.finish());
assertTrue(channel.finish());
TextWebSocketFrame frame = channel.readInbound();
Assert.assertTrue(frame.isFinalFragment());
Assert.assertEquals(1, frame.rsv());
Assert.assertArrayEquals(content1, toBytes(frame.content()));
assertTrue(frame.isFinalFragment());
assertEquals(1, frame.rsv());
assertArrayEquals(content1, toBytes(frame.content()));
PingWebSocketFrame frame2 = channel.readInbound();
Assert.assertTrue(frame2.isFinalFragment());
Assert.assertEquals(0, frame2.rsv());
Assert.assertArrayEquals(content1, toBytes(frame2.content()));
assertTrue(frame2.isFinalFragment());
assertEquals(0, frame2.rsv());
assertArrayEquals(content1, toBytes(frame2.content()));
PongWebSocketFrame frame3 = channel.readInbound();
Assert.assertTrue(frame3.isFinalFragment());
Assert.assertEquals(0, frame3.rsv());
Assert.assertArrayEquals(content1, toBytes(frame3.content()));
assertTrue(frame3.isFinalFragment());
assertEquals(0, frame3.rsv());
assertArrayEquals(content1, toBytes(frame3.content()));
TextWebSocketFrame frame4 = channel.readInbound();
Assert.assertTrue(frame4.isFinalFragment());
Assert.assertEquals(0, frame4.rsv());
Assert.assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
assertTrue(frame4.isFinalFragment());
assertEquals(0, frame4.rsv());
assertArrayEquals(aggregatedContent, toBytes(frame4.content()));
Assert.assertNull(channel.readInbound());
assertNull(channel.readInbound());
}
@Test
@ -113,7 +118,7 @@ public class WebSocketFrameAggregatorTest {
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
try {
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
Assert.fail();
fail();
} catch (TooLongFrameException e) {
// expected
}
@ -124,7 +129,7 @@ public class WebSocketFrameAggregatorTest {
channel.writeInbound(new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content1)));
try {
channel.writeInbound(new ContinuationWebSocketFrame(false, 0, Unpooled.wrappedBuffer(content2)));
Assert.fail();
fail();
} catch (TooLongFrameException e) {
// expected
}

View File

@ -22,9 +22,11 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
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 {

View File

@ -29,13 +29,20 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.ClientHandshakeStateEvent;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler.ServerHandshakeStateEvent;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.util.List;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.function.Executable;
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 {
@ -66,7 +73,7 @@ public class WebSocketHandshakeHandOverTest {
}
}
@Before
@BeforeEach
public void setUp() {
serverReceivedHandshake = false;
serverHandshakeComplete = null;
@ -124,8 +131,8 @@ public class WebSocketHandshakeHandOverTest {
assertTrue(clientReceivedMessage);
}
@Test(expected = WebSocketHandshakeException.class)
public void testClientHandshakeTimeout() throws Exception {
@Test
public void testClientHandshakeTimeout() throws Throwable {
EmbeddedChannel serverChannel = createServerChannel(new SimpleChannelInboundHandler<Object>() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
@ -164,7 +171,7 @@ public class WebSocketHandshakeHandOverTest {
transferAllDataWithMerge(clientChannel, serverChannel);
// Server do not send the response back
// transferAllDataWithMerge(serverChannel, clientChannel);
WebSocketClientProtocolHandshakeHandler handshakeHandler =
final WebSocketClientProtocolHandshakeHandler handshakeHandler =
(WebSocketClientProtocolHandshakeHandler) clientChannel
.pipeline().get(WebSocketClientProtocolHandshakeHandler.class.getName());
@ -178,7 +185,12 @@ public class WebSocketHandshakeHandOverTest {
assertFalse(clientReceivedMessage);
// Should throw WebSocketHandshakeException
try {
handshakeHandler.getHandshakeFuture().syncUninterruptibly();
assertThrows(WebSocketHandshakeException.class, new Executable() {
@Override
public void execute() {
handshakeHandler.getHandshakeFuture().syncUninterruptibly();
}
});
} finally {
serverChannel.finishAndReleaseAll();
}
@ -218,7 +230,8 @@ public class WebSocketHandshakeHandOverTest {
}
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testClientHandshakerForceClose() throws Exception {
final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(
new URI("ws://localhost:1234/test"), WebSocketVersion.V13, null, true,

View File

@ -26,13 +26,16 @@ import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.flow.FlowControlHandler;
import io.netty.util.ReferenceCountUtil;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicReference;
import static io.netty.util.CharsetUtil.UTF_8;
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}.

View File

@ -29,12 +29,12 @@ import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTest {
@ -114,16 +114,16 @@ public class WebSocketServerHandshaker00Test extends WebSocketServerHandshakerTe
ch2.writeInbound(ch.readOutbound());
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) {
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
} else {
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
}
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();
req.release();
}

View File

@ -28,10 +28,11 @@ import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.util.ReferenceCountUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
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 {
@ -83,12 +84,12 @@ public class WebSocketServerHandshaker08Test extends WebSocketServerHandshakerTe
ch2.writeInbound(resBuf);
HttpResponse res = ch2.readInbound();
Assert.assertEquals(
assertEquals(
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
if (subProtocol) {
Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
} else {
Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
}
ReferenceCountUtil.release(res);
req.release();

View File

@ -33,16 +33,16 @@ import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.ReferenceCounted;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Iterator;
import static io.netty.handler.codec.http.HttpVersion.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
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.fail;
public class WebSocketServerHandshaker13Test extends WebSocketServerHandshakerTest {

View File

@ -22,9 +22,12 @@ import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpResponseStatus;
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 {

View File

@ -24,9 +24,12 @@ import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
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 {

View File

@ -36,21 +36,25 @@ import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.util.CharsetUtil;
import io.netty.util.ReferenceCountUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayDeque;
import java.util.Queue;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
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 {
private final Queue<FullHttpResponse> responses = new ArrayDeque<FullHttpResponse>();
@Before
@BeforeEach
public void setUp() {
responses.clear();
}

View File

@ -19,8 +19,14 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.CorruptedFrameException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.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 {
@ -39,19 +45,19 @@ public class WebSocketUtf8FrameValidatorTest {
TextWebSocketFrame frame = new TextWebSocketFrame(Unpooled.copiedBuffer(data));
try {
channel.writeInbound(frame);
Assert.fail();
fail();
} catch (CorruptedFrameException e) {
// expected exception
}
Assert.assertTrue(channel.finish());
assertTrue(channel.finish());
ByteBuf buf = channel.readOutbound();
Assert.assertNotNull(buf);
assertNotNull(buf);
try {
Assert.assertFalse(buf.isReadable());
assertFalse(buf.isReadable());
} finally {
buf.release();
}
Assert.assertNull(channel.readOutbound());
Assert.assertEquals(0, frame.refCnt());
assertNull(channel.readOutbound());
assertEquals(0, frame.refCnt());
}
}

View File

@ -15,7 +15,7 @@
*/
package io.netty.handler.codec.http.websocketx;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
@ -24,9 +24,9 @@ import io.netty.handler.codec.base64.Base64;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.EmptyArrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class WebSocketUtilTest {

View File

@ -24,10 +24,13 @@ import io.netty.handler.codec.http.HttpResponse;
import java.util.Collections;
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 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.atLeastOnce;
import static org.mockito.Mockito.mock;
@ -218,7 +221,7 @@ public class WebSocketClientExtensionHandlerTest {
verify(fallbackExtensionMock).newExtensionDecoder();
}
@Test(expected = CodecException.class)
@Test
public void testIfMainAndFallbackUseRSV1WillFail() {
// initialize
when(mainHandshakerMock.newRequestData()).
@ -248,7 +251,12 @@ public class WebSocketClientExtensionHandlerTest {
req2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
HttpResponse res = newUpgradeResponse("main, fallback");
ch.writeInbound(res);
try {
ch.writeInbound(res);
} catch (CodecException e) {
return;
}
fail("Expected to encounter a CodecException");
// test
assertEquals(2, reqExts.size());

View File

@ -15,9 +15,10 @@
*/
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 {

View File

@ -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.PongWebSocketFrame;
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 {

View File

@ -19,12 +19,14 @@ import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpHeaders;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.Assert.*;
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 {

View File

@ -25,10 +25,14 @@ import java.io.IOException;
import java.util.Collections;
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 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.*;
public class WebSocketServerExtensionHandlerTest {

View File

@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
import static io.netty.handler.codec.http.websocketx.extensions.compression.
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.WebSocketExtensionData;
@ -25,7 +29,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class DeflateFrameClientExtensionHandshakerTest {

View File

@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
import static io.netty.handler.codec.http.websocketx.extensions.compression.
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.WebSocketExtensionData;
@ -25,7 +29,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class DeflateFrameServerExtensionHandshakerTest {

View File

@ -22,13 +22,17 @@ import io.netty.handler.codec.compression.ZlibCodecFactory;
import io.netty.handler.codec.compression.ZlibWrapper;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Random;
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension.*;
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 {

View File

@ -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.ContinuationWebSocketFrame;
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtension;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Random;
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 {

View File

@ -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.compression.
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.channel.embedded.EmbeddedChannel;
@ -31,7 +35,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class PerMessageDeflateClientExtensionHandshakerTest {

View File

@ -28,14 +28,20 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
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.WebSocketExtensionFilter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Random;
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.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 {
@ -264,7 +270,7 @@ public class PerMessageDeflateDecoderTest {
assertFalse(decoderChannel.finish());
}
@Test(expected = DecoderException.class)
@Test
public void testIllegalStateWhenDecompressionInProgress() {
WebSocketExtensionFilter selectivityDecompressionFilter = new WebSocketExtensionFilter() {
@Override
@ -275,7 +281,7 @@ public class PerMessageDeflateDecoderTest {
EmbeddedChannel encoderChannel = new EmbeddedChannel(
ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
EmbeddedChannel decoderChannel = new EmbeddedChannel(
final EmbeddedChannel decoderChannel = new EmbeddedChannel(
new PerMessageDeflateDecoder(false, selectivityDecompressionFilter));
byte[] firstPayload = new byte[200];
@ -292,7 +298,7 @@ public class PerMessageDeflateDecoderTest {
BinaryWebSocketFrame firstPart = new BinaryWebSocketFrame(false, WebSocketExtension.RSV1,
compressedFirstPayload);
ContinuationWebSocketFrame finalPart = new ContinuationWebSocketFrame(true, WebSocketExtension.RSV1,
final ContinuationWebSocketFrame finalPart = new ContinuationWebSocketFrame(true, WebSocketExtension.RSV1,
compressedFinalPayload);
assertTrue(decoderChannel.writeInbound(firstPart));
@ -304,7 +310,12 @@ public class PerMessageDeflateDecoderTest {
//final part throwing exception
try {
decoderChannel.writeInbound(finalPart);
assertThrows(DecoderException.class, new Executable() {
@Override
public void execute() {
decoderChannel.writeInbound(finalPart);
}
});
} finally {
assertTrue(finalPart.release());
assertFalse(encoderChannel.finishAndReleaseAll());

View File

@ -28,7 +28,8 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
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.WebSocketExtensionFilter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Arrays;
import java.util.Random;
@ -36,7 +37,12 @@ import java.util.Random;
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.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 {
@ -236,7 +242,7 @@ public class PerMessageDeflateEncoderTest {
assertFalse(decoderChannel.finish());
}
@Test(expected = EncoderException.class)
@Test
public void testIllegalStateWhenCompressionInProgress() {
WebSocketExtensionFilter selectivityCompressionFilter = new WebSocketExtensionFilter() {
@Override
@ -244,7 +250,7 @@ public class PerMessageDeflateEncoderTest {
return frame.content().readableBytes() < 100;
}
};
EmbeddedChannel encoderChannel = new EmbeddedChannel(
final EmbeddedChannel encoderChannel = new EmbeddedChannel(
new PerMessageDeflateEncoder(9, 15, false, selectivityCompressionFilter));
byte[] firstPayload = new byte[200];
@ -254,7 +260,7 @@ public class PerMessageDeflateEncoderTest {
random.nextBytes(finalPayload);
BinaryWebSocketFrame firstPart = new BinaryWebSocketFrame(false, 0, Unpooled.wrappedBuffer(firstPayload));
ContinuationWebSocketFrame finalPart = new ContinuationWebSocketFrame(true, 0,
final ContinuationWebSocketFrame finalPart = new ContinuationWebSocketFrame(true, 0,
Unpooled.wrappedBuffer(finalPayload));
assertTrue(encoderChannel.writeOutbound(firstPart));
@ -266,7 +272,12 @@ public class PerMessageDeflateEncoderTest {
//final part throwing exception
try {
encoderChannel.writeOutbound(finalPart);
assertThrows(EncoderException.class, new Executable() {
@Override
public void execute() throws Throwable {
encoderChannel.writeOutbound(finalPart);
}
});
} finally {
assertTrue(finalPart.release());
assertFalse(encoderChannel.finishAndReleaseAll());
@ -290,14 +301,19 @@ public class PerMessageDeflateEncoderTest {
assertFalse(encoderChannel.finish());
}
@Test(expected = EncoderException.class)
@Test
public void testCodecExceptionForNotFinEmptyFrame() {
EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false));
final EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false));
TextWebSocketFrame emptyNotFinFrame = new TextWebSocketFrame(false, 0, "");
final TextWebSocketFrame emptyNotFinFrame = new TextWebSocketFrame(false, 0, "");
try {
encoderChannel.writeOutbound(emptyNotFinFrame);
assertThrows(EncoderException.class, new Executable() {
@Override
public void execute() {
encoderChannel.writeOutbound(emptyNotFinFrame);
}
});
} finally {
// EmptyByteBuf buffer
assertFalse(emptyNotFinFrame.release());

View File

@ -17,7 +17,11 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
import static io.netty.handler.codec.http.websocketx.extensions.compression.
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.WebSocketExtensionData;
@ -25,7 +29,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class PerMessageDeflateServerExtensionHandshakerTest {

View File

@ -25,12 +25,16 @@ import io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensio
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static io.netty.handler.codec.http.websocketx.extensions.compression.
PerMessageDeflateServerExtensionHandshaker.*;
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 {
@ -48,10 +52,10 @@ public class WebSocketServerCompressionHandlerTest {
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
Assert.assertTrue(exts.get(0).parameters().isEmpty());
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
assertTrue(exts.get(0).parameters().isEmpty());
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -69,10 +73,10 @@ public class WebSocketServerCompressionHandlerTest {
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
Assert.assertEquals("10", exts.get(0).parameters().get(CLIENT_MAX_WINDOW));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
assertEquals("10", exts.get(0).parameters().get(CLIENT_MAX_WINDOW));
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -90,10 +94,10 @@ public class WebSocketServerCompressionHandlerTest {
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
Assert.assertTrue(exts.get(0).parameters().isEmpty());
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
assertTrue(exts.get(0).parameters().isEmpty());
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -111,10 +115,10 @@ public class WebSocketServerCompressionHandlerTest {
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
Assert.assertEquals("10", exts.get(0).parameters().get(SERVER_MAX_WINDOW));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
assertEquals("10", exts.get(0).parameters().get(SERVER_MAX_WINDOW));
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -130,9 +134,9 @@ public class WebSocketServerCompressionHandlerTest {
HttpResponse res2 = ch.readOutbound();
Assert.assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -147,9 +151,9 @@ public class WebSocketServerCompressionHandlerTest {
HttpResponse res2 = ch.readOutbound();
Assert.assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
assertNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -166,10 +170,10 @@ public class WebSocketServerCompressionHandlerTest {
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
Assert.assertTrue(exts.get(0).parameters().isEmpty());
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
assertTrue(exts.get(0).parameters().isEmpty());
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
@Test
@ -188,10 +192,10 @@ public class WebSocketServerCompressionHandlerTest {
List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(
res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
Assert.assertTrue(exts.get(0).parameters().isEmpty());
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
Assert.assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
assertTrue(exts.get(0).parameters().isEmpty());
assertNotNull(ch.pipeline().get(PerMessageDeflateDecoder.class));
assertNotNull(ch.pipeline().get(PerMessageDeflateEncoder.class));
}
}