33import com .microsoft .playwright .Page ;
44import com .microsoft .playwright .junit .UsePlaywright ;
55import hudson .model .Result ;
6- import io .jenkins .plugins .pipelinegraphview .playwright .ManageAppearancePage ;
6+ import io .jenkins .plugins .casc .misc .ConfiguredWithCode ;
7+ import io .jenkins .plugins .casc .misc .JenkinsConfiguredWithCodeRule ;
8+ import io .jenkins .plugins .casc .misc .junit .jupiter .WithJenkinsConfiguredWithCode ;
79import io .jenkins .plugins .pipelinegraphview .playwright .PipelineJobPage ;
810import io .jenkins .plugins .pipelinegraphview .playwright .PlaywrightConfig ;
911import io .jenkins .plugins .pipelinegraphview .utils .PipelineState ;
1012import io .jenkins .plugins .pipelinegraphview .utils .TestUtils ;
11- import java .util .concurrent .CompletableFuture ;
12- import java .util .function .Supplier ;
1313import org .jenkinsci .plugins .workflow .job .WorkflowRun ;
14+ import org .jenkinsci .plugins .workflow .test .steps .SemaphoreStep ;
1415import org .junit .jupiter .api .Test ;
15- import org .jvnet .hudson .test .JenkinsRule ;
16- import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
16+ import org .jvnet .hudson .test .Issue ;
1717import org .slf4j .Logger ;
1818import org .slf4j .LoggerFactory ;
19- import org .springframework .util .function .ThrowingSupplier ;
2019
21- @ WithJenkins
20+ @ WithJenkinsConfiguredWithCode
2221@ UsePlaywright (PlaywrightConfig .class )
2322class PipelineGraphViewTest {
2423 private static final Logger log = LoggerFactory .getLogger (PipelineGraphViewTest .class );
@@ -28,10 +27,10 @@ class PipelineGraphViewTest {
2827 // http://localhost:8080/jenkins
2928
3029 @ Test
31- void smokeTest (Page p , JenkinsRule j ) {
30+ @ ConfiguredWithCode ("configure-appearance.yml" )
31+ void smokeTest (Page p , JenkinsConfiguredWithCodeRule j ) throws Exception {
3232 String name = "Integration Tests" ;
33- WorkflowRun run = setupJenkins (p , j .jenkins .getRootUrl (), (ThrowingSupplier <WorkflowRun >)
34- () -> TestUtils .createAndRunJob (j , name , "smokeTest.jenkinsfile" , Result .FAILURE ));
33+ WorkflowRun run = TestUtils .createAndRunJob (j , name , "smokeTest.jenkinsfile" , Result .FAILURE );
3534
3635 new PipelineJobPage (p , run .getParent ())
3736 .goTo ()
@@ -62,21 +61,46 @@ void smokeTest(Page p, JenkinsRule j) {
6261 .stageIsVisibleInTree ("B2" );
6362 }
6463
65- private static WorkflowRun setupJenkins (Page p , String rootUrl , Supplier <WorkflowRun > setupRun ) {
66- CompletableFuture <WorkflowRun > run = CompletableFuture .supplyAsync (setupRun );
67- CompletableFuture <Void > jenkinsSetup = CompletableFuture .runAsync (() -> {
68- log .info ("Setting up Jenkins to have the Pipeline Graph View on all pages" );
69- new ManageAppearancePage (p , rootUrl )
70- .goTo ()
71- .displayPipelineOnJobPage ()
72- .displayPipelineOnBuildPage ()
73- .setPipelineGraphAsConsoleProvider ()
74- .save ();
75- log .info ("Jenkins setup complete" );
76- });
64+ @ Issue ("GH#797" )
65+ @ Test
66+ @ ConfiguredWithCode ("configure-appearance.yml" )
67+ void runningStageSelected (Page p , JenkinsConfiguredWithCodeRule j ) throws Exception {
68+ String name = "gh797" ;
69+ WorkflowRun run = TestUtils .createAndRunJobNoWait (j , name , "gh797_errorAndContinueWithWait.jenkinsfile" )
70+ .waitForStart ();
71+ SemaphoreStep .waitForStart ("wait/1" , run );
7772
78- CompletableFuture .allOf (run , jenkinsSetup ).join ();
73+ new PipelineJobPage (p , run .getParent ())
74+ .goTo ()
75+ .hasBuilds (1 )
76+ .nthBuild (0 )
77+ .goToBuild ()
78+ .goToPipelineOverview ()
79+ .hasStagesInGraph (2 , "Caught1" , "Runs1" )
80+ .stageIsVisibleInTree ("Parallel1" )
81+ .stageIsVisibleInTree ("Runs1" )
82+ .stageIsSelected ("Runs1" );
83+
84+ SemaphoreStep .success ("wait/1" , run );
85+ j .assertBuildStatus (Result .SUCCESS , j .waitForCompletion (run ));
86+ }
7987
80- return run .join ();
88+ @ Test
89+ @ ConfiguredWithCode ("configure-appearance.yml" )
90+ void failedStageSelected (Page p , JenkinsConfiguredWithCodeRule j ) throws Exception {
91+ String name = "Pipeline Success Error Caught" ;
92+ WorkflowRun run = TestUtils .createAndRunJob (j , name , "gh797_errorAndContinue.jenkinsfile" , Result .SUCCESS );
93+
94+ new PipelineJobPage (p , run .getParent ())
95+ .goTo ()
96+ .hasBuilds (1 )
97+ .nthBuild (0 )
98+ .goToBuild ()
99+ .goToPipelineOverview ()
100+ .hasStagesInGraph (2 , "Caught1" , "Runs1" )
101+ .stageIsVisibleInTree ("Parallel1" )
102+ .stageIsVisibleInTree ("Caught1" )
103+ .stageIsVisibleInTree ("Runs1" )
104+ .stageIsSelected ("Caught1" );
81105 }
82106}
0 commit comments