Skip to content

Commit a2c396f

Browse files
committed
feat: MockWebServer is based on Vert.x Web
Signed-off-by: Marc Nuri <marc@marcnuri.com>
1 parent c69ce44 commit a2c396f

33 files changed

+651
-570
lines changed

junit/mockwebserver/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
<dependencies>
3434
<dependency>
35-
<groupId>com.squareup.okhttp3</groupId>
36-
<artifactId>mockwebserver</artifactId>
35+
<groupId>io.vertx</groupId>
36+
<artifactId>vertx-web</artifactId>
3737
</dependency>
3838
<dependency>
3939
<groupId>com.fasterxml.jackson.core</groupId>

junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/DefaultMockServer.java

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
package io.fabric8.mockwebserver;
1818

1919
import io.fabric8.mockwebserver.dsl.MockServerExpectation;
20+
import io.fabric8.mockwebserver.http.Dispatcher;
21+
import io.fabric8.mockwebserver.http.RecordedRequest;
2022
import io.fabric8.mockwebserver.internal.MockDispatcher;
21-
import io.fabric8.mockwebserver.internal.MockSSLContextFactory;
2223
import io.fabric8.mockwebserver.internal.MockServerExpectationImpl;
23-
import okhttp3.mockwebserver.Dispatcher;
24-
import okhttp3.mockwebserver.MockWebServer;
25-
import okhttp3.mockwebserver.RecordedRequest;
24+
import io.vertx.core.net.SelfSignedCertificate;
2625

27-
import java.io.IOException;
2826
import java.net.InetAddress;
2927
import java.net.Proxy;
3028
import java.util.HashMap;
@@ -64,8 +62,9 @@ public DefaultMockServer(Context context, MockWebServer server, Map<ServerReques
6462
this(context, server, responses, new MockDispatcher(responses), useHttps);
6563
}
6664

67-
public DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest, Queue<ServerResponse>> responses,
68-
Dispatcher dispatcher, boolean useHttps) {
65+
public DefaultMockServer(
66+
Context context, MockWebServer server, Map<ServerRequest, Queue<ServerResponse>> responses, Dispatcher dispatcher,
67+
boolean useHttps) {
6968
this.context = context;
7069
this.useHttps = useHttps;
7170
this.server = server;
@@ -78,7 +77,7 @@ public DefaultMockServer(Context context, MockWebServer server, Map<ServerReques
7877
private void startInternal() {
7978
if (initialized.compareAndSet(false, true)) {
8079
if (useHttps) {
81-
server.useHttps(MockSSLContextFactory.create().getSocketFactory(), false);
80+
server.useHttps();
8281
}
8382
onStart();
8483
}
@@ -91,37 +90,23 @@ private void shutdownInternal() {
9190
}
9291

9392
public final void start() {
94-
try {
95-
startInternal();
96-
server.start();
97-
} catch (IOException e) {
98-
throw new MockServerException("Exception when starting DefaultMockServer", e);
99-
}
93+
startInternal();
94+
server.start();
10095
}
10196

10297
public final void start(int port) {
103-
try {
104-
startInternal();
105-
server.start(port);
106-
} catch (IOException e) {
107-
throw new MockServerException("Exception when starting DefaultMockServer with port", e);
108-
}
98+
startInternal();
99+
server.start(port);
109100
}
110101

111102
public final void start(InetAddress inetAddress, int port) {
112-
try {
113-
startInternal();
114-
server.start(inetAddress, port);
115-
} catch (IOException e) {
116-
throw new MockServerException("Exception when starting DefaultMockServer with InetAddress and port", e);
117-
}
103+
startInternal();
104+
server.start(inetAddress, port);
118105
}
119106

120107
public final void shutdown() {
121108
try {
122109
server.shutdown();
123-
} catch (IOException e) {
124-
throw new MockServerException("Exception when stopping DefaultMockServer", e);
125110
} finally {
126111
shutdownInternal();
127112
}
@@ -159,6 +144,11 @@ public Proxy toProxyAddress() {
159144
return server.toProxyAddress();
160145
}
161146

147+
@Override
148+
public SelfSignedCertificate getSelfSignedCertificate() {
149+
return server.getSelfSignedCertificate();
150+
}
151+
162152
/**
163153
* {@inheritDoc}
164154
*/

junit/mockwebserver/src/main/java/io/fabric8/mockwebserver/MockServer.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
package io.fabric8.mockwebserver;
1717

1818
import io.fabric8.mockwebserver.dsl.MockServerExpectation;
19-
import okhttp3.mockwebserver.RecordedRequest;
19+
import io.fabric8.mockwebserver.http.RecordedRequest;
20+
import io.vertx.core.net.SelfSignedCertificate;
2021

2122
import java.net.Proxy;
2223
import java.util.concurrent.TimeUnit;
@@ -36,26 +37,33 @@ default void onShutdown() {
3637
}
3738

3839
/**
39-
* The port for the {@link okhttp3.mockwebserver.MockWebServer}.
40+
* The port for the {@link MockWebServer}.
4041
*
4142
* @return the MockWebServer port.
4243
*/
4344
int getPort();
4445

4546
/**
46-
* The host name for the {@link okhttp3.mockwebserver.MockWebServer}.
47-
*
47+
* The host name for the {@link MockWebServer}.
48+
*
4849
* @return the MockWebServer host name;
4950
*/
5051
String getHostName();
5152

5253
/**
53-
* Returns a {@link Proxy} for the {@link okhttp3.mockwebserver.MockWebServer} with the current HostName and Port.
54+
* Returns a {@link Proxy} for the {@link MockWebServer} with the current HostName and Port.
5455
*
5556
* @return a Proxy for the MockWebServer.
5657
*/
5758
Proxy toProxyAddress();
5859

60+
/**
61+
* Returns the {@link SelfSignedCertificate} for the Mock Web Server.
62+
*
63+
* @return the SelfSignedCertificate for the MockWebServer.
64+
*/
65+
SelfSignedCertificate getSelfSignedCertificate();
66+
5967
/**
6068
* Returns a String URL for connecting to this server.
6169
*
@@ -97,7 +105,7 @@ default void onShutdown() {
97105
RecordedRequest takeRequest(long timeout, TimeUnit unit) throws InterruptedException;
98106

99107
/**
100-
* Returns the last (most recent) HTTP request processed by the {@link okhttp3.mockwebserver.MockWebServer}.
108+
* Returns the last (most recent) HTTP request processed by the {@link MockWebServer}.
101109
*
102110
* n.b. This method clears the request queue.
103111
*

0 commit comments

Comments
 (0)