Fixing surefire breaking HttpManyWayToCommitTest
+ Reverting change to HttpTester.parseResponse(Input) + Providing new HttpTester.parsePartialResponse(Input) + InsufficientBytes tests no longer assert content strings with invalid characters (this was breaks the surefire report xml)
This commit is contained in:
parent
247d273e94
commit
472a40806e
|
@ -25,7 +25,6 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
@ -217,7 +216,17 @@ public class HttpTester
|
|||
}
|
||||
|
||||
public static Response parseResponse(Input in) throws IOException
|
||||
{
|
||||
{
|
||||
return parseResponse(in, false);
|
||||
}
|
||||
|
||||
public static Response parsePartialResponse(Input in) throws IOException
|
||||
{
|
||||
return parseResponse(in, true);
|
||||
}
|
||||
|
||||
private static Response parseResponse(Input in, boolean allowIncomplete) throws IOException
|
||||
{
|
||||
Response r;
|
||||
HttpParser parser=in.takeHttpParser();
|
||||
if (parser==null)
|
||||
|
@ -246,13 +255,9 @@ public class HttpTester
|
|||
}
|
||||
}
|
||||
|
||||
if (r.isComplete())
|
||||
if (allowIncomplete || r.isComplete())
|
||||
return r;
|
||||
|
||||
String te = r.get(HttpHeader.TRANSFER_ENCODING);
|
||||
if(te != null && te.toLowerCase(Locale.ENGLISH).contains("chunked"))
|
||||
return r;
|
||||
|
||||
LOG.info("Incomplete Response: (parser={}) {}", parser, r);
|
||||
|
||||
in.setHttpParser(parser);
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.eclipse.jetty.http;
|
|||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -30,14 +30,11 @@ import java.net.Socket;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpTesterTest
|
||||
{
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testExampleUsage() throws Exception
|
||||
{
|
||||
try(Socket socket = new Socket("www.google.com",80))
|
||||
|
@ -59,10 +56,8 @@ public class HttpTesterTest
|
|||
System.err.printf("%s: %s%n",field.getName(),field.getValue());
|
||||
System.err.printf("%n%s%n",response.getContent());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetRequestBuffer10()
|
||||
{
|
||||
|
|
|
@ -93,7 +93,7 @@ public abstract class AbstractHttpTest
|
|||
writer.flush();
|
||||
|
||||
HttpTester.Input input = HttpTester.from(socket.getInputStream());
|
||||
HttpTester.Response response = HttpTester.parseResponse(input);
|
||||
HttpTester.Response response = HttpTester.parsePartialResponse(input);
|
||||
if ("HTTP/1.1".equals(httpVersion)
|
||||
&& response.get("content-length") == null
|
||||
&& response.get("transfer-encoding") == null
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
|
@ -429,11 +429,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
|
|||
try
|
||||
{
|
||||
HttpTester.Response response = executeRequest();
|
||||
char badChar = (char) -1;
|
||||
String failed_body = "" + badChar + badChar + badChar;
|
||||
assertThat("response code", response.getStatus(), is(200));
|
||||
assertHeader(response, "content-length", "6");
|
||||
assertThat(response.getContent(), endsWith(failed_body));
|
||||
byte content[] = response.getContentBytes();
|
||||
assertThat("content bytes", content.length, is(6));
|
||||
String contentStr = new String(content, StandardCharsets.UTF_8);
|
||||
assertThat("content bytes as string", contentStr, is("foo"));
|
||||
}
|
||||
catch(EOFException e)
|
||||
{
|
||||
|
@ -450,11 +451,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
|
|||
try
|
||||
{
|
||||
HttpTester.Response response = executeRequest();
|
||||
char badChar = (char) -1;
|
||||
String failed_body = "" + badChar + badChar + badChar;
|
||||
assertThat("response code is 200", response.getStatus(), is(200));
|
||||
assertHeader(response, "content-length", "6");
|
||||
assertThat(response.getContent(), endsWith(failed_body));
|
||||
byte content[] = response.getContentBytes();
|
||||
assertThat("content bytes", content.length, is(3));
|
||||
String contentStr = new String(content, StandardCharsets.UTF_8);
|
||||
assertThat("content bytes as string", contentStr, is("foo"));
|
||||
}
|
||||
catch(EOFException e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue