add type info to Annotation @Parameter

add type info to Annotation @Parameter
This commit is contained in:
coderfengyun 2014-03-21 16:11:45 +08:00
parent bbeae6ffb6
commit 82be07d484
11 changed files with 2198 additions and 23 deletions

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<runScenario>
<pages>
<page>
<batches>
<batch>
<behaviors>
<behaviorModel>
<id>0</id>
<name>Get</name>
<parameters>
<parameter>
<key>url</key>
<value>
http://www.baidu.com
</value>
</parameter>
<parameter>
<key>parameters</key>
<value></value>
</parameter>
</parameters>
<type>USERBEHAVIOR</type>
<use>http</use>
</behaviorModel>
</behaviors>
<childId>2</childId>
<id>0</id>
<parentId>-1</parentId>
</batch>
<batch>
<behaviors>
<behaviorModel>
<id>0</id>
<name>Sleep</name>
<parameters>
<parameter>
<key>time</key>
<value>230</value>
</parameter>
</parameters>
<type>TIMERBEHAVIOR</type>
<use>timer</use>
</behaviorModel>
</behaviors>
<childId>-1</childId>
<id>1</id>
<parentId>-1</parentId>
</batch>
</batches>
</page>
</pages>
<poolSize>0</poolSize>
<usePlugins>
<usePlugin>
<id>http</id>
<name>Http</name>
<parameters />
</usePlugin>
<usePlugin>
<id>timer</id>
<name>ConstantTimer</name>
<parameters />
</usePlugin>
</usePlugins>
</runScenario>

View File

@ -5,8 +5,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface Parameter {
String value();
SupportTypes type();
}

View File

@ -7,6 +7,7 @@ import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.CommandLineReturn;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
@Plugin("CommandLine")
public class CommandLinePlugin {
@ -34,7 +35,8 @@ public class CommandLinePlugin {
}
@Behavior("Command")
public CommandLineReturn command(@Parameter("command") String command) {
public CommandLineReturn command(
@Parameter(value = "command", type = SupportTypes.Field) String command) {
try {
final Process process = Runtime.getRuntime().exec(command);
new Thread() {

View File

@ -5,6 +5,7 @@ import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.TimerReturn;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
@Plugin("ConstantTimer")
public class ConstantTimerPlugin {
@ -15,7 +16,8 @@ public class ConstantTimerPlugin {
}
@Behavior("Sleep")
public TimerReturn sleep(@Parameter("time") int time) {
public TimerReturn sleep(
@Parameter(value = "time", type = SupportTypes.Field) int time) {
try {
Thread.sleep(time);
return new TimerReturn(true);

View File

@ -4,6 +4,7 @@ import org.bench4q.agent.plugin.Behavior;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.LogReturn;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
@Plugin("Log")
public class LogPlugin {
@ -12,7 +13,8 @@ public class LogPlugin {
}
@Behavior("Log")
public LogReturn log(@Parameter("message") String message) {
public LogReturn log(
@Parameter(value = "message", type = SupportTypes.Field) String message) {
System.out.println(message);
return new LogReturn(true);
}

View File

@ -34,6 +34,7 @@ import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.result.HttpReturn;
import org.bench4q.agent.scenario.util.ParameterParser;
import org.bench4q.agent.scenario.util.Type.SupportTypes;
import org.bench4q.agent.scenario.util.types.Table;
@Plugin("Http")
@ -128,10 +129,11 @@ public class HttpPlugin {
* @return
*/
@Behavior("Get")
public HttpReturn get(@Parameter("url") String url,
@Parameter("queryParams") String queryParams,
@Parameter("headers") String headers,
@Parameter("respVarsToSaveInSession") String respVarsToSaveInSession) {
public HttpReturn get(
@Parameter(value = "url", type = SupportTypes.Field) String url,
@Parameter(value = "queryParams", type = SupportTypes.NField) String queryParams,
@Parameter(value = "headers", type = SupportTypes.Table) String headers,
@Parameter(value = "respVarsToSaveInSession", type = SupportTypes.Table) String respVarsToSaveInSession) {
GetMethod method = new GetMethod(completeUri(url));
if (isValid(queryParams)) {
@ -252,12 +254,13 @@ public class HttpPlugin {
* @return
*/
@Behavior("Post")
public HttpReturn post(@Parameter("url") String url,
@Parameter("queryParams") String queryParams,
@Parameter("headers") String headers,
@Parameter("bodyContent") String bodyContent,
@Parameter("bodyparameters") String bodyParams,
@Parameter("respVarsToSaveInSession") String respVarToSaveInSession) {
public HttpReturn post(
@Parameter(value = "url", type = SupportTypes.Field) String url,
@Parameter(value = "queryParams", type = SupportTypes.NField) String queryParams,
@Parameter(value = "headers", type = SupportTypes.Table) String headers,
@Parameter(value = "bodyContent", type = SupportTypes.Field) String bodyContent,
@Parameter(value = "bodyparameters", type = SupportTypes.NField) String bodyParams,
@Parameter(value = "respVarsToSaveInSession", type = SupportTypes.Table) String respVarToSaveInSession) {
PostMethod method = new PostMethod(completeUri(url));
setHeaders(method, headers);
if (isValid(queryParams)) {
@ -297,12 +300,13 @@ public class HttpPlugin {
}
@Behavior("Put")
public HttpReturn put(@Parameter("url") String url,
@Parameter("queryParams") String queryParams,
@Parameter("headers") String headers,
@Parameter("bodyContent") String bodyContent,
@Parameter("bodyparameters") String bodyParams,
@Parameter("respVarsToSaveInSession") String respVarToSaveInSession) {
public HttpReturn put(
@Parameter(value = "url", type = SupportTypes.Field) String url,
@Parameter(value = "queryParams", type = SupportTypes.NField) String queryParams,
@Parameter(value = "headers", type = SupportTypes.Table) String headers,
@Parameter(value = "bodyContent", type = SupportTypes.Field) String bodyContent,
@Parameter(value = "bodyparameters", type = SupportTypes.NField) String bodyParams,
@Parameter(value = "respVarsToSaveInSession", type = SupportTypes.Table) String respVarToSaveInSession) {
PutMethod method = new PutMethod(completeUri(url));
setHeaders(method, headers);
if (isValid(queryParams)) {
@ -323,10 +327,11 @@ public class HttpPlugin {
}
@Behavior("Delete")
public HttpReturn delete(@Parameter("url") String url,
@Parameter("queryParams") String queryParams,
@Parameter("headers") String headers,
@Parameter("respVarsToSaveInSession") String respVarToSaveInSession) {
public HttpReturn delete(
@Parameter(value = "url", type = SupportTypes.Field) String url,
@Parameter(value = "queryParams", type = SupportTypes.NField) String queryParams,
@Parameter(value = "headers", type = SupportTypes.Table) String headers,
@Parameter(value = "respVarsToSaveInSession", type = SupportTypes.Table) String respVarToSaveInSession) {
DeleteMethod method = new DeleteMethod(completeUri(url));
setHeaders(method, headers);
if (isValid(queryParams)) {

View File

@ -1,5 +1,8 @@
package org.bench4q.agent.scenario.util;
public class Type {
public static enum SupportTypes {
Field, NField, Table, Radio, CheckBox
}
}

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.scenario.util.types;
public class CheckBox {
}

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.scenario.util.types;
public class NField {
}

View File

@ -0,0 +1,5 @@
package org.bench4q.agent.scenario.util.types;
public class Radio {
}