This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 9d9bfc2 [ISSUE 2830] Update junit4 to junit5 - remove dup
dependencies in sub-modules and make wire-mock compatible (#2862)
9d9bfc2 is described below
commit 9d9bfc2e14616f1a9663ea3b000e80293b4173f2
Author: Han Gao <[email protected]>
AuthorDate: Fri Feb 11 11:24:03 2022 +0800
[ISSUE 2830] Update junit4 to junit5 - remove dup dependencies in
sub-modules and make wire-mock compatible (#2862)
* Update junit4 to junit5 - remove dup dependencies in sub-modules
* change the way to use wire mock to make it compatible with junit5
* small changes
---
.../register/client/http/OkHttpToolsTest.java | 28 ++++++++------
.../shenyu-sync-data-consul/pom.xml | 5 ---
.../shenyu-sync-data-etcd/pom.xml | 5 ---
.../sync/data/http/HttpSyncDataServiceTest.java | 44 ++++++++++++----------
.../shenyu-sync-data-websocket/pom.xml | 5 ---
.../shenyu-sync-data-zookeeper/pom.xml | 6 ---
6 files changed, 40 insertions(+), 53 deletions(-)
diff --git
a/shenyu-register-center/shenyu-register-client/shenyu-register-client-http/src/test/java/org/apache/shenyu/register/client/http/OkHttpToolsTest.java
b/shenyu-register-center/shenyu-register-client/shenyu-register-client-http/src/test/java/org/apache/shenyu/register/client/http/OkHttpToolsTest.java
index 97e7157..24e48ff 100644
---
a/shenyu-register-center/shenyu-register-client/shenyu-register-client-http/src/test/java/org/apache/shenyu/register/client/http/OkHttpToolsTest.java
+++
b/shenyu-register-center/shenyu-register-client/shenyu-register-client-http/src/test/java/org/apache/shenyu/register/client/http/OkHttpToolsTest.java
@@ -17,44 +17,48 @@
package org.apache.shenyu.register.client.http;
-import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.WireMockServer;
+import
com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import org.apache.shenyu.register.client.http.utils.OkHttpTools;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import wiremock.com.google.common.net.HttpHeaders;
import wiremock.org.apache.http.entity.ContentType;
import java.io.IOException;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
/**
* Test case for {@link OkHttpTools}.
*/
public final class OkHttpToolsTest {
- @Rule
- public WireMockRule wireMockRule = new
WireMockRule(WireMockConfiguration.wireMockConfig().dynamicPort(), false);
+ private WireMockServer wireMockServer;
private String url;
private final String json = "{\"appName\":\"shenyu\"}";
- @Before
+ @BeforeEach
public void setUpWireMock() {
- wireMockRule.stubFor(post(urlPathEqualTo("/"))
+ this.wireMockServer = new WireMockServer(
+ options()
+ .extensions(new ResponseTemplateTransformer(false))
+ .dynamicPort());
+ this.wireMockServer.start();
+ wireMockServer.stubFor(post(urlPathEqualTo("/"))
.willReturn(aResponse()
.withHeader(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_JSON.toString())
.withBody(json)
.withStatus(200))
);
- url = "http://localhost:" + wireMockRule.port();
+ url = "http://localhost:" + wireMockServer.port();
}
@Test
diff --git a/shenyu-sync-data-center/shenyu-sync-data-consul/pom.xml
b/shenyu-sync-data-center/shenyu-sync-data-consul/pom.xml
index 4c0774e..65fbe25 100644
--- a/shenyu-sync-data-center/shenyu-sync-data-consul/pom.xml
+++ b/shenyu-sync-data-center/shenyu-sync-data-consul/pom.xml
@@ -42,11 +42,6 @@
<artifactId>consul-api</artifactId>
<version>${consul.api.version}</version>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml
b/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml
index 442e658..fe29c4d 100644
--- a/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml
+++ b/shenyu-sync-data-center/shenyu-sync-data-etcd/pom.xml
@@ -36,11 +36,6 @@
<artifactId>jetcd-core</artifactId>
<version>0.5.0</version>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-http/src/test/java/org/apache/shenyu/sync/data/http/HttpSyncDataServiceTest.java
b/shenyu-sync-data-center/shenyu-sync-data-http/src/test/java/org/apache/shenyu/sync/data/http/HttpSyncDataServiceTest.java
index f3ce83a..2848aa6 100644
---
a/shenyu-sync-data-center/shenyu-sync-data-http/src/test/java/org/apache/shenyu/sync/data/http/HttpSyncDataServiceTest.java
+++
b/shenyu-sync-data-center/shenyu-sync-data-http/src/test/java/org/apache/shenyu/sync/data/http/HttpSyncDataServiceTest.java
@@ -17,8 +17,8 @@
package org.apache.shenyu.sync.data.http;
-import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.WireMockServer;
+import
com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import org.apache.shenyu.common.dto.ConfigData;
import org.apache.shenyu.common.dto.PluginData;
import org.apache.shenyu.common.enums.ConfigGroupEnum;
@@ -28,12 +28,11 @@ import org.apache.shenyu.sync.data.api.AuthDataSubscriber;
import org.apache.shenyu.sync.data.api.MetaDataSubscriber;
import org.apache.shenyu.sync.data.api.PluginDataSubscriber;
import org.apache.shenyu.sync.data.http.config.HttpConfig;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.util.ReflectionTestUtils;
@@ -46,17 +45,18 @@ import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static
com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public final class HttpSyncDataServiceTest {
/**
@@ -64,8 +64,7 @@ public final class HttpSyncDataServiceTest {
*/
private static final Logger LOG =
LoggerFactory.getLogger(HttpSyncDataServiceTest.class);
- @Rule
- public WireMockRule wireMockRule = new
WireMockRule(WireMockConfiguration.wireMockConfig().dynamicPort(), false);
+ private WireMockServer wireMockServer;
private PluginDataSubscriber pluginDataSubscriber;
@@ -75,21 +74,26 @@ public final class HttpSyncDataServiceTest {
private HttpSyncDataService httpSyncDataService;
- @Before
+ @BeforeEach
public void before() {
- wireMockRule.stubFor(get(urlPathEqualTo("/platform/login"))
+ this.wireMockServer = new WireMockServer(
+ options()
+ .extensions(new ResponseTemplateTransformer(false))
+ .dynamicPort());
+ this.wireMockServer.start();
+ wireMockServer.stubFor(get(urlPathEqualTo("/platform/login"))
.willReturn(aResponse()
.withHeader(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_JSON.toString())
.withBody(this.mockLoginResponseJson())
.withStatus(200))
);
- wireMockRule.stubFor(get(urlPathEqualTo("/configs/fetch"))
+ wireMockServer.stubFor(get(urlPathEqualTo("/configs/fetch"))
.willReturn(aResponse()
.withHeader(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_JSON.toString())
.withBody(this.mockConfigsFetchResponseJson())
.withStatus(200))
);
- wireMockRule.stubFor(post(urlPathEqualTo("/configs/listener"))
+ wireMockServer.stubFor(post(urlPathEqualTo("/configs/listener"))
.willReturn(aResponse()
.withHeader(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_JSON.toString())
.withBody(this.mockConfigsListenResponseJson())
@@ -111,7 +115,7 @@ public final class HttpSyncDataServiceTest {
Collections.singletonList(metaDataSubscriber),
Collections.singletonList(authDataSubscriber));
}
- @After
+ @AfterEach
public void after() {
try {
httpSyncDataService.close();
@@ -133,7 +137,7 @@ public final class HttpSyncDataServiceTest {
}
private String getMockServerUrl() {
- return "http://127.0.0.1:" + wireMockRule.port();
+ return "http://127.0.0.1:" + wireMockServer.port();
}
// mock configs listen api response
diff --git a/shenyu-sync-data-center/shenyu-sync-data-websocket/pom.xml
b/shenyu-sync-data-center/shenyu-sync-data-websocket/pom.xml
index 0258c15..6c6b9fd 100644
--- a/shenyu-sync-data-center/shenyu-sync-data-websocket/pom.xml
+++ b/shenyu-sync-data-center/shenyu-sync-data-websocket/pom.xml
@@ -49,10 +49,5 @@
<version>${undertow.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
b/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
index 08cb764..70521a3 100644
--- a/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
+++ b/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
@@ -52,11 +52,5 @@
<version>${curator-test.version}</version>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-junit-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>