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