source: trunk/autoquest-plugin-php/src/main/java/de/ugoe/cs/autoquest/plugin/php/eventcore/WebRequest.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
  • Property svn:mime-type set to text/plain
File size: 4.6 KB
Line 
1package de.ugoe.cs.autoquest.plugin.php.eventcore;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import de.ugoe.cs.autoquest.IReplayDecorator;
7import de.ugoe.cs.autoquest.eventcore.IReplayable;
8
9/**
10 * <p>
11 * Contains all information related to a web request, i.e., the path, the POST variables and the GET
12 * variables. The generated replay are for the command line tool {@code curl}. The requests do not
13 * contain correct values for the POST and GET request. Instead, only the parameters that are part
14 * of the requests are added and the values of the parameters are DATA_$PARAMNAME$_DATA, where
15 * $PARAMNAME$ is the upper case string of the parameter name. This allows test data generators to
16 * insert concrete values, as EventBench does not include a test data generator for web software.
17 * </p>
18 *
19 * @author Steffen Herbold
20 * @version 1.0
21 */
22public class WebRequest implements IReplayable {
23
24    /**
25     * <p>
26     * Id for object serialization.
27     * </p>
28     */
29    private static final long serialVersionUID = 1L;
30
31    /**
32     * <p>
33     * POST variables of the web request.
34     * </p>
35     */
36    List<String> postVars;
37
38    /**
39     * <p>
40     * GET variables of the web request.
41     * </p>
42     */
43    List<String> getVars;
44
45    /**
46     * <p>
47     * URI of the web request.
48     * </p>
49     */
50    String targetUri;
51
52    /**
53     * <p>
54     * URL of the server.
55     * </p>
56     */
57    String serverUrl;
58
59    /**
60     * <p>
61     * Constructor. Creates a new WebRequest.
62     * </p>
63     *
64     * @param uri
65     *            URI of the request
66     * @param postVars
67     *            POST variables of the request
68     * @param getVars
69     *            GET variables of the request
70     */
71    public WebRequest(String url, String uri, List<String> postVars, List<String> getVars) {
72        serverUrl = url;
73        targetUri = uri;
74        this.postVars = new ArrayList<String>(postVars); // defensive copy
75        this.getVars = new ArrayList<String>(getVars);
76    }
77
78    /*
79     * (non-Javadoc)
80     *
81     * @see de.ugoe.cs.autoquest.eventcore.IReplayable#getReplay()
82     */
83    @Override
84    public String getReplay() {
85        StringBuilder builder = new StringBuilder();
86        builder.append("curl");
87        if (!postVars.isEmpty()) {
88            boolean isFirstPost = true;
89            for (String postVar : postVars) {
90                if (isFirstPost) {
91                    builder.append(" --data \"");
92                    isFirstPost = false;
93                }
94                else {
95                    builder.append('&');
96                }
97                builder.append(postVar + "=DATA_" + postVar.toUpperCase() + "_DATA");
98            }
99            builder.append('\"');
100        }
101        builder.append(' ');
102        if (serverUrl != null) {
103            builder.append(serverUrl);
104        }
105        builder.append(targetUri);
106        if (!getVars.isEmpty()) {
107            boolean isFirstGet = true;
108            for (String getVar : getVars) {
109                if (isFirstGet) {
110                    builder.append('?');
111                    isFirstGet = false;
112                }
113                else {
114                    builder.append('&');
115                }
116                builder.append(getVar + "=DATA_" + getVar.toUpperCase() + "_DATA");
117            }
118        }
119        return builder.toString();
120    }
121
122    /**
123     * <p>
124     * Two {@link WebRequest}s are equal, if their {@link #targetUri}, {@link #postVars}, and
125     * {@link #getVars} are equal.
126     * </p>
127     *
128     * @see java.lang.Object#equals(java.lang.Object)
129     */
130    @Override
131    public boolean equals(Object other) {
132        if (this == other) {
133            return true;
134        }
135        if (other instanceof WebRequest) {
136            return targetUri.equals(((WebRequest) other).targetUri) &&
137                postVars.equals(((WebRequest) other).postVars) &&
138                getVars.equals(((WebRequest) other).getVars);
139        }
140        return false;
141    }
142
143    /*
144     * (non-Javadoc)
145     *
146     * @see java.lang.Object#hashCode()
147     */
148    @Override
149    public int hashCode() {
150        int multiplier = 17;
151        int hash = 42;
152
153        hash = multiplier * hash + targetUri.hashCode();
154        hash = multiplier * hash + postVars.hashCode();
155        hash = multiplier * hash + getVars.hashCode();
156
157        return hash;
158    }
159
160    /*
161     * (non-Javadoc)
162     *
163     * @see de.ugoe.cs.autoquest.eventcore.IReplayable#getDecorator()
164     */
165    @Override
166    public IReplayDecorator getDecorator() {
167        return null;
168    }
169
170}
Note: See TracBrowser for help on using the repository browser.