parent
0e3189689b
commit
7127807383
|
@ -57,15 +57,6 @@ public enum MiddlewareType implements BaseEnum {
|
|||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前中间件类型的字符串值。
|
||||
*
|
||||
* @return 当前中间件类型的字符串值
|
||||
*/
|
||||
public String getStringValue() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前中间件类型的描述信息。
|
||||
*
|
||||
|
|
|
@ -74,17 +74,6 @@ public enum ProtoCryptoType implements BaseEnum {
|
|||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加密方式的描述信息。
|
||||
*
|
||||
* <p>此方法直接返回枚举定义时的描述信息(`readme`)。
|
||||
*
|
||||
* @return 加密方式的描述信息。
|
||||
*/
|
||||
public String getStringValue() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举值的描述信息。
|
||||
* <p>
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
package com.cmcc.magent.service;
|
||||
|
||||
import com.cmcc.magent.common.ErrorCode;
|
||||
import com.cmcc.magent.common.MiddlewareManagerCommand;
|
||||
import com.cmcc.magent.common.MulReturnType;
|
||||
import com.cmcc.magent.pojo.po.DeploymentContext;
|
||||
import com.cmcc.magent.pojo.po.DeploymentTaskStatus;
|
||||
import com.cmcc.magent.pojo.po.RemoteFileDetails;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* MiddlewareManagerService 接口用于管理中间件相关的操作。
|
||||
|
|
|
@ -9,8 +9,9 @@ import org.springframework.test.context.ActiveProfiles;
|
|||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* NoneEnumTest 是 {@link NoneEnum} 的单元测试类。
|
||||
|
@ -69,51 +70,6 @@ public class EnumCoverTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 {@link NoneEnum#getEnumString()} 方法。
|
||||
* <p>
|
||||
* 验证是否能正确返回枚举的字符串值。
|
||||
* </p>
|
||||
*
|
||||
* <p>测试逻辑:</p>
|
||||
* <ul>
|
||||
* <li>调用 {@link NoneEnum#NONE_ENUM#getStringValue()}。</li>
|
||||
* <li>断言返回的字符串值是否等于预期值 {@code ""}(空字符串)。</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("BaseEnum相关枚举类型接口")
|
||||
void testGetStringValue() {
|
||||
final String result = NoneEnum.NONE_ENUM.getEnumString();
|
||||
|
||||
// Verify the results
|
||||
assertThat(result).isEqualTo("NONE_ENUM");
|
||||
|
||||
final String var = UtilsFormatType.FORMAT_NONE.getEnumString();
|
||||
assertThat(var).isEqualTo("FORMAT_NONE");
|
||||
assertThat(NoneEnum.NONE_ENUM.getValue()).isEqualTo(0);
|
||||
assertFalse(NoneEnum.NONE_ENUM.getDescription().isEmpty());
|
||||
|
||||
assertThat(UtilsFormatType.FORMAT_NONE.getValue()).isEqualTo(4);
|
||||
assertThat(UtilsFormatType.FORMAT_NONE.getDescription().length()).isGreaterThan(0);
|
||||
|
||||
assertThat(ProtoCryptoType.CRYPTO_NONE.getValue()).isEqualTo(0);
|
||||
assertThat(ProtoCryptoType.CRYPTO_NONE.getDescription().length()).isGreaterThan(0);
|
||||
assertThat(ProtoCryptoType.CRYPTO_NONE.getStringValue().length()).isGreaterThan(0);
|
||||
|
||||
assertThat(CommonStatus.NORMAL.getValue()).isEqualTo(0);
|
||||
assertThat(CommonStatus.NORMAL.getDescription().length()).isGreaterThan(0);
|
||||
assertThat(CommonStatus.NORMAL.getEnumString().length()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("遍历枚举")
|
||||
void testEnumCover() {
|
||||
for (ErrorCode e : ErrorCode.values()) {
|
||||
assertThat(e).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ErrorCode转HTTP状态码")
|
||||
void testGetHttpCode() {
|
||||
|
@ -173,4 +129,33 @@ public class EnumCoverTest {
|
|||
assertThat(ErrorCode.ERR_USER_ROLE_NOTEXISTS.getHttpCode()).isEqualTo(500);
|
||||
assertThat(ErrorCode.ERR_RESOURCE_USED.getHttpCode()).isEqualTo(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖测试枚举方法。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("BaseEnum相关枚举类型接口")
|
||||
void testGetStringValue() {
|
||||
assertThat(ErrorCode.ERR_OK.getCode()).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖测试枚举方法。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("MiddlewareType枚举转换")
|
||||
void testStringToMiddlewareType() {
|
||||
String[] success = {"REDIS", "ZEDIS", "NGINX", "ZGINX", "KEEPALIVED", "Redis", "reDis", "ReDis"};
|
||||
String[] fail = {"REDIS1", "1ZEDIS", "User Custom"};
|
||||
|
||||
for (String s : success) {
|
||||
assertNotNull(MiddlewareType.getEnumByString(s));
|
||||
assertNotEquals(MiddlewareType.MIDDLEWARE_CUSTOM, MiddlewareType.getEnumByString(s));
|
||||
}
|
||||
|
||||
for (String s : fail) {
|
||||
assertThat(MiddlewareType.getEnumByString(s)).isNotNull();
|
||||
assertEquals(MiddlewareType.MIDDLEWARE_CUSTOM, MiddlewareType.getEnumByString(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
|
@ -50,11 +50,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
*/
|
||||
@DisplayName("Controller 全局异常处理测试")
|
||||
public class ControllerExceptionHandlerTest {
|
||||
private final String REQ_TYPE_GET = "GET";
|
||||
private final String REQ_TYPE_POST = "POST";
|
||||
private final String LOCAL_IP = "127.0.0.1";
|
||||
private final String REQ_PATH = "/api/middleware/status";
|
||||
private final String REQ_PATH_CMD = "/api/middleware/deployment";
|
||||
private final String TOKEN = UUID.randomUUID().toString();
|
||||
private final String DEPLOYMENT_ID = UUID.randomUUID().toString();
|
||||
private final String AUTHOR = "Bearer " + TOKEN;
|
||||
|
@ -106,6 +102,7 @@ public class ControllerExceptionHandlerTest {
|
|||
}
|
||||
|
||||
private void verifyResult(String exMessage) {
|
||||
String REQ_TYPE_GET = "GET";
|
||||
verify(operationLogService, times(1)).systemOperationLog(eq(REQ_TYPE_GET),
|
||||
any(HttpServletRequest.class),
|
||||
any(HttpServletResponse.class),
|
||||
|
@ -113,6 +110,7 @@ public class ControllerExceptionHandlerTest {
|
|||
eq("SYSLOG_TYPE_CREATE"),
|
||||
eq("SYSLOG_DESC_EXCEPTION"),
|
||||
eq(ErrorCode.ERR_SYSTEMEXCEPTION));
|
||||
String LOCAL_IP = "127.0.0.1";
|
||||
verify(logger, times(1)).error(anyString(),
|
||||
eq(REQ_TYPE_GET),
|
||||
eq(REQ_PATH),
|
||||
|
|
Loading…
Reference in New Issue