1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package lib;
25 
26 /**
27  * The class is a simple implementation of Status class. It implements simple
28  * Status behaviour: its state, reason and log are defined when creating
29  * the SimpleSTatus instance.
30  */
31 class SimpleStatus {
32     /* Run states. */
33 
34     /**
35      * The constatnt represents PASSED runtime state.
36      */
37     public final static int PASSED = 0;
38 
39     /**
40      * The constant represents EXCEPTION runtime state.
41      */
42     public final static int EXCEPTION = 3;
43 
44     /**
45      * The constant represents EXCLUDED runtime state.
46      */
47     public final static int EXCLUDED = 2;
48 
49     /**
50      * The constant represents SKIPPED runtime state.
51      */
52     public final static int SKIPPED = 1;
53 
54     /**
55      * This is a private indicator for a user defined runtime state
56      */
57     private final static int USER_DEFINED = 4;
58 
59     /* Test states */
60 
61     /**
62      * The constant represents FAILED state.
63      */
64     public final static boolean FAILED = false;
65 
66     /**
67      * The constant represents OK state.
68      */
69     public final static boolean OK = true;
70 
71     /**
72      * The field is holding state of the status.
73      */
74     protected final boolean state;
75 
76     /**
77      * The field is holding reason of the status.
78      */
79     protected final int runState;
80 
81     /**
82      * This is the run state: either SKIPPED, PASSED, etc.
83      * or user defined. Deriving classes can overwrite it for own run states.
84      */
85     protected String runStateString;
86 
87     /**
88      * The constructor initialize state and reason field.
89      */
SimpleStatus( int runState, boolean state )90     protected SimpleStatus( int runState, boolean state ) {
91         this.state = state;
92         this.runState = runState;
93         if ( runState == PASSED ) {
94             runStateString = "PASSED";
95         } else if ( runState == EXCLUDED ) {
96             runStateString = "EXCLUDED";
97         } else if ( runState == SKIPPED ) {
98             runStateString = "SKIPPED";
99         } else if ( runState == EXCEPTION ) {
100             runStateString = "EXCEPTION";
101         } else {
102             runStateString = "UNKNOWN";
103         }
104     }
105 
106     /**
107      * The constructor initialize state and reson field.
108      */
SimpleStatus(String runStateString, boolean state)109     protected SimpleStatus(String runStateString, boolean state) {
110         this.state = state;
111         this.runState = USER_DEFINED;
112         this.runStateString = runStateString;
113     }
114 
115     /**
116      * getState implementation. Just returns the state field value.
117      */
getState()118     public boolean getState() {
119         return state;
120     }
121 
122     /**
123      * getRunState() implementation. Just returns th runState field value.
124      */
getRunState()125     public int getRunState() {
126         return runState;
127     }
128 
129     /**
130      * getReason implementation. Just returns the reason field value.
131      */
getRunStateString()132     public String getRunStateString() {
133         return runStateString;
134     }
135 
136     /**
137      * Get the ressult: passed or failed.
138      */
getStateString()139     public String getStateString() {
140         if (state)
141             return "OK";
142         return "FAILED";
143 
144     }
145 }