001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2014 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * SonarQube is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * SonarQube is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public License
017     * along with this program; if not, write to the Free Software Foundation,
018     * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019     */
020    package org.sonar.api.batch.sensor.test;
021    
022    import org.sonar.api.batch.fs.InputFile;
023    
024    import javax.annotation.Nullable;
025    
026    /**
027     * Represents result of execution of a single test in a test file.
028     * @since 5.0
029     */
030    public interface TestCaseExecution {
031    
032      /**
033       * Test execution status.
034       */
035      enum Status {
036        OK, FAILURE, ERROR, SKIPPED;
037    
038        public static Status of(@Nullable String s) {
039          return s == null ? null : valueOf(s.toUpperCase());
040        }
041      }
042    
043      /**
044       * Test type.
045       */
046      enum Type {
047        UNIT, INTEGRATION;
048      }
049    
050      /**
051       * InputFile where this test is located.
052       */
053      InputFile testFile();
054    
055      /**
056       * Set file where this test is located. Mandatory.
057       */
058      TestCaseExecution inTestFile(InputFile testFile);
059    
060      /**
061       * Duration in milliseconds
062       */
063      Long durationInMs();
064    
065      /**
066       * Duration in milliseconds
067       */
068      TestCaseExecution durationInMs(long duration);
069    
070      /**
071       * Name of this test case.
072       */
073      String name();
074    
075      /**
076       * Set name of this test. Name is mandatory.
077       */
078      TestCaseExecution name(String name);
079    
080      /**
081       * Status of execution of the test.
082       */
083      Status status();
084    
085      /**
086       * Status of execution of the test.
087       */
088      TestCaseExecution status(Status status);
089    
090      /**
091       * Message (usually in case of {@link Status#ERROR} or {@link Status#FAILURE}).
092       */
093      String message();
094    
095      /**
096       * Message (usually in case of {@link Status#ERROR} or {@link Status#FAILURE}).
097       */
098      TestCaseExecution message(String message);
099    
100      /**
101       * Type of test.
102       */
103      Type type();
104    
105      /**
106       * Type of test.
107       */
108      TestCaseExecution ofType(Type type);
109    
110      /**
111       * Stacktrace (usually in case of {@link Status#ERROR}).
112       */
113      String stackTrace();
114    
115      /**
116       * Set stacktrace (usually in case of {@link Status#ERROR}).
117       */
118      TestCaseExecution stackTrace(String stackTrace);
119    
120      /**
121       * Call this method only once when your are done with defining the test case execution.
122       */
123      void save();
124    
125    }