KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > httpunit > HttpTestEntryStep


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.httpunit;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28
29 /**
30  */

31 public final class HttpTestEntryStep {
32     static final String JavaDoc POST = "post";
33     static final String JavaDoc GET = "get";
34     
35     private String JavaDoc name;
36     private boolean isPost;
37     private String JavaDoc url;
38     private int expectedCode = 200;
39     private String JavaDoc redirectUrl;
40     private final Map JavaDoc<String JavaDoc, String JavaDoc> parameters;
41     private final Set JavaDoc<String JavaDoc> errors;
42     private final Set JavaDoc<String JavaDoc> messages;
43     
44     /**
45      */

46     public HttpTestEntryStep() {
47         parameters = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
48         messages = new HashSet JavaDoc<String JavaDoc>();
49         errors = new HashSet JavaDoc<String JavaDoc>();
50     }
51     
52     /**
53      * @return String
54      */

55     String JavaDoc getName() {
56         return name;
57     }
58
59     /**
60      * @param name
61      */

62     public void setName(String JavaDoc name) {
63         this.name = name;
64     }
65     
66     /**
67      * @return boolean
68      */

69     boolean isPost() {
70         return isPost;
71     }
72
73     /**
74      * @param method
75      */

76     public void setMethod(String JavaDoc method) {
77         isPost = method == null || method.equals(GET) ? false : true;
78     }
79
80     /**
81      * @return String
82      */

83     String JavaDoc getUrl() {
84         return url;
85     }
86
87     /**
88      * @param url
89      */

90     public void setUrl(String JavaDoc url) {
91         this.url = url;
92     }
93
94     /**
95      * @return int
96      */

97     int getExpectedCode() {
98         return expectedCode;
99     }
100
101     /**
102      * @param expectedCode
103      */

104     public void setExpectedCode(int expectedCode) {
105         this.expectedCode = expectedCode;
106     }
107
108     /**
109      * @return String
110      */

111     public String JavaDoc getRedirectUrl() {
112         return redirectUrl;
113     }
114
115     /**
116      * @param redirectUrl
117      */

118     public void setRedirectUrl(String JavaDoc redirectUrl) {
119         this.redirectUrl = redirectUrl;
120     }
121
122     /**
123      * @return Map<String, String>
124      */

125     Map JavaDoc<String JavaDoc, String JavaDoc> getParameters() {
126         return Collections.unmodifiableMap(parameters);
127     }
128     
129     /**
130      * @param parameter
131      */

132     public void addParameter(Parameter parameter) {
133         parameters.put(parameter.getKey(), parameter.getValue());
134     }
135     /**
136      * @return Collection<String>
137      */

138     Collection JavaDoc<String JavaDoc> getErrors() {
139         return Collections.unmodifiableSet(errors);
140     }
141
142     /**
143      * @param message
144      */

145     public void addError(Value message) {
146         String JavaDoc realMessage = message.getValue();
147         if (realMessage != null)
148             errors.add(realMessage);
149     }
150
151     /**
152      * @return Collection<String>
153      */

154     Collection JavaDoc<String JavaDoc> getMessages() {
155         return Collections.unmodifiableSet(messages);
156     }
157
158     /**
159      * @param message
160      */

161     public void addMessage(Value message) {
162         String JavaDoc realMessage = message.getValue();
163         if (realMessage != null)
164             messages.add(realMessage);
165     }
166     
167     @Override JavaDoc
168     public String JavaDoc toString() {
169         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
170         buffer.append("Name='").append(name).append("' ");
171         buffer.append("IsPort='").append(isPost).append("' ");
172         buffer.append("Url='").append(url).append("' ");
173         buffer.append("ExpectedCode='").append(expectedCode).append("' ");
174         buffer.append("RedirectUrl='").append(redirectUrl).append("' ");
175         buffer.append("Parameters='").append(parameters).append("' ");
176         buffer.append("Errors='").append(errors).append("' ");
177         buffer.append("Messages='").append(messages).append("'");
178         return buffer.toString();
179     }
180     
181     /**
182      */

183     public static final class Value {
184
185         private String JavaDoc value;
186         
187         /**
188          * @return String
189          */

190         private String JavaDoc getValue() {
191             return value;
192         }
193         
194         /**
195          * @param value
196          */

197         public void setValue(String JavaDoc value) {
198             this.value = value;
199         }
200     }
201     
202     /**
203      */

204     public static final class Parameter {
205         private String JavaDoc key;
206         private String JavaDoc value;
207         
208         private String JavaDoc getKey() {
209             return key;
210         }
211         
212         /**
213          * @param key
214          */

215         public void setKey(String JavaDoc key) {
216             this.key = key;
217         }
218         
219         /**
220          * @return String
221          */

222         private String JavaDoc getValue() {
223             return value;
224         }
225         
226         /**
227          * @param value
228          */

229         public void setValue(String JavaDoc value) {
230             this.value = value;
231         }
232     }
233 }
Popular Tags