[BUG 283172] fix build on windows

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@543 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2009-07-10 21:50:22 +00:00
parent b8d470dedb
commit ebb3c4966c
3 changed files with 49 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import org.eclipse.jetty.server.Server;
public abstract class AbstractJettyTestCase extends TestCase
{
public static final boolean IS_ON_WINDOWS = System.getProperty("os.name").startsWith("Windows");
private File baseDir;
public File getBaseDir()
@ -87,4 +88,21 @@ public abstract class AbstractJettyTestCase extends TestCase
throw new AssertionFailedError("No valid connector port found.");
}
/**
* Utility method to convert "\n" found to "\r\n" if running on windows.
*
* @param str
* input string.
* @return
*/
public String toSystemLN(String str)
{
if (!IS_ON_WINDOWS)
{
return str;
}
return str.replaceAll("\n","\r\n");
}
}

View File

@ -45,6 +45,7 @@ public class DefaultHandlerTest extends AbstractJettyTestCase
private TestableJettyServer server;
private int serverPort;
@Override
@Before
public void setUp() throws Exception
{
@ -59,6 +60,7 @@ public class DefaultHandlerTest extends AbstractJettyTestCase
serverPort = server.getServerPort();
}
@Override
@After
public void tearDown() throws Exception
{
@ -76,7 +78,8 @@ public class DefaultHandlerTest extends AbstractJettyTestCase
InputStream in = conn.getInputStream();
String response = IO.toString(in);
assertEquals("Response","ABCDEFGHIJKLMNOPQRSTUVWXYZ\n",response);
assertEquals("Response",toSystemLN("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"),response);
}
@Test

View File

@ -41,8 +41,11 @@ import org.eclipse.jetty.util.ByteArrayOutputStream2;
*/
public class HttpResponseTester
{
private static final boolean IS_ON_WINDOWS = System.getProperty("os.name").startsWith("Windows");
private class PH extends HttpParser.EventHandler
{
@Override
public void content(Buffer ref) throws IOException
{
if (content == null)
@ -50,6 +53,7 @@ public class HttpResponseTester
content.write(ref.asArray());
}
@Override
public void headerComplete() throws IOException
{
contentType = fields.get(HttpHeaders.CONTENT_TYPE_BUFFER);
@ -63,15 +67,18 @@ public class HttpResponseTester
}
}
@Override
public void messageComplete(long contextLength) throws IOException
{
}
@Override
public void parsedHeader(Buffer name, Buffer value) throws IOException
{
fields.add(name,value);
}
@Override
public void startRequest(Buffer method, Buffer url, Buffer version) throws IOException
{
reset();
@ -80,6 +87,7 @@ public class HttpResponseTester
HttpResponseTester.this.version = getString(version);
}
@Override
public void startResponse(Buffer version, int status, Buffer reason) throws IOException
{
reset();
@ -336,13 +344,30 @@ public class HttpResponseTester
public void assertBody(String expected)
{
Assert.assertNotNull("Response.content should not be null",this.content);
Assert.assertEquals("Response.content",expected,this.content.toString());
Assert.assertEquals("Response.content",toSystemLN(expected),this.content.toString());
}
public void assertBody(String msg, String expected)
{
Assert.assertNotNull(msg + ": Response.content should not be null",this.content);
Assert.assertEquals(msg + ": Response.content",expected,this.content.toString());
Assert.assertEquals(msg + ": Response.content",toSystemLN(expected),this.content.toString());
}
/**
* Utility method to convert "\n" found to "\r\n" if running on windows.
*
* @param str
* input string.
* @return
*/
public String toSystemLN(String str)
{
if (!IS_ON_WINDOWS)
{
return str;
}
return str.replaceAll("\n","\r\n");
}
public void assertNoBody(String msg)