* [Improvement][UT] Upgrade jUnit to 5.+ (#10976) * Refactor AlertServerTest with jUnit-5 as an example
This commit is contained in:
parent
7d80ea34ac
commit
b52da64001
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
Mockito.when(alertConfig.getPort()).thenReturn(50052);
|
||||
@BeforeEach
|
||||
void init() {
|
||||
Mockito.lenient().when(pluginDao.checkPluginDefineTableExist()).thenReturn(true);
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
41
pom.xml
41
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-->
|
||||
|
|
|
|||
Loading…
Reference in New Issue