2121import org .apache .bigtop .manager .common .enums .Command ;
2222import org .apache .bigtop .manager .common .utils .JsonUtils ;
2323import org .apache .bigtop .manager .dao .po .ComponentPO ;
24+ import org .apache .bigtop .manager .dao .po .HostPO ;
2425import org .apache .bigtop .manager .dao .po .TaskPO ;
2526import org .apache .bigtop .manager .dao .repository .ComponentDao ;
2627import org .apache .bigtop .manager .dao .repository .HostDao ;
2728import org .apache .bigtop .manager .dao .repository .TaskDao ;
2829import 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 ;
2932import org .apache .bigtop .manager .server .utils .StackUtils ;
3033
3134import 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