• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.93
/src/main/java/com/meterware/httpunit/FixedURLWebRequestSource.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.httpunit;
21

22
import com.meterware.httpunit.protocol.ParameterProcessor;
23
import com.meterware.httpunit.protocol.UploadFileSpec;
24

25
import java.io.IOException;
26
import java.net.URL;
27
import java.util.ArrayList;
28
import java.util.Arrays;
29
import java.util.HashMap;
30
import java.util.Iterator;
31
import java.util.List;
32
import java.util.Map;
33

34
import org.w3c.dom.Node;
35

36
/**
37
 * An implementation of web request source whose URL does not change under user action.
38
 **/
39
abstract class FixedURLWebRequestSource extends WebRequestSource {
40

41
    /** The Constant NO_VALUES. */
42
    private static final String[] NO_VALUES = {};
1✔
43

44
    /** The preset parameter map. */
45
    private Map _presetParameterMap;
46

47
    /** The preset parameter list. */
48
    private ArrayList _presetParameterList;
49

50
    /** The character set. */
51
    private String _characterSet;
52

53
    /**
54
     * Instantiates a new fixed URL web request source.
55
     *
56
     * @param response
57
     *            the response
58
     * @param node
59
     *            the node
60
     * @param baseURL
61
     *            the base URL
62
     * @param attribute
63
     *            the attribute
64
     * @param frame
65
     *            the frame
66
     * @param defaultTarget
67
     *            the default target
68
     * @param characterSet
69
     *            the character set
70
     */
71
    public FixedURLWebRequestSource(WebResponse response, Node node, URL baseURL, String attribute, FrameSelector frame,
72
            String defaultTarget, String characterSet) {
73
        super(response, node, baseURL, attribute, frame, defaultTarget);
1✔
74
        _characterSet = characterSet;
1✔
75
    }
1✔
76

77
    // ------------------------------------------- WebRequestSource methods
78
    // -------------------------------------------------
79

80
    /**
81
     * Creates and returns a web request which will simulate clicking on this link.
82
     **/
83
    @Override
84
    public WebRequest getRequest() {
85
        return new GetMethodWebRequest(this);
1✔
86
    }
87

88
    /**
89
     * Returns an array containing the names of any parameters defined as part of this link's URL.
90
     **/
91
    @Override
92
    public String[] getParameterNames() {
93
        ArrayList parameterNames = new ArrayList(getPresetParameterMap().keySet());
×
94
        return (String[]) parameterNames.toArray(new String[parameterNames.size()]);
×
95
    }
96

97
    /**
98
     * Returns the multiple default values of the named parameter.
99
     **/
100
    @Override
101
    public String[] getParameterValues(String name) {
102
        final String[] values = (String[]) getPresetParameterMap().get(name);
1✔
103
        return values == null ? NO_VALUES : values;
1✔
104
    }
105

106
    @Override
107
    protected void addPresetParameter(String name, String value) {
108
        _presetParameterMap.put(name, HttpUnitUtils.withNewValue((String[]) _presetParameterMap.get(name), value));
1✔
109
        _presetParameterList.add(new PresetParameter(name, value));
1✔
110
    }
1✔
111

112
    @Override
113
    protected String getEmptyParameterValue() {
114
        return "";
1✔
115
    }
116

117
    @Override
118
    protected void setDestination(String destination) {
119
        super.setDestination(destination);
1✔
120
        _presetParameterList = null;
1✔
121
        _presetParameterMap = null;
1✔
122
    }
1✔
123

124
    // ------------------------------------------- ParameterHolder methods
125
    // --------------------------------------------------
126

127
    /**
128
     * Specifies the position at which an image button (if any) was clicked.
129
     **/
130
    @Override
131
    void selectImageButtonPosition(SubmitButton imageButton, int x, int y) {
132
        throw new IllegalNonFormParametersRequest();
×
133
    }
134

135
    /**
136
     * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter
137
     * processor.\ These parameters always go on the URL, no matter what encoding method is used.
138
     **/
139

140
    @Override
141
    void recordPredefinedParameters(ParameterProcessor processor) throws IOException {
142
    }
1✔
143

144
    /**
145
     * Iterates through the parameters in this holder, recording them in the supplied parameter processor.
146
     **/
147
    @Override
148
    public void recordParameters(ParameterProcessor processor) throws IOException {
149
        Iterator i = getPresetParameterList().iterator();
1✔
150
        while (i.hasNext()) {
1✔
151
            PresetParameter o = (PresetParameter) i.next();
1✔
152
            processor.addParameter(o.getName(), o.getValue(), getCharacterSet());
1✔
153
        }
1✔
154
    }
1✔
155

156
    /**
157
     * Removes a parameter name from this collection.
158
     **/
159
    @Override
160
    void removeParameter(String name) {
161
        throw new IllegalNonFormParametersRequest();
×
162
    }
163

164
    /**
165
     * Sets the value of a parameter in a web request.
166
     **/
167
    @Override
168
    void setParameter(String name, String value) {
169
        setParameter(name, new String[] { value });
×
170
    }
×
171

172
    /**
173
     * Sets the multiple values of a parameter in a web request.
174
     **/
175
    @Override
176
    void setParameter(String name, String[] values) {
177
        if (values == null) {
1!
178
            throw new IllegalArgumentException("May not supply a null argument array to setParameter()");
×
179
        }
180
        if (!getPresetParameterMap().containsKey(name) || !equals(getParameterValues(name), values)) {
1!
181
            throw new IllegalNonFormParametersRequest();
1✔
182
        }
183
    }
1✔
184

185
    @Override
186
    String getCharacterSet() {
187
        return _characterSet;
1✔
188
    }
189

190
    /**
191
     * Equals.
192
     *
193
     * @param left
194
     *            the left
195
     * @param right
196
     *            the right
197
     *
198
     * @return true, if successful
199
     */
200
    private boolean equals(String[] left, String[] right) {
201
        if (left.length != right.length) {
1✔
202
            return false;
1✔
203
        }
204
        List rightValues = Arrays.asList(right);
1✔
205
        for (String element : left) {
1✔
206
            if (!rightValues.contains(element)) {
1!
207
                return false;
×
208
            }
209
        }
210
        return true;
1✔
211
    }
212

213
    /**
214
     * Sets the multiple values of a file upload parameter in a web request.
215
     **/
216
    @Override
217
    void setParameter(String name, UploadFileSpec[] files) {
218
        throw new IllegalNonFormParametersRequest();
×
219
    }
220

221
    /**
222
     * Returns true if the specified parameter is a file field.
223
     **/
224
    @Override
225
    boolean isFileParameter(String name) {
226
        return false;
×
227
    }
228

229
    @Override
230
    boolean isSubmitAsMime() {
231
        return false;
×
232
    }
233

234
    /**
235
     * Gets the preset parameter map.
236
     *
237
     * @return the preset parameter map
238
     */
239
    private Map getPresetParameterMap() {
240
        if (_presetParameterMap == null) {
1✔
241
            loadPresetParameters();
1✔
242
        }
243
        return _presetParameterMap;
1✔
244
    }
245

246
    /**
247
     * Gets the preset parameter list.
248
     *
249
     * @return the preset parameter list
250
     */
251
    private ArrayList getPresetParameterList() {
252
        if (_presetParameterList == null) {
1✔
253
            loadPresetParameters();
1✔
254
        }
255
        return _presetParameterList;
1✔
256
    }
257

258
    /**
259
     * Load preset parameters.
260
     */
261
    private void loadPresetParameters() {
262
        _presetParameterMap = new HashMap<>();
1✔
263
        _presetParameterList = new ArrayList<>();
1✔
264
        loadDestinationParameters();
1✔
265
    }
1✔
266

267
}
268

269
class PresetParameter {
270
    private String _name;
271
    private String _value;
272

273
    public PresetParameter(String name, String value) {
1✔
274
        _name = name;
1✔
275
        _value = value;
1✔
276
    }
1✔
277

278
    public String getName() {
279
        return _name;
1✔
280
    }
281

282
    public String getValue() {
283
        return _value;
1✔
284
    }
285
}
286

287
class IllegalNonFormParametersRequest extends IllegalRequestParameterException {
288

289
    private static final long serialVersionUID = 1L;
290

291
    public IllegalNonFormParametersRequest() {
1✔
292
    }
1✔
293

294
    @Override
295
    public String getMessage() {
296
        return "May not modify parameters for a request not derived from a form with parameter checking enabled.";
×
297
    }
298

299
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc