KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > test > RequestDescriptor


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

15 package org.apache.tapestry.test;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.hivemind.impl.BaseLocatable;
25
26 /**
27  *
28  *
29  * @author Howard Lewis Ship
30  * @since 4.0
31  */

32 public class RequestDescriptor extends BaseLocatable
33 {
34     private String JavaDoc _servletName;
35     private String JavaDoc _servletPath;
36
37     /** Map, on name, to {@link org.apache.tapestry.test.ParameterList}. **/
38     private Map JavaDoc _parameters = new HashMap JavaDoc();
39
40     /** Map of {@link ResponseAssertion}. **/
41     private List JavaDoc _assertions = new ArrayList JavaDoc();
42
43     public void addAssertion(ResponseAssertion assertion)
44     {
45         _assertions.add(assertion);
46     }
47
48     /**
49      * Invokes all assertions for the request.
50      */

51
52     public void executeAssertions(ScriptedTestSession session)
53     {
54         Iterator JavaDoc i = _assertions.iterator();
55         while (i.hasNext())
56         {
57             ResponseAssertion a = (ResponseAssertion) i.next();
58
59             a.execute(session);
60         }
61     }
62
63     public void addParameter(String JavaDoc name, String JavaDoc value)
64     {
65         ParameterList pl = (ParameterList) _parameters.get(name);
66         if (pl == null)
67         {
68             pl = new ParameterList();
69             _parameters.put(name, pl);
70         }
71
72         pl.add(value);
73     }
74
75     /**
76      * Returns the values for the given parameter name.
77      *
78      * @return array of strings, or null if no values have been recorded for
79      * the given name
80      */

81     public String JavaDoc[] getParameterValues(String JavaDoc name)
82     {
83         ParameterList pl = (ParameterList) _parameters.get(name);
84
85         if (pl == null)
86             return null;
87
88         return pl.getValues();
89     }
90
91     public String JavaDoc getServletName()
92     {
93         return _servletName;
94     }
95
96     public void setServletName(String JavaDoc string)
97     {
98         _servletName = string;
99     }
100
101     public String JavaDoc getServletPath()
102     {
103         return _servletPath;
104     }
105
106     public void setServletPath(String JavaDoc string)
107     {
108         _servletPath = string;
109     }
110
111     /**
112      * Returns names of all parameters. Order is not determinate. May return empty (but not null).
113      */

114     public String JavaDoc[] getParameterNames()
115     {
116         Collection JavaDoc c = _parameters.keySet();
117
118         return (String JavaDoc[]) c.toArray(new String JavaDoc[c.size()]);
119     }
120
121 }
122
Popular Tags