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 1d0b1b3f BIGTOP-4377: Add ut cases for command job classes in server 
module (#184)
1d0b1b3f is described below

commit 1d0b1b3fddea20e88f38126d58bdecb7e85763cc
Author: xianrenzw <[email protected]>
AuthorDate: Tue Mar 25 16:42:35 2025 +0800

    BIGTOP-4377: Add ut cases for command job classes in server module (#184)
---
 bigtop-manager-server/pom.xml                      |   6 ++
 .../server/command/job/cluster/ClusterAddJob.java  |   3 +-
 .../command/job/cluster/ClusterAddJobTest.java     |  84 +++++++++++++++++
 .../command/job/cluster/ClusterRestartJobTest.java |  90 ++++++++++++++++++
 .../command/job/cluster/ClusterStartJobTest.java   |  90 ++++++++++++++++++
 .../command/job/cluster/ClusterStopJobTest.java    |  90 ++++++++++++++++++
 .../command/job/component/ComponentAddJobTest.java |  99 ++++++++++++++++++++
 .../job/component/ComponentRestartJobTest.java     |  90 ++++++++++++++++++
 .../job/component/ComponentStartJobTest.java       |  90 ++++++++++++++++++
 .../job/component/ComponentStopJobTest.java        |  90 ++++++++++++++++++
 .../server/command/job/host/HostAddJobTest.java    |  84 +++++++++++++++++
 .../command/job/host/HostRestartJobTest.java       |  90 ++++++++++++++++++
 .../server/command/job/host/HostStartJobTest.java  |  90 ++++++++++++++++++
 .../server/command/job/host/HostStopJobTest.java   |  90 ++++++++++++++++++
 .../command/job/service/ServiceAddJobTest.java     | 104 +++++++++++++++++++++
 .../command/job/service/ServiceCheckJobTest.java   |  90 ++++++++++++++++++
 .../job/service/ServiceConfigureJobTest.java       |  95 +++++++++++++++++++
 .../command/job/service/ServiceRestartJobTest.java |  90 ++++++++++++++++++
 .../command/job/service/ServiceStartJobTest.java   |  90 ++++++++++++++++++
 .../command/job/service/ServiceStopJobTest.java    |  90 ++++++++++++++++++
 20 files changed, 1643 insertions(+), 2 deletions(-)

diff --git a/bigtop-manager-server/pom.xml b/bigtop-manager-server/pom.xml
index 9a5f49e6..d8122231 100644
--- a/bigtop-manager-server/pom.xml
+++ b/bigtop-manager-server/pom.xml
@@ -156,6 +156,12 @@
             <groupId>org.apache.sshd</groupId>
             <artifactId>sshd-core</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJob.java
 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJob.java
index 0661b322..7e44096b 100644
--- 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJob.java
+++ 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJob.java
@@ -21,7 +21,6 @@ package org.apache.bigtop.manager.server.command.job.cluster;
 import org.apache.bigtop.manager.dao.po.JobPO;
 import org.apache.bigtop.manager.dao.po.StagePO;
 import org.apache.bigtop.manager.dao.po.TaskPO;
-import org.apache.bigtop.manager.server.command.job.AbstractJob;
 import org.apache.bigtop.manager.server.command.job.JobContext;
 import org.apache.bigtop.manager.server.command.stage.HostCheckStage;
 import org.apache.bigtop.manager.server.command.stage.SetupJdkStage;
@@ -38,7 +37,7 @@ import org.apache.bigtop.manager.server.service.HostService;
 
 import java.util.List;
 
-public class ClusterAddJob extends AbstractJob {
+public class ClusterAddJob extends AbstractClusterJob {
 
     private HostService hostService;
 
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJobTest.java
new file mode 100644
index 00000000..e1224a82
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterAddJobTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.command.job.cluster;
+
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.HostCheckStage;
+import org.apache.bigtop.manager.server.command.stage.SetupJdkStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ClusterAddJobTest {
+
+    @Mock
+    private ClusterAddJob clusterAddJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(clusterAddJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(clusterAddJob, "stages", stages);
+
+        MockedConstruction<HostCheckStage> mocked1 = 
mockConstruction(HostCheckStage.class);
+        MockedConstruction<SetupJdkStage> mocked2 = 
mockConstruction(SetupJdkStage.class);
+        MockedStatic<StageContext> mocked3 = mockStatic(StageContext.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        doCallRealMethod().when(clusterAddJob).createStages();
+        clusterAddJob.createStages();
+
+        assertEquals(1, mocked1.constructed().size());
+        assertEquals(1, mocked2.constructed().size());
+        assertEquals(2, stages.size());
+        assertTrue(stages.containsAll(mocked1.constructed()));
+        assertTrue(stages.containsAll(mocked2.constructed()));
+
+        mocked1.close();
+        mocked2.close();
+        mocked3.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(clusterAddJob).getName();
+        assertEquals("Add cluster", clusterAddJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterRestartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterRestartJobTest.java
new file mode 100644
index 00000000..e9a3b18c
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterRestartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.cluster;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.eq;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ClusterRestartJobTest {
+
+    @Mock
+    private ClusterRestartJob clusterRestartJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(clusterRestartJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(clusterRestartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentStopStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentStartStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.STOP), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.START), any()))
+                .thenReturn(stageList2);
+
+        doCallRealMethod().when(clusterRestartJob).createStages();
+        clusterRestartJob.createStages();
+
+        assertEquals(2, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(clusterRestartJob).getName();
+        assertEquals("Restart cluster", clusterRestartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterStartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterStartJobTest.java
new file mode 100644
index 00000000..2da05686
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterStartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.cluster;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ClusterStartJobTest {
+
+    @Mock
+    private ClusterStartJob clusterStartJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.START);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(clusterStartJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(clusterStartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStartStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.START), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(clusterStartJob).createStages();
+        clusterStartJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(clusterStartJob).getName();
+        assertEquals("Start cluster", clusterStartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterStopJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterStopJobTest.java
new file mode 100644
index 00000000..153079a0
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/cluster/ClusterStopJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.cluster;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ClusterStopJobTest {
+
+    @Mock
+    private ClusterStopJob clusterStopJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.STOP);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(clusterStopJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(clusterStopJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStopStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.STOP), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(clusterStopJob).createStages();
+        clusterStopJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(clusterStopJob).getName();
+        assertEquals("Stop cluster", clusterStopJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentAddJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentAddJobTest.java
new file mode 100644
index 00000000..863b2010
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentAddJobTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.command.job.component;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentAddStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentConfigureStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentInitStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentPrepareStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ComponentAddJobTest {
+
+    @Mock
+    private ComponentAddJob componentAddJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(componentAddJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(componentAddJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentAddStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentConfigureStage.class));
+        List<Stage> stageList3 = List.of(
+                mock(ComponentInitStage.class), 
mock(ComponentStartStage.class), mock(ComponentPrepareStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.ADD), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.CONFIGURE), any()))
+                .thenReturn(stageList2);
+        when(ComponentStageHelper.createComponentStages(
+                        any(), eq(List.of(Command.INIT, Command.START, 
Command.PREPARE)), any()))
+                .thenReturn(stageList3);
+
+        doCallRealMethod().when(componentAddJob).createStages();
+        componentAddJob.createStages();
+
+        assertEquals(5, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+        assertTrue(stages.containsAll(stageList3));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(componentAddJob).getName();
+        assertEquals("Add components", componentAddJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentRestartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentRestartJobTest.java
new file mode 100644
index 00000000..c146c0c9
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentRestartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.component;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ComponentRestartJobTest {
+
+    @Mock
+    private ComponentRestartJob componentRestartJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(componentRestartJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(componentRestartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentStopStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentStartStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.STOP), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.START), any()))
+                .thenReturn(stageList2);
+
+        doCallRealMethod().when(componentRestartJob).createStages();
+        componentRestartJob.createStages();
+
+        assertEquals(2, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(componentRestartJob).getName();
+        assertEquals("Restart components", componentRestartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentStartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentStartJobTest.java
new file mode 100644
index 00000000..5c93e08d
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentStartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.component;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ComponentStartJobTest {
+
+    @Mock
+    private ComponentStartJob componentStartJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.START);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(componentStartJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(componentStartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStartStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.START), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(componentStartJob).createStages();
+        componentStartJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(componentStartJob).getName();
+        assertEquals("Start components", componentStartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentStopJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentStopJobTest.java
new file mode 100644
index 00000000..7ee3dc21
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/component/ComponentStopJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.component;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ComponentStopJobTest {
+
+    @Mock
+    private ComponentStopJob componentStopJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.STOP);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(componentStopJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(componentStopJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStopStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.STOP), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(componentStopJob).createStages();
+        componentStopJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(componentStopJob).getName();
+        assertEquals("Stop components", componentStopJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostAddJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostAddJobTest.java
new file mode 100644
index 00000000..91d52c82
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostAddJobTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.command.job.host;
+
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.HostCheckStage;
+import org.apache.bigtop.manager.server.command.stage.SetupJdkStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedConstruction;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.doCallRealMethod;
+import static org.mockito.Mockito.mockConstruction;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class HostAddJobTest {
+
+    @Mock
+    private HostAddJob hostAddJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(hostAddJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(hostAddJob, "stages", stages);
+
+        MockedConstruction<HostCheckStage> mocked1 = 
mockConstruction(HostCheckStage.class);
+        MockedConstruction<SetupJdkStage> mocked2 = 
mockConstruction(SetupJdkStage.class);
+        MockedStatic<StageContext> mocked3 = mockStatic(StageContext.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        doCallRealMethod().when(hostAddJob).createStages();
+        hostAddJob.createStages();
+
+        assertEquals(1, mocked1.constructed().size());
+        assertEquals(1, mocked2.constructed().size());
+        assertEquals(2, stages.size());
+        assertTrue(stages.containsAll(mocked1.constructed()));
+        assertTrue(stages.containsAll(mocked2.constructed()));
+
+        mocked1.close();
+        mocked2.close();
+        mocked3.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(hostAddJob).getName();
+        assertEquals("Add hosts", hostAddJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostRestartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostRestartJobTest.java
new file mode 100644
index 00000000..65362d52
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostRestartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.host;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class HostRestartJobTest {
+
+    @Mock
+    private HostRestartJob hostRestartJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(hostRestartJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(hostRestartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentStopStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentStartStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.STOP), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.START), any()))
+                .thenReturn(stageList2);
+
+        doCallRealMethod().when(hostRestartJob).createStages();
+        hostRestartJob.createStages();
+
+        assertEquals(2, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(hostRestartJob).getName();
+        assertEquals("Restart host", hostRestartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostStartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostStartJobTest.java
new file mode 100644
index 00000000..e606cfee
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostStartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.host;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class HostStartJobTest {
+
+    @Mock
+    private HostStartJob hostStartJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.START);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(hostStartJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(hostStartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStartStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.START), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(hostStartJob).createStages();
+        hostStartJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(hostStartJob).getName();
+        assertEquals("Start host", hostStartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostStopJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostStopJobTest.java
new file mode 100644
index 00000000..0403201e
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/host/HostStopJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.host;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class HostStopJobTest {
+
+    @Mock
+    private HostStopJob hostStopJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.STOP);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(hostStopJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(hostStopJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStopStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.STOP), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(hostStopJob).createStages();
+        hostStopJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(hostStopJob).getName();
+        assertEquals("Stop host", hostStopJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceAddJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceAddJobTest.java
new file mode 100644
index 00000000..d96d650e
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceAddJobTest.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.command.job.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentAddStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentCheckStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentConfigureStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentInitStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentPrepareStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ServiceAddJobTest {
+
+    @Mock
+    private ServiceAddJob serviceAddJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(serviceAddJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(serviceAddJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentAddStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentConfigureStage.class));
+        List<Stage> stageList3 = List.of(
+                mock(ComponentInitStage.class), 
mock(ComponentStartStage.class), mock(ComponentPrepareStage.class));
+        List<Stage> stageList4 = List.of(mock(ComponentCheckStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.ADD), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.CONFIGURE), any()))
+                .thenReturn(stageList2);
+        when(ComponentStageHelper.createComponentStages(
+                        any(), eq(List.of(Command.INIT, Command.START, 
Command.PREPARE)), any()))
+                .thenReturn(stageList3);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.CHECK), any()))
+                .thenReturn(stageList4);
+
+        doCallRealMethod().when(serviceAddJob).createStages();
+        serviceAddJob.createStages();
+
+        assertEquals(6, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+        assertTrue(stages.containsAll(stageList3));
+        assertTrue(stages.containsAll(stageList4));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(serviceAddJob).getName();
+        assertEquals("Add services", serviceAddJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceCheckJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceCheckJobTest.java
new file mode 100644
index 00000000..69fd613c
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceCheckJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ServiceCheckJobTest {
+
+    @Mock
+    private ServiceCheckJob serviceCheckJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.CHECK);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(serviceCheckJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(serviceCheckJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStartStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.CHECK), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(serviceCheckJob).createStages();
+        serviceCheckJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(serviceCheckJob).getName();
+        assertEquals("Check services", serviceCheckJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceConfigureJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceConfigureJobTest.java
new file mode 100644
index 00000000..e6c749c2
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceConfigureJobTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.command.job.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentConfigureStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ServiceConfigureJobTest {
+
+    @Mock
+    private ServiceConfigureJob serviceConfigureJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(serviceConfigureJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(serviceConfigureJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentConfigureStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentStopStage.class));
+        List<Stage> stageList3 = List.of(mock(ComponentStartStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.CONFIGURE), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.STOP), any()))
+                .thenReturn(stageList2);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.START), any()))
+                .thenReturn(stageList3);
+
+        doCallRealMethod().when(serviceConfigureJob).createStages();
+        serviceConfigureJob.createStages();
+
+        assertEquals(3, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+        assertTrue(stages.containsAll(stageList3));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(serviceConfigureJob).getName();
+        assertEquals("Configure services", serviceConfigureJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceRestartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceRestartJobTest.java
new file mode 100644
index 00000000..30c20804
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceRestartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ServiceRestartJobTest {
+
+    @Mock
+    private ServiceRestartJob serviceRestartJob;
+
+    @Test
+    public void testCreateStages() {
+        JobContext jobContext = new JobContext();
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(serviceRestartJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(serviceRestartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList1 = List.of(mock(ComponentStopStage.class));
+        List<Stage> stageList2 = List.of(mock(ComponentStartStage.class));
+
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.STOP), any()))
+                .thenReturn(stageList1);
+        when(ComponentStageHelper.createComponentStages(any(), 
eq(Command.START), any()))
+                .thenReturn(stageList2);
+
+        doCallRealMethod().when(serviceRestartJob).createStages();
+        serviceRestartJob.createStages();
+
+        assertEquals(2, stages.size());
+        assertTrue(stages.containsAll(stageList1));
+        assertTrue(stages.containsAll(stageList2));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(serviceRestartJob).getName();
+        assertEquals("Restart services", serviceRestartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceStartJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceStartJobTest.java
new file mode 100644
index 00000000..fc885f2a
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceStartJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStartStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ServiceStartJobTest {
+
+    @Mock
+    private ServiceStartJob serviceStartJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.START);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(serviceStartJob, "jobContext", 
jobContext);
+        ReflectionTestUtils.setField(serviceStartJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStartStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.START), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(serviceStartJob).createStages();
+        serviceStartJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(serviceStartJob).getName();
+        assertEquals("Start services", serviceStartJob.getName());
+    }
+}
diff --git 
a/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceStopJobTest.java
 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceStopJobTest.java
new file mode 100644
index 00000000..5250f71b
--- /dev/null
+++ 
b/bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/job/service/ServiceStopJobTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.command.job.service;
+
+import org.apache.bigtop.manager.common.enums.Command;
+import org.apache.bigtop.manager.server.command.helper.ComponentStageHelper;
+import org.apache.bigtop.manager.server.command.job.JobContext;
+import org.apache.bigtop.manager.server.command.stage.ComponentStopStage;
+import org.apache.bigtop.manager.server.command.stage.Stage;
+import org.apache.bigtop.manager.server.command.stage.StageContext;
+import org.apache.bigtop.manager.server.model.dto.CommandDTO;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.ArrayList;
+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.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ServiceStopJobTest {
+
+    @Mock
+    private ServiceStopJob serviceStopJob;
+
+    @Test
+    public void testCreateStages() {
+        CommandDTO commandDTO = new CommandDTO();
+        commandDTO.setCommand(Command.STOP);
+        JobContext jobContext = new JobContext();
+        jobContext.setCommandDTO(commandDTO);
+        List<Stage> stages = new ArrayList<>();
+        ReflectionTestUtils.setField(serviceStopJob, "jobContext", jobContext);
+        ReflectionTestUtils.setField(serviceStopJob, "stages", stages);
+
+        MockedStatic<?> mocked1 = mockStatic(StageContext.class);
+        MockedStatic<?> mocked2 = mockStatic(ComponentStageHelper.class, 
InvocationOnMock::callRealMethod);
+
+        when(StageContext.fromCommandDTO(any())).thenReturn(new 
StageContext());
+
+        List<Stage> stageList = List.of(mock(ComponentStopStage.class));
+        mocked2.when(() -> 
ComponentStageHelper.createComponentStages(anyMap(), eq(Command.STOP), any()))
+                .thenReturn(stageList);
+
+        doCallRealMethod().when(serviceStopJob).createStages();
+        serviceStopJob.createStages();
+
+        assertEquals(1, stages.size());
+        assertTrue(stages.containsAll(stageList));
+
+        mocked1.close();
+        mocked2.close();
+    }
+
+    @Test
+    public void testGetName() {
+        doCallRealMethod().when(serviceStopJob).getName();
+        assertEquals("Stop services", serviceStopJob.getName());
+    }
+}

Reply via email to