KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > latka > validators > StatusTextValidator


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.latka.validators;
18
19 import org.apache.commons.latka.ValidationException;
20
21 import org.apache.commons.latka.http.Response;
22
23 /**
24  * Validates a Response according to its HTTP status text
25  * (the text portion of the status line, eg typically
26  * 'OK' for 200 responses). The status text is not
27  * strictly standardizes the way status codes are; in most
28  * cases, you are better off checking just the
29  * status code.
30  *
31  * @author Morgan Delagrange
32  * @author dIon Gillard
33  * @version $Id: StatusTextValidator.java 155424 2005-02-26 13:09:29Z dirkv $
34  */

35 public class StatusTextValidator extends BaseValidator {
36
37     // --------------------------------------------------------------- Attributes
38

39     protected String JavaDoc _statusText = null;
40
41     // ------------------------------------------------------------- Constructors
42

43     public StatusTextValidator() {
44         this(null,null);
45     }
46
47     public StatusTextValidator(String JavaDoc label, String JavaDoc text) {
48         super(label);
49         _statusText = text;
50     }
51
52     // ------------------------------------------------------------------ Methods
53

54     public void setStatusText(String JavaDoc text) {
55         _statusText = text;
56     }
57
58     public void validate(Response response)
59     throws ValidationException {
60
61         String JavaDoc responseStatusText = response.getStatusText();
62         if (!_statusText.equals(responseStatusText)) {
63             fail("EXPECTED STATUS TEXT '" + _statusText + "', FOUND '" + responseStatusText +
64                  "'");
65         }
66     }
67 }
68
Popular Tags