001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.assertions;
020:
021: import java.io.Serializable;
022:
023: /**
024: * @author Michael Stover
025: */
026: public class AssertionResult implements Serializable {
027: public static final String RESPONSE_WAS_NULL = "Response was null"; // $NON-NLS-1$
028:
029: /** Name of the assertion. */
030: private String name;
031:
032: /** True if the assertion failed. */
033: private boolean failure;
034:
035: /** True if there was an error checking the assertion. */
036: private boolean error;
037:
038: /** A message describing the failure. */
039: private String failureMessage;
040:
041: /**
042: * Create a new Assertion Result. The result will indicate no failure or
043: * error.
044: * @deprecated - use the named constructor
045: */
046: public AssertionResult() { // Needs to be public for tests
047: }
048:
049: /**
050: * Create a new Assertion Result. The result will indicate no failure or
051: * error.
052: *
053: * @param name the name of the assertion
054: */
055: public AssertionResult(String name) {
056: setName(name);
057: }
058:
059: /**
060: * Get the name of the assertion
061: *
062: * @return the name of the assertion
063: */
064: public String getName() {
065: return name;
066: }
067:
068: /**
069: * Set the name of the assertion
070: *
071: * @param name the name of the assertion
072: */
073: public void setName(String name) {
074: this .name = name;
075: }
076:
077: /**
078: * Check if the assertion failed. If it failed, the failure message may give
079: * more details about the failure.
080: *
081: * @return true if the assertion failed, false if the sample met the
082: * assertion criteria
083: */
084: public boolean isFailure() {
085: return failure;
086: }
087:
088: /**
089: * Check if an error occurred while checking the assertion. If an error
090: * occurred, the failure message may give more details about the error.
091: *
092: * @return true if an error occurred while checking the assertion, false
093: * otherwise.
094: */
095: public boolean isError() {
096: return error;
097: }
098:
099: /**
100: * Get the message associated with any failure or error. This method may
101: * return null if no message was set.
102: *
103: * @return a failure or error message, or null if no message has been set
104: */
105: public String getFailureMessage() {
106: return failureMessage;
107: }
108:
109: /**
110: * Set the flag indicating whether or not an error occurred.
111: *
112: * @param e
113: * true if an error occurred, false otherwise
114: */
115: public void setError(boolean e) {
116: error = e;
117: }
118:
119: /**
120: * Set the flag indicating whether or not a failure occurred.
121: *
122: * @param f
123: * true if a failure occurred, false otherwise
124: */
125: public void setFailure(boolean f) {
126: failure = f;
127: }
128:
129: /**
130: * Set the failure message giving more details about a failure or error.
131: *
132: * @param message
133: * the message to set
134: */
135: public void setFailureMessage(String message) {
136: failureMessage = message;
137: }
138:
139: /**
140: * Convenience method for setting up failed results
141: *
142: * @param message
143: * the message to set
144: * @return this
145: *
146: */
147: public AssertionResult setResultForFailure(String message) {
148: error = false;
149: failure = true;
150: failureMessage = message;
151: return this ;
152: }
153:
154: /**
155: * Convenience method for setting up results where the response was null
156: *
157: * @return assertion result with appropriate fields set up
158: */
159: public AssertionResult setResultForNull() {
160: error = false;
161: failure = true;
162: failureMessage = RESPONSE_WAS_NULL;
163: return this ;
164: }
165:
166: public String toString() {
167: return getName() != null ? getName() : super.toString();
168: }
169: }
|