diff --git a/Bench4Q-Agent/.gitignore b/Bench4Q-Agent/.gitignore index 5e56e040..7738863b 100644 --- a/Bench4Q-Agent/.gitignore +++ b/Bench4Q-Agent/.gitignore @@ -1 +1,2 @@ /bin +/ScenarioParameters diff --git a/Bench4Q-Agent/Scripts/HBaseScript.xml b/Bench4Q-Agent/Scripts/HBaseScript.xml index 6b88dc4f..078a3275 100644 --- a/Bench4Q-Agent/Scripts/HBaseScript.xml +++ b/Bench4Q-Agent/Scripts/HBaseScript.xml @@ -1,265 +1,397 @@ - - - - - - - - 0 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 1 - - - endUser - 100 - - - USERBEHAVIOR - hBase - - - 1 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 1001 - - - endUser - 1100 - - - USERBEHAVIOR - hBase - - - 2 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 2001 - - - endUser - 2100 - - - USERBEHAVIOR - hBase - - - 3 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 3001 - - - endUser - 3100 - - - USERBEHAVIOR - hBase - - - 4 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 4001 - - - endUser - 4100 - - - USERBEHAVIOR - hBase - - - 5 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 5001 - - - endUser - 5100 - - - USERBEHAVIOR - hBase - - - 6 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 6001 - - - endUser - 6100 - - - USERBEHAVIOR - hBase - - - 7 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 7001 - - - endUser - 7100 - - - USERBEHAVIOR - hBase - - - 8 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 8001 - - - endUser - 8100 - - - USERBEHAVIOR - hBase - - - 9 - Send - - - beginTime - 201309111715001 - - - endTime - 201309112215001 - - - beginUser - 9001 - - - endUser - 9100 - - - USERBEHAVIOR - hBase - - - -1 - 0 - -1 - - - - - 1 - - - hBase - Hbase - - - + + + param_HBase + sequencial + Ppara_Table + Once + + + + + + + + + 0 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 1 + + + endUser + 100 + + + USERBEHAVIOR + hBase + + + 1 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 2 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 2001 + + + endUser + 2100 + + + USERBEHAVIOR + hBase + + + 3 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 4 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 4001 + + + endUser + 4100 + + + USERBEHAVIOR + hBase + + + 5 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 6 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 6001 + + + endUser + 6100 + + + USERBEHAVIOR + hBase + + + 7 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 8 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 8001 + + + endUser + 8100 + + + USERBEHAVIOR + hBase + + + 9 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 10 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 10001 + + + endUser + 10100 + + + USERBEHAVIOR + hBase + + + 11 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 12 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 12001 + + + endUser + 12100 + + + USERBEHAVIOR + hBase + + + 13 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 14 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 14001 + + + endUser + 14100 + + + USERBEHAVIOR + hBase + + + 15 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 16 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 16001 + + + endUser + 16100 + + + USERBEHAVIOR + hBase + + + 17 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 18 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 18001 + + + endUser + 18100 + + + USERBEHAVIOR + hBase + + + 19 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + -1 + 0 + -1 + + + + + 1 + + + hBase + Hbase + + + + timer + ConstantTimer + + + diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java index ea3a5b4e..d9ec09be 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java @@ -14,6 +14,7 @@ import org.apache.commons.io.FileUtils; import org.bench4q.agent.plugin.basic.hbase.HBasePlugin; import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.TestHelper; +import org.bench4q.share.models.agent.DefinedParameterModel; import org.bench4q.share.models.agent.ParameterModel; import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.scriptrecord.BatchModel; @@ -24,34 +25,53 @@ import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; public class Test_HBasePlugin { @Test public void testBuildScenario() { - RunScenarioModel result = buildScenario(10); - assertEquals(1, result.getUsePlugins().size()); + int behaviorSize = 20; + RunScenarioModel result = buildScenario(behaviorSize); + assertEquals(1, result.getDefinedParameters().size()); + assertEquals("param_HBase", result.getDefinedParameters().get(0) + .getName()); + assertEquals(2, result.getUsePlugins().size()); assertEquals("hBase", result.getUsePlugins().get(0).getId()); assertEquals("Hbase", result.getUsePlugins().get(0).getName()); + assertEquals("timer", result.getUsePlugins().get(1).getId()); + assertEquals("ConstantTimer", result.getUsePlugins().get(1).getName()); + assertEquals(1, result.getPages().size()); assertEquals(1, result.getPages().get(0).getBatches().size()); - assertEquals(10, result.getPages().get(0).getBatches().get(0) + assertEquals(behaviorSize, result.getPages().get(0).getBatches().get(0) .getBehaviors().size()); - for (int i = 0; i < 10; i++) { + for (int i = 0; i < behaviorSize; i++) { BehaviorModel behavior = result.getPages().get(0).getBatches() .get(0).getBehaviors().get(i); assertEquals(i, behavior.getId()); - assertEquals("Send", behavior.getName()); - assertEquals(4, behavior.getParameters().size()); - assertEquals("USERBEHAVIOR", behavior.getType()); - assertEquals("hBase", behavior.getUse()); - assertEquals("beginTime", behavior.getParameters().get(0).getKey()); - assertEquals("201309111715001", behavior.getParameters().get(0) - .getValue()); - assertEquals("endTime", behavior.getParameters().get(1).getKey()); - assertEquals("201309112215001", behavior.getParameters().get(1) - .getValue()); - assertEquals(1000 * i + 1 + "", behavior.getParameters().get(2) - .getValue()); - assertEquals("beginUser", behavior.getParameters().get(2).getKey()); - assertEquals(1000 * i + 100 + "", behavior.getParameters().get(3) - .getValue()); - assertEquals("endUser", behavior.getParameters().get(3).getKey()); + if (i % 2 == 0) { + assertEquals("Send", behavior.getName()); + assertEquals(4, behavior.getParameters().size()); + assertEquals("USERBEHAVIOR", behavior.getType()); + assertEquals("hBase", behavior.getUse()); + assertEquals("beginTime", behavior.getParameters().get(0) + .getKey()); + assertEquals("201309111715001", behavior.getParameters().get(0) + .getValue()); + assertEquals("endTime", behavior.getParameters().get(1) + .getKey()); + assertEquals("201309112215001", behavior.getParameters().get(1) + .getValue()); + assertEquals(1000 * i + 1 + "", behavior.getParameters().get(2) + .getValue()); + assertEquals("beginUser", behavior.getParameters().get(2) + .getKey()); + assertEquals(1000 * i + 100 + "", + behavior.getParameters().get(3).getValue()); + assertEquals("endUser", behavior.getParameters().get(3) + .getKey()); + } else { + assertEquals("Sleep", behavior.getName()); + assertEquals(1, behavior.getParameters().size()); + assertEquals("TIMERBEHAVIOR", behavior.getType()); + assertEquals("time", behavior.getParameters().get(0).getKey()); + assertEquals("5000", behavior.getParameters().get(0).getValue()); + } } try { result.setPoolSize(1); @@ -67,13 +87,15 @@ public class Test_HBasePlugin { public static RunScenarioModel buildScenario(int behaviorSize) { RunScenarioModel runScenarioModel = new RunScenarioModel(); + DefinedParameterModel dp = new DefinedParameterModel("param_HBase", + "Ppara_Table", "sequencial", "Once"); + List definedParamters = new ArrayList(); + definedParamters.add(dp); + runScenarioModel.setDefinedParameters(definedParamters); List usePluginList = new ArrayList(); - UsePluginModel plugin = new UsePluginModel(); - plugin.setId("hBase"); - plugin.setName("Hbase"); - plugin.setParameters(Collections. emptyList()); - usePluginList.add(plugin); + usePluginList.add(buildUpPlugin("hBase", "Hbase")); + usePluginList.add(buildUpPlugin("timer", "ConstantTimer")); runScenarioModel.setUsePlugins(usePluginList); List pageList = new ArrayList(); @@ -86,7 +108,10 @@ public class Test_HBasePlugin { List behaviorList = new ArrayList(); for (int i = 0; i < behaviorSize; i++) { - behaviorList.add(createABehavior(i)); + if (i % 2 == 0) + behaviorList.add(createABehavior(i)); + else + behaviorList.add(createTimer(i)); } batch.setBehaviors(behaviorList); batchModelList.add(batch); @@ -96,6 +121,21 @@ public class Test_HBasePlugin { return runScenarioModel; } + private static BehaviorModel createTimer(int i) { + List parameters = new ArrayList(); + parameters.add(ParameterModel.createParameter("time", "5000")); + return BehaviorModel.TimerBehaviorBuilder(i, "Sleep", "timer", + parameters); + } + + private static UsePluginModel buildUpPlugin(String id, String name) { + UsePluginModel plugin = new UsePluginModel(); + plugin.setId(id); + plugin.setName(name); + plugin.setParameters(Collections. emptyList()); + return plugin; + } + private static BehaviorModel createABehavior(int i) { List parameters = new ArrayList(); parameters.add(ParameterModel.createParameter("beginTime", diff --git a/Bench4Q-Master/Scripts/HBaseScript.xml b/Bench4Q-Master/Scripts/HBaseScript.xml new file mode 100644 index 00000000..d937cbb1 --- /dev/null +++ b/Bench4Q-Master/Scripts/HBaseScript.xml @@ -0,0 +1,390 @@ + + + + + + + + + + 0 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 1 + + + endUser + 100 + + + USERBEHAVIOR + hBase + + + 1 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 2 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 2001 + + + endUser + 2100 + + + USERBEHAVIOR + hBase + + + 3 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 4 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 4001 + + + endUser + 4100 + + + USERBEHAVIOR + hBase + + + 5 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 6 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 6001 + + + endUser + 6100 + + + USERBEHAVIOR + hBase + + + 7 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 8 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 8001 + + + endUser + 8100 + + + USERBEHAVIOR + hBase + + + 9 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 10 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 10001 + + + endUser + 10100 + + + USERBEHAVIOR + hBase + + + 11 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 12 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 12001 + + + endUser + 12100 + + + USERBEHAVIOR + hBase + + + 13 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 14 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 14001 + + + endUser + 14100 + + + USERBEHAVIOR + hBase + + + 15 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 16 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 16001 + + + endUser + 16100 + + + USERBEHAVIOR + hBase + + + 17 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + 18 + Send + + + beginTime + 201309111715001 + + + endTime + 201309112215001 + + + beginUser + 18001 + + + endUser + 18100 + + + USERBEHAVIOR + hBase + + + 19 + Sleep + + + time + 5000 + + + TIMERBEHAVIOR + timer + + + -1 + 0 + -1 + + + + + 1 + + + hBase + Hbase + + + + timer + ConstantTimer + + + + diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java index 3bc29f54..d8f953a6 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/service/Test_ScriptService.java @@ -2,12 +2,15 @@ package org.bench4q.master.test.service; import static org.junit.Assert.*; +import java.io.File; +import java.io.IOException; import java.util.Date; import java.util.LinkedList; import java.util.List; import javax.xml.bind.JAXBException; +import org.apache.commons.io.FileUtils; import org.bench4q.master.domain.entity.Script; import org.bench4q.master.domain.entity.User; import org.bench4q.master.domain.repository.UserRepository; @@ -74,6 +77,17 @@ public class Test_ScriptService { assertTrue(doSaveAScript(user)); } + @Test + public void testSaveScriptWithDefinedParameters() throws IOException { + User user = this.getUserRepository().getUser("admin"); + this.getScriptService().saveScript( + "HBaseScript", + user.getId(), + FileUtils.readFileToString(new File("Scripts" + + System.getProperty("file.separator") + + "HBaseScript.xml"))); + } + private boolean doSaveAScript(User user) throws JAXBException { return this.getScriptService().saveScript( "ad", @@ -156,9 +170,13 @@ public class Test_ScriptService { @After public void cleanUp() { - User user = this.getUserRepository().getUser("test1"); - assertTrue(this.getScriptService().deleteScript( - getUploadScriptId(user), user.getId())); - this.getUserRepository().detach("test1"); + try { + User user = this.getUserRepository().getUser("test1"); + int uploadScriptId = getUploadScriptId(user); + assertTrue(this.getScriptService().deleteScript(uploadScriptId, + user.getId())); + this.getUserRepository().detach("test1"); + } catch (Exception e) { + } } } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/test/testplan/TestPlanTester.java b/Bench4Q-Master/src/test/java/org/bench4q/master/test/testplan/TestPlanTester.java index 01ab04af..dbb128be 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/test/testplan/TestPlanTester.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/test/testplan/TestPlanTester.java @@ -40,7 +40,7 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan { private TestPlanModel testPlanBusinessModel = new TestPlanModel(); private String _url = TestBase.BASE_URL + "/testPlan"; private int scriptSumNum; - public static int SCRIPTID1 = 78; + public static int SCRIPTID1 = 3; private static int SCRIPTID2 = 2; private static String Monitor_Host_Name = "133.133.12.3"; private static String monitor_port = "5556"; @@ -49,8 +49,7 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan { return testPlanBusinessModel; } - public void setTestPlanBusinessModel( - TestPlanModel testPlanBusinessModel) { + public void setTestPlanBusinessModel(TestPlanModel testPlanBusinessModel) { this.testPlanBusinessModel = testPlanBusinessModel; } @@ -159,8 +158,7 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan { return stringWriter.toString(); } - public static TestPlanModel createATestPlanWithZeroMonitor( - int scriptId) { + public static TestPlanModel createATestPlanWithZeroMonitor(int scriptId) { TestPlanModel testPlanBusinessModel = new TestPlanModel(); testPlanBusinessModel.setMonitorModels(new ArrayList()); testPlanBusinessModel @@ -168,8 +166,7 @@ public class TestPlanTester extends TestBase_MakeUpTestPlan { return testPlanBusinessModel; } - public static TestPlanModel createATestPlanWithNullMonitorList( - int scriptId) { + public static TestPlanModel createATestPlanWithNullMonitorList(int scriptId) { TestPlanModel testPlanBusinessModel = new TestPlanModel(); testPlanBusinessModel.setMonitorModels(null); testPlanBusinessModel diff --git a/Bench4Q-Web/src/main/webapp/bench4q-css/editor.css b/Bench4Q-Web/src/main/webapp/bench4q-css/editor.css index 87715c1c..65261e9b 100644 --- a/Bench4Q-Web/src/main/webapp/bench4q-css/editor.css +++ b/Bench4Q-Web/src/main/webapp/bench4q-css/editor.css @@ -172,4 +172,24 @@ td { font-weight:bold; color: #3689BB; +} + +.sample_frame { + padding:10px; + margin: 10px 10px 10px 10px; + border: #3689BB solid thin; +} + +.sample_sub_frame { + border: #F0ECE0 solid thin; + margin-top: 5px; + margin-bottom: 5px; + margin-left: 10px; + margin-right: 10px; + padding-top:10px; + padding-left:10px; + padding-bottom:10px; +} +p{ + color: #4E9BCB; } \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/plugin.jsp b/Bench4Q-Web/src/main/webapp/plugin.jsp index 6480af63..cb37edc3 100644 --- a/Bench4Q-Web/src/main/webapp/plugin.jsp +++ b/Bench4Q-Web/src/main/webapp/plugin.jsp @@ -272,8 +272,8 @@ body { - + \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/base.js b/Bench4Q-Web/src/main/webapp/script/base.js index 6f70e502..cfa51618 100644 --- a/Bench4Q-Web/src/main/webapp/script/base.js +++ b/Bench4Q-Web/src/main/webapp/script/base.js @@ -141,3 +141,61 @@ function loadProperties(){ mode:'map', // 用 Map 的方式使用资源文件中的值 } ); } +function HashMap() { + this.arrKey = new Array(); + this.arrValue = new Array(); + + this.exists = function(strKey) { + strKey = strKey.toUpperCase(); + for (var i = 0; i < this.arrKey.length; i++) { + if (this.arrKey[i] == strKey) { + return true; + } + } + return false; + }; + this.length = function() { + return this.arrKey.length; + }; + + this.put = function(strKey, objValue) { + strKey = strKey.toUpperCase(); + for (var i = 0; i < this.arrKey.length; i++) { + if (this.arrKey[i] == strKey) { + this.arrValue[i] = objValue; + return; + } + } + this.arrKey[this.arrKey.length] = strKey; + this.arrValue[this.arrValue.length] = objValue; + }; + + this.get = function(strKey) { + strKey = strKey.toUpperCase(); + for (var i = 0; i < this.arrKey.length; i++) { + if (this.arrKey[i] == strKey) { + return this.arrValue[i]; + } + } + return null; + }; + + this.remove = function(strKey) { + strKey = strKey.toUpperCase(); + for (var i = 0; i < this.arrKey.length; i++) { + if (this.arrKey[i] == strKey) { + this.arrKey.splice(i, 1); + this.arrValue.splice(i, 1); + return; + } + } + }; + + this.getKeys = function() { + return this.arrKey; + }; + + this.getValues = function() { + return this.arrValue; + }; +} \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/behaviorsForm.js b/Bench4Q-Web/src/main/webapp/script/behaviorsForm.js new file mode 100644 index 00000000..848048ba --- /dev/null +++ b/Bench4Q-Web/src/main/webapp/script/behaviorsForm.js @@ -0,0 +1,268 @@ +function createBehaviorsForm(data, behaviorData, behaviorIndex) { + var methodParams = new Array(); + var fieldHTML = ""; + for (var i = 0; i < data.length; i++) { + methodParams.push(data[i]); + } + for (var j = 0; j < methodParams.length; j++) { + var methodParamModel = new MethodParamModel(methodParams[j].name, + methodParams[j].lable, methodParams[j].valueSeperator, + methodParams[j].fieldSeperator, methodParams[j].paramType, + methodParams[j].methodParamProperties); + var methodParamProperties = new Array(); + for (var q = 0; q < methodParamModel.methodParamProperties.length; q++) { + var methodParamPropertyModel = new MethodParamPropertyModel( + methodParamModel.methodParamProperties[q].key, + methodParamModel.methodParamProperties[q].value); + methodParamProperties.push(methodParamPropertyModel); + } + var type = methodParamModel.paramType; + var size = 0, cols = "", rows = ""; + for (var p = 0; p < methodParamProperties.length; p++) { + var methodParamProertyModel = methodParamProperties[p]; + if (methodParamProertyModel.key == "size") { + size = methodParamProertyModel.value; + } else if (methodParamProertyModel.key == "cols") { + cols = methodParamProertyModel.value; + } else if (methodParamProertyModel.key == "rows") { + rows = methodParamProertyModel.value; + } + } + if (type == "Field") { + fieldHTML += createField(methodParamModel.lable, + methodParamModel.name, size, behaviorIndex); + } else if (type == "MultiField") { + fieldHTML += createMultiField(methodParamModel.lable, + methodParamModel.name, size, behaviorIndex); + } else if (type == "Table") { + fieldHTML += createTable(methodParamModel, cols, behaviorIndex); + } else if (type == "CheckBox") { + fieldHTML += createCheckBox(methodParamModel, rows, behaviorIndex); + } + } + return fieldHTML; +} + + +function createField(label, name, size, behaviorIndex) { + if (size == 0) { + size = 20; + } + var divNode = document.createElement("div"); + var p = document.createElement("p"); + var labelNode = document.createTextNode(label); + var div = document.createElement("div"); + var nameNode = document.createTextNode(name); + var input = document.createElement("input"); + + $(divNode).attr("class", "Field sample_frame"); + $(divNode).attr("id", behaviorIndex + "_" + name); + $(div).attr("class", "sample_sub_frame"); + $(input).attr("type", "text"); + $(input).attr("size", size); + $(input).attr("id", name + "_input"); + + p.appendChild(labelNode); + div.appendChild(nameNode); + div.appendChild(input); + divNode.appendChild(p); + divNode.appendChild(div); + return divNode.outerHTML; +} + +function createMultiField(label, name, size, behaviorIndex) { + if (size == 0) { + size = 20; + } + var divNode = document.createElement("div"); + var p = document.createElement("p"); + var labelNode = document.createTextNode(name + ":" + label); + var div = document.createElement("div"); + var addFieldButton = document.createElement("button"); + var addFieldNode = document.createTextNode($.i18n + .prop("plugin_jsp_addField")); + var removeFieldButton = document.createElement("button"); + var removeFieldNode = document.createTextNode($.i18n + .prop("plugin_jsp_removeField")); + var br = document.createElement("br"); + var table = document.createElement("table"); + + $(divNode).attr("class", "MultiField sample_frame"); + $(divNode).attr("id", behaviorIndex + "_" + name); + $(div).attr("class", "sample_sub_frame"); + $(addFieldButton).attr("type", "submit"); + $(addFieldButton).attr("class", "btn-large"); + $(addFieldButton).attr("onClick", + "addField(" + size + "," + behaviorIndex + ");"); + $(removeFieldButton).attr("type", "submit"); + $(removeFieldButton).attr("class", "btn-large"); + $(removeFieldButton).attr("onClick", "removeField(this)"); + $(table).attr("id", "addFieldTable_" + behaviorIndex); + $(table).attr("class", "table-margin"); + + p.appendChild(labelNode); + addFieldButton.appendChild(addFieldNode); + removeFieldButton.appendChild(removeFieldNode); + div.appendChild(addFieldButton); + div.appendChild(removeFieldButton); + div.appendChild(br); + div.appendChild(table); + divNode.appendChild(p); + divNode.appendChild(div); + return divNode.outerHTML; +} + +var field; +function addField(size, addId) { + field = $("#addFieldTable_" + addId).children().length; + var data = "field_" + field + ":"; + field = field + 1; + var newTrNode = document.createElement("tr"); + var newTdNode1 = document.createElement("td"); + var newTdNode2 = document.createElement("td"); + newTdNode1.setAttribute("class", data); + var textNode = document.createTextNode(data); + var inputNode = document.createElement("input"); + inputNode.setAttribute("type", "text"); + inputNode.setAttribute("size", size); + + newTdNode1.appendChild(textNode); + newTdNode2.appendChild(inputNode); + newTrNode.appendChild(newTdNode1); + newTrNode.appendChild(newTdNode2); + document.getElementById("addFieldTable_" + addId).appendChild(newTrNode); +} + +function removeField(selectedNode) { + var table = selectedNode.nextSibling.nextSibling; + var deletedNode = table.lastChild; + table.removeChild(deletedNode); +} + +function createTable(methodParamModel, cols, behaviorIndex) { + var name = methodParamModel.name; + var label = methodParamModel.lable; + var valueSeperator = methodParamModel.valueSeperator; + var table_content = cols.split(valueSeperator); + var tr = document.createElement("tr"); + for (var i = 0; i < table_content.length; i++) { + var th = document.createElement("th"); + var text = document.createTextNode(table_content[i]); + th.appendChild(text); + tr.appendChild(th); + } + var tr_content = document.createElement("tr"); + for (var j = 0; j < table_content.length; j++) { + var td_content = document.createElement("td"); + var text_content = document.createElement("input"); + text_content.setAttribute("type", "text"); + td_content.appendChild(text_content); + tr_content.appendChild(td_content); + } + var divNode = document.createElement("div"); + var p = document.createElement("p"); + var labelNode = document.createTextNode(label); + var div = document.createElement("div"); + var nameNode = document.createTextNode(name); + var br1 = document.createElement("br"); + var br2 = document.createElement("br"); + var addColButton = document.createElement("button"); + var addColNode = document.createTextNode($.i18n.prop("plugin_jsp_addCol")); + var removeColButton = document.createElement("button"); + var removeColNode = document.createTextNode($.i18n + .prop("plugin_jsp_removeCol")); + var table = document.createElement("table"); + var thead = document.createElement("thead"); + var tbody = document.createElement("tbody"); + + $(divNode).attr("class", "Table sample_frame"); + $(divNode).attr("id", behaviorIndex + "_" + name); + $(div).attr("class", "sample_sub_frame"); + $(addColButton).attr("type", "submit"); + $(addColButton).attr("class", "btn-large"); + $(addColButton).attr("onClick", "addCol(this)"); + $(removeColButton).attr("type", "submit"); + $(removeColButton).attr("class", "btn-large"); + $(removeColButton).attr("onClick", "removeCol(this)"); + $(table).attr("class", behaviorIndex + "_operateTableCols"); + $(table).attr("class", "table-margin"); + + p.appendChild(labelNode); + addColButton.appendChild(addColNode); + removeColButton.appendChild(removeColNode); + thead.appendChild(tr); + tbody.appendChild(tr_content); + table.appendChild(thead); + table.appendChild(tbody); + div.appendChild(nameNode); + div.appendChild(br1); + div.appendChild(addColButton); + div.appendChild(removeColButton); + div.appendChild(br2); + div.appendChild(table); + divNode.appendChild(p); + divNode.appendChild(div); + return divNode.outerHTML; + +} + +function addCol(selectedNode) { + var tbody = selectedNode.nextSibling.nextSibling.nextSibling.lastChild; + var length = tbody.previousSibling.firstChild.childNodes.length; + var tr = document.createElement("tr"); + for (var i = 0; i < length; i++) { + var td = document.createElement("td"); + var input = document.createElement("input"); + input.setAttribute("type", "text"); + td.appendChild(input); + tr.appendChild(td); + } + tbody.appendChild(tr); +} + +function removeCol(selectedNode) { + var tbody = selectedNode.nextSibling.nextSibling.lastChild; + var removeNode = tbody.lastChild; + tbody.removeChild(removeNode); +} + +function createCheckBox(methodParamModel, rows, behaviorIndex) { + var name = methodParamModel.name; + var label = methodParamModel.lable; + var valueSeperator = methodParamModel.valueSeperator; + var cb_content = rows.split(valueSeperator); + + var result = document.createElement("div"); + var divNode = document.createElement("div"); + var p = document.createElement("p"); + var div = document.createElement("div"); + var br = document.createElement("br"); + var divInput = document.createElement("div"); + var labelNode = document.createTextNode(label); + var nameNode = document.createTextNode(name); + $(divNode).attr("class", "CheckBox sample_frame"); + $(divNode).attr("id", "checkbox_" + name + "_" + behaviorIndex); + $(div).attr("class", "sample_sub_frame"); + $(divInput).attr("class", "sample_sub_frame"); + p.appendChild(labelNode); + for (var i = 0; i < cb_content.length; i++) { + var checkBoxNode = document.createElement("input"); + var brInput = document.createElement("br"); + checkBoxNode.setAttribute("type", "checkbox"); + checkBoxNode.setAttribute("name", "checkbox_" + name + "_" + + behaviorIndex); + checkBoxNode.setAttribute("value", cb_content[i]); + var checkBoxValue = document.createTextNode(cb_content[i]); + divInput.appendChild(checkBoxNode); + divInput.appendChild(checkBoxValue); + divInput.appendChild(brInput); + } + div.appendChild(nameNode); + div.appendChild(br); + div.appendChild(divInput); + divNode.appendChild(p); + divNode.appendChild(div); + result.appendChild(divNode); + return $(result).html(); + +} \ No newline at end of file diff --git a/Bench4Q-Web/src/main/webapp/script/editScript.js b/Bench4Q-Web/src/main/webapp/script/editScript.js index 08cb4fcc..f48232b2 100644 --- a/Bench4Q-Web/src/main/webapp/script/editScript.js +++ b/Bench4Q-Web/src/main/webapp/script/editScript.js @@ -1,23 +1,122 @@ -var rsm; -var pluginNameList=new Array(); -var behaviors=new Array(); -var parameters=new Array(); - -function loadUsePluigns(data){ - for(var i=0;i" + "

sample:" + + behaviorData + "

"; + + documentHtml = "

" + + behaviorData + + "

" + + boxHeader + + "
" + + fieldHTML + + "
"; + document.getElementById("showPluginMethodForm").innerHTML += documentHtml; + }); +} + diff --git a/Bench4Q-Web/src/main/webapp/script/jsonEditorApp.js b/Bench4Q-Web/src/main/webapp/script/jsonEditorApp.js index a6fd936b..335fa14c 100644 --- a/Bench4Q-Web/src/main/webapp/script/jsonEditorApp.js +++ b/Bench4Q-Web/src/main/webapp/script/jsonEditorApp.js @@ -2,6 +2,7 @@ $(function() { var scriptId = getvars()['scriptId']; editor.load(scriptId); }); +var modelData; function getvars() { var vars = [], hash; @@ -37,6 +38,7 @@ editor.load = function(scriptId) { } else { data = eval('(' + data.data + ')'); } + modelData=data; editor.originalData = data; var codeContainer = document.getElementById("codeEditor"); var options = { @@ -49,8 +51,8 @@ editor.load = function(scriptId) { codeEditor = new jsoneditor.JSONEditor(codeContainer, options); codeEditor.set(data); loadUsePluigns(data); - loadBehaviors(data); - + /*loadBehaviors(data);*/ + //alert(data.pages.length); }, "json"); var $submit = $("#submit"); diff --git a/Bench4Q-Web/src/main/webapp/script/plugin-new.js b/Bench4Q-Web/src/main/webapp/script/plugin-new.js index 9bf2a0fc..ab7411da 100644 --- a/Bench4Q-Web/src/main/webapp/script/plugin-new.js +++ b/Bench4Q-Web/src/main/webapp/script/plugin-new.js @@ -5,7 +5,7 @@ var pluginMethodList = new Array(); var usePluginList = new Array(); var behaviors = new Array(); var clickPluginMethodNode = -1; -var clickPluginChoosedNode=0; +var clickPluginChoosedNode = 0; var place = ""; $(document).ready(function() { loadPluginList(); @@ -73,7 +73,7 @@ function createLineWithRadio(lineText, nameAttr) { return $(divNode).html() + "
"; } -function createALine(pluginName,index,list){ +function createALine(pluginName, index, list) { var div = document.createElement("div"); var p = document.createElement("p"); var i = document.createElement("i"); @@ -82,10 +82,10 @@ function createALine(pluginName,index,list){ i.setAttribute("class", "icon-hand-right"); p.setAttribute("id", index); p.setAttribute("class", ""); - if(list=="pluginMethodList"){ + if (list == "pluginMethodList") { p.setAttribute("onClick", "showMethodDocument(this)");// loadMethodParams - }else if(list=="pluginChoosedList"){ - p.setAttribute("onClick", "choosePlugin("+index+");"); + } else if (list == "pluginChoosedList") { + p.setAttribute("onClick", "choosePlugin(" + index + ");"); } p.setAttribute("style", "cursor:pointer;width:85%"); p.appendChild(i); @@ -94,15 +94,15 @@ function createALine(pluginName,index,list){ return div; } -function choosePlugin(index){ - clickPluginChoosedNode=index; - var pluginChoosedNode=$('#pluginArea').children(); - var length=pluginChoosedNode.length; - for(var i=0;i= clickPluginMethodNode + 1; j--) { @@ -245,7 +246,7 @@ function createPluginMethodLines() { document.getElementById("showPluginMethod").innerHTML = ""; document.getElementById('behaviorArea').innerHTML = ""; for (var j = 0; j < pluginMethodList.length; j++) { - var div=createALine(pluginMethodList[j], j,"pluginMethodList"); + var div = createALine(pluginMethodList[j], j, "pluginMethodList"); document.getElementById('behaviorArea').appendChild(div); loadMethodParams(pluginMethodList[j], j); } @@ -274,21 +275,22 @@ function showMethodDocument(selectedNode) { } function removeInsertPluginByClicked() { - var length=$('#behaviorArea').children().length; + var length = $('#behaviorArea').children().length; var removeDocumentNode = document.getElementById("showPluginMethod").childNodes; - for(var i=parseInt(clickPluginMethodNode+1);i" - + "

sample:" - + behaviorData - + "

"; - - documentHtml = "

" - + behaviorData - + "

" - + boxHeader - + "
" - + fieldHTML - + "
" - + "  
"; - document.getElementById("showPluginMethod").innerHTML += documentHtml; - }); + $.post("loadMethodParameters", { + pluginName : plugin, + methodName : method + }, function(data) { + if (!data.success) { + alert(data.failedMessage); + return; + } + data = data.data; + var documentHtml = ""; + var boxHeader = ""; + boxHeader = "
" + + "" + "

sample:" + + behaviorData + "

"; + var fieldHTML=createBehaviorsForm(data, behaviorData, behaviorIndex); + documentHtml = "

" + + behaviorData + + "

" + + boxHeader + + "
" + + fieldHTML + + "
" + + "  
"; + + document.getElementById("showPluginMethod").innerHTML += documentHtml; + }); } - -function createField(label, name, size, behaviorIndex) { - if (size == 0) { - size = 20; - } - var divNode = document.createElement("div"); - var p = document.createElement("p"); - var labelNode = document.createTextNode(label); - var div = document.createElement("div"); - var nameNode = document.createTextNode(name); - var input = document.createElement("input"); - - $(divNode).attr("class", "Field sample_frame"); - $(divNode).attr("id", behaviorIndex + "_" + name); - $(div).attr("class", "sample_sub_frame"); - $(input).attr("type", "text"); - $(input).attr("size", size); - $(input).attr("id", name + "_input"); - - p.appendChild(labelNode); - div.appendChild(nameNode); - div.appendChild(input); - divNode.appendChild(p); - divNode.appendChild(div); - return divNode.outerHTML; -} - -function createMultiField(label, name, size, behaviorIndex) { - if (size == 0) { - size = 20; - } - var divNode = document.createElement("div"); - var p = document.createElement("p"); - var labelNode = document.createTextNode(name + ":" + label); - var div = document.createElement("div"); - var addFieldButton = document.createElement("button"); - var addFieldNode = document.createTextNode($.i18n - .prop("plugin_jsp_addField")); - var removeFieldButton = document.createElement("button"); - var removeFieldNode = document.createTextNode($.i18n - .prop("plugin_jsp_removeField")); - var br = document.createElement("br"); - var table = document.createElement("table"); - - $(divNode).attr("class", "MultiField sample_frame"); - $(divNode).attr("id", behaviorIndex + "_" + name); - $(div).attr("class", "sample_sub_frame"); - $(addFieldButton).attr("type", "submit"); - $(addFieldButton).attr("class", "btn-large"); - $(addFieldButton).attr("onClick", - "addField(" + size + "," + behaviorIndex + ");"); - $(removeFieldButton).attr("type", "submit"); - $(removeFieldButton).attr("class", "btn-large"); - $(removeFieldButton).attr("onClick", "removeField(this)"); - $(table).attr("id", "addFieldTable_" + behaviorIndex); - $(table).attr("class", "table-margin"); - - p.appendChild(labelNode); - addFieldButton.appendChild(addFieldNode); - removeFieldButton.appendChild(removeFieldNode); - div.appendChild(addFieldButton); - div.appendChild(removeFieldButton); - div.appendChild(br); - div.appendChild(table); - divNode.appendChild(p); - divNode.appendChild(div); - return divNode.outerHTML; -} - -var field; -function addField(size, addId) { - field = $("#addFieldTable_" + addId).children().length; - var data = "field_" + field + ":"; - field = field + 1; - var newTrNode = document.createElement("tr"); - var newTdNode1 = document.createElement("td"); - var newTdNode2 = document.createElement("td"); - newTdNode1.setAttribute("class", data); - var textNode = document.createTextNode(data); - var inputNode = document.createElement("input"); - inputNode.setAttribute("type", "text"); - inputNode.setAttribute("size", size); - - newTdNode1.appendChild(textNode); - newTdNode2.appendChild(inputNode); - newTrNode.appendChild(newTdNode1); - newTrNode.appendChild(newTdNode2); - document.getElementById("addFieldTable_" + addId).appendChild(newTrNode); -} - -function removeField(selectedNode) { - var table = selectedNode.nextSibling.nextSibling; - var deletedNode = table.lastChild; - table.removeChild(deletedNode); -} - -function createTable(methodParamModel, cols, behaviorIndex) { - var name = methodParamModel.name; - var label = methodParamModel.lable; - var valueSeperator = methodParamModel.valueSeperator; - var table_content = cols.split(valueSeperator); - var tr = document.createElement("tr"); - for (var i = 0; i < table_content.length; i++) { - var th = document.createElement("th"); - var text = document.createTextNode(table_content[i]); - th.appendChild(text); - tr.appendChild(th); - } - var tr_content = document.createElement("tr"); - for (var j = 0; j < table_content.length; j++) { - var td_content = document.createElement("td"); - var text_content = document.createElement("input"); - text_content.setAttribute("type", "text"); - td_content.appendChild(text_content); - tr_content.appendChild(td_content); - } - var divNode = document.createElement("div"); - var p = document.createElement("p"); - var labelNode = document.createTextNode(label); - var div = document.createElement("div"); - var nameNode = document.createTextNode(name); - var br1 = document.createElement("br"); - var br2 = document.createElement("br"); - var addColButton = document.createElement("button"); - var addColNode = document.createTextNode($.i18n.prop("plugin_jsp_addCol")); - var removeColButton = document.createElement("button"); - var removeColNode = document.createTextNode($.i18n - .prop("plugin_jsp_removeCol")); - var table = document.createElement("table"); - var thead = document.createElement("thead"); - var tbody = document.createElement("tbody"); - - $(divNode).attr("class", "Table sample_frame"); - $(divNode).attr("id", behaviorIndex + "_" + name); - $(div).attr("class", "sample_sub_frame"); - $(addColButton).attr("type", "submit"); - $(addColButton).attr("class", "btn-large"); - $(addColButton).attr("onClick", "addCol(this)"); - $(removeColButton).attr("type", "submit"); - $(removeColButton).attr("class", "btn-large"); - $(removeColButton).attr("onClick", "removeCol(this)"); - $(table).attr("class", behaviorIndex + "_operateTableCols"); - $(table).attr("class", "table-margin"); - - p.appendChild(labelNode); - addColButton.appendChild(addColNode); - removeColButton.appendChild(removeColNode); - thead.appendChild(tr); - tbody.appendChild(tr_content); - table.appendChild(thead); - table.appendChild(tbody); - div.appendChild(nameNode); - div.appendChild(br1); - div.appendChild(addColButton); - div.appendChild(removeColButton); - div.appendChild(br2); - div.appendChild(table); - divNode.appendChild(p); - divNode.appendChild(div); - return divNode.outerHTML; - -} - -function addCol(selectedNode) { - var tbody = selectedNode.nextSibling.nextSibling.nextSibling.lastChild; - var length = tbody.previousSibling.firstChild.childNodes.length; - var tr = document.createElement("tr"); - for (var i = 0; i < length; i++) { - var td = document.createElement("td"); - var input = document.createElement("input"); - input.setAttribute("type", "text"); - td.appendChild(input); - tr.appendChild(td); - } - tbody.appendChild(tr); -} - -function removeCol(selectedNode) { - var tbody = selectedNode.nextSibling.nextSibling.lastChild; - var removeNode = tbody.lastChild; - tbody.removeChild(removeNode); -} - -function createCheckBox(methodParamModel, rows, behaviorIndex) { - var name = methodParamModel.name; - var label = methodParamModel.lable; - var valueSeperator = methodParamModel.valueSeperator; - var cb_content = rows.split(valueSeperator); - - var result = document.createElement("div"); - var divNode = document.createElement("div"); - var p = document.createElement("p"); - var div = document.createElement("div"); - var br = document.createElement("br"); - var divInput = document.createElement("div"); - var labelNode = document.createTextNode(label); - var nameNode = document.createTextNode(name); - $(divNode).attr("class", "CheckBox sample_frame"); - $(divNode).attr("id", "checkbox_" + name + "_" + behaviorIndex); - $(div).attr("class", "sample_sub_frame"); - $(divInput).attr("class", "sample_sub_frame"); - p.appendChild(labelNode); - for (var i = 0; i < cb_content.length; i++) { - var checkBoxNode = document.createElement("input"); - var brInput = document.createElement("br"); - checkBoxNode.setAttribute("type", "checkbox"); - checkBoxNode.setAttribute("name", "checkbox_" + name + "_" - + behaviorIndex); - checkBoxNode.setAttribute("value", cb_content[i]); - var checkBoxValue = document.createTextNode(cb_content[i]); - divInput.appendChild(checkBoxNode); - divInput.appendChild(checkBoxValue); - divInput.appendChild(brInput); - } - div.appendChild(nameNode); - div.appendChild(br); - div.appendChild(divInput); - divNode.appendChild(p); - divNode.appendChild(div); - result.appendChild(divNode); - return $(result).html(); - -} - - function saveBehavior(selectedNode) { var uploadNode = selectedNode.parentNode.previousSibling; var div = uploadNode.childNodes; diff --git a/Bench4Q-Web/src/main/webapp/script/pluginModel.js b/Bench4Q-Web/src/main/webapp/script/pluginModel.js index d91d6104..b42cd66b 100644 --- a/Bench4Q-Web/src/main/webapp/script/pluginModel.js +++ b/Bench4Q-Web/src/main/webapp/script/pluginModel.js @@ -48,61 +48,3 @@ function UsePluginModel(id, name, parameters) { this.parameters = parameters; } -function HashMap() { - this.arrKey = new Array(); - this.arrValue = new Array(); - - this.exists = function(strKey) { - strKey = strKey.toUpperCase(); - for (var i = 0; i < this.arrKey.length; i++) { - if (this.arrKey[i] == strKey) { - return true; - } - } - return false; - }; - this.length = function() { - return this.arrKey.length; - }; - - this.put = function(strKey, objValue) { - strKey = strKey.toUpperCase(); - for (var i = 0; i < this.arrKey.length; i++) { - if (this.arrKey[i] == strKey) { - this.arrValue[i] = objValue; - return; - } - } - this.arrKey[this.arrKey.length] = strKey; - this.arrValue[this.arrValue.length] = objValue; - }; - - this.get = function(strKey) { - strKey = strKey.toUpperCase(); - for (var i = 0; i < this.arrKey.length; i++) { - if (this.arrKey[i] == strKey) { - return this.arrValue[i]; - } - } - return null; - }; - - this.remove = function(strKey) { - strKey = strKey.toUpperCase(); - for (var i = 0; i < this.arrKey.length; i++) { - if (this.arrKey[i] == strKey) { - this.arrKey.splice(i, 1); - this.arrValue.splice(i, 1); - return; - } - } - }; - - this.getKeys = function() { - return this.arrKey; - }; - - this.getValues = function() { - return this.arrValue; - }; -} \ No newline at end of file