View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.its;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.apache.maven.surefire.its.fixture.MavenLauncher;
25  import org.apache.maven.surefire.its.fixture.OutputValidator;
26  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
27  import org.junit.Test;
28  import org.junit.runner.RunWith;
29  import org.junit.runners.Parameterized;
30  
31  import static org.hamcrest.Matchers.containsString;
32  import static org.hamcrest.Matchers.equalTo;
33  import static org.junit.runners.Parameterized.Parameter;
34  
35  /**
36   * Base test class for SUREFIRE-580, configuration parameter {@code skipAfterFailureCount}.
37   *
38   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
39   * @since 2.19
40   */
41  @RunWith(Parameterized.class)
42  public abstract class AbstractFailFastIT extends SurefireJUnit4IntegrationTestCase {
43      private static final String LEGACY_FORK_NODE = "org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory";
44  
45      private static final String SUREFIRE_FORK_NODE =
46              "org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory";
47  
48      @Parameter(0)
49      @SuppressWarnings("checkstyle:visibilitymodifier")
50      public String description;
51  
52      @Parameter(1)
53      @SuppressWarnings("checkstyle:visibilitymodifier")
54      public String profile;
55  
56      @Parameter(2)
57      @SuppressWarnings("checkstyle:visibilitymodifier")
58      public Map<String, String> properties;
59  
60      @Parameter(3)
61      @SuppressWarnings("checkstyle:visibilitymodifier")
62      public int total;
63  
64      @Parameter(4)
65      @SuppressWarnings("checkstyle:visibilitymodifier")
66      public int failures;
67  
68      @Parameter(5)
69      @SuppressWarnings("checkstyle:visibilitymodifier")
70      public int errors;
71  
72      @Parameter(6)
73      @SuppressWarnings("checkstyle:visibilitymodifier")
74      public int skipped;
75  
76      @Parameter(7)
77      @SuppressWarnings("checkstyle:visibilitymodifier")
78      public boolean useProcessPipes;
79  
80      protected abstract String withProvider();
81  
82      private OutputValidator prepare(String description, String profile, Map<String, String> properties) {
83          MavenLauncher launcher = unpack("/fail-fast-" + withProvider(), "_" + description)
84                  .maven()
85                  .debugLogging();
86  
87          if (profile != null) {
88              launcher.activateProfile(profile);
89          }
90  
91          if (!useProcessPipes) {
92              launcher.activateProfile("tcp");
93          }
94  
95          if (failures != 0 || errors != 0) {
96              launcher.withFailure();
97          }
98  
99          return launcher.sysProp(properties).executeTest();
100     }
101 
102     static Map<String, String> props(int forkCount, int skipAfterFailureCount, boolean reuseForks) {
103         Map<String, String> props = new HashMap<>(3);
104         props.put("surefire.skipAfterFailureCount", "" + skipAfterFailureCount);
105         props.put("forkCount", "" + forkCount);
106         props.put("reuseForks", "" + reuseForks);
107         return props;
108     }
109 
110     @Test
111     public void test() throws Exception {
112         String cls = useProcessPipes ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
113         prepare(description, profile, properties)
114                 .assertTestSuiteResults(total, errors, failures, skipped)
115                 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
116     }
117 }