/** * This test should only be run after the Servlet container for the UWS service * has been restarted. It expects that the UWS service has no Jobs. */ @Test public void testForbidden() { log.debug("testForbidden"); try { // Request the UWS service. WebConversation conversation = new WebConversation(); WebResponse response = get(conversation, serviceUrl); int code = response.getResponseCode(); Assert.assertEquals(403, code); } catch(HttpException expected) { log.debug("caught expected exception: " + expected); Assert.assertEquals(403, expected.getResponseCode()); } catch (Exception unexpected) { log.error("unexpected exception", unexpected); Assert.fail("unexpected exception: " + unexpected); } }
assertEquals(responseCode.intValue(), ex.getResponseCode());
/** * Here we expect an errorCode other than 200, and look for it checking for * text is omitted as it doesnt work. It would never work on java1.3, but * one may have expected java1.4+ to have access to the error stream in * responses. Clearly not. * * @param request * @param errorCode * @param errorText optional text string to search for * @throws MalformedURLException * @throws IOException * @throws SAXException */ protected void expectErrorCode(WebRequest request, int errorCode, String errorText) throws MalformedURLException, IOException, SAXException { String failureText = "Expected error " + errorCode + " from " + request.getURL(); try { newClient().getResponse(request); fail(errorText + " -got success instead"); } catch (HttpException e) { assertEquals(failureText, errorCode, e.getResponseCode()); /* * checking for text omitted as it doesnt work. if(errorText!=null) { * assertTrue( "Failed to find "+errorText+" in "+ * e.getResponseMessage(), e.getMessage().indexOf(errorText)>=0); } */ } } }
assertEquals(failureText, errorCode, e.getResponseCode());
/** * Here we expect an errorCode other than 200, and look for it checking for * text is omitted as it doesnt work. It would never work on java1.3, but * one may have expected java1.4+ to have access to the error stream in * responses. Clearly not. * * @param request * @param errorCode * @param errorText optional text string to search for * @throws MalformedURLException * @throws IOException * @throws SAXException */ protected void expectErrorCode(WebRequest request, int errorCode, String errorText) throws MalformedURLException, IOException, SAXException { String failureText = "Expected error " + errorCode + " from " + request.getURL(); try { newClient().getResponse(request); fail(errorText + " -got success instead"); } catch (HttpException e) { assertEquals(failureText, errorCode, e.getResponseCode()); /* * checking for text omitted as it doesnt work. if(errorText!=null) { * assertTrue( "Failed to find "+errorText+" in "+ * e.getResponseMessage(), e.getMessage().indexOf(errorText)>=0); } */ } } }