1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package lib; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir /** 31*cdf0e10cSrcweir * Status represents a result of a testing activity performed. The result is 32*cdf0e10cSrcweir * described in two ways: state and runtime state. The state describes if the 33*cdf0e10cSrcweir * activity was successful (OK state) or not (FAILED state). The runtime state 34*cdf0e10cSrcweir * describes what happend during the activity: the test can be: 35*cdf0e10cSrcweir * - PASSED - the activity completed normally (although it can complete with 36*cdf0e10cSrcweir * FAILED state) 37*cdf0e10cSrcweir * - SKIPPED - the activity was not performed because of a reason (it also can 38*cdf0e10cSrcweir * has OK or FAILED state) 39*cdf0e10cSrcweir * - EXCEPTION - the activity was abnormally terminated because of an 40*cdf0e10cSrcweir * unexpected exception. It always has a FAILED state. 41*cdf0e10cSrcweir * - EXCLUDED - the activity is expected to fail. The state represents how 42*cdf0e10cSrcweir * the state really completed: OK or FAILED. 43*cdf0e10cSrcweir * - other variants are not formalized now and can be represented by 44*cdf0e10cSrcweir * Status.failed() method. They always have a FAILED state. 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir public class Status extends SimpleStatus { 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir /** 49*cdf0e10cSrcweir * Construct a status: use runState and state 50*cdf0e10cSrcweir * @param runState: either PASSED, SKIPPED, etc. 51*cdf0e10cSrcweir * @param state: OK or FAILED. 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir public Status(int runState, boolean state ) { 54*cdf0e10cSrcweir super(runState, state); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /** 58*cdf0e10cSrcweir * Construct a status: use own message and state. 59*cdf0e10cSrcweir * @parame messaeg An own message for the status. 60*cdf0e10cSrcweir * @param state: OK or FAILED. 61*cdf0e10cSrcweir */ 62*cdf0e10cSrcweir public Status(String message, boolean state) { 63*cdf0e10cSrcweir super( message, state ); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir /** 67*cdf0e10cSrcweir * This is a factory method for creating a Status representing normal 68*cdf0e10cSrcweir * actibity termination. 69*cdf0e10cSrcweir * 70*cdf0e10cSrcweir * @param state describes a test state (OK if state == true, FAILED 71*cdf0e10cSrcweir * otherwise). 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir public static Status passed( boolean state ) { 74*cdf0e10cSrcweir return new Status(PASSED, state ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir /** 78*cdf0e10cSrcweir * This is a factory method for creating a Status representing an exception 79*cdf0e10cSrcweir * activity termination. The Status alway has FAILED state. 80*cdf0e10cSrcweir * 81*cdf0e10cSrcweir * @param t the exception with that the activity completed. 82*cdf0e10cSrcweir */ 83*cdf0e10cSrcweir public static Status exception( Throwable t ) { 84*cdf0e10cSrcweir return new ExceptionStatus( t ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /** 88*cdf0e10cSrcweir * This is a factory method for creating a Status representing a skipped 89*cdf0e10cSrcweir * activity. 90*cdf0e10cSrcweir * 91*cdf0e10cSrcweir * @param state describes a test state (OK if state == true, FAILED 92*cdf0e10cSrcweir * otherwise). 93*cdf0e10cSrcweir */ 94*cdf0e10cSrcweir public static Status skipped( boolean state ) { 95*cdf0e10cSrcweir return new Status( SKIPPED, state ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /** 99*cdf0e10cSrcweir * This is a factory method for creating a Status representing that the 100*cdf0e10cSrcweir * result of the activity was excluded. It alwas has FAILED state. 101*cdf0e10cSrcweir */ 102*cdf0e10cSrcweir public static Status excluded() { 103*cdf0e10cSrcweir return new Status( EXCLUDED, false ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /** 107*cdf0e10cSrcweir * Creates a Status representing an activity failed for an arbitrary reason. 108*cdf0e10cSrcweir * It always has FAILED state. 109*cdf0e10cSrcweir * 110*cdf0e10cSrcweir * @param reason describes why the activity failed 111*cdf0e10cSrcweir */ 112*cdf0e10cSrcweir public static Status failed(final String reason) { 113*cdf0e10cSrcweir return new Status(reason, FAILED); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /** 117*cdf0e10cSrcweir * The method returns a human-readable description of the status. 118*cdf0e10cSrcweir * The Status implementation of the method returns the status state 119*cdf0e10cSrcweir * description and appends to it it the reason, for example: 120*cdf0e10cSrcweir * "FAILED.The getLabel works wrong", "PASSED.OK". 121*cdf0e10cSrcweir */ 122*cdf0e10cSrcweir public String toString() { 123*cdf0e10cSrcweir String str = getRunStateString() + "." + getStateString();; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir return str; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir /** 129*cdf0e10cSrcweir * Checks whether the status runstate is passed. 130*cdf0e10cSrcweir */ 131*cdf0e10cSrcweir public boolean isPassed() { 132*cdf0e10cSrcweir return getRunState() == PASSED; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir /** 136*cdf0e10cSrcweir * Checks whether the status runstate is skipped. 137*cdf0e10cSrcweir */ 138*cdf0e10cSrcweir public boolean isSkipped() { 139*cdf0e10cSrcweir return getRunState() == SKIPPED; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir /** 143*cdf0e10cSrcweir * Checks whether the status runstate is excluded. 144*cdf0e10cSrcweir */ 145*cdf0e10cSrcweir public boolean isExcluded() { 146*cdf0e10cSrcweir return getRunState() == EXCLUDED; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir /** 150*cdf0e10cSrcweir * Checks whether the status runstate is exception. 151*cdf0e10cSrcweir */ 152*cdf0e10cSrcweir public boolean isException() { 153*cdf0e10cSrcweir return getRunState() == EXCEPTION; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir /** 157*cdf0e10cSrcweir * Checks whether the status state is failed. 158*cdf0e10cSrcweir */ 159*cdf0e10cSrcweir public boolean isFailed() { 160*cdf0e10cSrcweir return !getState(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir /** 164*cdf0e10cSrcweir * Checks whether the status state is ok. 165*cdf0e10cSrcweir */ 166*cdf0e10cSrcweir public boolean isOK() { 167*cdf0e10cSrcweir return getState(); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir public String getDescription () { 171*cdf0e10cSrcweir return getRunStateString(); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir } 174