diff options
Diffstat (limited to 'container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ErrorResponseContentCreatorTest.java')
-rw-r--r-- | container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ErrorResponseContentCreatorTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ErrorResponseContentCreatorTest.java b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ErrorResponseContentCreatorTest.java new file mode 100644 index 00000000000..d66f22801f7 --- /dev/null +++ b/container-core/src/test/java/com/yahoo/jdisc/http/server/jetty/ErrorResponseContentCreatorTest.java @@ -0,0 +1,44 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc.http.server.jetty; + + +import org.junit.Test; + +import javax.servlet.http.HttpServletResponse; +import java.nio.charset.StandardCharsets; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + + +/** + * @author bjorncs + */ +public class ErrorResponseContentCreatorTest { + + @Test + public void response_content_matches_expected_string() { + String expectedHtml = + "<html>\n" + + "<head>\n" + + "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n" + + "<title>Error 200</title>\n" + + "</head>\n" + + "<body>\n" + + "<h2>HTTP ERROR: 200</h2>\n" + + "<p>Problem accessing http://foo.bar. Reason:\n" + + "<pre> My custom error message</pre></p>\n" + + "<hr/>\n" + + "</body>\n" + + "</html>\n"; + + ErrorResponseContentCreator c = new ErrorResponseContentCreator(); + byte[] rawContent = c.createErrorContent( + "http://foo.bar", + HttpServletResponse.SC_OK, + Optional.of("My custom error message")); + String actualHtml = new String(rawContent, StandardCharsets.ISO_8859_1); + assertEquals(expectedHtml, actualHtml); + } + +} |