001 /*
002 * Copyright 1999-2002,2004 The Apache Software Foundation.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.apache.commons.latka.validators;
018
019 import org.apache.commons.latka.ValidationException;
020
021 import org.apache.commons.latka.http.Response;
022
023 /**
024 * Validates a Response according to its HTTP status text
025 * (the text portion of the status line, eg typically
026 * 'OK' for 200 responses). The status text is not
027 * strictly standardizes the way status codes are; in most
028 * cases, you are better off checking just the
029 * status code.
030 *
031 * @author Morgan Delagrange
032 * @author dIon Gillard
033 * @version $Id: StatusTextValidator.java 155424 2005-02-26 13:09:29Z dirkv $
034 */
035 public class StatusTextValidator extends BaseValidator {
036
037 // --------------------------------------------------------------- Attributes
038
039 protected String _statusText = null;
040
041 // ------------------------------------------------------------- Constructors
042
043 public StatusTextValidator() {
044 this(null,null);
045 }
046
047 public StatusTextValidator(String label, String text) {
048 super(label);
049 _statusText = text;
050 }
051
052 // ------------------------------------------------------------------ Methods
053
054 public void setStatusText(String text) {
055 _statusText = text;
056 }
057
058 public void validate(Response response)
059 throws ValidationException {
060
061 String responseStatusText = response.getStatusText();
062 if (!_statusText.equals(responseStatusText)) {
063 fail("EXPECTED STATUS TEXT '" + _statusText + "', FOUND '" + responseStatusText +
064 "'");
065 }
066 }
067 }