10
10
import org .cornutum .tcases .io .SystemInputResources ;
11
11
import org .cornutum .tcases .io .SystemTestResources ;
12
12
import org .cornutum .tcases .openapi .ApiCommand .Options ;
13
+ import org .cornutum .tcases .openapi .resolver .ResolverException ;
13
14
14
15
import org .apache .commons .io .FileUtils ;
15
16
import org .apache .commons .io .IOUtils ;
@@ -461,6 +462,254 @@ public void run_8() throws Exception
461
462
assertThat ( "Output model created" , outFile .exists (), is ( true ));
462
463
}
463
464
465
+ /**
466
+ * Tests {@link ApiCommand#run run()} using the following inputs.
467
+ * <P>
468
+ * <TABLE border="1" cellpadding="8">
469
+ * <TR align="left"><TH colspan=2> 9. run (Success) </TH></TR>
470
+ * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR>
471
+ * <TR><TD> Perspective </TD> <TD> (not applicable) </TD> </TR>
472
+ * <TR><TD> Model-Type </TD> <TD> Default </TD> </TR>
473
+ * <TR><TD> Condition-Handler </TD> <TD> Log </TD> </TR>
474
+ * <TR><TD> Output-File.Defined </TD> <TD> No </TD> </TR>
475
+ * <TR><TD> Output-File.Path </TD> <TD> (not applicable) </TD> </TR>
476
+ * <TR><TD> Output-Dir.Defined </TD> <TD> No </TD> </TR>
477
+ * <TR><TD> Output-Dir.Exists </TD> <TD> (not applicable) </TD> </TR>
478
+ * <TR><TD> Read-Only-Enforced </TD> <TD> Yes </TD> </TR>
479
+ * <TR><TD> Write-Only-Enforced </TD> <TD> No </TD> </TR>
480
+ * <TR><TD> Output-Transformer </TD> <TD> (not applicable) </TD> </TR>
481
+ * <TR><TD> Request-Cases.Selected </TD> <TD> Yes </TD> </TR>
482
+ * <TR><TD> Request-Cases.Random-Seed </TD> <TD> Defined </TD> </TR>
483
+ * <TR><TD> Request-Cases.Max-Tries </TD> <TD> Default </TD> </TR>
484
+ * <TR><TD> Request-Cases.Condition-Handler </TD> <TD> Fail </TD> </TR>
485
+ * <TR><TD> Api-Spec.Defined </TD> <TD> No </TD> </TR>
486
+ * <TR><TD> Api-Spec.Path </TD> <TD> (not applicable) </TD> </TR>
487
+ * </TABLE>
488
+ * </P>
489
+ */
490
+ @ Test
491
+ public void run_9 () throws Exception
492
+ {
493
+ // Given...
494
+ File apiFile = getResourceFile ( "api-run-9.json" );
495
+ StringBuffer outFile = new StringBuffer ();
496
+
497
+ String [] args =
498
+ {
499
+ "-D" ,
500
+ "-c" , "log,fail" ,
501
+ "-R" ,
502
+ "-r" , "1234567"
503
+ };
504
+
505
+ expectFailure ( ResolverException .class )
506
+ .when ( () -> runWithStdIO ( new Options ( args ), apiFile , outFile ))
507
+ .then ( failure -> assertThat ( "Failure" , failure .getMessage (), is ( "Error processing RequestCaseDef[3,POST,/array,SUCCESS], param0, value, unique item[1] of 3" )));
508
+ }
509
+
510
+ /**
511
+ * Tests {@link ApiCommand#run run()} using the following inputs.
512
+ * <P>
513
+ * <TABLE border="1" cellpadding="8">
514
+ * <TR align="left"><TH colspan=2> 10. run (Success) </TH></TR>
515
+ * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR>
516
+ * <TR><TD> Perspective </TD> <TD> (not applicable) </TD> </TR>
517
+ * <TR><TD> Model-Type </TD> <TD> Test </TD> </TR>
518
+ * <TR><TD> Condition-Handler </TD> <TD> Ignore </TD> </TR>
519
+ * <TR><TD> Output-File.Defined </TD> <TD> Yes </TD> </TR>
520
+ * <TR><TD> Output-File.Path </TD> <TD> Absolute </TD> </TR>
521
+ * <TR><TD> Output-Dir.Defined </TD> <TD> No </TD> </TR>
522
+ * <TR><TD> Output-Dir.Exists </TD> <TD> (not applicable) </TD> </TR>
523
+ * <TR><TD> Read-Only-Enforced </TD> <TD> No </TD> </TR>
524
+ * <TR><TD> Write-Only-Enforced </TD> <TD> Yes </TD> </TR>
525
+ * <TR><TD> Output-Transformer </TD> <TD> (not applicable) </TD> </TR>
526
+ * <TR><TD> Request-Cases.Selected </TD> <TD> Yes </TD> </TR>
527
+ * <TR><TD> Request-Cases.Random-Seed </TD> <TD> Default </TD> </TR>
528
+ * <TR><TD> Request-Cases.Max-Tries </TD> <TD> Defined </TD> </TR>
529
+ * <TR><TD> Request-Cases.Condition-Handler </TD> <TD> Default </TD> </TR>
530
+ * <TR><TD> Api-Spec.Defined </TD> <TD> No </TD> </TR>
531
+ * <TR><TD> Api-Spec.Path </TD> <TD> (not applicable) </TD> </TR>
532
+ * </TABLE>
533
+ * </P>
534
+ */
535
+ @ Test
536
+ public void run_10 () throws Exception
537
+ {
538
+ // Given...
539
+ File apiFile = getResourceFile ( "api-run-10.json" );
540
+ File outFile = new File ( apiFile .getParentFile (), "api-run-10-Output.json" );
541
+
542
+ outFile .delete ();
543
+
544
+ String [] args =
545
+ {
546
+ "-D" ,
547
+ "-c" , "ignore" ,
548
+ "-f" , outFile .getPath (),
549
+ "-W" ,
550
+ "-m" , "123"
551
+ };
552
+
553
+ // When...
554
+ runWithStdIO ( new Options ( args ), apiFile , null );
555
+
556
+ // Then...
557
+ assertThat ( "Output model created" , outFile .exists (), is ( true ));
558
+ }
559
+
560
+ /**
561
+ * Tests {@link ApiCommand#run run()} using the following inputs.
562
+ * <P>
563
+ * <TABLE border="1" cellpadding="8">
564
+ * <TR align="left"><TH colspan=2> 11. run (Success) </TH></TR>
565
+ * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR>
566
+ * <TR><TD> Perspective </TD> <TD> (not applicable) </TD> </TR>
567
+ * <TR><TD> Model-Type </TD> <TD> Default </TD> </TR>
568
+ * <TR><TD> Condition-Handler </TD> <TD> Default </TD> </TR>
569
+ * <TR><TD> Output-File.Defined </TD> <TD> No </TD> </TR>
570
+ * <TR><TD> Output-File.Path </TD> <TD> (not applicable) </TD> </TR>
571
+ * <TR><TD> Output-Dir.Defined </TD> <TD> Yes </TD> </TR>
572
+ * <TR><TD> Output-Dir.Exists </TD> <TD> Yes </TD> </TR>
573
+ * <TR><TD> Read-Only-Enforced </TD> <TD> Yes </TD> </TR>
574
+ * <TR><TD> Write-Only-Enforced </TD> <TD> No </TD> </TR>
575
+ * <TR><TD> Output-Transformer </TD> <TD> (not applicable) </TD> </TR>
576
+ * <TR><TD> Request-Cases.Selected </TD> <TD> Yes </TD> </TR>
577
+ * <TR><TD> Request-Cases.Random-Seed </TD> <TD> Defined </TD> </TR>
578
+ * <TR><TD> Request-Cases.Max-Tries </TD> <TD> Default </TD> </TR>
579
+ * <TR><TD> Request-Cases.Condition-Handler </TD> <TD> Log </TD> </TR>
580
+ * <TR><TD> Api-Spec.Defined </TD> <TD> Yes </TD> </TR>
581
+ * <TR><TD> Api-Spec.Path </TD> <TD> Relative </TD> </TR>
582
+ * </TABLE>
583
+ * </P>
584
+ */
585
+ @ Test
586
+ public void run_11 () throws Exception
587
+ {
588
+ // Given...
589
+ File apiFile = getResourceFile ( "api-run-11.json" );
590
+ File outDir = new File ( apiFile .getParentFile (), "11" );
591
+ File outFile = new File ( outDir , "api-run-11-Request-Cases.json" );
592
+
593
+ FileUtils .deleteDirectory ( outDir );
594
+
595
+ String [] args =
596
+ {
597
+ "-D" ,
598
+ "-c" , ",log" ,
599
+ "-o" , outDir .getPath (),
600
+ "-R" ,
601
+ "-r" , "1234567890" ,
602
+ apiFile .getPath ()
603
+ };
604
+
605
+ // When...
606
+ ApiCommand .run ( new Options ( args ));
607
+
608
+ // Then...
609
+ assertThat ( "Output model created" , outFile .exists (), is ( true ));
610
+ }
611
+
612
+ /**
613
+ * Tests {@link ApiCommand#run run()} using the following inputs.
614
+ * <P>
615
+ * <TABLE border="1" cellpadding="8">
616
+ * <TR align="left"><TH colspan=2> 12. run (Success) </TH></TR>
617
+ * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR>
618
+ * <TR><TD> Perspective </TD> <TD> (not applicable) </TD> </TR>
619
+ * <TR><TD> Model-Type </TD> <TD> Default </TD> </TR>
620
+ * <TR><TD> Condition-Handler </TD> <TD> Fail </TD> </TR>
621
+ * <TR><TD> Output-File.Defined </TD> <TD> Yes </TD> </TR>
622
+ * <TR><TD> Output-File.Path </TD> <TD> Relative </TD> </TR>
623
+ * <TR><TD> Output-Dir.Defined </TD> <TD> Yes </TD> </TR>
624
+ * <TR><TD> Output-Dir.Exists </TD> <TD> No </TD> </TR>
625
+ * <TR><TD> Read-Only-Enforced </TD> <TD> No </TD> </TR>
626
+ * <TR><TD> Write-Only-Enforced </TD> <TD> Yes </TD> </TR>
627
+ * <TR><TD> Output-Transformer </TD> <TD> (not applicable) </TD> </TR>
628
+ * <TR><TD> Request-Cases.Selected </TD> <TD> Yes </TD> </TR>
629
+ * <TR><TD> Request-Cases.Random-Seed </TD> <TD> Default </TD> </TR>
630
+ * <TR><TD> Request-Cases.Max-Tries </TD> <TD> Defined </TD> </TR>
631
+ * <TR><TD> Request-Cases.Condition-Handler </TD> <TD> Ignore </TD> </TR>
632
+ * <TR><TD> Api-Spec.Defined </TD> <TD> Yes </TD> </TR>
633
+ * <TR><TD> Api-Spec.Path </TD> <TD> Absolute </TD> </TR>
634
+ * </TABLE>
635
+ * </P>
636
+ */
637
+ @ Test
638
+ public void run_12 () throws Exception
639
+ {
640
+ // Given...
641
+ File apiFile = getResourceFile ( "api-run-12.json" );
642
+ File outDir = new File ( apiFile .getParentFile (), "12" );
643
+ File outFile = new File ( outDir , "api-run-12-Output.json" );
644
+
645
+ FileUtils .deleteDirectory ( outDir );
646
+
647
+ String [] args =
648
+ {
649
+ "-D" ,
650
+ "-c" , "fail,ignore" ,
651
+ "-o" , outDir .getPath (),
652
+ "-f" , outFile .getName (),
653
+ "-W" ,
654
+ apiFile .getPath ()
655
+ };
656
+
657
+ // When...
658
+ ApiCommand .run ( new Options ( args ));
659
+
660
+ // Then...
661
+ assertThat ( "Output model created" , outFile .exists (), is ( true ));
662
+ }
663
+
664
+ /**
665
+ * Tests {@link ApiCommand#run run()} using the following inputs.
666
+ * <P>
667
+ * <TABLE border="1" cellpadding="8">
668
+ * <TR align="left"><TH colspan=2> 13. run (Success) </TH></TR>
669
+ * <TR align="left"><TH> Input Choice </TH> <TH> Value </TH></TR>
670
+ * <TR><TD> Perspective </TD> <TD> (not applicable) </TD> </TR>
671
+ * <TR><TD> Model-Type </TD> <TD> Input </TD> </TR>
672
+ * <TR><TD> Condition-Handler </TD> <TD> Default </TD> </TR>
673
+ * <TR><TD> Output-File.Defined </TD> <TD> No </TD> </TR>
674
+ * <TR><TD> Output-File.Path </TD> <TD> (not applicable) </TD> </TR>
675
+ * <TR><TD> Output-Dir.Defined </TD> <TD> No </TD> </TR>
676
+ * <TR><TD> Output-Dir.Exists </TD> <TD> (not applicable) </TD> </TR>
677
+ * <TR><TD> Read-Only-Enforced </TD> <TD> No </TD> </TR>
678
+ * <TR><TD> Write-Only-Enforced </TD> <TD> No </TD> </TR>
679
+ * <TR><TD> Output-Transformer </TD> <TD> (not applicable) </TD> </TR>
680
+ * <TR><TD> Request-Cases.Selected </TD> <TD> Yes </TD> </TR>
681
+ * <TR><TD> Request-Cases.Random-Seed </TD> <TD> Default </TD> </TR>
682
+ * <TR><TD> Request-Cases.Max-Tries </TD> <TD> Default </TD> </TR>
683
+ * <TR><TD> Request-Cases.Condition-Handler </TD> <TD> Default </TD> </TR>
684
+ * <TR><TD> Api-Spec.Defined </TD> <TD> Yes </TD> </TR>
685
+ * <TR><TD> Api-Spec.Path </TD> <TD> Relative </TD> </TR>
686
+ * </TABLE>
687
+ * </P>
688
+ */
689
+ @ Test
690
+ public void run_13 () throws Exception
691
+ {
692
+ // Given...
693
+ File apiFile = getResourceFile ( "api-run-13.json" );
694
+ File outFile = new File ( apiFile .getParentFile (), "api-run-13-Requests-Input.json" );
695
+
696
+ outFile .delete ();
697
+
698
+ String [] args =
699
+ {
700
+ "-D" ,
701
+ "-I" ,
702
+ "-c" , " , " ,
703
+ apiFile .getPath ()
704
+ };
705
+
706
+ // When...
707
+ ApiCommand .run ( new Options ( args ));
708
+
709
+ // Then...
710
+ assertThat ( "Output model created" , outFile .exists (), is ( true ));
711
+ }
712
+
464
713
/**
465
714
* Return the file for the given resource.
466
715
*/
@@ -475,7 +724,7 @@ private File getResourceFile( String resource)
475
724
* If <CODE>stdIn</CODE> is non-null, redirect standard input to read from the given file.
476
725
* If <CODE>stdOut</CODE> is non-null, redirect standard output to write to the given buffer.
477
726
*/
478
- private void runWithStdIO ( Options options , File stdIn , StringBuffer stdOut )
727
+ private void runWithStdIO ( Options options , File stdIn , StringBuffer stdOut ) throws Exception
479
728
{
480
729
InputStream prevIn = System .in ;
481
730
PrintStream prevOut = System .out ;
@@ -499,10 +748,6 @@ private void runWithStdIO( Options options, File stdIn, StringBuffer stdOut)
499
748
500
749
ApiCommand .run ( options );
501
750
}
502
- catch ( Exception e )
503
- {
504
- throw new RuntimeException ( "Can't run with options=" + options , e );
505
- }
506
751
finally
507
752
{
508
753
IOUtils .closeQuietly ( newIn );
0 commit comments