/** * Fetches the specified <code>page</code> from the local Jetty server and checks whether the HTTP * response status code matches with the expected code. * * @param page Page to be fetched. * @param expectedCode HTTP response status code expected while fetching the page. * @throws Exception When an error occurs or test case fails. */ private void fetchPage(String page, int expectedCode) throws Exception { URL url = new URL("http", "127.0.0.1", port, page); Response response = null; response = http.getResponse(url, WebPage.newBuilder().build(), true); int code = response.getCode(); assertEquals("HTTP Status Code for " + url, expectedCode, code); }
/** * Fetches the specified <code>page</code> from the local Jetty server and checks whether the HTTP * response status code matches with the expected code. Also use jsp pages for redirection. * * @param page Page to be fetched. * @param expectedCode HTTP response status code expected while fetching the page. */ private void fetchPage(String page, int expectedCode) throws Exception { URL url = new URL("http", "127.0.0.1", port, page); CrawlDatum crawlDatum = new CrawlDatum(); Response response = http.getResponse(url, crawlDatum, true); ProtocolOutput out = http.getProtocolOutput(new Text(url.toString()), crawlDatum); Content content = out.getContent(); assertEquals("HTTP Status Code for " + url, expectedCode, response.getCode()); if (page.compareTo("/nonexists.html") != 0 && page.compareTo("/brokenpage.jsp") != 0 && page.compareTo("/redirection") != 0) { assertEquals("ContentType " + url, "application/xhtml+xml", content.getContentType()); } }