1
package org.apache.maven.surefire.its;
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
22
import org.apache.maven.it.VerificationException;
23
import org.apache.maven.it.Verifier;
24
import org.apache.maven.it.util.ResourceExtractor;
25
import org.apache.maven.surefire.its.misc.HelperAssertions;
28
import java.io.IOException;
29
import java.util.Calendar;
30
import java.util.List;
33
* Verifies the runOrder setting and its effect
35
* @author Kristian Rosenvold
37
public class RunOrderIT
38
extends AbstractSurefireIntegrationTestClass
40
private static final String[] TESTS_IN_ALPHABETICAL_ORDER = { "TA", "TB", "TC" };
42
private static final String[] TESTS_IN_REVERSE_ALPHABETICAL_ORDER = { "TC", "TB", "TA" };
44
// testing random is left as an exercise to the reader. Patches welcome
48
private Verifier verifier;
51
throws IOException, VerificationException
53
testDir = ResourceExtractor.simpleExtractResources( getClass(), "/runOrder" );
54
verifier = new Verifier( testDir.getAbsolutePath() );
57
public void tearDown()
60
verifier.resetStreams();
63
public void testAlphabetical()
66
executeWithRunOrder( "alphabetical" );
67
assertTestnamesAppearInSpecificOrder( TESTS_IN_ALPHABETICAL_ORDER );
70
public void testReverseAlphabetical()
73
executeWithRunOrder( "reversealphabetical" );
74
assertTestnamesAppearInSpecificOrder( TESTS_IN_REVERSE_ALPHABETICAL_ORDER );
77
public void testHourly()
80
int startHour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
81
executeWithRunOrder( "hourly" );
82
int endHour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
83
if ( startHour != endHour )
85
return; // Race condition, cannot test when hour changed mid-run
89
( ( startHour % 2 ) == 0 ) ? TESTS_IN_ALPHABETICAL_ORDER : TESTS_IN_REVERSE_ALPHABETICAL_ORDER;
90
assertTestnamesAppearInSpecificOrder( testnames );
93
public void testNonExistingRunOrder()
98
executeTestsWithRunOrder( "nonExistingRunOrder" );
100
catch ( VerificationException e )
103
verifier.verifyTextInLog( "There's no RunOrder with the name nonExistingRunOrder." );
106
private void executeWithRunOrder( String runOrder )
107
throws IOException, VerificationException
109
executeTestsWithRunOrder( runOrder );
110
verifier.verifyErrorFreeLog();
111
HelperAssertions.assertTestSuiteResults( 3, 0, 0, 0, testDir );
114
private void executeTestsWithRunOrder( String runOrder )
115
throws VerificationException
117
List<String> goals = getInitialGoals();
118
goals.add( "-DrunOrder=" + runOrder );
120
executeGoals( verifier, goals );
123
private void assertTestnamesAppearInSpecificOrder( String[] testnames )
124
throws VerificationException
126
if ( !testnamesAppearInSpecificOrder( testnames ) )
128
throw new VerificationException( "Response does not contain expected item" );
132
private boolean testnamesAppearInSpecificOrder( String[] testnames ) throws VerificationException
135
for ( String line : getLog() )
137
if ( line.startsWith( testnames[i] ) )
139
if ( i == testnames.length - 1 )
149
private List<String> getLog()
150
throws VerificationException
152
return verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );