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.api.report;
20  
21  /**
22   * This report entry should be used in {@link TestOutputReceiver#writeTestOutput(OutputReportEntry)}.
23   *
24   * {@inheritDoc}
25   */
26  public final class TestOutputReportEntry implements OutputReportEntry {
27      private final String log;
28      private final boolean isStdOut;
29      private final boolean newLine;
30      private final RunMode runMode;
31      private final Long testRunId;
32  
33      /**
34       * Wraps the output from the running test-case.
35       *
36       * @param log stdout/sterr output from running tests
37       * @param isStdOut Indicates if this is stdout
38       * @param newLine print on new line
39       * @param runMode the phase of testset
40       * @param testRunId unique id of the test run pointing to the test description
41       */
42      public TestOutputReportEntry(String log, boolean isStdOut, boolean newLine, RunMode runMode, Long testRunId) {
43          this.log = log;
44          this.isStdOut = isStdOut;
45          this.newLine = newLine;
46          this.runMode = runMode;
47          this.testRunId = testRunId;
48      }
49  
50      /**
51       * Wraps the output from the running test-case.
52       *
53       * @param log stdout/sterr output from running tests
54       * @param isStdOut Indicates if this is stdout
55       * @param newLine print on new line
56       */
57      private TestOutputReportEntry(String log, boolean isStdOut, boolean newLine) {
58          this(log, isStdOut, newLine, null, null);
59      }
60  
61      public TestOutputReportEntry(OutputReportEntry reportEntry, RunMode runMode, Long testRunId) {
62          log = reportEntry.getLog();
63          isStdOut = reportEntry.isStdOut();
64          newLine = reportEntry.isNewLine();
65          this.runMode = runMode;
66          this.testRunId = testRunId;
67      }
68  
69      @Override
70      public String getLog() {
71          return log;
72      }
73  
74      @Override
75      public boolean isStdOut() {
76          return isStdOut;
77      }
78  
79      @Override
80      public boolean isNewLine() {
81          return newLine;
82      }
83  
84      public RunMode getRunMode() {
85          return runMode;
86      }
87  
88      public Long getTestRunId() {
89          return testRunId;
90      }
91  
92      public static OutputReportEntry stdOut(String log) {
93          return new TestOutputReportEntry(log, true, false);
94      }
95  
96      public static TestOutputReportEntry stdOutln(String log) {
97          return new TestOutputReportEntry(log, true, true);
98      }
99  
100     public static TestOutputReportEntry stdErr(String log) {
101         return new TestOutputReportEntry(log, false, false);
102     }
103 
104     public static TestOutputReportEntry stdErrln(String log) {
105         return new TestOutputReportEntry(log, false, true);
106     }
107 }