|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
RequestDescriptor.java | 100% | 100% | 100% | 100% |
|
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;
|
|
18 |
import java.util.Collection;
|
|
19 |
import java.util.HashMap;
|
|
20 |
import java.util.Iterator;
|
|
21 |
import java.util.List;
|
|
22 |
import java.util.Map;
|
|
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 _servletName;
|
|
35 |
private String _servletPath;
|
|
36 |
|
|
37 |
/** Map, on name, to {@link org.apache.tapestry.test.ParameterList}. **/
|
|
38 |
private Map _parameters = new HashMap(); |
|
39 |
|
|
40 |
/** Map of {@link ResponseAssertion}. **/
|
|
41 |
private List _assertions = new ArrayList(); |
|
42 |
|
|
43 | 5 |
public void addAssertion(ResponseAssertion assertion) |
44 |
{ |
|
45 | 5 |
_assertions.add(assertion); |
46 |
} |
|
47 |
|
|
48 |
/**
|
|
49 |
* Invokes all assertions for the request.
|
|
50 |
*/
|
|
51 |
|
|
52 | 4 |
public void executeAssertions(ScriptedTestSession session) |
53 |
{ |
|
54 | 4 |
Iterator i = _assertions.iterator(); |
55 | 4 |
while (i.hasNext())
|
56 |
{ |
|
57 | 5 |
ResponseAssertion a = (ResponseAssertion) i.next(); |
58 |
|
|
59 | 5 |
a.execute(session); |
60 |
} |
|
61 |
} |
|
62 |
|
|
63 | 10 |
public void addParameter(String name, String value) |
64 |
{ |
|
65 | 10 |
ParameterList pl = (ParameterList) _parameters.get(name); |
66 | 10 |
if (pl == null) |
67 |
{ |
|
68 | 7 |
pl = new ParameterList();
|
69 | 7 |
_parameters.put(name, pl); |
70 |
} |
|
71 |
|
|
72 | 10 |
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 | 6 |
public String[] getParameterValues(String name)
|
82 |
{ |
|
83 | 6 |
ParameterList pl = (ParameterList) _parameters.get(name); |
84 |
|
|
85 | 6 |
if (pl == null) |
86 | 1 |
return null; |
87 |
|
|
88 | 5 |
return pl.getValues();
|
89 |
} |
|
90 |
|
|
91 | 6 |
public String getServletName()
|
92 |
{ |
|
93 | 6 |
return _servletName;
|
94 |
} |
|
95 |
|
|
96 | 8 |
public void setServletName(String string) |
97 |
{ |
|
98 | 8 |
_servletName = string; |
99 |
} |
|
100 |
|
|
101 | 2 |
public String getServletPath()
|
102 |
{ |
|
103 | 2 |
return _servletPath;
|
104 |
} |
|
105 |
|
|
106 | 7 |
public void setServletPath(String string) |
107 |
{ |
|
108 | 7 |
_servletPath = string; |
109 |
} |
|
110 |
|
|
111 |
/**
|
|
112 |
* Returns names of all parameters. Order is not determinate. May return empty (but not null).
|
|
113 |
*/
|
|
114 | 2 |
public String[] getParameterNames()
|
115 |
{ |
|
116 | 2 |
Collection c = _parameters.keySet(); |
117 |
|
|
118 | 2 |
return (String[]) c.toArray(new String[c.size()]); |
119 |
} |
|
120 |
|
|
121 |
} |
|
122 |
|
|