diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/AbstractJettyTestCase.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/AbstractJettyTestCase.java index b6246ce9125..900aa7cf544 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/AbstractJettyTestCase.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/AbstractJettyTestCase.java @@ -95,34 +95,4 @@ 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; - } - - StringBuffer ret = new StringBuffer(); - for (char c : str.toCharArray()) - { - switch (c) - { - case '\n': - ret.append("\r\n"); - break; - default: - ret.append(c); - } - } - - return ret.toString(); - } } diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java index 88012c45fbc..0906e7835f0 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DefaultHandlerTest.java @@ -78,8 +78,9 @@ public class DefaultHandlerTest extends AbstractJettyTestCase InputStream in = conn.getInputStream(); String response = IO.toString(in); + String expected = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; - assertEquals("Response",toSystemLN("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"),response); + assertEquals("Response",expected,response); } @Test diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java index c8787a784c4..5d65fe87cce 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java @@ -47,6 +47,7 @@ import org.junit.Test; */ public abstract class RFC2616BaseTest extends AbstractJettyTestCase { + private static final String ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; /** STRICT RFC TESTS */ private static final boolean STRICT = false; private List responses; @@ -1135,7 +1136,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase response = http.request(req1); response.assertStatusOK(); - response.assertBody("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); + response.assertBody(ALPHA); } private void assertBadContentRange(String rangedef) throws IOException @@ -1251,7 +1252,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase @Test public void test14_16_PartialRange() throws Exception { - String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + String alpha = ALPHA; // server should not return a 416 if at least one syntactically valid ranges // are is satisfiable @@ -1271,7 +1272,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase @Test public void test14_16_PartialRange_MixedRanges() throws Exception { - String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + String alpha = ALPHA; // server should not return a 416 if at least one syntactically valid ranges // are is satisfiable @@ -1313,7 +1314,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase @Test public void test14_16_PartialRange_MixedBytes() throws Exception { - String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + String alpha = ALPHA; // server should not return a 416 if at least one syntactically valid ranges // are is satisfiable @@ -1352,7 +1353,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase @Test public void test14_16_PartialRange_MixedMultiple() throws Exception { - String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + String alpha = ALPHA; // server should not return a 416 if at least one syntactically valid ranges // are is satisfiable @@ -1506,7 +1507,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase // tested yet // - String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + String alpha = ALPHA; // First 3 bytes assertByteRange("bytes=0-2","0-2/27",alpha.substring(0,2 + 1)); @@ -1661,7 +1662,7 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase // tested yet // - String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; + String alpha = ALPHA; // server should not return a 416 if at least one syntactically valid ranges // are is satisfiable diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/StringUtil.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/StringUtil.java index 55f0eaa7ed9..6c34557e086 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/StringUtil.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/StringUtil.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.test.support; public class StringUtil { + public static final String LN = System.getProperty("line.separator"); + public static boolean isBlank(String str) { if (str == null) @@ -101,4 +103,38 @@ public class StringUtil return ret; } + + /** + * Utility method to convert "\n" found to "\r\n" if running on windows. + * + * @param str + * input string. + * @return + */ + public static String toSystemLN(String str) + { + boolean linesep = false; + StringBuffer ret = new StringBuffer(); + for (char c : str.toCharArray()) + { + switch (c) + { + case '\r': + linesep = true; + break; + case '\n': + linesep = true; + break; + default: + if (linesep) + { + ret.append(LN); + linesep = false; + } + ret.append(c); + } + } + + return ret.toString(); + } } diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTester.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTester.java index a7b97d030e8..07deaf00287 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTester.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTester.java @@ -41,8 +41,6 @@ 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 @@ -344,45 +342,17 @@ public class HttpResponseTester public void assertBody(String expected) { Assert.assertNotNull("Response.content should not be null",this.content); - Assert.assertEquals("Response.content",toSystemLN(expected),this.content.toString()); + String actual = this.content.toString(); + Assert.assertEquals("Response.content",expected,actual); } public void assertBody(String msg, String expected) { Assert.assertNotNull(msg + ": Response.content should not be null",this.content); - Assert.assertEquals(msg + ": Response.content",toSystemLN(expected),this.content.toString()); + String actual = this.content.toString(); + Assert.assertEquals(msg + ": Response.content",expected,actual); } - /** - * 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; - } - - StringBuffer ret = new StringBuffer(); - for (char c : str.toCharArray()) - { - switch (c) - { - case '\n': - ret.append("\r\n"); - break; - default: - ret.append(c); - } - } - - return ret.toString(); - } - public void assertNoBody(String msg) { Assert.assertNull(msg + ": Response.content should be null",this.content); diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTesterTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTesterTest.java index 91018005b97..f06bd70ca88 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTesterTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/rawhttp/HttpResponseTesterTest.java @@ -52,7 +52,9 @@ public class HttpResponseTesterTest extends AbstractJettyTestCase assertEquals("Response[Content-Length]",28,response.getLongHeader("Content-Length")); assertEquals("Response[Connection]","close",response.getHeader("Connection")); - assertEquals("Response.content",toSystemLN("ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n"),response.getContent().toString()); + String expected = "ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n"; + + assertEquals("Response.content",expected,response.getContent().toString()); } @Test