diff --git a/Bench4Q-Agent/pom.xml b/Bench4Q-Agent/pom.xml index 85c40981..9e19d812 100644 --- a/Bench4Q-Agent/pom.xml +++ b/Bench4Q-Agent/pom.xml @@ -102,6 +102,11 @@ jdom b7 + + com.google.code.gson + gson + 2.2.4 + diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/BatchRequest.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/BatchRequest.java new file mode 100644 index 00000000..649d4768 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/BatchRequest.java @@ -0,0 +1,82 @@ +package org.bench4q.agent.plugin.basic.http; + +import java.util.List; + +public class BatchRequest { + private List batchItems; + + public List getBatchItems() { + return batchItems; + } + + public void setBatchItems(List batchItems) { + this.batchItems = batchItems; + } + + public static class BatchItem { + private String method; + private String url; + private String queryParams; + private String headers; + private String bodyContent; + private String bodyparameters; + private String respVarsToSaveInSession; + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getQueryParams() { + return queryParams; + } + + public void setQueryParams(String queryParams) { + this.queryParams = queryParams; + } + + public String getHeaders() { + return headers; + } + + public void setHeaders(String headers) { + this.headers = headers; + } + + public String getBodyContent() { + return bodyContent; + } + + public void setBodyContent(String bodyContent) { + this.bodyContent = bodyContent; + } + + public String getBodyparameters() { + return bodyparameters; + } + + public void setBodyparameters(String bodyparameters) { + this.bodyparameters = bodyparameters; + } + + public String getRespVarsToSaveInSession() { + return respVarsToSaveInSession; + } + + public void setRespVarsToSaveInSession(String respVarsToSaveInSession) { + this.respVarsToSaveInSession = respVarsToSaveInSession; + } + + } +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java index 6b2ce15c..e4830c5f 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java @@ -40,12 +40,13 @@ import org.bench4q.agent.plugin.ParameterBarn; import org.bench4q.agent.plugin.Constructor; import org.bench4q.agent.plugin.Parameter; import org.bench4q.agent.plugin.Plugin; +import org.bench4q.agent.plugin.basic.http.BatchRequest.BatchItem; import org.bench4q.agent.plugin.behavior.Behavior; import org.bench4q.agent.plugin.behavior.BehaviorType; import org.bench4q.agent.utils.ParameterParser; import org.bench4q.agent.utils.Type.SupportTypes; import org.bench4q.agent.utils.types.Table; -import org.bench4q.agent.utils.types.Table.Row; +import com.google.gson.Gson; @Plugin("Http") public class HttpPlugin extends ParameterBarn { @@ -116,22 +117,24 @@ public class HttpPlugin extends ParameterBarn { return uri; } - public List batch_request( + @Behavior(value = "Get", type = BehaviorType.USER_BEHAVIOR) + public List batchRequest( @Parameter(value = "requests", type = SupportTypes.Table) String requests) { ExecutorService executorService = Executors.newFixedThreadPool(2); List result = new LinkedList(); try { - Table requestTable = Table.buildTable(requests, - Arrays.asList("Method", "Url")); - List> results = new LinkedList>(); - for (final Row row : requestTable.getRows()) { - Callable task = buildTas(row); + Gson gson = new Gson(); + BatchRequest batchRequest = gson.fromJson(requests, + BatchRequest.class); + List> futures = new LinkedList>(); + for (BatchItem item : batchRequest.getBatchItems()) { + Callable task = buildTasks(item); if (task == null) { continue; } - results.add(executorService.submit(task)); + futures.add(executorService.submit(task)); } - for (Future future : results) { + for (Future future : futures) { try { result.add(future.get()); } catch (Exception e) { @@ -146,40 +149,49 @@ public class HttpPlugin extends ParameterBarn { } - private Callable buildTas(final Row row) { - // switch (row.getCell(0).toLowerCase()) { - // case "get": - // return new Callable() { - // @Override - // public HttpReturn call() throws Exception { - // return get(row.getCell(1), null, null, null); - // } - // }; - // case "post": - // return new Callable() { - // @Override - // public HttpReturn call() throws Exception { - // return post(row.getCell(1), null, null, null, null, null); - // } - // }; - // case "put": - // return new Callable() { - // @Override - // public HttpReturn call() throws Exception { - // return put(row.getCell(1), null, null, null, null, null); - // } - // }; - // case "delete": - // return new Callable() { - // @Override - // public HttpReturn call() throws Exception { - // return delete(row.getCell(1), null, null, null); - // } - // }; - // default: - // return null; - // } - return null; + private Callable buildTasks(final BatchItem item) { + switch (item.getMethod().toLowerCase()) { + case "get": + return new Callable() { + @Override + public HttpReturn call() throws Exception { + return get(item.getUrl(), item.getQueryParams(), + item.getHeaders(), + item.getRespVarsToSaveInSession()); + } + }; + case "post": + return new Callable() { + @Override + public HttpReturn call() throws Exception { + return post(item.getUrl(), item.getQueryParams(), + item.getHeaders(), item.getBodyContent(), + item.getBodyparameters(), + item.getRespVarsToSaveInSession()); + } + }; + case "put": + return new Callable() { + @Override + public HttpReturn call() throws Exception { + return put(item.getUrl(), item.getQueryParams(), + item.getHeaders(), item.getBodyContent(), + item.getBodyparameters(), + item.getRespVarsToSaveInSession()); + } + }; + case "delete": + return new Callable() { + @Override + public HttpReturn call() throws Exception { + return delete(item.getUrl(), item.getQueryParams(), + item.getHeaders(), + item.getRespVarsToSaveInSession()); + } + }; + default: + return null; + } } /** diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java index 3ff8160d..04b183bc 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java @@ -1,5 +1,8 @@ package org.bench4q.agent.plugin.basic.http; +import java.util.HashMap; +import java.util.Map; + import org.apache.commons.httpclient.Header; import org.bench4q.agent.plugin.basic.PluginReturn; @@ -79,4 +82,11 @@ public class HttpReturn extends PluginReturn { this.setUrl(url); } + public Map getExtraResult() { + Map result = new HashMap(); + result.put("contentLength", this.getContentLength() + ""); + result.put("contentType", this.getContentType()); + result.put("statusCode", this.getStatusCode() + ""); + return result; + } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java index 570eb1d6..5729e150 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.PriorityQueue; import java.util.Queue; import java.util.Set; @@ -178,4 +179,9 @@ public class Solution { builder.setCharAt(1, 'a'); System.out.println(builder.toString()); } + + @Test + public void test3() { + PriorityQueue queue = new PriorityQueue(); + } } \ No newline at end of file diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java index 22df2af5..97af7505 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java @@ -2,7 +2,9 @@ package org.bench4q.agent.test.plugin; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -10,6 +12,7 @@ import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.cookie.MalformedCookieException; import org.apache.commons.io.FileUtils; import org.bench4q.agent.plugin.basic.PluginReturn; +import org.bench4q.agent.plugin.basic.http.BatchRequest; import org.bench4q.agent.plugin.basic.http.HttpPlugin; import org.bench4q.agent.plugin.basic.http.HttpReturn; import org.bench4q.agent.scenario.Scenario; @@ -23,6 +26,8 @@ import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import com.google.gson.Gson; + import static org.junit.Assert.*; @RunWith(SpringJUnit4ClassRunner.class) @@ -153,4 +158,33 @@ public class Test_HttpPlugin extends TestBase { UUID.randomUUID()); vUser.run(); } + + @Test + public void test_BatchRequest() { + BatchRequest.BatchItem batchItem = buildItem("Get", + "http://www.baidu.com"); + BatchRequest batchRequest = new BatchRequest(); + batchRequest.setBatchItems(Arrays.asList(batchItem, + buildItem("Get", "http://www.csdn.net/"))); + String batchItemInJson = new Gson().toJson(batchRequest); + System.out.println(batchItemInJson); + List returns = this.httpPlugin + .batchRequest(batchItemInJson); + for (HttpReturn return1 : returns) { + System.out.println(return1.getUrl()); + assertEquals(200, return1.getStatusCode()); + } + } + + private BatchRequest.BatchItem buildItem(String method, String url) { + BatchRequest.BatchItem batchItem = new BatchRequest.BatchItem(); + batchItem.setMethod(method); + batchItem.setUrl(url); + batchItem.setHeaders(""); + batchItem.setQueryParams(""); + batchItem.setBodyContent(""); + batchItem.setBodyparameters(""); + batchItem.setRespVarsToSaveInSession(""); + return batchItem; + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java b/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java index d3b0b59d..17bd7389 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/api/PluginController.java @@ -147,7 +147,7 @@ public class PluginController extends BaseController { "addPlugin/{pluginName}/{methodName}"); } String pluginUIContent = plugin; - System.out.println(pluginUIContent); + logger.info(pluginUIContent); PluginResponseModel pluginResponseModel = new PluginResponseModel(); pluginResponseModel.setSuccess(this.getPluginService().addPlugin( pluginUIContent)); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/domain-diagram.ucls b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/domain-diagram.ucls new file mode 100644 index 00000000..9b0ad97b --- /dev/null +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/domain-diagram.ucls @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java index bb298611..1a09c2c1 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/agent/scriptrecord/UsePluginModel.java @@ -12,6 +12,7 @@ import org.bench4q.share.models.agent.ParameterModel; @XmlRootElement(name = "usePlugin") public class UsePluginModel { private String id; + private String nickName; private String name; private List parameters; @@ -24,6 +25,15 @@ public class UsePluginModel { this.id = id; } + @XmlElement + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + @XmlElement public String getName() { return name; diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java index 272618a9..31408133 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java @@ -60,7 +60,6 @@ public class PluginMessager extends MasterMessager { public PluginResponseModel addPlugin(String accessToken, String plugin) { String url = this.getBaseUrl() + "/addPlugin"; - System.out.println(plugin); HttpResponse httpResponse = null; try {