1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define private public
17 #define protected public
18
19 #include "request_manager.h"
20
21 #include <gtest/gtest.h>
22
23 #include <cstdint>
24 #include <memory>
25 #include <vector>
26
27 #include "gmock/gmock.h"
28 #include "log.h"
29 #include "request_common.h"
30 #include "request_manager_impl.h"
31
32 using namespace testing::ext;
33 using namespace OHOS::Request;
34
35 #undef private
36 #undef protected
37
38 class RequestManagerTest : public testing::Test {
39 public:
40 static void SetUpTestCase(void);
41 static void TearDownTestCase(void);
42 void SetUp();
43 void TearDown();
44 };
45
SetUpTestCase(void)46 void RequestManagerTest::SetUpTestCase(void)
47 {
48 // input testSuit setup step,setup invoked before all testCases
49 }
50
TearDownTestCase(void)51 void RequestManagerTest::TearDownTestCase(void)
52 {
53 // input testSuit teardown step,teardown invoked after all testCases
54 }
55
SetUp(void)56 void RequestManagerTest::SetUp(void)
57 {
58 // input testCase setup step,setup invoked before each testCase
59 testing::UnitTest *test = testing::UnitTest::GetInstance();
60 ASSERT_NE(test, nullptr);
61 const testing::TestInfo *testInfo = test->current_test_info();
62 ASSERT_NE(testInfo, nullptr);
63 string testCaseName = string(testInfo->name());
64 REQUEST_HILOGI("[SetUp] %{public}s start", testCaseName.c_str());
65 GTEST_LOG_(INFO) << testCaseName.append(" start");
66 }
67
TearDown(void)68 void RequestManagerTest::TearDown(void)
69 {
70 // input testCase teardown step,teardown invoked after each testCase
71 }
72
73 /**
74 * @tc.name: CreateTest001
75 * @tc.desc: Test the basic functionality of the Create interface to create a new task
76 * @tc.precon: RequestManager instance is available and initialized
77 * @tc.step: 1. Get RequestManager singleton instance
78 * 2. Prepare valid Config parameters
79 * 3. Set sequence number and task ID
80 * 4. Call Create method with parameters
81 * @tc.expect: Create method executes successfully without throwing exceptions
82 * @tc.type: FUNC
83 * @tc.require: issueNumber
84 * @tc.level: Level 1
85 */
86 HWTEST_F(RequestManagerTest, CreateTest001, TestSize.Level1)
87 {
88 EXPECT_NE(RequestManager::GetInstance(), nullptr);
89 Config config;
90 int32_t seq = 1;
91 std::string tid = "1";
92 RequestManager::GetInstance()->Create(config, seq, tid);
93 }
94
95 /**
96 * @tc.name: GetTaskTest001
97 * @tc.desc: Test the GetTask interface to retrieve task information by task ID and token
98 * @tc.precon: RequestManager instance is available and a task has been created
99 * @tc.step: 1. Get RequestManager singleton instance
100 * 2. Create a task with valid parameters
101 * 3. Prepare task ID and token strings
102 * 4. Call GetTask method with task ID and token
103 * @tc.expect: GetTask method returns successfully and populates the Config object
104 * @tc.type: FUNC
105 * @tc.require: issueNumber
106 * @tc.level: Level 1
107 */
108 HWTEST_F(RequestManagerTest, GetTaskTest001, TestSize.Level1)
109 {
110 EXPECT_NE(RequestManager::GetInstance(), nullptr);
111 std::string tidStr = "tid";
112 std::string token = "token";
113 Config config;
114 int32_t seq = 1;
115 std::string tid = "1";
116 RequestManager::GetInstance()->Create(config, seq, tid);
117 RequestManager::GetInstance()->RequestManager::GetInstance()->GetTask(tidStr, token, config);
118 }
119
120 /**
121 * @tc.name: StartTest001
122 * @tc.desc: Test the Start interface to begin task execution
123 * @tc.precon: RequestManager instance is available and a task exists
124 * @tc.step: 1. Get RequestManager singleton instance
125 * 2. Prepare a valid task ID string
126 * 3. Call Start method with the task ID
127 * @tc.expect: Start method executes successfully without throwing exceptions
128 * @tc.type: FUNC
129 * @tc.require: issueNumber
130 * @tc.level: Level 1
131 */
132 HWTEST_F(RequestManagerTest, StartTest001, TestSize.Level1)
133 {
134 EXPECT_NE(RequestManager::GetInstance(), nullptr);
135 std::string tidStr = "tid";
136 RequestManager::GetInstance()->Start(tidStr);
137 }
138
139 /**
140 * @tc.name: StopTest001
141 * @tc.desc: Test the Stop interface to halt task execution
142 * @tc.precon: RequestManager instance is available and a task is running
143 * @tc.step: 1. Get RequestManager singleton instance
144 * 2. Prepare a valid task ID string
145 * 3. Call Stop method with the task ID
146 * @tc.expect: Stop method executes successfully without throwing exceptions
147 * @tc.type: FUNC
148 * @tc.require: issueNumber
149 * @tc.level: Level 1
150 */
151 HWTEST_F(RequestManagerTest, StopTest001, TestSize.Level1)
152 {
153 EXPECT_NE(RequestManager::GetInstance(), nullptr);
154 std::string tid = "tid";
155 RequestManager::GetInstance()->Stop(tid);
156 }
157
158 /**
159 * @tc.name: QueryTest001
160 * @tc.desc: Test the Query interface to retrieve task information
161 * @tc.precon: RequestManager instance is available and a task exists
162 * @tc.step: 1. Get RequestManager singleton instance
163 * 2. Prepare a valid task ID string
164 * 3. Create a TaskInfo object
165 * 4. Call Query method with task ID and TaskInfo reference
166 * @tc.expect: Query method populates the TaskInfo object successfully
167 * @tc.type: FUNC
168 * @tc.require: issueNumber
169 * @tc.level: Level 1
170 */
171 HWTEST_F(RequestManagerTest, QueryTest001, TestSize.Level1)
172 {
173 EXPECT_NE(RequestManager::GetInstance(), nullptr);
174 std::string tid = "tid";
175 TaskInfo info;
176 RequestManager::GetInstance()->Query(tid, info);
177 }
178
179 /**
180 * @tc.name: TouchTest001
181 * @tc.desc: Test the Touch interface to update task access timestamp
182 * @tc.precon: RequestManager instance is available and a task exists
183 * @tc.step: 1. Get RequestManager singleton instance
184 * 2. Prepare valid task ID and token strings
185 * 3. Create a TaskInfo object
186 * 4. Call Touch method with task ID, token, and TaskInfo reference
187 * @tc.expect: Touch method updates task timestamp and populates TaskInfo successfully
188 * @tc.type: FUNC
189 * @tc.require: issueNumber
190 * @tc.level: Level 1
191 */
192 HWTEST_F(RequestManagerTest, Touch001, TestSize.Level1)
193 {
194 EXPECT_NE(RequestManager::GetInstance(), nullptr);
195 std::string tid = "tid";
196 std::string token = "token";
197 TaskInfo info;
198 RequestManager::GetInstance()->Touch(tid, token, info);
199 }
200
201 /**
202 * @tc.name: SearchTest001
203 * @tc.desc: Test the Search interface to find tasks matching filter criteria
204 * @tc.precon: RequestManager instance is available and tasks may exist
205 * @tc.step: 1. Get RequestManager singleton instance
206 * 2. Create a Filter object with search criteria
207 * 3. Create a vector to store matching task IDs
208 * 4. Call Search method with filter and task ID vector
209 * @tc.expect: Search method populates the task ID vector with matching results
210 * @tc.type: FUNC
211 * @tc.require: issueNumber
212 * @tc.level: Level 1
213 */
214 HWTEST_F(RequestManagerTest, SearchTest001, TestSize.Level1)
215 {
216 EXPECT_NE(RequestManager::GetInstance(), nullptr);
217 Filter filter;
218 std::vector<std::string> tids;
219 RequestManager::GetInstance()->Search(filter, tids);
220 }
221
222 /**
223 * @tc.name: ShowTest001
224 * @tc.desc: Test the Show interface to display task details
225 * @tc.precon: RequestManager instance is available and a task exists
226 * @tc.step: 1. Get RequestManager singleton instance
227 * 2. Prepare a valid task ID string
228 * 3. Create a TaskInfo object
229 * 4. Call Show method with task ID and TaskInfo reference
230 * @tc.expect: Show method populates TaskInfo with detailed task information
231 * @tc.type: FUNC
232 * @tc.require: issueNumber
233 * @tc.level: Level 1
234 */
235 HWTEST_F(RequestManagerTest, ShowTest001, TestSize.Level1)
236 {
237 EXPECT_NE(RequestManager::GetInstance(), nullptr);
238 std::string tid = "tid";
239 TaskInfo info;
240 RequestManager::GetInstance()->Show(tid, info);
241 }
242
243 /**
244 * @tc.name: PauseTest001
245 * @tc.desc: Test the Pause interface to temporarily halt task execution for both API versions
246 * @tc.precon: RequestManager instance is available and a running task exists
247 * @tc.step: 1. Get RequestManager singleton instance
248 * 2. Prepare a valid task ID string
249 * 3. Call Pause method with task ID and Version::API9
250 * 4. Call Pause method with task ID and Version::API10
251 * @tc.expect: Both Pause calls execute successfully without throwing exceptions
252 * @tc.type: FUNC
253 * @tc.require: issueNumber
254 * @tc.level: Level 1
255 */
256 HWTEST_F(RequestManagerTest, PauseTest001, TestSize.Level1)
257 {
258 EXPECT_NE(RequestManager::GetInstance(), nullptr);
259 std::string tid = "tid";
260 RequestManager::GetInstance()->Pause(tid, Version::API9);
261 RequestManager::GetInstance()->Pause(tid, Version::API10);
262 }
263
264 /**
265 * @tc.name: QueryMimeTypeTest001
266 * @tc.desc: Test the QueryMimeType interface to retrieve MIME type of task content
267 * @tc.precon: RequestManager instance is available and a task with content exists
268 * @tc.step: 1. Get RequestManager singleton instance
269 * 2. Prepare a valid task ID string
270 * 3. Prepare a string to store MIME type
271 * 4. Call QueryMimeType method with task ID and MIME type reference
272 * @tc.expect: QueryMimeType method populates MIME type string successfully
273 * @tc.type: FUNC
274 * @tc.require: issueNumber
275 * @tc.level: Level 1
276 */
277 HWTEST_F(RequestManagerTest, QueryMimeTypeTest001, TestSize.Level1)
278 {
279 EXPECT_NE(RequestManager::GetInstance(), nullptr);
280 std::string tid = "tid";
281 std::string mimeType = "mimeType";
282 RequestManager::GetInstance()->QueryMimeType(tid, mimeType);
283 }
284
285 /**
286 * @tc.name: RemoveTest001
287 * @tc.desc: Test the Remove interface to delete tasks for both API versions
288 * @tc.precon: RequestManager instance is available and a task exists
289 * @tc.step: 1. Get RequestManager singleton instance
290 * 2. Prepare a valid task ID string
291 * 3. Call Remove method with task ID and Version::API9
292 * 4. Call Remove method with task ID and Version::API10
293 * @tc.expect: Both Remove calls execute successfully without throwing exceptions
294 * @tc.type: FUNC
295 * @tc.require: issueNumber
296 * @tc.level: Level 1
297 */
298 HWTEST_F(RequestManagerTest, RemoveTest001, TestSize.Level1)
299 {
300 EXPECT_NE(RequestManager::GetInstance(), nullptr);
301 std::string tid = "tid";
302 RequestManager::GetInstance()->Remove(tid, Version::API9);
303 RequestManager::GetInstance()->Remove(tid, Version::API10);
304 }
305
306 /**
307 * @tc.name: ResumeTest001
308 * @tc.desc: Test the Resume interface to continue paused task execution
309 * @tc.precon: RequestManager instance is available and a paused task exists
310 * @tc.step: 1. Get RequestManager singleton instance
311 * 2. Prepare a valid task ID string
312 * 3. Call Resume method with the task ID
313 * @tc.expect: Resume method executes successfully without throwing exceptions
314 * @tc.type: FUNC
315 * @tc.require: issueNumber
316 * @tc.level: Level 1
317 */
318 HWTEST_F(RequestManagerTest, ResumeTest001, TestSize.Level1)
319 {
320 EXPECT_NE(RequestManager::GetInstance(), nullptr);
321 std::string tid = "tid";
322 RequestManager::GetInstance()->Resume(tid);
323 }
324
325 /**
326 * @tc.name: SubscribeTest001
327 * @tc.desc: Test the Subscribe interface to register for task notifications
328 * @tc.precon: RequestManager instance is available and a task exists
329 * @tc.step: 1. Get RequestManager singleton instance
330 * 2. Prepare a valid task ID string
331 * 3. Call Subscribe method with the task ID
332 * @tc.expect: Subscribe method executes successfully without throwing exceptions
333 * @tc.type: FUNC
334 * @tc.require: issueNumber
335 * @tc.level: Level 1
336 */
337 HWTEST_F(RequestManagerTest, SubscribeTest001, TestSize.Level1)
338 {
339 EXPECT_NE(RequestManager::GetInstance(), nullptr);
340 std::string taskId = "taskId";
341 RequestManager::GetInstance()->Subscribe(taskId);
342 }
343
344 /**
345 * @tc.name: UnsubscribeTest001
346 * @tc.desc: Test the Unsubscribe interface to unregister from task notifications
347 * @tc.precon: RequestManager instance is available and a task is subscribed
348 * @tc.step: 1. Get RequestManager singleton instance
349 * 2. Prepare a valid task ID string
350 * 3. Call Unsubscribe method with the task ID
351 * @tc.expect: Unsubscribe method executes successfully without throwing exceptions
352 * @tc.type: FUNC
353 * @tc.require: issueNumber
354 * @tc.level: Level 1
355 */
356 HWTEST_F(RequestManagerTest, Unsubscribe001, TestSize.Level1)
357 {
358 EXPECT_NE(RequestManager::GetInstance(), nullptr);
359 std::string taskId = "taskId";
360 RequestManager::GetInstance()->Unsubscribe(taskId);
361 }
362
363 class RMTResponseListenerImpl : public IResponseListener {
364 public:
~RMTResponseListenerImpl()365 ~RMTResponseListenerImpl(){};
OnResponseReceive(const std::shared_ptr<Response> & response)366 void OnResponseReceive(const std::shared_ptr<Response> &response) override
367 {
368 (void)response;
369 return;
370 }
371 };
372
373 class RMTNotifyDataListenerImpl : public INotifyDataListener {
374 public:
~RMTNotifyDataListenerImpl()375 ~RMTNotifyDataListenerImpl(){};
OnNotifyDataReceive(const std::shared_ptr<NotifyData> & notifyData)376 void OnNotifyDataReceive(const std::shared_ptr<NotifyData> ¬ifyData) override
377 {
378 (void)notifyData;
379 return;
380 }
OnFaultsReceive(const std::shared_ptr<int32_t> & tid,const std::shared_ptr<SubscribeType> & type,const std::shared_ptr<Reason> & reason)381 void OnFaultsReceive(const std::shared_ptr<int32_t> &tid, const std::shared_ptr<SubscribeType> &type,
382 const std::shared_ptr<Reason> &reason) override
383 {
384 }
OnWaitReceive(std::int32_t taskId,WaitingReason reason)385 void OnWaitReceive(std::int32_t taskId, WaitingReason reason) override
386 {
387 }
388 };
389
390 /**
391 * @tc.name: AddAndRemoveListenerTest001
392 * @tc.desc: Test the AddListener and RemoveListener interfaces for both response and notification listeners
393 * @tc.precon: RequestManager instance is available and listener implementations exist
394 * @tc.step: 1. Get RequestManager singleton instance
395 * 2. Create response listener implementation
396 * 3. Add response listener for RESPONSE type
397 * 4. Remove response listener for RESPONSE type
398 * 5. Create notification listener implementation
399 * 6. Add notification listener for COMPLETED type
400 * 7. Remove notification listener for COMPLETED type
401 * @tc.expect: All AddListener and RemoveListener calls execute successfully
402 * @tc.type: FUNC
403 * @tc.require: issueNumber
404 * @tc.level: Level 1
405 */
406 HWTEST_F(RequestManagerTest, AddAndRemoveListenerTest001, TestSize.Level1)
407 {
408 EXPECT_NE(RequestManager::GetInstance(), nullptr);
409 string taskId = "taskId";
410 SubscribeType type = SubscribeType::RESPONSE;
411 std::shared_ptr<RMTResponseListenerImpl> listener = std::make_shared<RMTResponseListenerImpl>();
412 RequestManager::GetInstance()->AddListener(taskId, type, listener);
413 RequestManager::GetInstance()->RemoveListener(taskId, type, listener);
414 type = SubscribeType::COMPLETED;
415 std::shared_ptr<RMTNotifyDataListenerImpl> listener2 = std::make_shared<RMTNotifyDataListenerImpl>();
416 RequestManager::GetInstance()->AddListener(taskId, type, listener2);
417 RequestManager::GetInstance()->RemoveListener(taskId, type, listener2);
418 }
419
TestRestoreCallback()420 void TestRestoreCallback()
421 {
422 }
423
424 /**
425 * @tc.name: RemoveAllListenersTest001
426 * @tc.desc: Test the RemoveAllListeners and RestoreListener interfaces
427 * @tc.precon: RequestManager instance is available and listeners have been added
428 * @tc.step: 1. Get RequestManager singleton instance
429 * 2. Create response listener implementation
430 * 3. Add response listener for RESPONSE type
431 * 4. Create notification listener implementation
432 * 5. Add notification listener for COMPLETED type
433 * 6. Call RemoveAllListeners to remove all listeners
434 * 7. Call RestoreListener with callback function
435 * 8. Verify callback is set correctly
436 * 9. Call RestoreListener with nullptr
437 * @tc.expect: All operations execute successfully and callback is properly set
438 * @tc.type: FUNC
439 * @tc.require: issueNumber
440 * @tc.level: Level 1
441 */
442 HWTEST_F(RequestManagerTest, RemoveAllListenersTest001, TestSize.Level1)
443 {
444 string taskId = "taskId";
445 SubscribeType type = SubscribeType::RESPONSE;
446 std::shared_ptr<RMTResponseListenerImpl> listener = std::make_shared<RMTResponseListenerImpl>();
447 RequestManager::GetInstance()->AddListener(taskId, type, listener);
448 type = SubscribeType::COMPLETED;
449 std::shared_ptr<RMTNotifyDataListenerImpl> listener2 = std::make_shared<RMTNotifyDataListenerImpl>();
450 RequestManager::GetInstance()->AddListener(taskId, type, listener2);
451 RequestManager::GetInstance()->RemoveAllListeners(taskId);
452 RequestManager::GetInstance()->RestoreListener(TestRestoreCallback);
453 EXPECT_EQ(RequestManagerImpl::GetInstance()->callback_, TestRestoreCallback);
454 RequestManager::GetInstance()->RestoreListener(nullptr);
455 }
456
457 /**
458 * @tc.name: LoadRequestServerTest001
459 * @tc.desc: Test the LoadRequestServer interface to initialize the request server
460 * @tc.precon: RequestManager instance is available and server is not loaded
461 * @tc.step: 1. Get RequestManager singleton instance
462 * 2. Call LoadRequestServer method
463 * @tc.expect: LoadRequestServer method executes successfully without throwing exceptions
464 * @tc.type: FUNC
465 * @tc.require: issueNumber
466 * @tc.level: Level 1
467 */
468 HWTEST_F(RequestManagerTest, LoadRequestServerTest001, TestSize.Level1)
469 {
470 EXPECT_NE(RequestManager::GetInstance(), nullptr);
471 RequestManager::GetInstance()->LoadRequestServer();
472 }
473
474 /**
475 * @tc.name: IsSaReadyTest001
476 * @tc.desc: Test the IsSaReady interface to check system ability readiness
477 * @tc.precon: RequestManager instance is available and initialized
478 * @tc.step: 1. Get RequestManager singleton instance
479 * 2. Call IsSaReady method
480 * @tc.expect: IsSaReady method returns a valid boolean value indicating readiness
481 * @tc.type: FUNC
482 * @tc.require: issueNumber
483 * @tc.level: Level 1
484 */
485 HWTEST_F(RequestManagerTest, IsSaReadyTest001, TestSize.Level1)
486 {
487 EXPECT_NE(RequestManager::GetInstance(), nullptr);
488 RequestManager::GetInstance()->IsSaReady();
489 }
490
491 /**
492 * @tc.name: ReopenChannelTest001
493 * @tc.desc: Test the ReopenChannel interface to re-establish communication channel
494 * @tc.precon: RequestManager instance is available and channel may need reopening
495 * @tc.step: 1. Get RequestManager singleton instance
496 * 2. Call ReopenChannel method
497 * @tc.expect: ReopenChannel method executes successfully without throwing exceptions
498 * @tc.type: FUNC
499 * @tc.require: issueNumber
500 * @tc.level: Level 1
501 */
502 HWTEST_F(RequestManagerTest, ReopenChannelTest001, TestSize.Level1)
503 {
504 EXPECT_NE(RequestManager::GetInstance(), nullptr);
505 RequestManager::GetInstance()->ReopenChannel();
506 }
507
508 /**
509 * @tc.name: SubscribeSATest001
510 * @tc.desc: Test the SubscribeSA interface to register for system ability notifications
511 * @tc.precon: RequestManager instance is available and SA subscription is needed
512 * @tc.step: 1. Get RequestManager singleton instance
513 * 2. Call SubscribeSA method
514 * @tc.expect: SubscribeSA method executes successfully without throwing exceptions
515 * @tc.type: FUNC
516 * @tc.require: issueNumber
517 * @tc.level: Level 1
518 */
519 HWTEST_F(RequestManagerTest, SubscribeSATest001, TestSize.Level1)
520 {
521 EXPECT_NE(RequestManager::GetInstance(), nullptr);
522 RequestManager::GetInstance()->SubscribeSA();
523 }
524
525 /**
526 * @tc.name: UnsubscribeSATest001
527 * @tc.desc: Test the UnsubscribeSA interface to unregister from system ability notifications
528 * @tc.precon: RequestManager instance is available and SA subscription exists
529 * @tc.step: 1. Get RequestManager singleton instance
530 * 2. Call UnsubscribeSA method
531 * @tc.expect: UnsubscribeSA method executes successfully without throwing exceptions
532 * @tc.type: FUNC
533 * @tc.require: issueNumber
534 * @tc.level: Level 1
535 */
536 HWTEST_F(RequestManagerTest, UnsubscribeSATest001, TestSize.Level1)
537 {
538 EXPECT_NE(RequestManager::GetInstance(), nullptr);
539 RequestManager::GetInstance()->UnsubscribeSA();
540 }
541
542 /**
543 * @tc.name: GetNextSeqTest001
544 * @tc.desc: Test the GetNextSeq interface to generate sequential task identifiers
545 * @tc.precon: RequestManager instance is available and initialized
546 * @tc.step: 1. Get RequestManager singleton instance
547 * 2. Call GetNextSeq method to get current sequence
548 * 3. Call GetNextSeq method again
549 * 4. Verify the second call returns incremented value
550 * @tc.expect: Second GetNextSeq call returns value one greater than first call
551 * @tc.type: FUNC
552 * @tc.require: issueNumber
553 * @tc.level: Level 1
554 */
555 HWTEST_F(RequestManagerTest, GetNextSeqTest001, TestSize.Level1)
556 {
557 int32_t ret = RequestManager::GetInstance()->GetNextSeq();
558 EXPECT_EQ(RequestManager::GetInstance()->GetNextSeq(), ret + 1);
559 }
560
561 /**
562 * @tc.name: CreateGroupTest001
563 * @tc.desc: Test the CreateGroup interface to create a new task group with notification settings
564 * @tc.precon: RequestManager instance is available and group ID is unique
565 * @tc.step: 1. Get RequestManager singleton instance
566 * 2. Prepare a unique group ID string
567 * 3. Set gauge parameter to true
568 * 4. Create Notification object with title, text, and disable=false
569 * 5. Call CreateGroup method with parameters
570 * @tc.expect: CreateGroup returns 0 indicating successful group creation
571 * @tc.type: FUNC
572 * @tc.require: issueNumber
573 * @tc.level: Level 1
574 */
575 HWTEST_F(RequestManagerTest, CreateGroupTest001, TestSize.Level1)
576 {
577 EXPECT_NE(RequestManager::GetInstance(), nullptr);
578 std::string gid = "gid";
579 bool gauge = true;
580 Notification info{
581 .text = "text",
582 .title = "title",
583 .disable = false,
584 };
585
586 EXPECT_EQ(RequestManager::GetInstance()->CreateGroup(gid, gauge, info), 0);
587 }
588
589 /**
590 * @tc.name: AttachGroupTest001
591 * @tc.desc: Test the AttachGroup interface to associate tasks with an existing group
592 * @tc.precon: RequestManager instance is available and group exists
593 * @tc.step: 1. Get RequestManager singleton instance
594 * 2. Prepare a valid group ID string
595 * 3. Create empty vector of task IDs
596 * 4. Call AttachGroup method with group ID and task IDs
597 * @tc.expect: AttachGroup returns 21900008 indicating no tasks to attach
598 * @tc.type: FUNC
599 * @tc.require: issueNumber
600 * @tc.level: Level 1
601 */
602 HWTEST_F(RequestManagerTest, AttachGroupTest001, TestSize.Level1)
603 {
604 EXPECT_NE(RequestManager::GetInstance(), nullptr);
605 std::string gid = "gid";
606 std::vector<std::string> tids;
607 EXPECT_EQ(RequestManager::GetInstance()->AttachGroup(gid, tids), 21900008);
608 }
609
610 /**
611 * @tc.name: DeleteGroupTest001
612 * @tc.desc: Test the DeleteGroup interface to remove an existing task group
613 * @tc.precon: RequestManager instance is available and group exists
614 * @tc.step: 1. Get RequestManager singleton instance
615 * 2. Prepare a valid group ID string
616 * 3. Call DeleteGroup method with the group ID
617 * @tc.expect: DeleteGroup returns 21900008 indicating group deletion initiated
618 * @tc.type: FUNC
619 * @tc.require: issueNumber
620 * @tc.level: Level 1
621 */
622 HWTEST_F(RequestManagerTest, DeleteGroupTest001, TestSize.Level1)
623 {
624 EXPECT_NE(RequestManager::GetInstance(), nullptr);
625 std::string gid = "gid";
626 EXPECT_EQ(RequestManager::GetInstance()->DeleteGroup(gid), 21900008);
627 }