1 package org.apache.maven.surefire.its;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.maven.artifact.versioning.ArtifactVersion;
24 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
25 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
26 import org.apache.maven.artifact.versioning.VersionRange;
27 import org.apache.maven.it.VerificationException;
28 import org.apache.maven.it.Verifier;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37
38
39 public abstract class AbstractSurefireIntegrationTestClass
40 extends TestCase
41 {
42 private String surefireVersion = System.getProperty( "surefire.version" );
43
44 private String testNgVersion = System.getProperty( "testng.version" );
45
46 protected List<String> getInitialGoals()
47 {
48 return getInitialGoals( testNgVersion );
49 }
50
51 protected List<String> getInitialGoals( String testNgVersion )
52 {
53 List<String> goals = new ArrayList<String>();
54 goals.add( "-Dsurefire.version=" + surefireVersion );
55
56 if ( testNgVersion != null )
57 {
58 goals.add( "-DtestNgVersion=" + testNgVersion );
59
60 ArtifactVersion v = new DefaultArtifactVersion( testNgVersion );
61 try
62 {
63 if ( VersionRange.createFromVersionSpec( "(,5.12.1)" ).containsVersion( v ) )
64 {
65 goals.add( "-DtestNgClassifier=jdk15" );
66 }
67 }
68 catch ( InvalidVersionSpecificationException e )
69 {
70 throw new RuntimeException( e.getMessage(), e );
71 }
72 }
73
74 return goals;
75 }
76
77 protected void executeGoal( Verifier verifier, String goal )
78 throws VerificationException
79 {
80 List<String> goals = getInitialGoals();
81 goals.add( goal );
82 executeGoals( verifier, goals );
83 }
84
85 @SuppressWarnings( { "unchecked" } )
86 protected void executeGoals( Verifier verifier, List<String> goals )
87 throws VerificationException
88 {
89 if ( !verifier.getCliOptions().contains( "-s" ) )
90 {
91 String settingsPath = System.getProperty( "maven.settings.file" );
92 if ( settingsPath.indexOf( ' ' ) >= 0 )
93 {
94 settingsPath = '"' + settingsPath + '"';
95 }
96 verifier.getCliOptions().add( "-s" );
97 verifier.getCliOptions().add( settingsPath );
98 }
99
100 verifier.executeGoals( goals );
101 }
102
103 protected String getSurefireVersion()
104 {
105 return surefireVersion;
106 }
107 }