Skip to content

Commit

Permalink
cherry-pick Fix alert status spelling error
Browse files Browse the repository at this point in the history
  • Loading branch information
qingwli authored and zhuangchong committed Oct 29, 2022
1 parent 2c93dc6 commit 5eaf105
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public Result verifyGroupName(@ApiIgnore @RequestAttribute(value = Constants.SES
boolean exist = alertPluginInstanceService.checkExistPluginInstanceName(alertInstanceName);
if (exist) {
logger.error("alert plugin instance {} has exist, can't create again.", alertInstanceName);
return Result.error(Status.PLUGIN_INSTANCE_ALREADY_EXIT);
return Result.error(Status.PLUGIN_INSTANCE_ALREADY_EXISTS);
} else {
return Result.success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public enum Status {
GET_ALERT_PLUGIN_INSTANCE_ERROR(110007, "get alert plugin instance error", "获取告警组和告警组插件实例错误"),
CREATE_ALERT_PLUGIN_INSTANCE_ERROR(110008, "create alert plugin instance error", "创建告警组和告警组插件实例错误"),
QUERY_ALL_ALERT_PLUGIN_INSTANCE_ERROR(110009, "query all alert plugin instance error", "查询所有告警实例失败"),
PLUGIN_INSTANCE_ALREADY_EXIT(110010, "plugin instance already exit", "该告警插件实例已存在"),
PLUGIN_INSTANCE_ALREADY_EXISTS(110010, "plugin instance already exists", "该告警插件实例已存在"),
LIST_PAGING_ALERT_PLUGIN_INSTANCE_ERROR(110011, "query plugin instance page error", "分页查询告警实例失败"),
DELETE_ALERT_PLUGIN_INSTANCE_ERROR_HAS_ALERT_GROUP_ASSOCIATED(110012, "failed to delete the alert instance, there is an alarm group associated with this alert instance",
"删除告警实例失败,存在与此告警实例关联的警报组"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
Expand All @@ -62,6 +64,8 @@
@Lazy
public class AlertPluginInstanceServiceImpl extends BaseServiceImpl implements AlertPluginInstanceService {

private static final Logger logger = LoggerFactory.getLogger(AlertPluginInstanceServiceImpl.class);

@Autowired
private AlertPluginInstanceMapper alertPluginInstanceMapper;

Expand Down Expand Up @@ -93,7 +97,9 @@ public Map<String, Object> create(User loginUser, int pluginDefineId, String ins
return result;
}
if (alertPluginInstanceMapper.existInstanceName(alertPluginInstance.getInstanceName()) == Boolean.TRUE) {
putMsg(result, Status.PLUGIN_INSTANCE_ALREADY_EXIT);
logger.error("Plugin instance with the same name already exists, name:{}.",
alertPluginInstance.getInstanceName());
putMsg(result, Status.PLUGIN_INSTANCE_ALREADY_EXISTS);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ public void testVerifyGroupNamePluginInstanceNameExist() throws Exception {

when(alertPluginInstanceService.checkExistPluginInstanceName(eq(instanceName)))
.thenReturn(true);

Result expectResponseContent = JSONUtils.parseObject("{\"code\":110010,\"msg\":\"plugin instance already exit\",\"data\":null,\"failed\":true,\"success\":false}"
, Result.class);

//When

Result expectResponseContent = JSONUtils.parseObject(
"{\"code\":110010,\"msg\":\"plugin instance already exists\",\"data\":null,\"failed\":true,\"success\":false}",
Result.class);

// When
final MvcResult mvcResult = mockMvc.perform(get("/alert-plugin-instances/verify-name")
.header(SESSION_ID, sessionId)
.params(paramsMap))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
Expand Down Expand Up @@ -172,7 +173,8 @@ public void testCreate() {
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, null, 1, ALART_INSTANCE_CREATE, baseServiceLogger)).thenReturn(true);
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.ALERT_PLUGIN_INSTANCE, null, 0, baseServiceLogger)).thenReturn(true);
Map<String, Object> result = alertPluginInstanceService.create(user, 1, "test", uiParams);
Assert.assertEquals(Status.PLUGIN_INSTANCE_ALREADY_EXIT, result.get(Constants.STATUS));

Assertions.assertEquals(Status.PLUGIN_INSTANCE_ALREADY_EXISTS, result.get(Constants.STATUS));
Mockito.when(alertPluginInstanceMapper.insert(Mockito.any())).thenReturn(1);
result = alertPluginInstanceService.create(user, 1, "test1", uiParams);
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
Expand Down

0 comments on commit 5eaf105

Please sign in to comment.