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 16import Server from '../common/Server' 17import fileio from '@ohos.fileio' 18import request from "@ohos.request"; 19import commonEvent from '@ohos.commonEventManager'; 20import common from '@ohos.app.ability.common'; 21import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; 22import { BusinessError } from '@kit.BasicServicesKit'; 23 24export default function requestUploadJSUnit() { 25 describe('requestUploadJSUnit', () => { 26 console.info('====>################################request upload Test start'); 27 28 let baseContext: common.Context; 29 /** 30 * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. 31 */ 32 beforeAll((done: Function) => { 33 try { 34 console.info('====>beforeAll: startServer'); 35 new Server().startServer(); 36 console.info('====>beforeAll: startServer success!'); 37 let context: common.Context | undefined = AppStorage.get('context'); 38 if (context !== undefined){ 39 baseContext = context; 40 console.info('====>beforeAll requestUploadJSUnit baseContext:'+JSON.stringify(baseContext)) 41 } else { 42 console.info('====>beforeAll requestUploadJSUnit baseContext is undefined') 43 } 44 let pathDir: string = baseContext.cacheDir; 45 let filePath = pathDir + `/test.txt`; 46 let fd = fileio.openSync(filePath, 0o100 | 0o2, 0o666); 47 let content = ''.padEnd(1 * 1024, 'Hello world'); 48 fileio.writeSync(fd, content); 49 fileio.closeSync(fd); 50 console.info('====>beforeAll: text.txt file generate'); 51 done(); 52 } catch (err) { 53 console.info('====>beforeAll: text.txt file generate failed: ' + err); 54 done(); 55 } 56 }) 57 58 /** 59 * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. 60 */ 61 beforeEach(() => { 62 console.info('====>beforeEach: Prerequisites is executed.'); 63 }); 64 65 /** 66 * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. 67 */ 68 afterEach(() => { 69 console.info('====>afterEach: Test case-level clearance conditions is executed.'); 70 }); 71 72 /** 73 * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. 74 */ 75 afterAll(() => { 76 console.info('====>afterAll: Test suite-level cleanup condition is executed'); 77 }); 78 79 let attachments: Array<request.agent.FormItem> = [{ 80 name: "uploadTest", 81 value: { 82 path: "./test.txt", 83 filename: "test.txt", 84 mimeType: "application/octet-stream" 85 } 86 }]; 87 88 let config: request.agent.Config = { 89 action: request.agent.Action.UPLOAD, 90 url: 'http://127.0.0.1:8080', 91 title: 'uploadTest', 92 description: 'Sample code for event listening', 93 mode: request.agent.Mode.BACKGROUND, 94 overwrite: true, 95 method: "POST", 96 data: attachments, 97 saveas: "./", 98 network: request.agent.Network.CELLULAR, 99 metered: false, 100 roaming: true, 101 retry: true, 102 redirect: true, 103 index: 0, 104 begins: 0, 105 ends: -1, 106 gauge: false, 107 precise: false, 108 token: "it is a secret" 109 }; 110 111 let sleep = (timeout: number): Promise<null> => { 112 return new Promise(resolve => { 113 const st = setTimeout(() => { 114 resolve(null); 115 clearTimeout(st); 116 }, timeout); 117 }); 118 }; 119 120 /** 121 * @tc.number SUB_Misc_REQUEST_Create_Upload_Callback_0010 122 * @tc.desc Starts a upload session. 123 * @tc.size : MEDIUM 124 * @tc.type : Function 125 * @tc.level : Level 2 126 */ 127 it('SUB_Misc_REQUEST_Create_Upload_Callback_0010', 0, async (done: Function) => { 128 console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0010 is starting-----------------------"); 129 request.agent.create(baseContext, config, async (err, task)=>{ 130 console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0010 uploadTask: " + task); 131 try{ 132 if(err){ 133 console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0010 create err: " + JSON.stringify(err)); 134 expect().assertFail(); 135 } 136 expect(task !== undefined).assertEqual(true); 137 console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0010 create success: " + task); 138 await request.agent.remove(task.tid); 139 console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Callback_0010 end-----------------------"); 140 done(); 141 }catch(error){ 142 console.info("====>SUB_Misc_REQUEST_Create_Upload_Callback_0010 create fail: " + JSON.stringify(error)); 143 await request.agent.remove(task.tid); 144 done(); 145 } 146 147 }); 148 }); 149 150 /** 151 * @tc.number SUB_Misc_REQUEST_Create_Upload_Promise_0010 152 * @tc.desc Starts a upload session. 153 * @tc.size : MEDIUM 154 * @tc.type : Function 155 * @tc.level : Level 2 156 */ 157 it('SUB_Misc_REQUEST_Create_Upload_Promise_0010', 0, async (done: Function) => { 158 console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0010 is starting-----------------------"); 159 let task: request.agent.Task | undefined; 160 try { 161 task = await request.agent.create(baseContext, config); 162 expect(task !== undefined).assertEqual(true); 163 await request.agent.remove(task.tid); 164 console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0010 create success: " + task); 165 console.info("-----------------------SUB_Misc_REQUEST_Create_Upload_Promise_0010 end-----------------------"); 166 done(); 167 } catch (err) { 168 console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0010 catch error: " + JSON.stringify(err)); 169 if(task !== undefined){ 170 await request.agent.remove(task.tid); 171 console.info("====>SUB_Misc_REQUEST_Create_Upload_Promise_0010 agent.remove success"); 172 } 173 expect().assertFail(); 174 done(); 175 } 176 }); 177 178 /** 179 * @tc.number SUB_Misc_REQUEST_Remove_Upload_Callback_0010 180 * @tc.desc Delete the upload task. 181 * @tc.size : MEDIUM 182 * @tc.type : Function 183 * @tc.level : Level 2 184 */ 185 it('SUB_Misc_REQUEST_Remove_Upload_Callback_0010', 0, async (done: Function) => { 186 console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0010 is starting-----------------------"); 187 try { 188 let task = await request.agent.create(baseContext, config); 189 request.agent.remove(task.tid, err => { 190 try { 191 if(err){ 192 console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0010 remove err: " + JSON.stringify(err)); 193 expect().assertFail(); 194 } 195 expect(task !== undefined).assertEqual(true); 196 console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0010 remove success: " + task); 197 console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Callback_0010 end-----------------------"); 198 done(); 199 } catch (err) { 200 console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0010 remove fail: " + JSON.stringify(err)); 201 done(); 202 } 203 }); 204 } catch (error) { 205 console.info("====>SUB_Misc_REQUEST_Remove_Upload_Callback_0010 catch error: " + JSON.stringify(error)); 206 expect().assertFail(); 207 done(); 208 } 209 210 }); 211 212 /** 213 * @tc.number SUB_Misc_REQUEST_Remove_Upload_Promise_0010 214 * @tc.desc Delete the upload task. 215 * @tc.size : MEDIUM 216 * @tc.type : Function 217 * @tc.level : Level 2 218 */ 219 it('SUB_Misc_REQUEST_Remove_Upload_Promise_0010', 0, async (done: Function) => { 220 console.info("====>-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0010 is starting-----------------------"); 221 try { 222 let task = await request.agent.create(baseContext, config); 223 await request.agent.remove(task.tid); 224 expect(true).assertEqual(true); 225 console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0010 remove success: " + task); 226 console.info("-----------------------SUB_Misc_REQUEST_Remove_Upload_Promise_0010 end-----------------------"); 227 done(); 228 } catch (err) { 229 console.info("====>SUB_Misc_REQUEST_Remove_Upload_Promise_0010 catch error: " + JSON.stringify(err)); 230 expect().assertFail(); 231 done(); 232 } 233 }); 234 235 /** 236 * @tc.number SUB_Misc_REQUEST_Start_Upload_Callback_0010 237 * @tc.desc Suspend the upload task 238 * @tc.size : MEDIUM 239 * @tc.type : Function 240 * @tc.level : Level 2 241 */ 242 it('SUB_Misc_REQUEST_Start_Upload_Callback_0010', 0, async (done: Function) => { 243 console.info("====>-----------------------SUB_Misc_REQUEST_Start_Upload_Callback_0010 is starting-----------------------"); 244 request.agent.create(baseContext, config, async (err, task)=>{ 245 console.info("====>SUB_Misc_REQUEST_Start_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); 246 task.start(async err => { 247 try{ 248 if(err){ 249 console.info("====>SUB_Misc_REQUEST_Start_Upload_Callback_0010 upload start err: " + JSON.stringify(err)); 250 expect().assertFail(); 251 } 252 expect(true).assertEqual(true); 253 console.info("====>SUB_Misc_REQUEST_Start_Upload_Callback_0010 upload start success: " + task); 254 console.info("-----------------------SUB_Misc_REQUEST_Start_Upload_Callback_0010 end-----------------------"); 255 await sleep(100); 256 done(); 257 }catch(err){ 258 console.info("====>SUB_Misc_REQUEST_Start_Upload_Callback_0010 catch err: " + JSON.stringify(err)); 259 done(); 260 } 261 }); 262 }); 263 }); 264 265 /** 266 * @tc.number SUB_Misc_REQUEST_Start_Upload_Promise_0010 267 * @tc.desc Suspend the upload task 268 * @tc.size : MEDIUM 269 * @tc.type : Function 270 * @tc.level : Level 2 271 */ 272 it('SUB_Misc_REQUEST_Start_Upload_Promise_0010', 0, async (done: Function) => { 273 console.info("====>-----------------------SUB_Misc_REQUEST_Start_Upload_Promise_0010 is starting-----------------------"); 274 try { 275 let task = await request.agent.create(baseContext, config); 276 await task.start(); 277 expect(true).assertEqual(true); 278 console.info("====>SUB_Misc_REQUEST_Start_Upload_Promise_0010 upload start success: " + JSON.stringify(task)); 279 console.info("-----------------------SUB_Misc_REQUEST_Start_Upload_Promise_0010 end-----------------------"); 280 await sleep(100); 281 done(); 282 } catch (err) { 283 console.info("====>SUB_Misc_REQUEST_Start_Upload_Promise_0010 upload start err: " + JSON.stringify(err)); 284 expect().assertFail(); 285 done(); 286 } 287 }); 288 289 /** 290 * @tc.number SUB_Misc_REQUEST_Pause_Upload_Callback_0010 291 * @tc.desc Restore the upload task 292 * @tc.size : MEDIUM 293 * @tc.type : Function 294 * @tc.level : Level 2 295 */ 296 it('SUB_Misc_REQUEST_Pause_Upload_Callback_0010', 0, async (done: Function) => { 297 console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Upload_Callback_0010 is starting-----------------------"); 298 request.agent.create(baseContext, config, async (err, task)=>{ 299 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); 300 task.start(err => { 301 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 upload start: " + JSON.stringify(err)); 302 task.pause(async err => { 303 try{ 304 if(err){ 305 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 upload pause err: " + JSON.stringify(err)); 306 expect().assertFail(); 307 } 308 expect(true).assertEqual(true); 309 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 upload pause success: " + task); 310 console.info("-----------------------SUB_Misc_REQUEST_Pause_Upload_Callback_0010 end-----------------------"); 311 await sleep(100); 312 done(); 313 }catch(err){ 314 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Callback_0010 catch err: " + JSON.stringify(err)); 315 done(); 316 } 317 }); 318 }); 319 }); 320 }); 321 322 /** 323 * @tc.number SUB_Misc_REQUEST_Pause_Upload_Promise_0010 324 * @tc.desc Restore the upload task 325 * @tc.size : MEDIUM 326 * @tc.type : Function 327 * @tc.level : Level 2 328 */ 329 it('SUB_Misc_REQUEST_Pause_Upload_Promise_0010', 0, async (done: Function) => { 330 console.info("====>-----------------------SUB_Misc_REQUEST_Pause_Upload_Promise_0010 is starting-----------------------"); 331 let task = await request.agent.create(baseContext, config); 332 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Promise_0010 create task: " + JSON.stringify(task)); 333 task.start(async err => { 334 try { 335 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Promise_0010 upload start: " + JSON.stringify(err)); 336 await task.pause(); 337 expect(true).assertEqual(true); 338 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Promise_0010 upload pause success: " + task); 339 console.info("-----------------------SUB_Misc_REQUEST_Pause_Upload_Promise_0010 end-----------------------"); 340 done(); 341 } catch (err) { 342 console.info("====>SUB_Misc_REQUEST_Pause_Upload_Promise_0010 upload pause err: " + JSON.stringify(err)); 343 expect().assertFail(); 344 done(); 345 } 346 }); 347 }); 348 349 /** 350 * @tc.number SUB_Misc_REQUEST_Resume_Upload_Callback_0010 351 * @tc.desc Get the upload task info 352 * @tc.size : MEDIUM 353 * @tc.type : Function 354 * @tc.level : Level 2 355 */ 356 it('SUB_Misc_REQUEST_Resume_Upload_Callback_0010', 0, async (done: Function) => { 357 console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Upload_Callback_0010 is starting-----------------------"); 358 request.agent.create(baseContext, config, async (err, task)=>{ 359 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); 360 task.start(err => { 361 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 start: " + JSON.stringify(err)); 362 task.pause(err => { 363 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 pause: " + JSON.stringify(err)); 364 task.resume(async err => { 365 try{ 366 if(err){ 367 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 upload resume err: " + JSON.stringify(err)); 368 expect().assertFail(); 369 } 370 expect(true).assertEqual(true); 371 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 upload resume success: " + task); 372 console.info("-----------------------SUB_Misc_REQUEST_Resume_Upload_Callback_0010 end-----------------------"); 373 await sleep(100); 374 done(); 375 }catch(err){ 376 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Callback_0010 catch err: " + JSON.stringify(err)); 377 done(); 378 } 379 }) 380 }) 381 }); 382 }); 383 }); 384 385 /** 386 * @tc.number SUB_Misc_REQUEST_Resume_Upload_Promise_0010 387 * @tc.desc Get the upload task info 388 * @tc.size : MEDIUM 389 * @tc.type : Function 390 * @tc.level : Level 2 391 */ 392 it('SUB_Misc_REQUEST_Resume_Upload_Promise_0010', 0, async (done: Function) => { 393 console.info("====>-----------------------SUB_Misc_REQUEST_Resume_Upload_Promise_0010 is starting-----------------------"); 394 let task = await request.agent.create(baseContext, config); 395 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 create task: " + JSON.stringify(task)); 396 task.start(err => { 397 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 start: " + JSON.stringify(err)); 398 task.pause(async err => { 399 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 pause: " + JSON.stringify(err)); 400 try { 401 await task.resume(); 402 expect(true).assertEqual(true); 403 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 upload resume success: " + task); 404 console.info("-----------------------SUB_Misc_REQUEST_Resume_Upload_Promise_0010 end-----------------------"); 405 done(); 406 } catch (err) { 407 console.info("====>SUB_Misc_REQUEST_Resume_Upload_Promise_0010 upload resume err: " + JSON.stringify(err)); 408 expect().assertFail(); 409 done(); 410 } 411 }); 412 }); 413 }); 414 415 /** 416 * @tc.number SUB_Misc_REQUEST_Stop_Upload_Callback_0010 417 * @tc.desc Get the upload task info 418 * @tc.size : MEDIUM 419 * @tc.type : Function 420 * @tc.level : Level 2 421 */ 422 it('SUB_Misc_REQUEST_Stop_Upload_Callback_0010', 0, async (done: Function) => { 423 console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Upload_Callback_0010 is starting-----------------------"); 424 request.agent.create(baseContext, config, async (err, task)=>{ 425 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 uploadTask: " + JSON.stringify(task)); 426 task.start(err => { 427 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 start: " + JSON.stringify(err)); 428 task.stop(async err => { 429 try{ 430 if(err){ 431 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 upload stop err: " + JSON.stringify(err)); 432 expect().assertFail() ; 433 } 434 expect(true).assertEqual(true); 435 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 upload stop success: " + task); 436 console.info("-----------------------SUB_Misc_REQUEST_Stop_Upload_Callback_0010 end-----------------------"); 437 await sleep(100); 438 done(); 439 }catch(err){ 440 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Callback_0010 catch err: " + JSON.stringify(err)); 441 done(); 442 } 443 }); 444 }); 445 }); 446 }); 447 448 /** 449 * @tc.number SUB_Misc_REQUEST_Stop_Upload_Promise_0010 450 * @tc.desc Get the upload task info 451 * @tc.size : MEDIUM 452 * @tc.type : Function 453 * @tc.level : Level 2 454 */ 455 it('SUB_Misc_REQUEST_Stop_Upload_Promise_0010', 0, async (done: Function) => { 456 console.info("====>-----------------------SUB_Misc_REQUEST_Stop_Upload_Promise_0010 is starting-----------------------"); 457 let task = await request.agent.create(baseContext, config); 458 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Promise_0010 create task: " + JSON.stringify(task)); 459 task.start(async err => { 460 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Promise_0010 start: " + JSON.stringify(err)); 461 try { 462 await task.stop(); 463 expect(true).assertEqual(true); 464 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Promise_0010 upload stop success: " + task); 465 done(); 466 } catch (err) { 467 console.info("====>SUB_Misc_REQUEST_Stop_Upload_Promise_0010 upload stop err: " + JSON.stringify(err)); 468 await sleep(100); 469 done(); 470 } 471 }) 472 }); 473 474 /* 475 * @tc.number: SUB_REQUEST_Agent_UploadConfig_1700 476 * @tc.name: SUB_REQUEST_Agent_UploadConfig_1700 477 * @tc.desc: different upload path or upload file name of config 478 * @tc.size: MediumTest 479 * @tc.type: Function 480 * @tc.level: Level 2 481 */ 482 it('SUB_REQUEST_Agent_UploadConfig_1700', 0, async (done: Function) => { 483 console.info("====>-----------------------SUB_REQUEST_Agent_UploadConfig_1700 is starting-----------------------"); 484 let value: ESObject = { 485 path: undefined, 486 filename: 'el1BaseNormal.txt' 487 } 488 489 let att: Array<ESObject> = [{ 490 name: 'uploadTest', 491 value: value 492 }] 493 494 let config_: request.agent. Config = JSON.parse(JSON.stringify(config)); 495 config_.data = att 496 console.info("====>SUB_REQUEST_Agent_UploadConfig_1700 config: " + JSON.stringify(config_)); 497 try { 498 let on_completedCallback =(pro: request.agent.Progress) => { 499 task.off('completed', on_completedCallback); 500 console.info("====>SUB_REQUEST_Agent_UploadConfig_1700 pro: " + JSON.stringify(pro)); 501 expect().assertFail(); 502 done(); 503 } 504 505 let task: request.agent.Task = await request.agent.create(baseContext, config_); 506 task.on('completed', on_completedCallback); 507 await task.start(); 508 } catch (err) { 509 console.info("====>SUB_REQUEST_Agent_UploadConfig_1700 create catch err: " + JSON.stringify(err)); 510 expect(err.code).assertEqual(401); 511 done(); 512 } 513 }); 514 515 /** 516 * @tc.number SUB_REQUEST_Upload_broadcastEvent_0100 517 * @tc.name SUB_REQUEST_Upload_broadcastEvent_0100 518 * @tc.desc monitor complete task. 519 * @tc.size : MediumTest 520 * @tc.type : Function 521 * @tc.level : Level 2 522 */ 523 it('SUB_REQUEST_Upload_broadcastEvent_0100', 0, async (done: Function) => { 524 console.info("====>-----------------------SUB_REQUEST_Upload_broadcastEvent_0100 is starting-----------------------"); 525 let attachments: Array<request.agent.FormItem> = [{ 526 name: "uploadTest", 527 value: { 528 path: "./test.txt", 529 filename: "test.txt", 530 mimeType: "application/octet-stream" 531 } 532 }]; 533 let config:request.agent.Config = { 534 action: request.agent.Action.UPLOAD, 535 url: 'http://127.0.0.1:8080', 536 title: 'createTest', 537 description: 'XTS download test!', 538 network: request.agent.Network.ANY, 539 overwrite: true, 540 mode: request.agent.Mode.FOREGROUND, 541 method: "POST", 542 data:attachments, 543 }; 544 545 let task: request.agent.Task; 546 let unSubscriberCallback = (err: BusinessError) => { 547 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 unSubscriberCallback start"); 548 if (err){ 549 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 unSubscriberCallback failed:" + 550 JSON.stringify(err)); 551 } else { 552 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 unSubscriberCallback finish"); 553 } 554 } 555 556 let subscriberCallback = (err: BusinessError, data: ESObject) =>{ 557 try { 558 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 subscriberCallback data:" 559 + JSON.stringify(data)); 560 commonEvent.unsubscribe(subscriber, unSubscriberCallback); 561 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 data.code: " + data.code); 562 expect(data.code).assertEqual(64); 563 done(); 564 } catch (err) { 565 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 subscriberCallback error: " + JSON.stringify(err)); 566 done(); 567 } 568 } 569 let commonEventSubscribeInfo: commonEvent.CommonEventSubscribeInfo = { 570 events: [ request.agent.BroadcastEvent.COMPLETE ] 571 } 572 let subscriber: ESObject; 573 commonEvent.createSubscriber(commonEventSubscribeInfo).then((data)=>{ 574 subscriber = data; 575 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 subscriber data:" + data); 576 commonEvent.subscribe(subscriber, subscriberCallback); 577 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 subscriber finish"); 578 }) 579 580 try { 581 request.agent.create(baseContext, config, async (err, t) => { 582 try { 583 if(err){ 584 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 create err: " + JSON.stringify(err)); 585 expect().assertFail(); 586 } 587 task = t; 588 await task.start(); 589 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 task start"); 590 } catch (err) { 591 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 catch err: " + JSON.stringify(err)); 592 } 593 }); 594 } catch (err) { 595 console.info("====>SUB_REQUEST_Upload_broadcastEvent_0100 create catch err: " + JSON.stringify(err)); 596 expect().assertFail(); 597 } 598 }); 599 600 }) 601} 602