alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

JMeter example source code file (AssertionResult.java)

This example JMeter source code file (AssertionResult.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - JMeter tags/keywords

assertionresult, assertionresult, deprecated, io, needs, needs, non-nls-1, override, response, response_was_null, response_was_null, serializable, string, string

The JMeter AssertionResult.java source code

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.apache.jmeter.assertions;

import java.io.Serializable;

/**
 * Implements Response Assertion checking.
 */
public class AssertionResult implements Serializable {
    public static final String RESPONSE_WAS_NULL = "Response was null"; // $NON-NLS-1$

    private static final long serialVersionUID = 240L;

    /** Name of the assertion. */
    private final String name;

    /** True if the assertion failed. */
    private boolean failure;

    /** True if there was an error checking the assertion. */
    private boolean error;

    /** A message describing the failure. */
    private String failureMessage;

    /**
     * Create a new Assertion Result. The result will indicate no failure or
     * error.
     * @deprecated - use the named constructor
     */
    @Deprecated
    public AssertionResult() { // Needs to be public for tests
        this.name = null;
    }

    /**
     * Create a new Assertion Result. The result will indicate no failure or
     * error.
     *
     * @param name the name of the assertion
     */
    public AssertionResult(String name) {
        this.name = name;
    }

    /**
     * Get the name of the assertion
     *
     * @return the name of the assertion
     */
    public String getName() {
        return name;
    }

    /**
     * Check if the assertion failed. If it failed, the failure message may give
     * more details about the failure.
     *
     * @return true if the assertion failed, false if the sample met the
     *         assertion criteria
     */
    public boolean isFailure() {
        return failure;
    }

    /**
     * Check if an error occurred while checking the assertion. If an error
     * occurred, the failure message may give more details about the error.
     *
     * @return true if an error occurred while checking the assertion, false
     *         otherwise.
     */
    public boolean isError() {
        return error;
    }

    /**
     * Get the message associated with any failure or error. This method may
     * return null if no message was set.
     *
     * @return a failure or error message, or null if no message has been set
     */
    public String getFailureMessage() {
        return failureMessage;
    }

    /**
     * Set the flag indicating whether or not an error occurred.
     *
     * @param e
     *            true if an error occurred, false otherwise
     */
    public void setError(boolean e) {
        error = e;
    }

    /**
     * Set the flag indicating whether or not a failure occurred.
     *
     * @param f
     *            true if a failure occurred, false otherwise
     */
    public void setFailure(boolean f) {
        failure = f;
    }

    /**
     * Set the failure message giving more details about a failure or error.
     *
     * @param message
     *            the message to set
     */
    public void setFailureMessage(String message) {
        failureMessage = message;
    }

    /**
     * Convenience method for setting up failed results
     *
     * @param message
     *            the message to set
     * @return this
     *
     */
    public AssertionResult setResultForFailure(String message) {
        error = false;
        failure = true;
        failureMessage = message;
        return this;
    }

    /**
     * Convenience method for setting up results where the response was null
     *
     * @return assertion result with appropriate fields set up
     */
    public AssertionResult setResultForNull() {
        error = false;
        failure = true;
        failureMessage = RESPONSE_WAS_NULL;
        return this;
    }

    @Override
    public String toString() {
        return getName() != null ? getName() : super.toString();
    }
}

Other JMeter examples (source code examples)

Here is a short list of links related to this JMeter AssertionResult.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.