Skip to content

Commit bf1f9bf

Browse files
authored
Update ComponentStartTaskTest.java
1 parent b96cf26 commit bf1f9bf

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

bigtop-manager-server/src/test/java/org/apache/bigtop/manager/server/command/task/ComponentStartTaskTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
import org.apache.bigtop.manager.common.enums.Command;
2222
import org.apache.bigtop.manager.common.utils.JsonUtils;
2323
import org.apache.bigtop.manager.dao.po.ComponentPO;
24+
import org.apache.bigtop.manager.dao.po.HostPO;
2425
import org.apache.bigtop.manager.dao.po.TaskPO;
2526
import org.apache.bigtop.manager.dao.repository.ComponentDao;
2627
import org.apache.bigtop.manager.dao.repository.HostDao;
2728
import org.apache.bigtop.manager.dao.repository.TaskDao;
2829
import org.apache.bigtop.manager.server.holder.SpringContextHolder;
30+
import org.apache.bigtop.manager.server.model.dto.ComponentDTO;
31+
import org.apache.bigtop.manager.server.model.dto.StackDTO;
2932
import org.apache.bigtop.manager.server.utils.StackUtils;
3033

3134
import org.junit.jupiter.api.AfterEach;
@@ -83,6 +86,18 @@ public void setUp() {
8386
when(SpringContextHolder.getBean(TaskDao.class)).thenReturn(taskDao);
8487
when(SpringContextHolder.getBean(ComponentDao.class)).thenReturn(componentDao);
8588

89+
// Mock StackUtils static methods
90+
stackUtilsMocked = mockStatic(StackUtils.class);
91+
ComponentDTO componentDTO = new ComponentDTO();
92+
componentDTO.setName("TestComponentName");
93+
componentDTO.setDisplayName("TestComponentDisplayName");
94+
stackUtilsMocked.when(() -> StackUtils.getComponentDTO("TestComponentName")).thenReturn(componentDTO);
95+
96+
StackDTO stackDTO = new StackDTO();
97+
stackDTO.setStackName("test-stack");
98+
stackDTO.setStackVersion("1.0.0");
99+
stackUtilsMocked.when(() -> StackUtils.getServiceStack("TestServiceName")).thenReturn(stackDTO);
100+
86101
componentStartTask = mock(ComponentStartTask.class);
87102

88103
taskContext.setComponentDisplayName("TestComponentDisplayName");
@@ -105,6 +120,9 @@ public void setUp() {
105120
@AfterEach
106121
public void tearDown() {
107122
springContextHolderMockedStatic.close();
123+
if (stackUtilsMocked != null) {
124+
stackUtilsMocked.close();
125+
}
108126
}
109127

110128
@Test
@@ -123,8 +141,12 @@ public void testGetCommand() {
123141
@Test
124142
public void testOnSuccess() {
125143
doCallRealMethod().when(componentStartTask).onSuccess();
144+
126145
List<ComponentPO> componentPOS = new ArrayList<>();
127-
componentPOS.add(new ComponentPO());
146+
ComponentPO existing = new ComponentPO();
147+
existing.setId(1L);
148+
existing.setName("TestComponentName");
149+
componentPOS.add(existing);
128150
when(componentDao.findByQuery(any())).thenReturn(componentPOS);
129151

130152
componentStartTask.onSuccess();

0 commit comments

Comments
 (0)