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