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.HashMap; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
import java.util.Properties; |
28 | |
import org.apache.maven.surefire.report.ConsoleOutputCapture; |
29 | |
import org.apache.maven.surefire.report.ConsoleOutputReceiver; |
30 | |
import org.apache.maven.surefire.report.ReporterException; |
31 | |
import org.apache.maven.surefire.report.ReporterFactory; |
32 | |
import org.apache.maven.surefire.report.RunListener; |
33 | |
import org.apache.maven.surefire.testset.TestSetFailedException; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public class TestNGXmlTestSuite |
42 | |
implements TestNgTestSuite |
43 | |
{ |
44 | |
private final List suiteFiles; |
45 | |
|
46 | |
private List<String> suiteFilePaths; |
47 | |
|
48 | |
private final String testSourceDirectory; |
49 | |
|
50 | |
private final Map options; |
51 | |
|
52 | |
private final File reportsDirectory; |
53 | |
|
54 | |
|
55 | |
private Map<File,String> testSets; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public TestNGXmlTestSuite( List<File> suiteFiles, String testSourceDirectory, Properties confOptions, File reportsDirectory ) |
62 | 0 | { |
63 | 0 | this.suiteFiles = suiteFiles; |
64 | |
|
65 | 0 | this.options = confOptions; |
66 | |
|
67 | 0 | this.testSourceDirectory = testSourceDirectory; |
68 | |
|
69 | 0 | this.reportsDirectory = reportsDirectory; |
70 | 0 | } |
71 | |
|
72 | |
public void execute( ReporterFactory reporterManagerFactory ) |
73 | |
throws ReporterException, TestSetFailedException |
74 | |
{ |
75 | 0 | if ( testSets == null ) |
76 | |
{ |
77 | 0 | throw new IllegalStateException( "You must call locateTestSets before calling execute" ); |
78 | |
} |
79 | |
|
80 | 0 | RunListener reporter = reporterManagerFactory.createReporter(); |
81 | 0 | ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) reporter ); |
82 | |
|
83 | 0 | TestNGDirectoryTestSuite.startTestSuite( reporter, this ); |
84 | 0 | TestNGExecutor.run( this.suiteFilePaths, this.testSourceDirectory, this.options, reporter, this, |
85 | |
reportsDirectory ); |
86 | 0 | TestNGDirectoryTestSuite.finishTestSuite( reporter, this ); |
87 | 0 | } |
88 | |
|
89 | |
public void execute( String testSetName, ReporterFactory reporterManagerFactory ) |
90 | |
throws TestSetFailedException |
91 | |
{ |
92 | 0 | throw new TestSetFailedException( "Cannot run individual test when suite files are specified" ); |
93 | |
} |
94 | |
|
95 | |
public Map locateTestSets( ClassLoader classLoader ) |
96 | |
throws TestSetFailedException |
97 | |
{ |
98 | 0 | if ( testSets != null ) |
99 | |
{ |
100 | 0 | throw new IllegalStateException( "You can't call locateTestSets twice" ); |
101 | |
} |
102 | |
|
103 | 0 | if ( this.suiteFiles == null ) |
104 | |
{ |
105 | 0 | throw new IllegalStateException( "No suite files were specified" ); |
106 | |
} |
107 | |
|
108 | 0 | this.testSets = new HashMap<File,String>(); |
109 | 0 | this.suiteFilePaths = new ArrayList<String>(); |
110 | |
|
111 | 0 | for ( Object suiteFile : suiteFiles ) |
112 | |
{ |
113 | 0 | File file = (File) suiteFile; |
114 | 0 | if ( !file.exists() || !file.isFile() ) |
115 | |
{ |
116 | 0 | throw new TestSetFailedException( "Suite file " + file + " is not a valid file" ); |
117 | |
} |
118 | 0 | this.testSets.put( file, file.getAbsolutePath() ); |
119 | 0 | this.suiteFilePaths.add( file.getAbsolutePath() ); |
120 | 0 | } |
121 | |
|
122 | 0 | return this.testSets; |
123 | |
} |
124 | |
|
125 | |
public String getSuiteName() |
126 | |
{ |
127 | 0 | String result = (String) options.get( "suitename" ); |
128 | 0 | if ( result == null ) |
129 | |
{ |
130 | 0 | result = "TestSuite"; |
131 | |
} |
132 | 0 | return result; |
133 | |
} |
134 | |
} |