1 38 package com.gargoylesoftware.htmlunit.jelly; 39 40 import org.apache.commons.jelly.JellyTagException; 41 import org.apache.commons.jelly.XMLOutput; 42 43 49 public class AssertStatusCodeTag extends HtmlUnitTagSupport { 50 private String code_; 51 52 57 public void doTag(final XMLOutput xmlOutput) throws JellyTagException { 58 invokeBody(xmlOutput); 59 final int expectedStatusCode; 60 try { 61 expectedStatusCode = Integer.parseInt(code_); 62 } 63 catch( final NumberFormatException e ) { 64 throw new JellyTagException("Invalid value for code: "+code_); 65 } 66 final int actualStatusCode = getHtmlPage().getWebResponse().getStatusCode(); 67 68 if( actualStatusCode != expectedStatusCode ) { 69 throw new JellyTagException("Expected status code "+expectedStatusCode 70 +" but got "+actualStatusCode+" instead"); 71 } 72 } 73 74 75 79 public void setCode( final String code ) { 80 code_ = code; 81 } 82 } 83 84 | Popular Tags |