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

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

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
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.pseudoserver;
9

10
import java.io.IOException;
11

12
import org.junit.jupiter.api.extension.AfterEachCallback;
13
import org.junit.jupiter.api.extension.BeforeEachCallback;
14
import org.junit.jupiter.api.extension.ExtensionContext;
15

16
/**
17
 * helper class for JUnit Tests of httpunit.
18
 */
19
public class PseudoServerTestSupport implements BeforeEachCallback, AfterEachCallback {
1✔
20

21
    /** The host path. */
22
    private String _hostPath;
23

24
    /** The server. */
25
    private PseudoServer _server;
26

27
    @Override
28
    public void beforeEach(ExtensionContext context) throws Exception {
29
        setUpServer();
1✔
30
    }
1✔
31

32
    @Override
33
    public void afterEach(ExtensionContext context) {
34
        tearDownServer();
1✔
35
    }
1✔
36

37
    /**
38
     * Sets the up server.
39
     *
40
     * @throws IOException
41
     *             Signals that an I/O exception has occurred.
42
     */
43
    public void setUpServer() throws IOException {
44
        _server = new PseudoServer();
1✔
45
        _hostPath = "http://localhost:" + _server.getConnectedPort();
1✔
46
    }
1✔
47

48
    /**
49
     * Tear down server.
50
     */
51
    public void tearDownServer() {
52
        if (_server != null) {
1!
53
            _server.shutDown();
1✔
54
        }
55
    }
1✔
56

57
    /**
58
     * Map to classpath.
59
     *
60
     * @param directory
61
     *            the directory
62
     */
63
    public void mapToClasspath(String directory) {
64
        _server.mapToClasspath(directory);
1✔
65
    }
1✔
66

67
    /**
68
     * Define resource.
69
     *
70
     * @param resourceName
71
     *            the resource name
72
     * @param servlet
73
     *            the servlet
74
     */
75
    public void defineResource(String resourceName, PseudoServlet servlet) {
76
        _server.setResource(resourceName, servlet);
1✔
77
    }
1✔
78

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

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

105
    /**
106
     * Define resource.
107
     *
108
     * @param resourceName
109
     *            the resource name
110
     * @param value
111
     *            the value
112
     * @param statusCode
113
     *            the status code
114
     */
115
    public void defineResource(String resourceName, String value, int statusCode) {
116
        _server.setErrorResource(resourceName, statusCode, value);
1✔
117
    }
1✔
118

119
    /**
120
     * Define resource.
121
     *
122
     * @param resourceName
123
     *            the resource name
124
     * @param value
125
     *            the value
126
     * @param contentType
127
     *            the content type
128
     */
129
    public void defineResource(String resourceName, String value, String contentType) {
130
        _server.setResource(resourceName, value, contentType);
1✔
131
    }
1✔
132

133
    /**
134
     * Adds the resource header.
135
     *
136
     * @param resourceName
137
     *            the resource name
138
     * @param header
139
     *            the header
140
     */
141
    public void addResourceHeader(String resourceName, String header) {
142
        _server.addResourceHeader(resourceName, header);
1✔
143
    }
1✔
144

145
    /**
146
     * Sets the resource char set.
147
     *
148
     * @param resourceName
149
     *            the resource name
150
     * @param setName
151
     *            the set name
152
     * @param reportCharSet
153
     *            the report char set
154
     */
155
    public void setResourceCharSet(String resourceName, String setName, boolean reportCharSet) {
156
        _server.setCharacterSet(resourceName, setName);
1✔
157
        _server.setSendCharacterSet(resourceName, reportCharSet);
1✔
158
    }
1✔
159

160
    /**
161
     * define a Web Page with the given page name and boy adding the html and body tags with pageName as the title of
162
     * the page use the given xml names space if it is not null.
163
     *
164
     * @param xmlns
165
     *            the xmlns
166
     * @param pageName
167
     *            the page name
168
     * @param body
169
     *            the body
170
     */
171
    public void defineWebPage(String xmlns, String pageName, String body) {
172
        String preamble = "";
1✔
173
        if (xmlns == null) {
1✔
174
            xmlns = "";
1✔
175
        } else {
176
            preamble = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1✔
177
            preamble += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
1✔
178
            xmlns = " xmlns=\"" + xmlns + "\"";
1✔
179
        }
180
        defineResource(pageName + ".html", preamble + "<html" + xmlns + ">\n<head><title>" + pageName
1✔
181
                + "</title></head>\n" + "<body>\n" + body + "\n</body>\n</html>");
182
    }
1✔
183

184
    /**
185
     * define a Web Page with the given page name and boy adding the html and body tags with pageName as the title of
186
     * the page.
187
     *
188
     * @param pageName
189
     *            the page name
190
     * @param body
191
     *            the body
192
     */
193
    public void defineWebPage(String pageName, String body) {
194
        defineWebPage(null, pageName, body);
1✔
195
    }
1✔
196

197
    /**
198
     * Gets the server.
199
     *
200
     * @return the server
201
     */
202
    public PseudoServer getServer() {
203
        return _server;
1✔
204
    }
205

206
    /**
207
     * Sets the server debug.
208
     *
209
     * @param enabled
210
     *            the new server debug
211
     */
212
    public void setServerDebug(boolean enabled) {
213
        _server.setDebug(enabled);
×
214
    }
×
215

216
    /**
217
     * Gets the host path.
218
     *
219
     * @return the host path
220
     */
221
    public String getHostPath() {
222
        return _hostPath;
1✔
223
    }
224

225
    /**
226
     * Gets the host port.
227
     *
228
     * @return the host port
229
     *
230
     * @throws IOException
231
     *             Signals that an I/O exception has occurred.
232
     */
233
    public int getHostPort() throws IOException {
234
        return _server.getConnectedPort();
1✔
235
    }
236
}
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