Browse Source

[Fix-7935] Rectify this issue with running test cases in the class of AlertGroupControllerTest. (#7954)

* fix a few issues
3.0.0/version-upgrade
calvin 3 years ago committed by GitHub
parent
commit
a81093d6cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java

50
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertGroupControllerTest.java

@ -28,26 +28,53 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.AlertType;
import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
import java.util.Date;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
/** /**
* alert group controller test * alert group controller test
*/ */
public class AlertGroupControllerTest extends AbstractControllerTest { public class AlertGroupControllerTest extends AbstractControllerTest {
private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class); private static final Logger logger = LoggerFactory.getLogger(AlertGroupController.class);
private static final String defaultTestAlertGroupName = "cxc test group name";
@Autowired
AlertGroupMapper alertGroupMapper;
private int createEntity() {
AlertGroup alertGroup = new AlertGroup();
alertGroup.setGroupName(defaultTestAlertGroupName);
alertGroup.setCreateTime(new Date());
alertGroup.setUpdateTime(new Date());
alertGroupMapper.insert(alertGroup);
return alertGroup.getId();
}
@After
public void clear() {
alertGroupMapper.delete(new QueryWrapper<AlertGroup>().lambda().eq(AlertGroup::getGroupName, defaultTestAlertGroupName));
}
@Test @Test
public void test010CreateAlertgroup() throws Exception { public void test010CreateAlertGroup() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("groupName", "cxc test group name"); paramsMap.add("groupName", defaultTestAlertGroupName);
paramsMap.add("groupType", AlertType.EMAIL.toString()); paramsMap.add("groupType", AlertType.EMAIL.toString());
paramsMap.add("description", "cxc junit 测试告警描述"); paramsMap.add("description", "cxc junit 测试告警描述");
paramsMap.add("alertInstanceIds", ""); paramsMap.add("alertInstanceIds", "");
@ -64,6 +91,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
@Test @Test
public void test020List() throws Exception { public void test020List() throws Exception {
createEntity();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
MvcResult mvcResult = mockMvc.perform(get("/alert-groups/list") MvcResult mvcResult = mockMvc.perform(get("/alert-groups/list")
.header("sessionId", sessionId) .header("sessionId", sessionId)
@ -79,6 +107,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
@Test @Test
public void test030ListPaging() throws Exception { public void test030ListPaging() throws Exception {
createEntity();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("pageNo", "1"); paramsMap.add("pageNo", "1");
paramsMap.add("searchVal", AlertType.EMAIL.toString()); paramsMap.add("searchVal", AlertType.EMAIL.toString());
@ -96,8 +125,9 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
@Test @Test
public void test040QueryAlertGroupById() throws Exception { public void test040QueryAlertGroupById() throws Exception {
int entityId = createEntity();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("id", "1"); paramsMap.add("id", Integer.toString(entityId));
MvcResult mvcResult = mockMvc.perform(post("/alert-groups/query") MvcResult mvcResult = mockMvc.perform(post("/alert-groups/query")
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
@ -110,13 +140,14 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
} }
@Test @Test
public void test050UpdateAlertgroup() throws Exception { public void test050UpdateAlertGroup() throws Exception {
int entityId = createEntity();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("groupName", "cxc test group name"); paramsMap.add("groupName", defaultTestAlertGroupName);
paramsMap.add("groupType", AlertType.EMAIL.toString()); paramsMap.add("groupType", AlertType.EMAIL.toString());
paramsMap.add("description", "update alter group"); paramsMap.add("description", "update alter group");
paramsMap.add("alertInstanceIds", ""); paramsMap.add("alertInstanceIds", "");
MvcResult mvcResult = mockMvc.perform(put("/alert-groups/1") MvcResult mvcResult = mockMvc.perform(put("/alert-groups/" + entityId)
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
@ -130,7 +161,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
@Test @Test
public void test060VerifyGroupName() throws Exception { public void test060VerifyGroupName() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("groupName", "cxc test group name"); paramsMap.add("groupName", defaultTestAlertGroupName);
MvcResult mvcResult = mockMvc.perform(get("/alert-groups/verify-name") MvcResult mvcResult = mockMvc.perform(get("/alert-groups/verify-name")
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
@ -158,9 +189,10 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
} }
@Test @Test
public void test080DelAlertgroupById() throws Exception { public void test080DelAlertGroupById() throws Exception {
int entityId = createEntity();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
MvcResult mvcResult = mockMvc.perform(delete("/alert-groups/1") MvcResult mvcResult = mockMvc.perform(delete("/alert-groups/" + entityId)
.header("sessionId", sessionId) .header("sessionId", sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())

Loading…
Cancel
Save