Skip to content

Commit

Permalink
Test for XmlPage detection (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 9, 2023
1 parent e94e0cc commit 1a55c4f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/java/org/htmlunit/DefaultPageCreatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,60 @@ protected void doGet(final HttpServletRequest request, final HttpServletResponse
}
}

/**
* @throws Exception if the test fails
*/
@Test
public void noContentTypeXml() throws Exception {
final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
servlets.put("/test", NoContentTypeXmlServlet.class);
startWebServer("./", null, servlets);

final WebClient client = getWebClient();
final XmlPage page = client.getPage(URL_FIRST + "test");
assertNotNull(page);
}

/**
* Servlet for {@link #noContentTypeLargeXmlHeader()}.
*/
public static class NoContentTypeXmlServlet extends HttpServlet {
/** {@inheritDoc} */
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
final Writer writer = response.getWriter();
writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"
+ "<root>Hello World</root>");
}
}

/**
* @throws Exception if the test fails
*/
@Test
public void noContentTypeXmlLeadingBlank() throws Exception {
final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
servlets.put("/test", NoContentTypeXmlLeadingBlankServlet.class);
startWebServer("./", null, servlets);

final WebClient client = getWebClient();
final XmlPage page = client.getPage(URL_FIRST + "test");
assertNotNull(page);
}

/**
* Servlet for {@link #noContentTypeLargeXmlHeader()}.
*/
public static class NoContentTypeXmlLeadingBlankServlet extends HttpServlet {
/** {@inheritDoc} */
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
final Writer writer = response.getWriter();
writer.write(" <?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
+ "<root>Hello World</root>");
}
}

/**
* @throws Exception if the test fails
*/
Expand Down

0 comments on commit 1a55c4f

Please sign in to comment.