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

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

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
    private static final String[] NO_VALUES = {};
1✔
42
    private Map _presetParameterMap;
43
    private ArrayList _presetParameterList;
44
    private String _characterSet;
45

46
    public FixedURLWebRequestSource(WebResponse response, Node node, URL baseURL, String attribute, FrameSelector frame,
47
            String defaultTarget, String characterSet) {
48
        super(response, node, baseURL, attribute, frame, defaultTarget);
1✔
49
        _characterSet = characterSet;
1✔
50
    }
1✔
51

52
    // ------------------------------------------- WebRequestSource methods
53
    // -------------------------------------------------
54

55
    /**
56
     * Creates and returns a web request which will simulate clicking on this link.
57
     **/
58
    @Override
59
    public WebRequest getRequest() {
60
        return new GetMethodWebRequest(this);
1✔
61
    }
62

63
    /**
64
     * Returns an array containing the names of any parameters defined as part of this link's URL.
65
     **/
66
    @Override
67
    public String[] getParameterNames() {
68
        ArrayList parameterNames = new ArrayList(getPresetParameterMap().keySet());
×
69
        return (String[]) parameterNames.toArray(new String[parameterNames.size()]);
×
70
    }
71

72
    /**
73
     * Returns the multiple default values of the named parameter.
74
     **/
75
    @Override
76
    public String[] getParameterValues(String name) {
77
        final String[] values = (String[]) getPresetParameterMap().get(name);
1✔
78
        return values == null ? NO_VALUES : values;
1✔
79
    }
80

81
    @Override
82
    protected void addPresetParameter(String name, String value) {
83
        _presetParameterMap.put(name, HttpUnitUtils.withNewValue((String[]) _presetParameterMap.get(name), value));
1✔
84
        _presetParameterList.add(new PresetParameter(name, value));
1✔
85
    }
1✔
86

87
    @Override
88
    protected String getEmptyParameterValue() {
89
        return "";
1✔
90
    }
91

92
    @Override
93
    protected void setDestination(String destination) {
94
        super.setDestination(destination);
1✔
95
        _presetParameterList = null;
1✔
96
        _presetParameterMap = null;
1✔
97
    }
1✔
98

99
    // ------------------------------------------- ParameterHolder methods
100
    // --------------------------------------------------
101

102
    /**
103
     * Specifies the position at which an image button (if any) was clicked.
104
     **/
105
    @Override
106
    void selectImageButtonPosition(SubmitButton imageButton, int x, int y) {
107
        throw new IllegalNonFormParametersRequest();
×
108
    }
109

110
    /**
111
     * Iterates through the fixed, predefined parameters in this holder, recording them in the supplied parameter
112
     * processor.\ These parameters always go on the URL, no matter what encoding method is used.
113
     **/
114

115
    @Override
116
    void recordPredefinedParameters(ParameterProcessor processor) throws IOException {
117
    }
1✔
118

119
    /**
120
     * Iterates through the parameters in this holder, recording them in the supplied parameter processor.
121
     **/
122
    @Override
123
    public void recordParameters(ParameterProcessor processor) throws IOException {
124
        Iterator i = getPresetParameterList().iterator();
1✔
125
        while (i.hasNext()) {
1✔
126
            PresetParameter o = (PresetParameter) i.next();
1✔
127
            processor.addParameter(o.getName(), o.getValue(), getCharacterSet());
1✔
128
        }
1✔
129
    }
1✔
130

131
    /**
132
     * Removes a parameter name from this collection.
133
     **/
134
    @Override
135
    void removeParameter(String name) {
136
        throw new IllegalNonFormParametersRequest();
×
137
    }
138

139
    /**
140
     * Sets the value of a parameter in a web request.
141
     **/
142
    @Override
143
    void setParameter(String name, String value) {
144
        setParameter(name, new String[] { value });
×
145
    }
×
146

147
    /**
148
     * Sets the multiple values of a parameter in a web request.
149
     **/
150
    @Override
151
    void setParameter(String name, String[] values) {
152
        if (values == null) {
1!
153
            throw new IllegalArgumentException("May not supply a null argument array to setParameter()");
×
154
        }
155
        if (!getPresetParameterMap().containsKey(name) || !equals(getParameterValues(name), values)) {
1!
156
            throw new IllegalNonFormParametersRequest();
1✔
157
        }
158
    }
1✔
159

160
    @Override
161
    String getCharacterSet() {
162
        return _characterSet;
1✔
163
    }
164

165
    private boolean equals(String[] left, String[] right) {
166
        if (left.length != right.length) {
1✔
167
            return false;
1✔
168
        }
169
        List rightValues = Arrays.asList(right);
1✔
170
        for (String element : left) {
1✔
171
            if (!rightValues.contains(element)) {
1!
172
                return false;
×
173
            }
174
        }
175
        return true;
1✔
176
    }
177

178
    /**
179
     * Sets the multiple values of a file upload parameter in a web request.
180
     **/
181
    @Override
182
    void setParameter(String name, UploadFileSpec[] files) {
183
        throw new IllegalNonFormParametersRequest();
×
184
    }
185

186
    /**
187
     * Returns true if the specified parameter is a file field.
188
     **/
189
    @Override
190
    boolean isFileParameter(String name) {
191
        return false;
×
192
    }
193

194
    @Override
195
    boolean isSubmitAsMime() {
196
        return false;
×
197
    }
198

199
    private Map getPresetParameterMap() {
200
        if (_presetParameterMap == null) {
1✔
201
            loadPresetParameters();
1✔
202
        }
203
        return _presetParameterMap;
1✔
204
    }
205

206
    private ArrayList getPresetParameterList() {
207
        if (_presetParameterList == null) {
1✔
208
            loadPresetParameters();
1✔
209
        }
210
        return _presetParameterList;
1✔
211
    }
212

213
    private void loadPresetParameters() {
214
        _presetParameterMap = new HashMap<>();
1✔
215
        _presetParameterList = new ArrayList<>();
1✔
216
        loadDestinationParameters();
1✔
217
    }
1✔
218

219
}
220

221
class PresetParameter {
222
    private String _name;
223
    private String _value;
224

225
    public PresetParameter(String name, String value) {
1✔
226
        _name = name;
1✔
227
        _value = value;
1✔
228
    }
1✔
229

230
    public String getName() {
231
        return _name;
1✔
232
    }
233

234
    public String getValue() {
235
        return _value;
1✔
236
    }
237
}
238

239
class IllegalNonFormParametersRequest extends IllegalRequestParameterException {
240

241
    private static final long serialVersionUID = 1L;
242

243
    public IllegalNonFormParametersRequest() {
1✔
244
    }
1✔
245

246
    @Override
247
    public String getMessage() {
248
        return "May not modify parameters for a request not derived from a form with parameter checking enabled.";
×
249
    }
250

251
}
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