8
8
import com .alibaba .fastjson .JSONObject ;
9
9
import com .microsoft .hydralab .center .service .StorageTokenManageService ;
10
10
import com .microsoft .hydralab .center .service .TestDataService ;
11
+ import com .microsoft .hydralab .center .service .generation .MaestroCaseGenerationService ;
11
12
import com .microsoft .hydralab .common .entity .agent .Result ;
12
13
import com .microsoft .hydralab .common .entity .center .SysUser ;
13
14
import com .microsoft .hydralab .common .entity .common .AndroidTestUnit ;
26
27
import com .microsoft .hydralab .common .util .FileUtil ;
27
28
import com .microsoft .hydralab .common .util .HydraLabRuntimeException ;
28
29
import com .microsoft .hydralab .common .util .LogUtils ;
30
+ import com .microsoft .hydralab .common .util .PageNode ;
29
31
import com .microsoft .hydralab .t2c .runner .T2CJsonGenerator ;
30
32
import org .apache .commons .io .IOUtils ;
31
33
import org .apache .commons .lang3 .StringUtils ;
34
+ import org .junit .jupiter .api .Assertions ;
32
35
import org .slf4j .Logger ;
33
36
import org .slf4j .LoggerFactory ;
34
37
import org .springframework .http .HttpStatus ;
47
50
import javax .servlet .http .HttpServletResponse ;
48
51
import java .io .File ;
49
52
import java .io .FileInputStream ;
53
+ import java .io .FileNotFoundException ;
50
54
import java .io .IOException ;
51
55
import java .io .InputStream ;
52
56
import java .net .HttpURLConnection ;
53
57
import java .net .URL ;
54
58
import java .nio .charset .StandardCharsets ;
59
+ import java .util .ArrayList ;
55
60
import java .util .List ;
56
61
57
62
import static com .microsoft .hydralab .center .util .CenterConstant .CENTER_TEMP_FILE_DIR ;
@@ -72,6 +77,8 @@ public class TestDetailController {
72
77
AttachmentService attachmentService ;
73
78
@ Resource
74
79
StorageServiceClientProxy storageServiceClientProxy ;
80
+ @ Resource
81
+ MaestroCaseGenerationService maestroCaseGenerationService ;
75
82
76
83
/**
77
84
* Authenticated USER:
@@ -412,4 +419,52 @@ public Result<String> generateT2CJsonFromSmartTest(@CurrentSecurityContext SysUs
412
419
return Result .ok (t2cJson );
413
420
}
414
421
422
+ @ GetMapping (value = {"/api/test/generateMaestro/{fileId}" }, produces = MediaType .APPLICATION_JSON_VALUE )
423
+ public Result generateMaestroFromSmartTest (@ CurrentSecurityContext SysUser requestor ,
424
+ @ PathVariable (value = "fileId" ) String fileId ,
425
+ @ RequestParam (value = "testRunId" ) String testRunId ,
426
+ HttpServletResponse response ) throws IOException {
427
+ if (requestor == null ) {
428
+ return Result .error (HttpStatus .UNAUTHORIZED .value (), "unauthorized" );
429
+ }
430
+
431
+ File graphZipFile = loadGraphFile (fileId );
432
+ File graphFile = new File (graphZipFile .getParentFile ().getAbsolutePath (), Const .SmartTestConfig .GRAPH_FILE_NAME );
433
+ TestRun testRun = testDataService .findTestRunById (testRunId );
434
+ TestTask testTask = testDataService .getTestTaskDetail (testRun .getTestTaskId ());
435
+
436
+ PageNode rootNode = maestroCaseGenerationService .parserXMLToPageNode (graphFile .getAbsolutePath ());
437
+ Assertions .assertNotNull (rootNode , "parser xml to page node failed" );
438
+ rootNode .setPageName (testTask .getPkgName ());
439
+ System .out .println (rootNode );
440
+ List <PageNode .ExplorePath > explorePaths = new ArrayList <>();
441
+ maestroCaseGenerationService .explorePageNodePath (rootNode , "" , "" , explorePaths );
442
+ File caseZipFile = maestroCaseGenerationService .generateCaseFile (rootNode , explorePaths );
443
+
444
+ if (caseZipFile == null ) {
445
+ return Result .error (HttpStatus .BAD_REQUEST .value (), "The file was not downloaded" );
446
+ }
447
+ try {
448
+ FileInputStream in = new FileInputStream (caseZipFile );
449
+ ServletOutputStream out = response .getOutputStream ();
450
+ response .setContentType ("application/octet-stream;charset=UTF-8" );
451
+ response .setHeader ("Content-Disposition" , "attachment;filename=" + caseZipFile .getName ());
452
+ int len ;
453
+ byte [] buffer = new byte [1024 * 10 ];
454
+ while ((len = in .read (buffer )) != -1 ) {
455
+ out .write (buffer , 0 , len );
456
+ }
457
+ out .flush ();
458
+ } catch (FileNotFoundException e ) {
459
+ throw new RuntimeException (e );
460
+ } catch (IOException e ) {
461
+ throw new RuntimeException (e );
462
+ } finally {
463
+ response .flushBuffer ();
464
+ caseZipFile .delete ();
465
+ }
466
+
467
+ return Result .ok ();
468
+ }
469
+
415
470
}
0 commit comments