|
What this is
Other links
The source code
// $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/control/IfController.java,v 1.3 2004/02/14 03:34:29 sebb Exp $
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed 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.control;
import java.io.Serializable;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.apache.jmeter.junit.JMeterTestCase;
/**
*
*@author Cyrus Montakab
* created 2003/06/30
*@version $Date: 2004/02/14 03:34:29 $ $Revision: 1.3 $
* This is a Conditional Controller; it will execute the set of statements
* (samplers/controllers, etc) while the 'condition' is true.
* In a programming world - this is equivalant of :
* if (condition) {
* statements ....
* }
* In JMeter you may have :
* Thread-Group (set to loop a number of times or indefinitely,
* ... Samplers ... (e.g. Counter )
* ... Other Controllers ....
* ... IfController ( condition set to something like - ${counter}<10)
* ... statements to perform if condition is true ...
* ... Other Controllers /Samplers
* }
*
***************************************/
public class IfController extends GenericController implements Serializable
{
private static Logger logger =
LoggingManager.getLoggerForClass();
private final static String CONDITION = "IfController.condition";
/**
* constructor
*/
public IfController() {
super();
}
/**
* constructor
*/
public IfController(String condition) {
super();
this.setCondition(condition);
}
/**
* Condition Accessor - this is gonna be like ${count}<10
*/
public void setCondition(String condition) {
setProperty(new StringProperty(CONDITION, condition));
}
/**
* Condition Accessor - this is gonna be like ${count}<10
*/
public String getCondition() {
return getPropertyAsString(CONDITION);
}
/**
* evaluate the condition clause
* Throw Exception If bad condition -
*/
private boolean evaluateCondition() throws Exception {
// condition string is going to be of the form : ${counter}<10
// the following replaces the ${xxx} with actual valuess
logger.debug(" getCondition() : [" + getCondition() + "]");
String resultStr = "";
boolean result = false;
// now evaluate the condition using JavaScript
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects(null);
Object cxResultObject =
cx.evaluateString(scope, getCondition()
/*** conditionString ***/
, "
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.