Fixing test failures in RFC2616 section 9.4
* A timing issue was discovered in the test case (not a bug in jetty), added some code to filter out the "Date: " header as there can be a difference in that header between the GET and HEAD calls. git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@645 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
9904d89778
commit
37059788f3
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
|
@ -165,4 +167,24 @@ public class StringAssert
|
|||
throw new AssertionFailedError(buf.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the list of String lines contains the same lines (without a regard for the order of those lines)
|
||||
*
|
||||
* @param msg
|
||||
* the assertion message
|
||||
* @param linesExpected
|
||||
* the list of expected lines
|
||||
* @param linesActual
|
||||
* the list of actual lines
|
||||
*/
|
||||
public static void assertContainsSame(String msg, List<String> linesExpected, List<String> linesActual)
|
||||
{
|
||||
Assert.assertEquals(msg + " line count",linesExpected.size(),linesActual.size());
|
||||
|
||||
for (String expected : linesExpected)
|
||||
{
|
||||
Assert.assertTrue(msg + ": expecting to see line <" + expected + ">",linesActual.contains(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -862,7 +862,20 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase
|
|||
int headResponseLength = rawHeadResponse.length();
|
||||
// Only interested in the response header from the GET request above.
|
||||
String rawGetResponse = response.getRawResponse().toString().substring(0,headResponseLength);
|
||||
assertEquals("9.4 HEAD equals GET",rawHeadResponse,rawGetResponse);
|
||||
|
||||
// As there is a possibility that the time between GET and HEAD requests
|
||||
// can cross the second mark. (eg: GET at 11:00:00.999 and HEAD at 11:00:01.001)
|
||||
// So with that knowledge, we will remove the 'Date:' header from both sides before comparing.
|
||||
List<String> linesGet = StringUtil.asLines(rawGetResponse);
|
||||
List<String> linesHead = StringUtil.asLines(rawHeadResponse);
|
||||
|
||||
StringUtil.removeStartsWith("Date: ",linesGet);
|
||||
StringUtil.removeStartsWith("Date: ",linesHead);
|
||||
|
||||
// Compare the 2 lists of lines to make sure they contain the same information
|
||||
// Do not worry about order of the headers, as that's not important to test,
|
||||
// just the existence of the same headers
|
||||
StringAssert.assertContainsSame("9.4 HEAD equals GET",linesGet,linesHead);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -16,6 +16,15 @@
|
|||
|
||||
package org.eclipse.jetty.test.support;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
||||
public class StringUtil
|
||||
{
|
||||
public static final String LN = System.getProperty("line.separator");
|
||||
|
@ -137,4 +146,40 @@ public class StringUtil
|
|||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static List<String> asLines(String raw) throws IOException
|
||||
{
|
||||
List<String> lines = new ArrayList<String>();
|
||||
StringReader sreader = null;
|
||||
BufferedReader buf = null;
|
||||
try
|
||||
{
|
||||
sreader = new StringReader(raw);
|
||||
buf = new BufferedReader(sreader);
|
||||
String line;
|
||||
while ((line = buf.readLine()) != null)
|
||||
{
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
IO.close(buf);
|
||||
IO.close(sreader);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static void removeStartsWith(String prefix, List<String> lines)
|
||||
{
|
||||
ListIterator<String> it = lines.listIterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
String line = it.next();
|
||||
if (line.startsWith(prefix))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue