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 45d36aa BIGTOP-4180: Add ut cases for controller classes in server
module (#35)
45d36aa is described below
commit 45d36aad6b039168f241ca48d3fc2cb6c721d0c3
Author: Zhiguo Wu <[email protected]>
AuthorDate: Mon Aug 5 15:45:38 2024 +0800
BIGTOP-4180: Add ut cases for controller classes in server module (#35)
---
.../manager/server/controller/HostController.java | 15 +-
.../manager/server/controller/LoginController.java | 10 --
.../server/controller/MonitoringController.java | 2 +-
.../manager/server/enums/heartbeat/HostState.java | 27 ---
.../server/controller/CommandControllerTest.java | 88 +++++++++
.../server/controller/ComponentControllerTest.java | 112 ++++++++++++
.../server/controller/ConfigControllerTest.java | 111 ++++++++++++
.../controller/HostComponentControllerTest.java | 138 +++++++++++++++
.../server/controller/HostControllerTest.java | 196 +++++++++++++++++++++
.../server/controller/JobControllerTest.java | 116 ++++++++++++
.../server/controller/LoginControllerTest.java | 113 ++++++++++++
.../controller/MonitoringControllerTest.java | 86 +++++++++
.../server/controller/ServiceControllerTest.java | 100 +++++++++++
.../server/controller/SseControllerTest.java | 116 ++++++++++++
.../server/controller/StackControllerTest.java | 104 +++++++++++
.../server/controller/UserControllerTest.java | 83 +++++++++
16 files changed, 1373 insertions(+), 44 deletions(-)
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
index b617f4a..561c39a 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/HostController.java
@@ -27,9 +27,11 @@ import org.apache.bigtop.manager.server.service.HostService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;
import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -55,21 +57,22 @@ public class HostController {
}
@Operation(summary = "get", description = "Get a host")
- // @GetMapping("/{id}")
- public ResponseEntity<HostVO> get(@PathVariable Long id) {
+ @GetMapping("/{id}")
+ public ResponseEntity<HostVO> get(@PathVariable Long id, @PathVariable
Long clusterId) {
return ResponseEntity.success(hostService.get(id));
}
@Operation(summary = "update", description = "Update a host")
- // @PutMapping("/{id}")
- public ResponseEntity<HostVO> update(@PathVariable Long id, @RequestBody
@Validated HostReq hostReq) {
+ @PutMapping("/{id}")
+ public ResponseEntity<HostVO> update(
+ @PathVariable Long clusterId, @PathVariable Long id, @RequestBody
@Validated HostReq hostReq) {
HostDTO hostDTO = HostConverter.INSTANCE.fromReq2DTO(hostReq);
return ResponseEntity.success(hostService.update(id, hostDTO));
}
@Operation(summary = "delete", description = "Delete a host")
- // @DeleteMapping("/{id}")
- public ResponseEntity<Boolean> delete(@PathVariable Long id) {
+ @DeleteMapping("/{id}")
+ public ResponseEntity<Boolean> delete(@PathVariable Long clusterId,
@PathVariable Long id) {
return ResponseEntity.success(hostService.delete(id));
}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/LoginController.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/LoginController.java
index 895afca..db92a78 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/LoginController.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/LoginController.java
@@ -21,7 +21,6 @@ package org.apache.bigtop.manager.server.controller;
import org.apache.bigtop.manager.server.annotations.Audit;
import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
import org.apache.bigtop.manager.server.exception.ApiException;
-import org.apache.bigtop.manager.server.holder.SessionUserHolder;
import org.apache.bigtop.manager.server.model.converter.LoginConverter;
import org.apache.bigtop.manager.server.model.dto.LoginDTO;
import org.apache.bigtop.manager.server.model.req.LoginReq;
@@ -30,7 +29,6 @@ import org.apache.bigtop.manager.server.service.LoginService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;
import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -58,12 +56,4 @@ public class LoginController {
LoginDTO loginDTO = LoginConverter.INSTANCE.fromReq2DTO(loginReq);
return ResponseEntity.success(loginService.login(loginDTO));
}
-
- @Operation(summary = "test", description = "test")
- @GetMapping(value = "/test")
- public ResponseEntity<String> test() {
- Long userId = SessionUserHolder.getUserId();
- // throw new
ServerException(ServerExceptionStatus.USERNAME_OR_PASSWORD_REQUIRED);
- return ResponseEntity.success("111");
- }
}
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
index de19f5c..9ddd213 100644
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
+++
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
@@ -37,7 +37,7 @@ import jakarta.annotation.Resource;
public class MonitoringController {
@Resource
- MonitoringService monitoringService;
+ private MonitoringService monitoringService;
@Operation(summary = "agent healthy", description = "agent healthy check")
@GetMapping("agenthealthy")
diff --git
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/heartbeat/HostState.java
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/heartbeat/HostState.java
deleted file mode 100644
index cb6386b..0000000
---
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/enums/heartbeat/HostState.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.heartbeat;
-
-public enum HostState {
- INITIALIZING,
-
- HEALTHY,
-
- LOST,
-}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/CommandControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/CommandControllerTest.java
new file mode 100644
index 0000000..5c53c67
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/CommandControllerTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+import org.apache.bigtop.manager.server.model.req.CommandReq;
+import org.apache.bigtop.manager.server.model.vo.CommandVO;
+import org.apache.bigtop.manager.server.service.CommandService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class CommandControllerTest {
+
+ @Mock
+ private CommandService commandService;
+
+ @InjectMocks
+ private CommandController commandController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void commandExecutesSuccessfully() {
+ CommandReq commandReq = new CommandReq();
+ CommandVO commandVO = new CommandVO();
+
when(commandService.command(any(CommandDTO.class))).thenReturn(commandVO);
+
+ ResponseEntity<CommandVO> response =
commandController.command(commandReq);
+
+ assertTrue(response.isSuccess());
+ assertEquals(commandVO, response.getData());
+ }
+
+ @Test
+ void commandHandlesInvalidRequest() {
+ CommandReq commandReq = new CommandReq(); // Assuming this is invalid
+ when(commandService.command(any(CommandDTO.class))).thenReturn(null);
+
+ ResponseEntity<CommandVO> response =
commandController.command(commandReq);
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ComponentControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ComponentControllerTest.java
new file mode 100644
index 0000000..ef631f2
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ComponentControllerTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.vo.ComponentVO;
+import org.apache.bigtop.manager.server.service.ComponentService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+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.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class ComponentControllerTest {
+
+ @Mock
+ private ComponentService componentService;
+
+ @InjectMocks
+ private ComponentController componentController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllComponents() {
+ Long clusterId = 1L;
+ List<ComponentVO> components = Arrays.asList(new ComponentVO(), new
ComponentVO());
+ when(componentService.list(clusterId)).thenReturn(components);
+
+ ResponseEntity<List<ComponentVO>> response =
componentController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(components, response.getData());
+ }
+
+ @Test
+ void getReturnsComponentById() {
+ Long id = 1L;
+ ComponentVO component = new ComponentVO();
+ when(componentService.get(id)).thenReturn(component);
+
+ ResponseEntity<ComponentVO> response = componentController.get(id);
+
+ assertTrue(response.isSuccess());
+ assertEquals(component, response.getData());
+ }
+
+ @Test
+ void listReturnsEmptyForNoComponents() {
+ Long clusterId = 1L;
+ when(componentService.list(clusterId)).thenReturn(List.of());
+
+ ResponseEntity<List<ComponentVO>> response =
componentController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+
+ @Test
+ void getReturnsNotFoundForInvalidId() {
+ Long id = 999L;
+ when(componentService.get(id)).thenReturn(null);
+
+ ResponseEntity<ComponentVO> response = componentController.get(id);
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ConfigControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ConfigControllerTest.java
new file mode 100644
index 0000000..401ba0b
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ConfigControllerTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO;
+import org.apache.bigtop.manager.server.service.ConfigService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class ConfigControllerTest {
+
+ @Mock
+ private ConfigService configService;
+
+ @InjectMocks
+ private ConfigController configController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllConfigurations() {
+ Long clusterId = 1L;
+ List<ServiceConfigVO> configs = Arrays.asList(new ServiceConfigVO(),
new ServiceConfigVO());
+ when(configService.list(clusterId)).thenReturn(configs);
+
+ ResponseEntity<List<ServiceConfigVO>> response =
configController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(configs, response.getData());
+ }
+
+ @Test
+ void latestReturnsLatestConfigurations() {
+ Long clusterId = 1L;
+ List<ServiceConfigVO> latestConfigs = Arrays.asList(new
ServiceConfigVO(), new ServiceConfigVO());
+ when(configService.latest(clusterId)).thenReturn(latestConfigs);
+
+ ResponseEntity<List<ServiceConfigVO>> response =
configController.latest(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(latestConfigs, response.getData());
+ }
+
+ @Test
+ void listReturnsEmptyForInvalidClusterId() {
+ Long clusterId = 999L;
+ when(configService.list(clusterId)).thenReturn(List.of());
+
+ ResponseEntity<List<ServiceConfigVO>> response =
configController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+
+ @Test
+ void latestReturnsEmptyForInvalidClusterId() {
+ Long clusterId = 999L;
+ when(configService.latest(clusterId)).thenReturn(List.of());
+
+ ResponseEntity<List<ServiceConfigVO>> response =
configController.latest(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/HostComponentControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/HostComponentControllerTest.java
new file mode 100644
index 0000000..7f11d84
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/HostComponentControllerTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.vo.HostComponentVO;
+import org.apache.bigtop.manager.server.service.HostComponentService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class HostComponentControllerTest {
+
+ @Mock
+ private HostComponentService hostComponentService;
+
+ @InjectMocks
+ private HostComponentController hostComponentController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllHostComponents() {
+ Long clusterId = 1L;
+ List<HostComponentVO> hostComponents = Arrays.asList(new
HostComponentVO(), new HostComponentVO());
+ when(hostComponentService.list(clusterId)).thenReturn(hostComponents);
+
+ ResponseEntity<List<HostComponentVO>> response =
hostComponentController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(hostComponents, response.getData());
+ }
+
+ @Test
+ void listByHostReturnsHostComponentsForHost() {
+ Long clusterId = 1L;
+ Long hostId = 1L;
+ List<HostComponentVO> hostComponents = Arrays.asList(new
HostComponentVO(), new HostComponentVO());
+ when(hostComponentService.listByHost(clusterId,
hostId)).thenReturn(hostComponents);
+
+ ResponseEntity<List<HostComponentVO>> response =
hostComponentController.listByHost(clusterId, hostId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(hostComponents, response.getData());
+ }
+
+ @Test
+ void listByServiceReturnsHostComponentsForService() {
+ Long clusterId = 1L;
+ Long serviceId = 1L;
+ List<HostComponentVO> hostComponents = Arrays.asList(new
HostComponentVO(), new HostComponentVO());
+ when(hostComponentService.listByService(clusterId,
serviceId)).thenReturn(hostComponents);
+
+ ResponseEntity<List<HostComponentVO>> response =
hostComponentController.listByService(clusterId, serviceId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(hostComponents, response.getData());
+ }
+
+ @Test
+ void listReturnsEmptyForInvalidClusterId() {
+ Long clusterId = 999L;
+ when(hostComponentService.list(clusterId)).thenReturn(List.of());
+
+ ResponseEntity<List<HostComponentVO>> response =
hostComponentController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+
+ @Test
+ void listByHostReturnsEmptyForInvalidHostId() {
+ Long clusterId = 1L;
+ Long hostId = 999L;
+ when(hostComponentService.listByHost(clusterId,
hostId)).thenReturn(List.of());
+
+ ResponseEntity<List<HostComponentVO>> response =
hostComponentController.listByHost(clusterId, hostId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+
+ @Test
+ void listByServiceReturnsEmptyForInvalidServiceId() {
+ Long clusterId = 1L;
+ Long serviceId = 999L;
+ when(hostComponentService.listByService(clusterId,
serviceId)).thenReturn(List.of());
+
+ ResponseEntity<List<HostComponentVO>> response =
hostComponentController.listByService(clusterId, serviceId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/HostControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/HostControllerTest.java
new file mode 100644
index 0000000..f7b6c2e
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/HostControllerTest.java
@@ -0,0 +1,196 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.dto.HostDTO;
+import org.apache.bigtop.manager.server.model.req.HostReq;
+import org.apache.bigtop.manager.server.model.req.HostnamesReq;
+import org.apache.bigtop.manager.server.model.vo.HostVO;
+import org.apache.bigtop.manager.server.service.HostService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class HostControllerTest {
+
+ @Mock
+ private HostService hostService;
+
+ @InjectMocks
+ private HostController hostController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllHosts() {
+ Long clusterId = 1L;
+ List<HostVO> hosts = Arrays.asList(new HostVO(), new HostVO());
+ when(hostService.list(clusterId)).thenReturn(hosts);
+
+ ResponseEntity<List<HostVO>> response = hostController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(hosts, response.getData());
+ }
+
+ @Test
+ void getReturnsHost() {
+ Long clusterId = 1L;
+ Long hostId = 1L;
+ HostVO host = new HostVO();
+ when(hostService.get(hostId)).thenReturn(host);
+
+ ResponseEntity<HostVO> response = hostController.get(hostId,
clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(host, response.getData());
+ }
+
+ @Test
+ void updateReturnsUpdatedHost() {
+ Long clusterId = 1L;
+ Long hostId = 1L;
+ HostReq hostReq = new HostReq();
+ HostVO updatedHost = new HostVO();
+ when(hostService.update(anyLong(),
any(HostDTO.class))).thenReturn(updatedHost);
+
+ ResponseEntity<HostVO> response = hostController.update(clusterId,
hostId, hostReq);
+
+ assertTrue(response.isSuccess());
+ assertEquals(updatedHost, response.getData());
+ }
+
+ @Test
+ void deleteReturnsSuccess() {
+ Long clusterId = 1L;
+ Long hostId = 1L;
+ when(hostService.delete(hostId)).thenReturn(true);
+
+ ResponseEntity<Boolean> response = hostController.delete(clusterId,
hostId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData());
+ }
+
+ @Test
+ void checkConnectionReturnsSuccess() {
+ Long clusterId = 1L;
+ HostnamesReq hostnamesReq = new HostnamesReq();
+ hostnamesReq.setHostnames(Arrays.asList("host1", "host2"));
+
when(hostService.checkConnection(hostnamesReq.getHostnames())).thenReturn(true);
+
+ ResponseEntity<Boolean> response =
hostController.checkConnection(clusterId, hostnamesReq);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData());
+ }
+
+ @Test
+ void listReturnsEmptyForInvalidClusterId() {
+ Long clusterId = 999L;
+ when(hostService.list(clusterId)).thenReturn(List.of());
+
+ ResponseEntity<List<HostVO>> response = hostController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertTrue(response.getData().isEmpty());
+ }
+
+ @Test
+ void getReturnsNullForInvalidHostId() {
+ Long clusterId = 1L;
+ Long hostId = 999L;
+ when(hostService.get(hostId)).thenReturn(null);
+
+ ResponseEntity<HostVO> response = hostController.get(hostId,
clusterId);
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+
+ @Test
+ void updateReturnsNullForInvalidHostId() {
+ Long clusterId = 1L;
+ Long hostId = 999L;
+ HostReq hostReq = new HostReq();
+ when(hostService.update(anyLong(),
any(HostDTO.class))).thenReturn(null);
+
+ ResponseEntity<HostVO> response = hostController.update(clusterId,
hostId, hostReq);
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+
+ @Test
+ void deleteReturnsFalseForInvalidHostId() {
+ Long clusterId = 1L;
+ Long hostId = 999L;
+ when(hostService.delete(hostId)).thenReturn(false);
+
+ ResponseEntity<Boolean> response = hostController.delete(clusterId,
hostId);
+
+ assertTrue(response.isSuccess());
+ assertFalse(response.getData());
+ }
+
+ @Test
+ void checkConnectionReturnsFalseForInvalidHostnames() {
+ Long clusterId = 1L;
+ HostnamesReq hostnamesReq = new HostnamesReq();
+ hostnamesReq.setHostnames(Arrays.asList("invalidHost1",
"invalidHost2"));
+
when(hostService.checkConnection(hostnamesReq.getHostnames())).thenReturn(false);
+
+ ResponseEntity<Boolean> response =
hostController.checkConnection(clusterId, hostnamesReq);
+
+ assertTrue(response.isSuccess());
+ assertFalse(response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/JobControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/JobControllerTest.java
new file mode 100644
index 0000000..9650074
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/JobControllerTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.vo.JobVO;
+import org.apache.bigtop.manager.server.model.vo.PageVO;
+import org.apache.bigtop.manager.server.service.JobService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class JobControllerTest {
+
+ @Mock
+ private JobService jobService;
+
+ @InjectMocks
+ private JobController jobController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllJobs() {
+ Long clusterId = 1L;
+ PageVO<JobVO> jobs = PageVO.of(Arrays.asList(new JobVO(), new
JobVO()), 2L);
+ when(jobService.list(clusterId)).thenReturn(jobs);
+
+ ResponseEntity<PageVO<JobVO>> response = jobController.list(clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(jobs, response.getData());
+ }
+
+ @Test
+ void getReturnsJobById() {
+ Long id = 1L;
+ Long clusterId = 1L;
+ JobVO job = new JobVO();
+ when(jobService.get(id)).thenReturn(job);
+
+ ResponseEntity<JobVO> response = jobController.get(id, clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(job, response.getData());
+ }
+
+ @Test
+ void retryRetriesJob() {
+ Long id = 1L;
+ Long clusterId = 1L;
+ JobVO job = new JobVO();
+ when(jobService.retry(id)).thenReturn(job);
+
+ ResponseEntity<JobVO> response = jobController.retry(id, clusterId);
+
+ assertTrue(response.isSuccess());
+ assertEquals(job, response.getData());
+ }
+
+ @Test
+ void getReturnsNotFoundForInvalidId() {
+ Long id = 999L;
+ Long clusterId = 1L;
+ when(jobService.get(id)).thenReturn(null);
+
+ ResponseEntity<JobVO> response = jobController.get(id, clusterId);
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/LoginControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/LoginControllerTest.java
new file mode 100644
index 0000000..095afef
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/LoginControllerTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
+import org.apache.bigtop.manager.server.exception.ApiException;
+import org.apache.bigtop.manager.server.model.dto.LoginDTO;
+import org.apache.bigtop.manager.server.model.req.LoginReq;
+import org.apache.bigtop.manager.server.model.vo.LoginVO;
+import org.apache.bigtop.manager.server.service.LoginService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class LoginControllerTest {
+
+ @Mock
+ private LoginService loginService;
+
+ @InjectMocks
+ private LoginController loginController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void loginReturnsSuccessForValidCredentials() {
+ LoginReq loginReq = new LoginReq();
+ loginReq.setUsername("validUser");
+ loginReq.setPassword("validPassword");
+
+ LoginVO loginVO = new LoginVO();
+ when(loginService.login(any(LoginDTO.class))).thenReturn(loginVO);
+
+ ResponseEntity<LoginVO> response = loginController.login(loginReq);
+
+ assertEquals(loginVO, response.getData());
+ }
+
+ @Test
+ void loginThrowsExceptionForMissingUsername() {
+ LoginReq loginReq = new LoginReq();
+ loginReq.setUsername("");
+ loginReq.setPassword("validPassword");
+
+ ApiException exception = assertThrows(ApiException.class, () ->
loginController.login(loginReq));
+
+ assertEquals(ApiExceptionEnum.USERNAME_OR_PASSWORD_REQUIRED,
exception.getEx());
+ }
+
+ @Test
+ void loginThrowsExceptionForMissingPassword() {
+ LoginReq loginReq = new LoginReq();
+ loginReq.setUsername("validUser");
+ loginReq.setPassword("");
+
+ ApiException exception = assertThrows(ApiException.class, () ->
loginController.login(loginReq));
+
+ assertEquals(ApiExceptionEnum.USERNAME_OR_PASSWORD_REQUIRED,
exception.getEx());
+ }
+
+ @Test
+ void loginThrowsExceptionForMissingUsernameAndPassword() {
+ LoginReq loginReq = new LoginReq();
+ loginReq.setUsername("");
+ loginReq.setPassword("");
+
+ ApiException exception = assertThrows(ApiException.class, () ->
loginController.login(loginReq));
+
+ assertEquals(ApiExceptionEnum.USERNAME_OR_PASSWORD_REQUIRED,
exception.getEx());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/MonitoringControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/MonitoringControllerTest.java
new file mode 100644
index 0000000..cc391a1
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/MonitoringControllerTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.service.MonitoringService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class MonitoringControllerTest {
+
+ @Mock
+ private MonitoringService monitoringService;
+
+ @InjectMocks
+ private MonitoringController monitoringController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void agentHostsHealthyStatusReturnsSuccess() {
+ JsonNode mockResponse = new ObjectMapper().createObjectNode();
+
when(monitoringService.queryAgentsHealthyStatus()).thenReturn(mockResponse);
+
+ ResponseEntity<JsonNode> response =
monitoringController.agentHostsHealthyStatus();
+
+ assertTrue(response.isSuccess());
+ assertEquals(mockResponse, response.getData());
+ }
+
+ @Test
+ void agentHostsHealthyStatusReturnsEmptyResponse() {
+ when(monitoringService.queryAgentsHealthyStatus()).thenReturn(null);
+
+ ResponseEntity<JsonNode> response =
monitoringController.agentHostsHealthyStatus();
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ServiceControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ServiceControllerTest.java
new file mode 100644
index 0000000..7dabe07
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/ServiceControllerTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.vo.ServiceVO;
+import org.apache.bigtop.manager.server.service.ServiceService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+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.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class ServiceControllerTest {
+
+ @Mock
+ private ServiceService serviceService;
+
+ @InjectMocks
+ private ServiceController serviceController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllServices() {
+ List<ServiceVO> services = Arrays.asList(new ServiceVO(), new
ServiceVO());
+ when(serviceService.list(any())).thenReturn(services);
+
+ ResponseEntity<List<ServiceVO>> response = serviceController.list(1L);
+
+ assertTrue(response.isSuccess());
+ assertEquals(services, response.getData());
+ }
+
+ @Test
+ void getReturnsServiceById() {
+ Long id = 1L;
+ ServiceVO service = new ServiceVO();
+ when(serviceService.get(id)).thenReturn(service);
+
+ ResponseEntity<ServiceVO> response = serviceController.get(id);
+
+ assertTrue(response.isSuccess());
+ assertEquals(service, response.getData());
+ }
+
+ @Test
+ void getReturnsNotFoundForInvalidId() {
+ Long id = 999L;
+ when(serviceService.get(id)).thenReturn(null);
+
+ ResponseEntity<ServiceVO> response = serviceController.get(id);
+
+ assertTrue(response.isSuccess());
+ assertNull(response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/SseControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/SseControllerTest.java
new file mode 100644
index 0000000..607ff82
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/SseControllerTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.service.TaskLogService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
+
+import reactor.core.publisher.FluxSink;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class SseControllerTest {
+
+ @Mock
+ private TaskLogService taskLogService;
+
+ @InjectMocks
+ private SseController sseController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void logReturnsSseEmitter() {
+ Long taskId = 1L;
+ Long clusterId = 1L;
+ doAnswer(invocation -> {
+ FluxSink<String> sink = invocation.getArgument(1);
+ sink.next("log message");
+ sink.complete();
+ return null;
+ })
+ .when(taskLogService)
+ .registerSink(eq(taskId), any());
+
+ SseEmitter emitter = sseController.log(taskId, clusterId);
+
+ assertNotNull(emitter);
+ }
+
+ @Test
+ void logHandlesExceptionDuringEmission() {
+ Long taskId = 1L;
+ Long clusterId = 1L;
+ doAnswer(invocation -> {
+ FluxSink<String> sink = invocation.getArgument(1);
+ sink.error(new RuntimeException("Test exception"));
+ return null;
+ })
+ .when(taskLogService)
+ .registerSink(eq(taskId), any());
+
+ SseEmitter emitter = sseController.log(taskId, clusterId);
+
+ assertNotNull(emitter);
+ }
+
+ @Test
+ void logCompletes() {
+ Long taskId = 1L;
+ Long clusterId = 1L;
+ doAnswer(invocation -> {
+ FluxSink<String> sink = invocation.getArgument(1);
+ sink.complete();
+ return null;
+ })
+ .when(taskLogService)
+ .registerSink(eq(taskId), any());
+
+ SseEmitter emitter = sseController.log(taskId, clusterId);
+
+ assertNotNull(emitter);
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/StackControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/StackControllerTest.java
new file mode 100644
index 0000000..60b072f
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/StackControllerTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.vo.ServiceComponentVO;
+import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO;
+import org.apache.bigtop.manager.server.model.vo.StackVO;
+import org.apache.bigtop.manager.server.service.StackService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class StackControllerTest {
+
+ @Mock
+ private StackService stackService;
+
+ @InjectMocks
+ private StackController stackController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void listReturnsAllStacks() {
+ List<StackVO> stacks = Arrays.asList(new StackVO(), new StackVO());
+ when(stackService.list()).thenReturn(stacks);
+
+ ResponseEntity<List<StackVO>> response = stackController.list();
+
+ assertTrue(response.isSuccess());
+ assertEquals(stacks, response.getData());
+ }
+
+ @Test
+ void componentsReturnsAllComponentsForValidStack() {
+ String stackName = "bigtop";
+ String stackVersion = "1.0.0";
+ List<ServiceComponentVO> components = Arrays.asList(new
ServiceComponentVO(), new ServiceComponentVO());
+ when(stackService.components(stackName,
stackVersion)).thenReturn(components);
+
+ ResponseEntity<List<ServiceComponentVO>> response =
stackController.components(stackName, stackVersion);
+
+ assertTrue(response.isSuccess());
+ assertEquals(components, response.getData());
+ }
+
+ @Test
+ void configurationsReturnsAllConfigurationsForValidStack() {
+ String stackName = "bigtop";
+ String stackVersion = "1.0.0";
+ List<ServiceConfigVO> configurations = Arrays.asList(new
ServiceConfigVO(), new ServiceConfigVO());
+ when(stackService.configurations(stackName,
stackVersion)).thenReturn(configurations);
+
+ ResponseEntity<List<ServiceConfigVO>> response =
stackController.configurations(stackName, stackVersion);
+
+ assertTrue(response.isSuccess());
+ assertEquals(configurations, response.getData());
+ }
+}
diff --git
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/UserControllerTest.java
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/UserControllerTest.java
new file mode 100644
index 0000000..7100b55
--- /dev/null
+++
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/controller/UserControllerTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.controller;
+
+import org.apache.bigtop.manager.server.model.req.UserReq;
+import org.apache.bigtop.manager.server.model.vo.UserVO;
+import org.apache.bigtop.manager.server.service.UserService;
+import org.apache.bigtop.manager.server.utils.MessageSourceUtils;
+import org.apache.bigtop.manager.server.utils.ResponseEntity;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class UserControllerTest {
+
+ @Mock
+ private UserService userService;
+
+ @InjectMocks
+ private UserController userController;
+
+ private MockedStatic<MessageSourceUtils> mockedMessageSourceUtils;
+
+ @BeforeEach
+ void setUp() {
+ mockedMessageSourceUtils =
Mockito.mockStatic(MessageSourceUtils.class);
+ when(MessageSourceUtils.getMessage(any())).thenReturn("Mocked
message");
+ }
+
+ @AfterEach
+ void tearDown() {
+ mockedMessageSourceUtils.close();
+ }
+
+ @Test
+ void currentReturnsCurrentUser() {
+ UserVO userVO = new UserVO();
+ when(userService.current()).thenReturn(userVO);
+
+ ResponseEntity<UserVO> response = userController.current();
+
+ assertEquals(userVO, response.getData());
+ }
+
+ @Test
+ void updateReturnsUpdatedUser() {
+ UserReq userReq = new UserReq();
+ UserVO userVO = new UserVO();
+ when(userService.update(any())).thenReturn(userVO);
+
+ ResponseEntity<UserVO> response = userController.update(userReq);
+
+ assertEquals(userVO, response.getData());
+ }
+}