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 java.io.IOException;
23 import java.util.Calendar;
24 import org.apache.maven.it.VerificationException;
25 import org.apache.maven.surefire.its.fixture.OutputValidator;
26 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
27 import org.apache.maven.surefire.its.fixture.SurefireLauncher;
28 import org.junit.Test;
29
30
31
32
33
34
35 public class RunOrderIT
36 extends SurefireJUnit4IntegrationTestCase
37 {
38 private static final String[] TESTS_IN_ALPHABETICAL_ORDER = { "TA", "TB", "TC" };
39
40 private static final String[] TESTS_IN_REVERSE_ALPHABETICAL_ORDER = { "TC", "TB", "TA" };
41
42
43
44 @Test
45 public void testAlphabetical()
46 throws Exception
47 {
48 OutputValidator validator = executeWithRunOrder( "alphabetical" );
49 assertTestnamesAppearInSpecificOrder( validator, TESTS_IN_ALPHABETICAL_ORDER );
50 }
51
52 @Test
53 public void testReverseAlphabetical()
54 throws Exception
55 {
56 OutputValidator validator = executeWithRunOrder( "reversealphabetical" );
57 assertTestnamesAppearInSpecificOrder( validator, TESTS_IN_REVERSE_ALPHABETICAL_ORDER );
58 }
59
60 @Test
61 public void testHourly()
62 throws Exception
63 {
64 int startHour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
65 OutputValidator validator = executeWithRunOrder( "hourly" );
66 int endHour = Calendar.getInstance().get( Calendar.HOUR_OF_DAY );
67 if ( startHour != endHour )
68 {
69 return;
70 }
71
72 String[] testnames =
73 ( ( startHour % 2 ) == 0 ) ? TESTS_IN_ALPHABETICAL_ORDER : TESTS_IN_REVERSE_ALPHABETICAL_ORDER;
74 assertTestnamesAppearInSpecificOrder( validator, testnames );
75 }
76
77 @Test
78 public void testNonExistingRunOrder()
79 throws Exception
80 {
81 unpack().forkMode( getForkMode() ).runOrder( "nonExistingRunOrder" ).maven().withFailure().executeTest().verifyTextInLog(
82 "There's no RunOrder with the name nonExistingRunOrder." );
83 }
84
85 private OutputValidator executeWithRunOrder( String runOrder )
86 throws IOException, VerificationException
87 {
88 return unpack().forkMode( getForkMode() ).runOrder( runOrder ).executeTest().verifyErrorFree( 3 );
89 }
90
91 protected String getForkMode()
92 {
93 return "once";
94 }
95
96 private SurefireLauncher unpack()
97 {
98 return unpack( "runOrder" );
99 }
100
101 private void assertTestnamesAppearInSpecificOrder( OutputValidator validator, String[] testnames )
102 throws VerificationException
103 {
104 if ( !validator.stringsAppearInSpecificOrderInLog( testnames ) )
105 {
106 throw new VerificationException( "Response does not contain expected item" );
107 }
108 }
109 }