/** * Verify that the server rejects an attempt to load the given page. * @param url a URL path (relative to Jenkins root) * @param statusCode the expected failure code (such as {@link HttpURLConnection#HTTP_FORBIDDEN}) * @since 1.504 */ public void assertFails(String url, int statusCode) throws Exception { assert !url.startsWith("/"); boolean currentConfiguration = isThrowExceptionOnFailingStatusCode(); // enforce the throwing of exception for the catch scope only setThrowExceptionOnFailingStatusCode(true); try { fail(url + " should have been rejected but produced: " + super.getPage(getContextPath() + url).getWebResponse().getContentAsString()); } catch (FailingHttpStatusCodeException x) { assertEquals(statusCode, x.getStatusCode()); } finally { setThrowExceptionOnFailingStatusCode(currentConfiguration); } }