|
|
|
@ -28,26 +28,53 @@ import org.apache.dolphinscheduler.api.enums.Status;
|
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertType; |
|
|
|
|
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.Test; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
import org.springframework.test.web.servlet.MvcResult; |
|
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* alert group controller test |
|
|
|
|
*/ |
|
|
|
|
public class AlertGroupControllerTest extends AbstractControllerTest { |
|
|
|
|
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 |
|
|
|
|
public void test010CreateAlertgroup() throws Exception { |
|
|
|
|
public void test010CreateAlertGroup() throws Exception { |
|
|
|
|
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("description", "cxc junit 测试告警描述"); |
|
|
|
|
paramsMap.add("alertInstanceIds", ""); |
|
|
|
@ -64,6 +91,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void test020List() throws Exception { |
|
|
|
|
createEntity(); |
|
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
|
MvcResult mvcResult = mockMvc.perform(get("/alert-groups/list") |
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
@ -79,6 +107,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void test030ListPaging() throws Exception { |
|
|
|
|
createEntity(); |
|
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
|
paramsMap.add("pageNo", "1"); |
|
|
|
|
paramsMap.add("searchVal", AlertType.EMAIL.toString()); |
|
|
|
@ -96,8 +125,9 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void test040QueryAlertGroupById() throws Exception { |
|
|
|
|
int entityId = createEntity(); |
|
|
|
|
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); |
|
|
|
|
paramsMap.add("id", "1"); |
|
|
|
|
paramsMap.add("id", Integer.toString(entityId)); |
|
|
|
|
MvcResult mvcResult = mockMvc.perform(post("/alert-groups/query") |
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
|
.params(paramsMap)) |
|
|
|
@ -110,13 +140,14 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void test050UpdateAlertgroup() throws Exception { |
|
|
|
|
public void test050UpdateAlertGroup() throws Exception { |
|
|
|
|
int entityId = createEntity(); |
|
|
|
|
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("description", "update alter group"); |
|
|
|
|
paramsMap.add("alertInstanceIds", ""); |
|
|
|
|
MvcResult mvcResult = mockMvc.perform(put("/alert-groups/1") |
|
|
|
|
MvcResult mvcResult = mockMvc.perform(put("/alert-groups/" + entityId) |
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
|
.params(paramsMap)) |
|
|
|
|
.andExpect(status().isOk()) |
|
|
|
@ -130,7 +161,7 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
|
|
|
|
|
@Test |
|
|
|
|
public void test060VerifyGroupName() throws Exception { |
|
|
|
|
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") |
|
|
|
|
.header("sessionId", sessionId) |
|
|
|
|
.params(paramsMap)) |
|
|
|
@ -158,9 +189,10 @@ public class AlertGroupControllerTest extends AbstractControllerTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void test080DelAlertgroupById() throws Exception { |
|
|
|
|
public void test080DelAlertGroupById() throws Exception { |
|
|
|
|
int entityId = createEntity(); |
|
|
|
|
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) |
|
|
|
|
.params(paramsMap)) |
|
|
|
|
.andExpect(status().isOk()) |
|
|
|
|