1 package org.apache.maven.surefire.testng;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.maven.surefire.report.RunListener;
28 import org.apache.maven.surefire.testset.TestSetFailedException;
29
30 import static org.apache.maven.surefire.testng.TestNGExecutor.run;
31
32
33
34
35
36
37
38 final class TestNGXmlTestSuite
39 extends TestSuite
40 {
41 private final List<File> suiteFiles;
42
43 private List<String> suiteFilePaths;
44
45 private final String testSourceDirectory;
46
47 private final Map<String, String> options;
48
49 private final File reportsDirectory;
50
51 private final int skipAfterFailureCount;
52
53
54
55
56
57 TestNGXmlTestSuite( List<File> suiteFiles, String testSourceDirectory, Map<String, String> confOptions,
58 File reportsDirectory, int skipAfterFailureCount )
59 {
60 this.suiteFiles = suiteFiles;
61 this.options = confOptions;
62 this.testSourceDirectory = testSourceDirectory;
63 this.reportsDirectory = reportsDirectory;
64 this.skipAfterFailureCount = skipAfterFailureCount;
65 }
66
67 void execute( RunListener reporter )
68 throws TestSetFailedException
69 {
70 if ( suiteFilePaths == null )
71 {
72 throw new IllegalStateException( "You must call locateTestSets before calling execute" );
73 }
74 startTestSuite( reporter );
75 run( suiteFilePaths, testSourceDirectory, options, reporter, reportsDirectory, skipAfterFailureCount );
76 finishTestSuite( reporter );
77 }
78
79 void locateTestSets()
80 throws TestSetFailedException
81 {
82 if ( suiteFilePaths != null )
83 {
84 throw new IllegalStateException( "You can't call locateTestSets twice" );
85 }
86
87 if ( suiteFiles.isEmpty() )
88 {
89 throw new IllegalStateException( "No suite files were specified" );
90 }
91
92 suiteFilePaths = new ArrayList<String>();
93
94 for ( File suiteFile : suiteFiles )
95 {
96 if ( !suiteFile.isFile() )
97 {
98 throw new TestSetFailedException( "Suite file " + suiteFile + " is not a valid file" );
99 }
100 suiteFilePaths.add( suiteFile.getAbsolutePath() );
101 }
102 }
103
104 @Override
105 Map<String, String> getOptions()
106 {
107 return options;
108 }
109 }