import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import bsh.Interpreter;
import bsh.NameSpace;
import bsh.Primitive;
import bsh.UtilEvalError;
import bsh.Variable;
public class BeanShellTest {
@Test
public void testDynamicVar() throws Exception {
Interpreter inter = new Interpreter();
inter.setNameSpace(new NameSpaceWarp(inter.getNameSpace(),
"mynamespace"));
Object re = inter.eval("A999=A001+A002;");
System.out.println(re);
Assert.assertEquals(300, re);
}
@Test
public void testPrimitive() throws Exception {
Interpreter inter = new Interpreter();
inter.set("SZGC0000", new Integer(109));
inter.set("SZGA1000", new Integer(6));
inter.set("SZGG1000", new Integer(0));
inter.set("SZGK1000", new Integer(0));
inter.set("SZGC0300", new Integer(103));
Object vvv = inter
.eval("SZGC0000==SZGA1000+SZGG1000+SZGK1000+SZGC0300;");
System.out.println("1====" + vvv);
Assert.assertFalse((Boolean) vvv);
inter.set("SZGC0000", 109);
inter.set("SZGA1000", 6);
inter.set("SZGG1000", 0);
inter.set("SZGK1000", 0);
inter.set("SZGC0300", 103);
vvv = inter.eval("SZGC0000==SZGA1000+SZGG1000+SZGK1000+SZGC0300;");
System.out.println("2======" + vvv);
Assert.assertTrue((Boolean) vvv);
}
static class NameSpaceWarp extends NameSpace {
private static final long serialVersionUID = 1L;
Map<String, Object> kpis;
public NameSpaceWarp(NameSpace ns, String name) {
super(ns, name);
kpis = Collections.synchronizedMap(new HashMap<String, Object>());
kpis.put("A001", 100);
kpis.put("A002", 200);
kpis.put("A003", 300);
}
@Override
protected Variable getVariableImpl(String name, boolean recurse)
throws UtilEvalError {
Variable var = super.getVariableImpl(name, recurse);
if (var == null && kpis.containsKey(name)) {
Object o = kpis.remove(name);
if (o == null) {
o = Primitive.NULL;
}
setVariable(name, o, false);
return super.getVariableImpl(name, recurse);
}
return var;
}
}
}
分享到:
相关推荐
请到...但不管怎样,如果你要让BeanShell与你的类与应用程序一起工作就必须将 BeanShell的jar文件加到classpath中。 你可以将BeanShell的jar 文件拖到JAVA_HOME的ext目录也可以直接加到classpath中。
beanshell的使用,介绍以及源码
BeanShell BeanShell
jmeter处理beanshell RSA加密接口处理流程。包含MD5,RSA,AES三种加密处理接口方法。
保存本地文件会把逐次请求的不同参数的结果分别保存。...BeanShell PostProcessor每次可以打开相同文件,在一个文件上 追加 写入 。可以实现存到同一文件中。 注意:保存结果到本地,也要创建***正则提取器***哦~~
JMeter处理Excel文件
BeanShell用户手册,官网原版,英文版本 BeanShell User's Manual 对应版本bsh_2.0b4.jar
什么是BeanShell BeanShell是一个小型的,免费的,可嵌入式的,具有面向对象脚本语言特性的Java代码解释器。简而言之,BeanShell可以动态的解释JAVA语言。...直接在 Java 中使用 JavaScript 的功能
beanshell和jdom的jar包 BeanShell执行标准Java语句和表达式,另外包括一些脚本命令和语法
JMeter beanShell修改http请求参数,尝试对http进行修改。
jmeter配置原件BeanShell使用方法场景介绍,Jmeter常用内置变量及方法介绍
很好的脚本语言,解析java数学表达式非常有用,
beanshell 源码 jar doc sound
BeanShell帮助文档pdf和jar包
how to use beanshell to debug java application
在很多中大型的应用中,如SCM(供应链管理)、CRM(客户关系管理)和ERP(企业资源计划)等,使用者往往要根据自身的需求,灵活的对某一些参数值进行变更,使得按照某固定公式计算的结果符合目前的情况。如不同时期...
beanshell 必需的jar bsh-2.0b4.jar bsf.jar
maven-script-beanshell-3.2.jar