You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ch...@apache.org on 2022/09/21 02:15:29 UTC
[dolphinscheduler] branch dev updated: [Improvement][UT] Upgrade jUnit to 5.+ (#10976) (#11332)
This is an automated email from the ASF dual-hosted git repository.
chufenggao pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new b52da64001 [Improvement][UT] Upgrade jUnit to 5.+ (#10976) (#11332)
b52da64001 is described below
commit b52da64001da3a4458510228d267e6c4abd84252
Author: Eric Gao <er...@gmail.com>
AuthorDate: Wed Sep 21 10:15:21 2022 +0800
[Improvement][UT] Upgrade jUnit to 5.+ (#10976) (#11332)
* [Improvement][UT] Upgrade jUnit to 5.+ (#10976)
* Refactor AlertServerTest with jUnit-5 as an example
---
.../dolphinscheduler-alert-server/pom.xml | 2 +-
.../dolphinscheduler/alert/AlertServerTest.java | 50 ++++++++++------------
dolphinscheduler-api/pom.xml | 9 ++--
.../api/controller/TaskInstanceControllerTest.java | 12 +++---
pom.xml | 41 ++++++++++++------
5 files changed, 66 insertions(+), 48 deletions(-)
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml
index 587619f9f1..b044e94881 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/pom.xml
@@ -26,7 +26,6 @@
<artifactId>dolphinscheduler-alert-server</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
-
<dependencies>
<!-- dolphinscheduler -->
<dependency>
@@ -158,4 +157,5 @@
</build>
</profile>
</profiles>
+
</project>
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
index e739ff4d03..63381a2619 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java
@@ -17,57 +17,53 @@
package org.apache.dolphinscheduler.alert;
-import junit.framework.TestCase;
-import org.apache.dolphinscheduler.dao.AlertDao;
import org.apache.dolphinscheduler.dao.PluginDao;
-import org.apache.dolphinscheduler.dao.entity.Alert;
import org.apache.dolphinscheduler.remote.NettyRemotingServer;
import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.powermock.reflect.Whitebox;
-import java.util.ArrayList;
-import java.util.List;
+@ExtendWith(MockitoExtension.class)
+public class AlertServerTest {
-
-@RunWith(MockitoJUnitRunner.class)
-public class AlertServerTest extends TestCase {
-
- @InjectMocks
- private AlertServer alertServer;
-
@Mock
private PluginDao pluginDao;
-
+
@Mock
private AlertConfig alertConfig;
@Mock
private AlertSenderService alertSenderService;
-
- @Test
- public void testStart() {
- Mockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true);
+ @InjectMocks
+ private AlertServer alertServer;
+
+ @BeforeEach
+ void init() {
+ Mockito.lenient().when(pluginDao.checkPluginDefineTableExist()).thenReturn(true);
- Mockito.when(alertConfig.getPort()).thenReturn(50052);
+ Mockito.lenient().when(alertConfig.getPort()).thenReturn(50052);
Mockito.doNothing().when(alertSenderService).start();
+ }
+ @Test
+ public void alertServerStartSuccessfully() {
+
alertServer.run(null);
-
+
NettyRemotingServer nettyRemotingServer = Whitebox.getInternalState(alertServer, "nettyRemotingServer");
-
+
NettyServerConfig nettyServerConfig = Whitebox.getInternalState(nettyRemotingServer, "serverConfig");
-
- Assert.assertEquals(50052, nettyServerConfig.getListenPort());
+
+ Assertions.assertEquals(50052, nettyServerConfig.getListenPort());
}
}
diff --git a/dolphinscheduler-api/pom.xml b/dolphinscheduler-api/pom.xml
index 6b8fc764f0..efaac0b7d5 100644
--- a/dolphinscheduler-api/pom.xml
+++ b/dolphinscheduler-api/pom.xml
@@ -26,7 +26,6 @@
<artifactId>dolphinscheduler-api</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
-
<dependencyManagement>
<dependencies>
<dependency>
@@ -38,7 +37,6 @@
</dependency>
</dependencies>
</dependencyManagement>
-
<dependencies>
<!-- dolphinscheduler -->
<dependency>
@@ -158,6 +156,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
@@ -192,7 +196,6 @@
<scope>test</scope>
</dependency>
</dependencies>
-
<build>
<testResources>
<testResource>
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java
index 7090a2f372..b73a21302d 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskInstanceControllerTest.java
@@ -71,9 +71,11 @@ public class TaskInstanceControllerTest extends AbstractControllerTest {
result.setMsg(Status.SUCCESS.getMsg());
when(taskInstanceService.queryTaskListPaging(any(), eq(1L), eq(1), eq(""), eq(""), eq(""), eq(""), any(), any(),
- eq(""), Mockito.any(), eq("192.168.xx.xx"), eq(TaskExecuteType.BATCH), any(), any())).thenReturn(result);
+ eq(""), Mockito.any(), eq("192.168.xx.xx"), eq(TaskExecuteType.BATCH), any(), any()))
+ .thenReturn(result);
Result taskResult = taskInstanceController.queryTaskListPaging(null, 1L, 1, "", "", "",
- "", "", TaskExecutionStatus.SUCCESS, "192.168.xx.xx", "2020-01-01 00:00:00", "2020-01-02 00:00:00", TaskExecuteType.BATCH, pageNo, pageSize);
+ "", "", TaskExecutionStatus.SUCCESS, "192.168.xx.xx", "2020-01-01 00:00:00", "2020-01-02 00:00:00",
+ TaskExecuteType.BATCH, pageNo, pageSize);
Assert.assertEquals(Integer.valueOf(Status.SUCCESS.getCode()), taskResult.getCode());
}
@@ -91,9 +93,9 @@ public class TaskInstanceControllerTest extends AbstractControllerTest {
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/task-instance/force-success", "cxc_1113")
.header(SESSION_ID, sessionId)
.params(paramsMap))
- .andExpect(status().isOk())
- .andExpect(content().contentType(MediaType.APPLICATION_JSON))
- .andReturn();
+ .andExpect(status().isOk())
+ .andExpect(content().contentType(MediaType.APPLICATION_JSON))
+ .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue());
diff --git a/pom.xml b/pom.xml
index 0efadbdb7f..ef784156f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,14 +64,15 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.boot.version>2.6.1</spring.boot.version>
<java.version>1.8</java.version>
- <junit.version>4.13.1</junit.version>
+ <junit.version>5.9.0</junit.version>
+ <mockito.version>3.9.0</mockito.version>
<spotbugs.version>3.1.12</spotbugs.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<maven-javadoc-plugin.version>2.10.3</maven-javadoc-plugin.version>
<maven-source-plugin.version>2.4</maven-source-plugin.version>
- <maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
+ <maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-shade-plugin.version>3.2.1</maven-shade-plugin.version>
<rpm-maven-plugion.version>2.2.0</rpm-maven-plugion.version>
@@ -309,6 +310,13 @@
<artifactId>dolphinscheduler-tools</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>${junit.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -321,9 +329,25 @@
of the submodules.
-->
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -581,13 +605,6 @@
<jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.surefire</groupId>
- <artifactId>surefire-junit4</artifactId>
- <version>${maven-surefire-plugin.version}</version>
- </dependency>
- </dependencies>
</plugin>
<!-- jenkins plugin jacoco report-->