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