xref: /aoo41x/main/qadevOOo/runner/lib/Status.java (revision e6b649b5)
1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package lib;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir /**
27cdf0e10cSrcweir  * Status represents a result of a testing activity performed. The result is
28cdf0e10cSrcweir  * described in two ways: state and runtime state. The state describes if the
29cdf0e10cSrcweir  * activity was successful (OK state) or not (FAILED state). The runtime state
30cdf0e10cSrcweir  * describes what happend during the activity: the test can be:
31cdf0e10cSrcweir  *   - PASSED - the activity completed normally (although it can complete with
32cdf0e10cSrcweir  *     FAILED state)
33cdf0e10cSrcweir  *   - SKIPPED - the activity was not performed because of a reason (it also can
34cdf0e10cSrcweir  *     has OK or FAILED state)
35cdf0e10cSrcweir  *   - EXCEPTION - the activity was abnormally terminated because of an
36cdf0e10cSrcweir  *     unexpected exception. It always has a FAILED state.
37cdf0e10cSrcweir  *   - EXCLUDED - the activity is expected to fail. The state represents how
38cdf0e10cSrcweir  *     the state really completed: OK or FAILED.
39cdf0e10cSrcweir  *   - other variants are not formalized now and can be represented by
40cdf0e10cSrcweir  *     Status.failed() method. They always have a FAILED state.
41cdf0e10cSrcweir  */
42cdf0e10cSrcweir public class Status extends SimpleStatus {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     /**
45cdf0e10cSrcweir      * Construct a status: use runState and state
46*e6b649b5SPedro Giffuni      * @param runState either PASSED, SKIPPED, etc.
47*e6b649b5SPedro Giffuni      * @param state OK or FAILED.
48cdf0e10cSrcweir      */
Status(int runState, boolean state )49cdf0e10cSrcweir     public Status(int runState, boolean state ) {
50cdf0e10cSrcweir         super(runState, state);
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /**
54cdf0e10cSrcweir      * Construct a status: use own message and state.
55242829adSPedro Giffuni      * @parame message An own message for the status.
56cdf0e10cSrcweir      * @param state: OK or FAILED.
57cdf0e10cSrcweir      */
Status(String message, boolean state)58cdf0e10cSrcweir     public Status(String message, boolean state) {
59cdf0e10cSrcweir         super( message, state );
60cdf0e10cSrcweir     }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /**
63cdf0e10cSrcweir      * This is a factory method for creating a Status representing normal
64cdf0e10cSrcweir      * actibity termination.
65cdf0e10cSrcweir      *
66cdf0e10cSrcweir      * @param state describes a test state (OK if state == true, FAILED
67cdf0e10cSrcweir      * otherwise).
68cdf0e10cSrcweir      */
passed( boolean state )69cdf0e10cSrcweir     public static Status passed( boolean state ) {
70cdf0e10cSrcweir         return new Status(PASSED, state );
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     /**
74cdf0e10cSrcweir      * This is a factory method for creating a Status representing an exception
75cdf0e10cSrcweir      * activity termination. The Status alway has FAILED state.
76cdf0e10cSrcweir      *
77cdf0e10cSrcweir      * @param t the exception with that the activity completed.
78cdf0e10cSrcweir      */
exception( Throwable t )79cdf0e10cSrcweir     public static Status exception( Throwable t ) {
80cdf0e10cSrcweir         return new ExceptionStatus( t );
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /**
84cdf0e10cSrcweir      * This is a factory method for creating a Status representing a skipped
85cdf0e10cSrcweir      * activity.
86cdf0e10cSrcweir      *
87cdf0e10cSrcweir      * @param state describes a test state (OK if state == true, FAILED
88cdf0e10cSrcweir      * otherwise).
89cdf0e10cSrcweir      */
skipped( boolean state )90cdf0e10cSrcweir     public static Status skipped( boolean state ) {
91cdf0e10cSrcweir         return new Status( SKIPPED, state );
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     /**
95cdf0e10cSrcweir      * This is a factory method for creating a Status representing that the
96cdf0e10cSrcweir      * result of the activity was excluded. It alwas has FAILED state.
97cdf0e10cSrcweir      */
excluded()98cdf0e10cSrcweir     public static Status excluded() {
99cdf0e10cSrcweir         return new Status( EXCLUDED, false );
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /**
103cdf0e10cSrcweir      * Creates a Status representing an activity failed for an arbitrary reason.
104cdf0e10cSrcweir      * It always has FAILED state.
105cdf0e10cSrcweir      *
106cdf0e10cSrcweir      * @param reason describes why the activity failed
107cdf0e10cSrcweir      */
failed(final String reason)108cdf0e10cSrcweir     public static Status failed(final String reason) {
109cdf0e10cSrcweir         return new Status(reason, FAILED);
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     /**
113cdf0e10cSrcweir      * The method returns a human-readable description of the status.
114cdf0e10cSrcweir      * The Status implementation of the method returns the status state
115cdf0e10cSrcweir      * description and appends to it it the reason, for example:
116cdf0e10cSrcweir      * "FAILED.The getLabel works wrong", "PASSED.OK".
117cdf0e10cSrcweir      */
toString()118cdf0e10cSrcweir     public String toString() {
119170fb961SPedro Giffuni         String str = getRunStateString() + "." + getStateString();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         return str;
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     /**
125cdf0e10cSrcweir      * Checks whether the status runstate is passed.
126cdf0e10cSrcweir      */
isPassed()127cdf0e10cSrcweir     public boolean isPassed() {
128cdf0e10cSrcweir         return getRunState() == PASSED;
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     /**
132cdf0e10cSrcweir      * Checks whether the status runstate is skipped.
133cdf0e10cSrcweir      */
isSkipped()134cdf0e10cSrcweir     public boolean isSkipped() {
135cdf0e10cSrcweir         return getRunState() == SKIPPED;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     /**
139cdf0e10cSrcweir      * Checks whether the status runstate is excluded.
140cdf0e10cSrcweir      */
isExcluded()141cdf0e10cSrcweir     public boolean isExcluded() {
142cdf0e10cSrcweir         return getRunState() == EXCLUDED;
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     /**
146cdf0e10cSrcweir      * Checks whether the status runstate is exception.
147cdf0e10cSrcweir      */
isException()148cdf0e10cSrcweir     public boolean isException() {
149cdf0e10cSrcweir         return getRunState() == EXCEPTION;
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     /**
153cdf0e10cSrcweir      * Checks whether the status state is failed.
154cdf0e10cSrcweir      */
isFailed()155cdf0e10cSrcweir     public boolean isFailed() {
156cdf0e10cSrcweir         return !getState();
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     /**
160cdf0e10cSrcweir      * Checks whether the status state is ok.
161cdf0e10cSrcweir      */
isOK()162cdf0e10cSrcweir     public boolean isOK() {
163cdf0e10cSrcweir         return getState();
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir 
getDescription()166cdf0e10cSrcweir     public String getDescription () {
167cdf0e10cSrcweir         return getRunStateString();
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir }
170