1 16 17 package org.apache.commons.latka.validators; 18 19 import org.apache.commons.latka.Validator; 20 import org.apache.commons.latka.ValidationException; 21 22 import org.apache.commons.latka.http.Response; 23 24 import java.text.MessageFormat ; 25 26 37 public class StatusCodeValidator extends BaseValidator implements Validator { 38 39 41 protected static final MessageFormat MESSAGE = new MessageFormat ("Expected status code \"{0,number,000}\". Found \"{1,number,000}\"."); 42 protected int _statusCode = 200; 43 44 46 public StatusCodeValidator() { 47 this(null,200); 48 } 49 50 public StatusCodeValidator(int code) { 51 this(null,code); 52 } 53 54 public StatusCodeValidator(String label) { 55 this(label,200); 56 } 57 58 public StatusCodeValidator(String label, int code) { 59 super(label); 60 _statusCode = code; 61 } 62 63 65 public void setStatusCode(int statusCode) { 66 _statusCode = statusCode; 67 } 68 69 public void validate(Response response) 70 throws ValidationException { 71 72 int responseStatusCode = response.getStatusCode(); 73 74 if (_statusCode != responseStatusCode) { 75 fail(MESSAGE.format(new Object [] { new Integer (_statusCode), new Integer (responseStatusCode) }).toString()); 76 } 77 } 78 } 79 | Popular Tags |