source: josm/trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTaskTestParent.java@ 17360

Last change on this file since 17360 was 17195, checked in by simon04, 4 years ago

see #15102 - see #16637 - Use WireMockServer.url()

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.downloadtasks;
3
4import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
5import static com.github.tomakehurst.wiremock.client.WireMock.get;
6import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
7import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
8
9import org.junit.Rule;
10import org.openstreetmap.josm.TestUtils;
11import org.openstreetmap.josm.testutils.JOSMTestRules;
12
13import com.github.tomakehurst.wiremock.junit.WireMockRule;
14
15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16
17/**
18 * Superclass of {@link DownloadGpsTaskTest}, {@link DownloadOsmTaskTest} and {@link DownloadNotesTaskTest}.
19 */
20public abstract class AbstractDownloadTaskTestParent {
21
22 /**
23 * Setup test.
24 */
25 @Rule
26 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
27 public JOSMTestRules test = new JOSMTestRules().https();
28
29 /**
30 * HTTP mock.
31 */
32 @Rule
33 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));
34
35 /**
36 * Returns the path to remote test file to download via http.
37 * @return the path to remote test file, relative to JOSM root directory
38 */
39 protected abstract String getRemoteFile();
40
41 /**
42 * Returns the {@code Content-Type} with which to serve the file referenced
43 * by {@link #getRemoteFile()}
44 * @return the {@code Content-Type} string for file {@link #getRemoteFile()}
45 */
46 protected String getRemoteContentType() {
47 return "text/xml";
48 }
49
50 /**
51 * Returns the http URL to remote test file to download.
52 * @return the http URL to remote test file to download
53 */
54 protected final String getRemoteFileUrl() {
55 return wireMockRule.url(getRemoteFile());
56 }
57
58 /**
59 * Mock the HTTP server.
60 */
61 protected final void mockHttp() {
62 wireMockRule.stubFor(get(urlEqualTo("/" + getRemoteFile()))
63 .willReturn(aResponse()
64 .withStatus(200)
65 .withHeader("Content-Type", getRemoteContentType())
66 .withBodyFile(getRemoteFile())));
67 }
68}
Note: See TracBrowser for help on using the repository browser.