• 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

93.62
/src/main/java/com/meterware/pseudoserver/PseudoServerTestSupport.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.pseudoserver;
21

22
import java.io.IOException;
23

24
import org.junit.jupiter.api.extension.AfterEachCallback;
25
import org.junit.jupiter.api.extension.BeforeEachCallback;
26
import org.junit.jupiter.api.extension.ExtensionContext;
27

28
/**
29
 * helper class for JUnit Tests of httpunit.
30
 */
31
public class PseudoServerTestSupport implements BeforeEachCallback, AfterEachCallback {
1✔
32

33
    /** The host path. */
34
    private String _hostPath;
35

36
    /** The server. */
37
    private PseudoServer _server;
38

39
    @Override
40
    public void beforeEach(ExtensionContext context) throws Exception {
41
        setUpServer();
1✔
42
    }
1✔
43

44
    @Override
45
    public void afterEach(ExtensionContext context) {
46
        tearDownServer();
1✔
47
    }
1✔
48

49
    /**
50
     * Sets the up server.
51
     *
52
     * @throws IOException
53
     *             Signals that an I/O exception has occurred.
54
     */
55
    public void setUpServer() throws IOException {
56
        _server = new PseudoServer();
1✔
57
        _hostPath = "http://localhost:" + _server.getConnectedPort();
1✔
58
    }
1✔
59

60
    /**
61
     * Tear down server.
62
     */
63
    public void tearDownServer() {
64
        if (_server != null) {
1!
65
            _server.shutDown();
1✔
66
        }
67
    }
1✔
68

69
    /**
70
     * Map to classpath.
71
     *
72
     * @param directory
73
     *            the directory
74
     */
75
    public void mapToClasspath(String directory) {
76
        _server.mapToClasspath(directory);
1✔
77
    }
1✔
78

79
    /**
80
     * Define resource.
81
     *
82
     * @param resourceName
83
     *            the resource name
84
     * @param servlet
85
     *            the servlet
86
     */
87
    public void defineResource(String resourceName, PseudoServlet servlet) {
88
        _server.setResource(resourceName, servlet);
1✔
89
    }
1✔
90

91
    /**
92
     * Define resource.
93
     *
94
     * @param resourceName
95
     *            the resource name
96
     * @param value
97
     *            the value
98
     */
99
    public void defineResource(String resourceName, String value) {
100
        _server.setResource(resourceName, value);
1✔
101
    }
1✔
102

103
    /**
104
     * Define resource.
105
     *
106
     * @param resourceName
107
     *            the resource name
108
     * @param value
109
     *            the value
110
     * @param contentType
111
     *            the content type
112
     */
113
    public void defineResource(String resourceName, byte[] value, String contentType) {
114
        _server.setResource(resourceName, value, contentType);
1✔
115
    }
1✔
116

117
    /**
118
     * Define resource.
119
     *
120
     * @param resourceName
121
     *            the resource name
122
     * @param value
123
     *            the value
124
     * @param statusCode
125
     *            the status code
126
     */
127
    public void defineResource(String resourceName, String value, int statusCode) {
128
        _server.setErrorResource(resourceName, statusCode, value);
1✔
129
    }
1✔
130

131
    /**
132
     * Define resource.
133
     *
134
     * @param resourceName
135
     *            the resource name
136
     * @param value
137
     *            the value
138
     * @param contentType
139
     *            the content type
140
     */
141
    public void defineResource(String resourceName, String value, String contentType) {
142
        _server.setResource(resourceName, value, contentType);
1✔
143
    }
1✔
144

145
    /**
146
     * Adds the resource header.
147
     *
148
     * @param resourceName
149
     *            the resource name
150
     * @param header
151
     *            the header
152
     */
153
    public void addResourceHeader(String resourceName, String header) {
154
        _server.addResourceHeader(resourceName, header);
1✔
155
    }
1✔
156

157
    /**
158
     * Sets the resource char set.
159
     *
160
     * @param resourceName
161
     *            the resource name
162
     * @param setName
163
     *            the set name
164
     * @param reportCharSet
165
     *            the report char set
166
     */
167
    public void setResourceCharSet(String resourceName, String setName, boolean reportCharSet) {
168
        _server.setCharacterSet(resourceName, setName);
1✔
169
        _server.setSendCharacterSet(resourceName, reportCharSet);
1✔
170
    }
1✔
171

172
    /**
173
     * define a Web Page with the given page name and boy adding the html and body tags with pageName as the title of
174
     * the page use the given xml names space if it is not null.
175
     *
176
     * @param xmlns
177
     *            the xmlns
178
     * @param pageName
179
     *            the page name
180
     * @param body
181
     *            the body
182
     */
183
    public void defineWebPage(String xmlns, String pageName, String body) {
184
        String preamble = "";
1✔
185
        if (xmlns == null) {
1✔
186
            xmlns = "";
1✔
187
        } else {
188
            preamble = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1✔
189
            preamble += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
1✔
190
            xmlns = " xmlns=\"" + xmlns + "\"";
1✔
191
        }
192
        defineResource(pageName + ".html", preamble + "<html" + xmlns + ">\n<head><title>" + pageName
1✔
193
                + "</title></head>\n" + "<body>\n" + body + "\n</body>\n</html>");
194
    }
1✔
195

196
    /**
197
     * define a Web Page with the given page name and boy adding the html and body tags with pageName as the title of
198
     * the page.
199
     *
200
     * @param pageName
201
     *            the page name
202
     * @param body
203
     *            the body
204
     */
205
    public void defineWebPage(String pageName, String body) {
206
        defineWebPage(null, pageName, body);
1✔
207
    }
1✔
208

209
    /**
210
     * Gets the server.
211
     *
212
     * @return the server
213
     */
214
    public PseudoServer getServer() {
215
        return _server;
1✔
216
    }
217

218
    /**
219
     * Sets the server debug.
220
     *
221
     * @param enabled
222
     *            the new server debug
223
     */
224
    public void setServerDebug(boolean enabled) {
225
        _server.setDebug(enabled);
×
226
    }
×
227

228
    /**
229
     * Gets the host path.
230
     *
231
     * @return the host path
232
     */
233
    public String getHostPath() {
234
        return _hostPath;
1✔
235
    }
236

237
    /**
238
     * Gets the host port.
239
     *
240
     * @return the host port
241
     *
242
     * @throws IOException
243
     *             Signals that an I/O exception has occurred.
244
     */
245
    public int getHostPort() throws IOException {
246
        return _server.getConnectedPort();
1✔
247
    }
248
}
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