This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git
The following commit(s) were added to refs/heads/main by this push:
new d3f6c2f8 BIGTOP-4346: Add ut cases for enums classes in server module
(#165)
d3f6c2f8 is described below
commit d3f6c2f8b5d81a6e878eb2a32d357235869080a8
Author: xianrenzw <[email protected]>
AuthorDate: Sat Feb 8 18:14:54 2025 +0800
BIGTOP-4346: Add ut cases for enums classes in server module (#165)
---
.../manager/server/enums/ApiExceptionEnumTest.java | 93 ++++++++++++++++++
.../server/enums/AuthPlatformStatusTest.java | 75 +++++++++++++++
.../manager/server/enums/ChatbotCommandTest.java | 106 +++++++++++++++++++++
.../manager/server/enums/CommandLevelTest.java | 75 +++++++++++++++
.../server/enums/HealthyStatusEnumTest.java | 43 +++++++++
.../manager/server/enums/HostAuthTypeEnumTest.java | 47 +++++++++
.../server/enums/InstalledStatusEnumTest.java | 68 +++++++++++++
.../manager/server/enums/ResponseStatusTest.java | 47 +++++++++
8 files changed, 554 insertions(+)
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnumTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnumTest.java
new file mode 100644
index 00000000..45ccc139
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ApiExceptionEnumTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mockStatic;
+
+@ExtendWith(MockitoExtension.class)
+class ApiExceptionEnumTest {
+
+ @AfterEach
+ void tearDown() {
+ for (ApiExceptionEnum exception : ApiExceptionEnum.values()) {
+ exception.setArgs(null);
+ }
+ }
+
+ @Test
+ void testEnumProperties() {
+ assertEquals(10000, ApiExceptionEnum.NEED_LOGIN.getCode());
+ assertEquals(LocaleKeys.LOGIN_REQUIRED,
ApiExceptionEnum.NEED_LOGIN.getKey());
+
+ assertEquals(11000, ApiExceptionEnum.CLUSTER_NOT_FOUND.getCode());
+ assertEquals(LocaleKeys.CLUSTER_NOT_FOUND,
ApiExceptionEnum.CLUSTER_NOT_FOUND.getKey());
+
+ assertEquals(12000, ApiExceptionEnum.HOST_NOT_FOUND.getCode());
+ assertEquals(LocaleKeys.HOST_NOT_FOUND,
ApiExceptionEnum.HOST_NOT_FOUND.getKey());
+ }
+
+ @Test
+ void testGetMessageWithoutArgs() {
+ try (MockedStatic<MessageSourceUtils> mocked =
mockStatic(MessageSourceUtils.class)) {
+ mocked.when(() ->
MessageSourceUtils.getMessage(LocaleKeys.CLUSTER_NOT_FOUND))
+ .thenReturn("Cluster not found");
+
+ String message = ApiExceptionEnum.CLUSTER_NOT_FOUND.getMessage();
+ assertEquals("Cluster not found", message);
+ }
+ }
+
+ @Test
+ void testGetMessageWithArgs() {
+ try (MockedStatic<MessageSourceUtils> mocked =
mockStatic(MessageSourceUtils.class)) {
+ String[] args = {"example.txt"};
+ mocked.when(() ->
MessageSourceUtils.getMessage(LocaleKeys.FILE_UPLOAD_FAILED, args))
+ .thenReturn("File upload failed: example.txt");
+
+ ApiExceptionEnum.FILE_UPLOAD_FAILED.setArgs(args);
+ String message = ApiExceptionEnum.FILE_UPLOAD_FAILED.getMessage();
+ assertEquals("File upload failed: example.txt", message);
+ }
+ }
+
+ @Test
+ void testSetArgs() {
+ String[] args = {"testArg"};
+ ApiExceptionEnum.FILE_UPLOAD_FAILED.setArgs(args);
+ assertArrayEquals(args, ApiExceptionEnum.FILE_UPLOAD_FAILED.getArgs());
+ }
+
+ @Test
+ void testNoArgsAfterReset() {
+ ApiExceptionEnum.FILE_UPLOAD_FAILED.setArgs(new String[] {"temp"});
+ tearDown();
+ assertNull(ApiExceptionEnum.FILE_UPLOAD_FAILED.getArgs());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/AuthPlatformStatusTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/AuthPlatformStatusTest.java
new file mode 100644
index 00000000..365d19ce
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/AuthPlatformStatusTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class AuthPlatformStatusTest {
+
+ @Test
+ // Normal path test: Check if the code for each status is correct
+ public void testStatusCodes() {
+ assertEquals(1, AuthPlatformStatus.ACTIVE.getCode());
+ assertEquals(2, AuthPlatformStatus.AVAILABLE.getCode());
+ assertEquals(3, AuthPlatformStatus.UNAVAILABLE.getCode());
+ }
+
+ @Test
+ // Boundary case test: Check if invalid codes return UNAVAILABLE
+ public void testInvalidCode() {
+ assertEquals(AuthPlatformStatus.UNAVAILABLE,
AuthPlatformStatus.fromCode(0));
+ assertEquals(AuthPlatformStatus.UNAVAILABLE,
AuthPlatformStatus.fromCode(4));
+ assertEquals(AuthPlatformStatus.UNAVAILABLE,
AuthPlatformStatus.fromCode(null));
+ }
+
+ @Test
+ // Normal path test: Check if the isAvailable method works correctly with
valid codes
+ public void testIsAvailable() {
+ assertTrue(AuthPlatformStatus.isAvailable(2));
+ assertFalse(AuthPlatformStatus.isAvailable(1));
+ assertFalse(AuthPlatformStatus.isAvailable(3));
+ }
+
+ @Test
+ // Normal path test: Check if the isActive method works correctly with
valid codes
+ public void testIsActive() {
+ assertTrue(AuthPlatformStatus.isActive(1));
+ assertFalse(AuthPlatformStatus.isActive(2));
+ assertFalse(AuthPlatformStatus.isActive(3));
+ }
+
+ @Test
+ // Normal path test: Check if the available method works correctly with
valid codes
+ public void testAvailable() {
+ assertTrue(AuthPlatformStatus.available(1));
+ assertTrue(AuthPlatformStatus.available(2));
+ assertFalse(AuthPlatformStatus.available(3));
+ }
+
+ @Test
+ // Boundary case test: Check if the available method returns false with
invalid codes
+ public void testAvailableWithInvalidCode() {
+ assertFalse(AuthPlatformStatus.available(0));
+ assertFalse(AuthPlatformStatus.available(4));
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ChatbotCommandTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ChatbotCommandTest.java
new file mode 100644
index 00000000..6dc95519
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ChatbotCommandTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ChatbotCommandTest {
+
+ @Test
+ public void testGetAllCommands() {
+ // Test getting all commands
+ List<String> allCommands = ChatbotCommand.getAllCommands();
+ assertEquals(3, allCommands.size());
+ assertTrue(allCommands.contains("info"));
+ assertTrue(allCommands.contains("search"));
+ assertTrue(allCommands.contains("help"));
+ }
+
+ @Test
+ public void testGetCommandWithValidInput() {
+ // Test getting valid command
+ assertEquals(ChatbotCommand.INFO, ChatbotCommand.getCommand("info"));
+ assertEquals(ChatbotCommand.SEARCH,
ChatbotCommand.getCommand("search"));
+ assertEquals(ChatbotCommand.HELP, ChatbotCommand.getCommand("help"));
+ }
+
+ @Test
+ public void testGetCommandWithInvalidInput() {
+ // Test getting invalid command
+ assertNull(ChatbotCommand.getCommand("unknown"));
+ assertNull(ChatbotCommand.getCommand(""));
+ assertNull(ChatbotCommand.getCommand(null));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithValidInput() {
+ // Test getting valid command from message
+ assertEquals(ChatbotCommand.INFO,
ChatbotCommand.getCommandFromMessage("/info"));
+ assertEquals(ChatbotCommand.SEARCH,
ChatbotCommand.getCommandFromMessage("/search some text"));
+ assertEquals(ChatbotCommand.HELP,
ChatbotCommand.getCommandFromMessage("/help"));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithInvalidInput() {
+ // Test getting invalid command from message
+ assertNull(ChatbotCommand.getCommandFromMessage("info"));
+ assertNull(ChatbotCommand.getCommandFromMessage("/unknown"));
+ assertNull(ChatbotCommand.getCommandFromMessage(""));
+ assertThrows(NullPointerException.class, () ->
ChatbotCommand.getCommandFromMessage(null));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithNoSlash() {
+ // Test message with no slash
+ assertNull(ChatbotCommand.getCommandFromMessage("info"));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithOnlySlash() {
+ // Test message with only slash
+ assertNull(ChatbotCommand.getCommandFromMessage("/"));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithMultipleSlashes() {
+ // Test message with multiple slashes
+ assertNull(ChatbotCommand.getCommandFromMessage("//info"));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithTrailingSpace() {
+ // Test message with trailing space after command
+ assertEquals(ChatbotCommand.INFO,
ChatbotCommand.getCommandFromMessage("/info "));
+ }
+
+ @Test
+ public void testGetCommandFromMessageWithCaseInsensitive() {
+ // Test message with case insensitive command
+ assertNull(ChatbotCommand.getCommandFromMessage("/INFO"));
+ assertNull(ChatbotCommand.getCommandFromMessage("/SEARCH"));
+ assertNull(ChatbotCommand.getCommandFromMessage("/HELP"));
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/CommandLevelTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/CommandLevelTest.java
new file mode 100644
index 00000000..b2b391a9
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/CommandLevelTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class CommandLevelTest {
+
+ @Test
+ public void testFromStringNormalPath() {
+ assertEquals(CommandLevel.CLUSTER, CommandLevel.fromString("CLUSTER"));
+ assertEquals(CommandLevel.SERVICE, CommandLevel.fromString("SERVICE"));
+ assertEquals(CommandLevel.COMPONENT,
CommandLevel.fromString("COMPONENT"));
+ assertEquals(CommandLevel.HOST, CommandLevel.fromString("HOST"));
+ }
+
+ @Test
+ public void testFromStringLowercaseInput() {
+ assertEquals(CommandLevel.CLUSTER, CommandLevel.fromString("cluster"));
+ assertEquals(CommandLevel.SERVICE, CommandLevel.fromString("service"));
+ assertEquals(CommandLevel.COMPONENT,
CommandLevel.fromString("component"));
+ assertEquals(CommandLevel.HOST, CommandLevel.fromString("host"));
+ }
+
+ @Test
+ public void testFromStringMixedCaseInput() {
+ assertEquals(CommandLevel.CLUSTER, CommandLevel.fromString("ClUsTeR"));
+ assertEquals(CommandLevel.SERVICE, CommandLevel.fromString("SeRvIcE"));
+ assertEquals(CommandLevel.COMPONENT,
CommandLevel.fromString("CoMpOnEnT"));
+ assertEquals(CommandLevel.HOST, CommandLevel.fromString("HoSt"));
+ }
+
+ @Test
+ public void testFromStringEmptyStringInput() {
+ assertThrows(IllegalArgumentException.class, () ->
CommandLevel.fromString(""));
+ }
+
+ @Test
+ public void testFromStringInvalidInput() {
+ assertThrows(IllegalArgumentException.class, () ->
CommandLevel.fromString("INVALID"));
+ }
+
+ @Test
+ public void testToLowercaseNormalPath() {
+ assertEquals("cluster", CommandLevel.CLUSTER.toLowerCase());
+ assertEquals("service", CommandLevel.SERVICE.toLowerCase());
+ assertEquals("component", CommandLevel.COMPONENT.toLowerCase());
+ assertEquals("host", CommandLevel.HOST.toLowerCase());
+ }
+
+ @Test
+ public void testToLowercaseRepeatedCall() {
+ assertEquals("cluster", CommandLevel.CLUSTER.toLowerCase());
+ assertEquals("cluster", CommandLevel.CLUSTER.toLowerCase());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/HealthyStatusEnumTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/HealthyStatusEnumTest.java
new file mode 100644
index 00000000..93337c27
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/HealthyStatusEnumTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class HealthyStatusEnumTest {
+
+ @Test
+ public void testFromCodeNormalCase() {
+ assertEquals(HealthyStatusEnum.HEALTHY, HealthyStatusEnum.fromCode(1));
+ assertEquals(HealthyStatusEnum.UNHEALTHY,
HealthyStatusEnum.fromCode(2));
+ assertEquals(HealthyStatusEnum.UNKNOWN, HealthyStatusEnum.fromCode(3));
+ }
+
+ @Test
+ public void testFromCodeBoundaryCase() {
+ // Test code less than minimum value
+ assertEquals(HealthyStatusEnum.UNKNOWN, HealthyStatusEnum.fromCode(0));
+ // Test code greater than maximum value
+ assertEquals(HealthyStatusEnum.UNKNOWN, HealthyStatusEnum.fromCode(4));
+ // Test null value
+ assertEquals(HealthyStatusEnum.UNKNOWN,
HealthyStatusEnum.fromCode(null));
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/HostAuthTypeEnumTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/HostAuthTypeEnumTest.java
new file mode 100644
index 00000000..0037104b
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/HostAuthTypeEnumTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class HostAuthTypeEnumTest {
+
+ @Test
+ public void testFromCodeNormalPath() {
+ // Test normal path
+ assertEquals(HostAuthTypeEnum.PASSWORD, HostAuthTypeEnum.fromCode(1));
+ assertEquals(HostAuthTypeEnum.KEY, HostAuthTypeEnum.fromCode(2));
+ assertEquals(HostAuthTypeEnum.NO_AUTH, HostAuthTypeEnum.fromCode(3));
+ }
+
+ @Test
+ public void testFromCodeEdgeCases() {
+ // Test below minimum value
+ assertThrows(IllegalArgumentException.class, () ->
HostAuthTypeEnum.fromCode(0));
+ // Test above maximum value
+ assertThrows(IllegalArgumentException.class, () ->
HostAuthTypeEnum.fromCode(4));
+ // Test null value
+ assertThrows(IllegalArgumentException.class, () ->
HostAuthTypeEnum.fromCode(null));
+ // Test negative value
+ assertThrows(IllegalArgumentException.class, () ->
HostAuthTypeEnum.fromCode(-1));
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/InstalledStatusEnumTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/InstalledStatusEnumTest.java
new file mode 100644
index 00000000..02952930
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/InstalledStatusEnumTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class InstalledStatusEnumTest {
+
+ @Test
+ // Test normal case: INSTALLING
+ public void testFromCodeNormalCase_INSTALLING() {
+ assertEquals(InstalledStatusEnum.INSTALLING,
InstalledStatusEnum.fromCode(1));
+ }
+
+ @Test
+ // Test normal case: SUCCESS
+ public void testFromCodeNormalCase_SUCCESS() {
+ assertEquals(InstalledStatusEnum.SUCCESS,
InstalledStatusEnum.fromCode(2));
+ }
+
+ @Test
+ // Test normal case: FAILED
+ public void testFromCodeNormalCase_FAILED() {
+ assertEquals(InstalledStatusEnum.FAILED,
InstalledStatusEnum.fromCode(3));
+ }
+
+ @Test
+ // Test boundary case: less than minimum value
+ public void testFromCodeBoundaryCaseLessThanMinValue() {
+ assertEquals(InstalledStatusEnum.FAILED,
InstalledStatusEnum.fromCode(0));
+ }
+
+ @Test
+ // Test boundary case: greater than maximum value
+ public void testFromCodeBoundaryCaseGreaterThanMaxValue() {
+ assertEquals(InstalledStatusEnum.FAILED,
InstalledStatusEnum.fromCode(4));
+ }
+
+ @Test
+ // Test boundary case: null value
+ public void testFromCodeBoundaryCaseNullValue() {
+ assertEquals(InstalledStatusEnum.FAILED,
InstalledStatusEnum.fromCode(null));
+ }
+
+ @Test
+ // Test boundary case: negative number
+ public void testFromCodeBoundaryCaseNegativeNumber() {
+ assertEquals(InstalledStatusEnum.FAILED,
InstalledStatusEnum.fromCode(-1));
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ResponseStatusTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ResponseStatusTest.java
new file mode 100644
index 00000000..6f19cd8c
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/enums/ResponseStatusTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bigtop.manager.server.enums;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ResponseStatusTest {
+
+ @Test
+ public void testSuccess() {
+ ResponseStatus status = ResponseStatus.SUCCESS;
+ assertEquals(0, status.getCode());
+ assertEquals(LocaleKeys.REQUEST_SUCCESS, status.getKey());
+ }
+
+ @Test
+ public void testInternalServerError() {
+ ResponseStatus status = ResponseStatus.INTERNAL_SERVER_ERROR;
+ assertEquals(-1, status.getCode());
+ assertEquals(LocaleKeys.REQUEST_FAILED, status.getKey());
+ }
+
+ @Test
+ public void testParameterError() {
+ ResponseStatus status = ResponseStatus.PARAMETER_ERROR;
+ assertEquals(1, status.getCode());
+ assertEquals(LocaleKeys.PARAMETER_ERROR, status.getKey());
+ }
+}