chang the the test of upload file

This commit is contained in:
fanfuxiaoran 2014-04-28 16:09:14 +08:00
parent a0b8002d55
commit 4dbbcd2f55
7 changed files with 659 additions and 657 deletions

View File

@ -7,9 +7,9 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.List; import java.util.List;
@ -48,7 +48,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile; import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -296,7 +295,7 @@ public class ScriptActionController {
public BaseResponseModel uploadScript( public BaseResponseModel uploadScript(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@RequestParam("script") CommonsMultipartFile script, @RequestParam("script") CommonsMultipartFile script,
@RequestParam String scriptName, List<File> paramFiles) @RequestParam String scriptName)
throws CustomGenericException { throws CustomGenericException {
if (script.isEmpty()) { if (script.isEmpty()) {
return new BaseResponseModel(false, "empty file"); return new BaseResponseModel(false, "empty file");
@ -308,12 +307,10 @@ public class ScriptActionController {
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
.unmarshal(RunScenarioModel.class, scenarioModel); .unmarshal(RunScenarioModel.class, scenarioModel);
HttpResponse httpResponse = this.getCommunicateWithMaster()
.uploadScriptWithParamFiles(accessToken, scriptName,
runScenarioModel, paramFiles);
OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper
.tryUnmarshal(OperateScriptServerResponseModel.class, .tryUnmarshal(OperateScriptServerResponseModel.class,
httpResponse.getContent()); "");
if (operateScriptServerResponseModel.isSuccess()) if (operateScriptServerResponseModel.isSuccess())
return new BaseResponseModel(true, (Object) new String( return new BaseResponseModel(true, (Object) new String(
@ -394,24 +391,20 @@ public class ScriptActionController {
return str; return str;
} }
@RequestMapping(value = "uploadEditScript", method = RequestMethod.POST) @RequestMapping(value = "uploadEditedScipt", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public BaseResponseModel uploadEditScript( public BaseResponseModel uploadEditScript(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@RequestParam String content, @RequestParam File file) @RequestParam String content, @RequestParam CommonsMultipartFile[] paramFiles )
throws CustomGenericException { throws CustomGenericException {
System.out.println("uploadEditScript");
ScenarioModel scenarioModel = null; ScenarioModel scenarioModel = null;
Gson gson = new Gson(); Gson gson = new Gson();
List<File> paramFiles=new LinkedList<File>();
paramFiles.add(file);
try { try {
scenarioModel = gson.fromJson(content, ScenarioModel.class); scenarioModel = gson.fromJson(content, ScenarioModel.class);
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(ScriptActionController.class).info( Logger.getLogger(ScriptActionController.class).info(
ExceptionLog.getStackTrace(e)); ExceptionLog.getStackTrace(e));
} }
RunScenarioModel runScenarioModel = scenarioModel.getRunScenarioModel(); RunScenarioModel runScenarioModel = scenarioModel.getRunScenarioModel();
List<PageModel> pageModels = runScenarioModel.getPages(); List<PageModel> pageModels = runScenarioModel.getPages();
List<UsePluginModel> usePluginModels = runScenarioModel.getUsePlugins(); List<UsePluginModel> usePluginModels = runScenarioModel.getUsePlugins();
@ -419,12 +412,11 @@ public class ScriptActionController {
if (!validateScenarioModel(pageModels, usePluginModels)) if (!validateScenarioModel(pageModels, usePluginModels))
return new BaseResponseModel(false, "invalidate script"); return new BaseResponseModel(false, "invalidate script");
try { try {
ObjectXmlExchange.toXml(RunScenarioModel.class, ObjectXmlExchange.toXml(RunScenarioModel.class, runScenarioModel);
runScenarioModel);
HttpResponse httpResponse = this.getCommunicateWithMaster()
HttpResponse httpResponse = this.getCommunicateWithMaster()
.uploadScriptWithParamFiles(accessToken, scriptName, .uploadScriptWithParamFiles(accessToken, scriptName,
runScenarioModel, paramFiles); runScenarioModel, paramFiles);
OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper
.tryUnmarshal(OperateScriptServerResponseModel.class, .tryUnmarshal(OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());

View File

@ -24,7 +24,7 @@ import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Component @Component
public class CommunicateWithMaster { public class CommunicateWithMaster {
@ -77,11 +77,11 @@ public class CommunicateWithMaster {
public HttpResponse uploadScriptWithParamFiles(String accessToken, public HttpResponse uploadScriptWithParamFiles(String accessToken,
String scriptName, RunScenarioModel runScenarioModel, String scriptName, RunScenarioModel runScenarioModel,
List<File> paramFiles) { CommonsMultipartFile[] paramFiles) {
String url = masterAddress + "RecordScript/uploadScript/" + scriptName; String url = masterAddress + "RecordScript/uploadScript/" + scriptName;
List<String> stringPart = new LinkedList<String>(); List<String> stringPart = new LinkedList<String>();
stringPart.add(MarshalHelper.tryMarshal(runScenarioModel)); stringPart.add(MarshalHelper.tryMarshal(runScenarioModel));
return this.getHttpRequester().postFiles( return this.getHttpRequester().postFilesMulti(
makeAccessTockenMap(accessToken), url, "paramFiles[]", makeAccessTockenMap(accessToken), url, "paramFiles[]",
paramFiles, "scenarioModel", stringPart); paramFiles, "scenarioModel", stringPart);
} }

View File

@ -1,104 +1,105 @@
function checkName(name) { function checkName(name) {
if (name == '') { if (name == '') {
document.getElementById('alertUserName').style.display = 'block'; document.getElementById('alertUserName').style.display = 'block';
} else { } else {
document.getElementById('alertUserName').style.display = 'none'; document.getElementById('alertUserName').style.display = 'none';
} }
} }
function checkPass(password) { function checkPass(password) {
if (password == "") { if (password == "") {
document.getElementById('alertPassWord').style.display = 'block'; document.getElementById('alertPassWord').style.display = 'block';
} else { } else {
document.getElementById('alertPassWord').style.display = 'none'; document.getElementById('alertPassWord').style.display = 'none';
} }
} }
$("body").keydown(function(e) {
var ee = e || window.event; $("body").keydown(function(e) {
if(ee.keyCode == 13){ var ee = e || window.event;
login(); if(ee.keyCode == 13){
} login();
}); }
});
function login() {
function login() {
var userName = $('#username').val();
var password = $('#password').val(); var userName = $('#username').val();
$.post('login', { var password = $('#password').val();
userName : userName, $.post('login', {
password : password userName : userName,
}, function(data) { password : password
}, function(data) {
if (data.success) {
$('#loginMsg').hide(); if (data.success) {
window.location.replace("homepage.jsp"); $('#loginMsg').hide();
window.location.replace("homepage.jsp");
}
}
else {
alert(data.failedMessage); else {
} alert(data.failedMessage);
},"json"); }
} },"json");
function adminLogin() { }
function adminLogin() {
var userName = $('#username').val();
var password = $('#password').val(); var userName = $('#username').val();
$.post('adminLogin', { var password = $('#password').val();
userName : userName, $.post('adminLogin', {
password : password userName : userName,
}, function(data) { password : password
if (data.success) { }, function(data) {
$('#loginMsg').hide(); if (data.success) {
window.location.replace("agentManage.jsp"); $('#loginMsg').hide();
window.location.replace("agentManage.jsp");
}
}
else {
alert(data.failedMessage); else {
} alert(data.failedMessage);
}); }
} });
function register() { }
var userName = $('#username').val(); function register() {
var password = $('#password').val(); var userName = $('#username').val();
var rePassword = $("#re_password").val(); var password = $('#password').val();
if (rePassword != password) { var rePassword = $("#re_password").val();
$('#username').val(""); if (rePassword != password) {
$('#password').val(""); $('#username').val("");
alert("password is wrong! retype again"); $('#password').val("");
} alert("password is wrong! retype again");
}
$.post('register', {
userName : userName, $.post('register', {
password : password, userName : userName,
rePassword:rePassword password : password,
}, function(data) { rePassword:rePassword
if (data.success) { }, function(data) {
$('#registerMsg').hide(); if (data.success) {
window.location.replace("registerSuccess.jsp"); $('#registerMsg').hide();
window.location.replace("registerSuccess.jsp");
}
}
else {
alert(data.failedMessage); else {
// $('#registerMsg').html($.i18n.prop('msgRegister')); alert(data.failedMessage);
$('#registerMsg').show(); // $('#registerMsg').html($.i18n.prop('msgRegister'));
} $('#registerMsg').show();
}, "json"); }
} }, "json");
}
$("#img").mouseover(function(){document.getElementById("img").setAttribute("src", "img/githubsignon1.jpg");});
$("#img").mouseover(function(){document.getElementById("img").setAttribute("src", "img/githubsignon1.jpg");});
$("#img").mouseout(function(){document.getElementById("img").setAttribute("src", "img/githubsignon.jpg");});
$("#img").mouseout(function(){document.getElementById("img").setAttribute("src", "img/githubsignon.jpg");});

View File

@ -1,482 +1,482 @@
var script = new Array(); var script = new Array();
$(document).ready(function() { $(document).ready(function() {
$.post("loadScript", {}, function(data) { $.post("loadScript", {}, function(data) {
if (!data.success) { if (!data.success) {
alert(data.failedMessage); alert(data.failedMessage);
return; return;
} }
data = data.data; data = data.data;
for ( var i = 0; i < data.length; i++) for ( var i = 0; i < data.length; i++)
script.push(data[i].name); script.push(data[i].name);
for ( var j = 0; j < script.length; j++) { for ( var j = 0; j < script.length; j++) {
var textNode = document.createTextNode(script[j]); var textNode = document.createTextNode(script[j]);
var optionNode = document.createElement("option"); var optionNode = document.createElement("option");
optionNode.setAttribute("value", script[j]); optionNode.setAttribute("value", script[j]);
optionNode.appendChild(textNode); optionNode.appendChild(textNode);
var selectNode = document.getElementsByName("select")[0]; var selectNode = document.getElementsByName("select")[0];
selectNode.appendChild(optionNode); selectNode.appendChild(optionNode);
} }
}); });
}); });
$(document).ready(function() { $(document).ready(function() {
loadSchedulePlot(); loadSchedulePlot();
}); });
function toggleTestExecutionPlan() { function toggleTestExecutionPlan() {
$("#loadTestExecutionPlan").slideToggle(); $("#loadTestExecutionPlan").slideToggle();
$('#loadConfigMessage').attr("class", "hide"); $('#loadConfigMessage').attr("class", "hide");
if ($("#icon-load").attr("class") == "icon-plus") if ($("#icon-load").attr("class") == "icon-plus")
$("#icon-load").attr("class", "icon-minus"); $("#icon-load").attr("class", "icon-minus");
else else
$("#icon-load").attr("class", "icon-plus"); $("#icon-load").attr("class", "icon-plus");
} }
function toggleUserScenarios() { function toggleUserScenarios() {
$("#userScenarios").slideToggle(); $("#userScenarios").slideToggle();
$('#alertMessage').attr("class", "hide"); $('#alertMessage').attr("class", "hide");
$('#userConfigMessage').attr("class", "hide"); $('#userConfigMessage').attr("class", "hide");
if ($("#icon-user").attr("class") == "icon-plus") if ($("#icon-user").attr("class") == "icon-plus")
$("#icon-user").attr("class", "icon-minus"); $("#icon-user").attr("class", "icon-minus");
else else
$("#icon-user").attr("class", "icon-plus"); $("#icon-user").attr("class", "icon-plus");
} }
function toggleIpConfig() { function toggleIpConfig() {
$("#ipConfig").slideToggle(); $("#ipConfig").slideToggle();
$('#ipConfigMessage').attr("class", "hide"); $('#ipConfigMessage').attr("class", "hide");
if ($("#icon-ip").attr("class").indexOf("icon-plus") >= 0) if ($("#icon-ip").attr("class").indexOf("icon-plus") >= 0)
$("#icon-ip").attr("class", "icon-minus"); $("#icon-ip").attr("class", "icon-minus");
else else
$("#icon-ip").attr("class", "icon-plus"); $("#icon-ip").attr("class", "icon-plus");
} }
var scenarioConfigContent; var scenarioConfigContent;
function addScenario() { function addScenario() {
var newTdNode = document.createElement("td"); var newTdNode = document.createElement("td");
var newINode = document.createElement("i"); var newINode = document.createElement("i");
newINode.setAttribute("class", "icon-trash"); newINode.setAttribute("class", "icon-trash");
newINode.setAttribute("style", "cursor:pointer"); newINode.setAttribute("style", "cursor:pointer");
newINode.setAttribute("onClick", "deleteScenarios(this)"); newINode.setAttribute("onClick", "deleteScenarios(this)");
newTdNode.appendChild(newINode); newTdNode.appendChild(newINode);
var lastInputNodeValue; var lastInputNodeValue;
var lengthBeforAddAction = $("#userConfig").find("input").length; var lengthBeforAddAction = $("#userConfig").find("input").length;
lastInputNodeValue = document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction - 1].value; lastInputNodeValue = document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction - 1].value;
if (document.getElementById("userConfig").childNodes.length == 2) { if (document.getElementById("userConfig").childNodes.length == 2) {
scenarioConfigContent = $("#userConfig").html(); scenarioConfigContent = $("#userConfig").html();
document.getElementById("userConfig").innerHTML = $("#userConfig").html()+ scenarioConfigContent; document.getElementById("userConfig").innerHTML = $("#userConfig").html()+ scenarioConfigContent;
var length = $("#userConfig").find("tr").length; var length = $("#userConfig").find("tr").length;
document.getElementById("userConfig").getElementsByTagName("tr")[length - 1].appendChild(newTdNode); document.getElementById("userConfig").getElementsByTagName("tr")[length - 1].appendChild(newTdNode);
} else { } else {
document.getElementById("userConfig").innerHTML =$("#userConfig").html()+ scenarioConfigContent; document.getElementById("userConfig").innerHTML =$("#userConfig").html()+ scenarioConfigContent;
var length = $("#userConfig").find("tr").length; var length = $("#userConfig").find("tr").length;
document.getElementById("userConfig").getElementsByTagName("tr")[length - 1].appendChild(newTdNode); document.getElementById("userConfig").getElementsByTagName("tr")[length - 1].appendChild(newTdNode);
} }
if (lengthBeforAddAction <= 2) { if (lengthBeforAddAction <= 2) {
var allocationLess = parseInt(100 / (lengthBeforAddAction + 1)); var allocationLess = parseInt(100 / (lengthBeforAddAction + 1));
var allocationMore = 100 - parseInt(100 / (lengthBeforAddAction + 1)) var allocationMore = 100 - parseInt(100 / (lengthBeforAddAction + 1))
* lengthBeforAddAction; * lengthBeforAddAction;
for ( var i = 0; i < lengthBeforAddAction; i++) { for ( var i = 0; i < lengthBeforAddAction; i++) {
document.getElementById("userConfig").getElementsByTagName("input")[i] document.getElementById("userConfig").getElementsByTagName("input")[i]
.setAttribute("value", allocationLess); .setAttribute("value", allocationLess);
} }
document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction] document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction]
.setAttribute("value", allocationMore); .setAttribute("value", allocationMore);
} else { } else {
var allocationLess = parseInt(lastInputNodeValue / 2); var allocationLess = parseInt(lastInputNodeValue / 2);
var allocationMore = lastInputNodeValue - allocationLess; var allocationMore = lastInputNodeValue - allocationLess;
document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction - 1] document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction - 1]
.setAttribute("value", allocationLess); .setAttribute("value", allocationLess);
document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction] document.getElementById("userConfig").getElementsByTagName("input")[lengthBeforAddAction]
.setAttribute("value", allocationMore); .setAttribute("value", allocationMore);
} }
if ($("#userConfig").find("input").length == 10) { if ($("#userConfig").find("input").length == 10) {
$("#userScenariosButton").attr("class", $("#userScenariosButton").attr("class",
"btn disabled"); "btn disabled");
$("#userScenariosButton").attr("onClick", $("#userScenariosButton").attr("onClick",
""); "");
} }
changeTotal(); changeTotal();
checkUserScenarios(); checkUserScenarios();
} }
function deleteScenarios(selectedNode) { function deleteScenarios(selectedNode) {
var deleteNode = selectedNode.parentNode.parentNode.parentNode; var deleteNode = selectedNode.parentNode.parentNode.parentNode;
var Node = deleteNode.parentNode; var Node = deleteNode.parentNode;
var previousSiblingNode = deleteNode.previousSibling; var previousSiblingNode = deleteNode.previousSibling;
Node.removeChild(deleteNode); Node.removeChild(deleteNode);
Node.removeChild(previousSiblingNode); Node.removeChild(previousSiblingNode);
if ($("#userConfig").find("input").length < 10) { if ($("#userConfig").find("input").length < 10) {
$("#userScenariosButton").attr("class", $("#userScenariosButton").attr("class",
"btn btn-primary"); "btn btn-primary");
$("#userScenariosButton").attr("onClick", $("#userScenariosButton").attr("onClick",
"addScenario()"); "addScenario()");
} }
changeTotal(); changeTotal();
checkUserScenarios(); checkUserScenarios();
} }
function addIP() { function addIP() {
var th1 = document.createElement("th"); var th1 = document.createElement("th");
var th2 = document.createElement("th"); var th2 = document.createElement("th");
var th3 = document.createElement("th"); var th3 = document.createElement("th");
var textNode = document.createTextNode("IP:"); var textNode = document.createTextNode("IP:");
var inputNode = document.createElement("input"); var inputNode = document.createElement("input");
var tr = document.createElement("tr"); var tr = document.createElement("tr");
//inputNode.attr({type:"text",class:"ip-input",onblur:"checkIP()"}); //inputNode.attr({type:"text",class:"ip-input",onblur:"checkIP()"});
inputNode.setAttribute("type", "text"); inputNode.setAttribute("type", "text");
inputNode.setAttribute("class", "ip-input"); inputNode.setAttribute("class", "ip-input");
inputNode.setAttribute("onblur", "checkIP()"); inputNode.setAttribute("onblur", "checkIP()");
var i = document.createElement("i"); var i = document.createElement("i");
i.setAttribute("class", "icon-trash"); i.setAttribute("class", "icon-trash");
i.setAttribute("style", "cursor:pointer"); i.setAttribute("style", "cursor:pointer");
i.setAttribute("onClick", "deleteIP(this)"); i.setAttribute("onClick", "deleteIP(this)");
th1.appendChild(textNode); th1.appendChild(textNode);
th2.appendChild(inputNode); th2.appendChild(inputNode);
th3.appendChild(i); th3.appendChild(i);
tr.appendChild(th1); tr.appendChild(th1);
tr.appendChild(th2); tr.appendChild(th2);
tr.appendChild(th3); tr.appendChild(th3);
document.getElementById("ipConfigTable").appendChild(tr); document.getElementById("ipConfigTable").appendChild(tr);
checkIP(); checkIP();
} }
function deleteIP(selectedNode) { function deleteIP(selectedNode) {
var deletedNode = selectedNode.parentNode.parentNode; var deletedNode = selectedNode.parentNode.parentNode;
var parentNode = deletedNode.parentNode; var parentNode = deletedNode.parentNode;
parentNode.removeChild(deletedNode); parentNode.removeChild(deletedNode);
checkIP(); checkIP();
} }
function changeTotal() { function changeTotal() {
var inputNode = document.getElementById("userConfig").getElementsByTagName("input"); var inputNode = document.getElementById("userConfig").getElementsByTagName("input");
var total = 0; var total = 0;
var length = inputNode.length; var length = inputNode.length;
for ( var i = 0; i < length; i++) { for ( var i = 0; i < length; i++) {
total = parseInt(total) + parseInt(inputNode[i].value); total = parseInt(total) + parseInt(inputNode[i].value);
} }
document.getElementById("totalNumber").innerHTML = total + "%"; document.getElementById("totalNumber").innerHTML = total + "%";
checkTotalAllocation(); checkTotalAllocation();
} }
function getScriptId(scriptName) { function getScriptId(scriptName) {
var scriptId; var scriptId;
$.ajaxSetup({ $.ajaxSetup({
async : false async : false
}); });
$.post("loadScript", {}, function(data) { $.post("loadScript", {}, function(data) {
if (data.success) { if (data.success) {
data = data.data; data = data.data;
for ( var i = 0; i < data.length; i++) { for ( var i = 0; i < data.length; i++) {
if (data[i].name == scriptName) { if (data[i].name == scriptName) {
scriptId = data[i].id; scriptId = data[i].id;
break; break;
} }
} }
} }
else alert(data.failedMessage); else alert(data.failedMessage);
}); });
return scriptId; return scriptId;
} }
function viewScript(node) { function viewScript(node) {
var scriptId; var scriptId;
var scriptName; var scriptName;
var selectNodes = document.getElementsByName("select"); var selectNodes = document.getElementsByName("select");
var index = node.parentNode.parentNode.rowIndex - 1; var index = node.parentNode.parentNode.rowIndex - 1;
scriptName = selectNodes[index].options[selectNodes[index].selectedIndex].value; scriptName = selectNodes[index].options[selectNodes[index].selectedIndex].value;
scriptId = getScriptId(scriptName); scriptId = getScriptId(scriptName);
window.open("script-edit.jsp?name=" + scriptName + "&scriptId=" + scriptId); window.open("script-edit.jsp?name=" + scriptName + "&scriptId=" + scriptId);
} }
function checkTotalAllocation() { function checkTotalAllocation() {
if (document.getElementById("totalNumber").childNodes[0].nodeValue == "100%") { if (document.getElementById("totalNumber").childNodes[0].nodeValue == "100%") {
$("#totalNumber").attr("class","total-right"); $("#totalNumber").attr("class","total-right");
$("#alertMessage").attr("class", "hide"); $("#alertMessage").attr("class", "hide");
} else { } else {
$("#totalNumber").attr("class","total-false"); $("#totalNumber").attr("class","total-false");
$("#alertMessage").attr("class", "show"); $("#alertMessage").attr("class", "show");
} }
} }
function checkRequireLoad() { function checkRequireLoad() {
if (parseInt($("#RequireLoad").val()) <= 0 if (parseInt($("#RequireLoad").val()) <= 0
|| $("#RequireLoad").val() == "") || $("#RequireLoad").val() == "")
$("#RequireLoad").attr("class", $("#RequireLoad").attr("class",
"load-config-input-alert"); "load-config-input-alert");
else else
$("#RequireLoad").attr("class", $("#RequireLoad").attr("class",
"load-config-input"); "load-config-input");
} }
function checkWarmUp() { function checkWarmUp() {
if (parseInt($("#WarmUp").val()) <= 0 if (parseInt($("#WarmUp").val()) <= 0
|| $("#WarmUp").val() == "") || $("#WarmUp").val() == "")
$("#WarmUp").attr("class", $("#WarmUp").attr("class",
"load-config-input-alert"); "load-config-input-alert");
else else
$("#WarmUp").attr("class", $("#WarmUp").attr("class",
"load-config-input"); "load-config-input");
} }
function checkCoolDown() { function checkCoolDown() {
if (parseInt($("#CoolDown").val()) <= 0 if (parseInt($("#CoolDown").val()) <= 0
|| $("#CoolDown").val() == "") || $("#CoolDown").val() == "")
$("#CoolDown").attr("class", $("#CoolDown").attr("class",
"load-config-input-alert"); "load-config-input-alert");
else else
$("#CoolDown").attr("class", $("#CoolDown").attr("class",
"load-config-input"); "load-config-input");
} }
function checkExecuteRange() { function checkExecuteRange() {
if (parseInt($("#ExecuteRange").val()) <= 0 if (parseInt($("#ExecuteRange").val()) <= 0
|| $("#ExecuteRange").val() == "") || $("#ExecuteRange").val() == "")
$("#ExecuteRange").attr("class", $("#ExecuteRange").attr("class",
"load-config-input-alert"); "load-config-input-alert");
else else
$("#ExecuteRange").attr("class", $("#ExecuteRange").attr("class",
"load-config-input"); "load-config-input");
} }
function checkLoadConfig() { function checkLoadConfig() {
checkExecuteRange(); checkExecuteRange();
checkCoolDown(); checkCoolDown();
checkRequireLoad(); checkRequireLoad();
checkWarmUp(); checkWarmUp();
if ($("#ExecuteRange").attr("class") == "load-config-input" if ($("#ExecuteRange").attr("class") == "load-config-input"
&& $("#CoolDown").attr("class") == "load-config-input" && $("#CoolDown").attr("class") == "load-config-input"
&& $("#WarmUp").attr("class") == "load-config-input" && $("#WarmUp").attr("class") == "load-config-input"
&& $("#RequireLoad").attr("class") == "load-config-input") && $("#RequireLoad").attr("class") == "load-config-input")
$("#loadConfigMessage").attr("class", $("#loadConfigMessage").attr("class",
"hide"); "hide");
else else
$("#loadConfigMessage").attr("class", $("#loadConfigMessage").attr("class",
"show"); "show");
} }
function checkUserScenarios() { function checkUserScenarios() {
var input = $("#userScenarios").find("input"); var input= $("#userScenarios").find("input");
var boolean = 0; var boolean = 0;
var number = 0; var number = 0;
for ( var i = 0; i < input.length; i++) { for ( var i = 0; i < input.length; i++) {
if (input[i].value == "" || parseInt(input[i].value) <= 0) { if (input[i].value == "" || parseInt(input[i].value) <= 0) {
input[i].setAttribute("class", "allocation-input-alert"); input[i].setAttribute("class", "allocation-input-alert");
boolean = 1; boolean = 1;
} else } else
input[i].setAttribute("class", "allocation-input"); input[i].setAttribute("class", "allocation-input");
} }
for ( var k = 0; k < input.length; k++) { for ( var k = 0; k < input.length; k++) {
if ($(input[k]).attr("class") == "allocation-input") if ($(input[k]).attr("class") == "allocation-input")
number++; number++;
} }
if (number == input.length) if (number == input.length)
boolean = 0; boolean = 0;
if (boolean == 1) if (boolean == 1)
$("#userConfigMessage").attr("class", $("#userConfigMessage").attr("class",
"show"); "show");
else else
$("#userConfigMessage").attr("class", $("#userConfigMessage").attr("class",
"hide"); "hide");
} }
function checkIP() { function checkIP() {
var input = $("#ipConfig").find("input"); var input = $("#ipConfig").find("input");
var patrn = /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/; var patrn = /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
var boolean = 0; var boolean = 0;
var number = 0; var number = 0;
for ( var i = 0; i < input.length; i++) { for ( var i = 0; i < input.length; i++) {
if (input[i].value == "" || patrn.exec(input[i].value) == null) { if (input[i].value == "" || patrn.exec(input[i].value) == null) {
input[i].setAttribute("class", "ip-input-alert"); input[i].setAttribute("class", "ip-input-alert");
boolean = 1; boolean = 1;
} else } else
input[i].setAttribute("class", "ip-input"); input[i].setAttribute("class", "ip-input");
} }
for ( var k = 0; k < input.length; k++) { for ( var k = 0; k < input.length; k++) {
if (input[k].getAttribute("class") == "ip-input") if (input[k].getAttribute("class") == "ip-input")
number++; number++;
} }
if (number == input.length) if (number == input.length)
boolean = 0; boolean = 0;
if (boolean == 1) if (boolean == 1)
$("#ipConfigMessage") $("#ipConfigMessage")
.attr("class", "show"); .attr("class", "show");
else else
$("#ipConfigMessage") $("#ipConfigMessage")
.attr("class", "hide"); .attr("class", "hide");
} }
function checkName() { function checkName() {
if ($("#testConfigurationName").val() == "") { if ($("#testConfigurationName").val() == "") {
$("#testConfigurationName").attr("class", $("#testConfigurationName").attr("class",
"name-input-alert"); "name-input-alert");
$("#nameMessage").attr("class", "show"); $("#nameMessage").attr("class", "show");
} else { } else {
$("#testConfigurationName").attr("class", $("#testConfigurationName").attr("class",
"name-input"); "name-input");
$("#nameMessage").attr("class", "hide"); $("#nameMessage").attr("class", "hide");
} }
} }
function checkAllInpute() { function checkAllInpute() {
checkLoadConfig(); checkLoadConfig();
checkUserScenarios(); checkUserScenarios();
checkIP(); checkIP();
checkName(); checkName();
} }
function loadSchedulePlot() { function loadSchedulePlot() {
var options = { var options = {
chart : { chart : {
renderTo : 'highchartsPlot', renderTo : 'highchartsPlot',
defaultSeriesType : 'line', defaultSeriesType : 'line',
type : 'area', type : 'area',
height : 300, height : 300,
}, },
plotOptions : { plotOptions : {
series : { series : {
fillOpacity : 0.5, fillOpacity : 0.5,
} }
}, },
credits : { credits : {
enabled : false enabled : false
}, },
legend : { legend : {
enabled : false enabled : false
}, },
title : { title : {
text : 'Load Schedule', text : 'Load Schedule',
x : -50 x : -50
}, },
xAxis : { xAxis : {
categories : [ 0 ], categories : [ 0 ],
min : 0, min : 0,
}, },
yAxis : { yAxis : {
plotLines : [ { plotLines : [ {
value : 0, value : 0,
width : 1, width : 1,
color : '#808080' color : '#808080'
} ], } ],
min : 0 min : 0
}, },
tooltip : { tooltip : {
formatter : function() { formatter : function() {
return '<b>' + 'Load Schedule' + '</b><br/>' + this.y return '<b>' + 'Load Schedule' + '</b><br/>' + this.y
+ 'users after' + this.x + 'seconds'; + 'users after' + this.x + 'seconds';
} }
}, },
series : [ { series : [ {
data : [ 0 ] data : [ 0 ]
} ] } ]
}; };
var RequireLoad = parseInt($("#RequireLoad").val()); var RequireLoad = parseInt($("#RequireLoad").val());
var WarmUp = parseInt($("#WarmUp").val()); var WarmUp = parseInt($("#WarmUp").val());
var CoolDown = parseInt($("#CoolDown").val()); var CoolDown = parseInt($("#CoolDown").val());
var ExecuteRange = parseInt($("#ExecuteRange").val()); var ExecuteRange = parseInt($("#ExecuteRange").val());
options.xAxis.categories.push(WarmUp); options.xAxis.categories.push(WarmUp);
options.xAxis.categories.push(WarmUp + ExecuteRange); options.xAxis.categories.push(WarmUp + ExecuteRange);
options.xAxis.categories.push(WarmUp + ExecuteRange + CoolDown); options.xAxis.categories.push(WarmUp + ExecuteRange + CoolDown);
options.series[0].data.push(RequireLoad); options.series[0].data.push(RequireLoad);
options.series[0].data.push(RequireLoad); options.series[0].data.push(RequireLoad);
options.series[0].data.push(0); options.series[0].data.push(0);
var chart = new Highcharts.Chart(options); var chart = new Highcharts.Chart(options);
} }
function ScriptModel(ID, load, warmup, cooldown, executeRange) { function ScriptModel(ID, load, warmup, cooldown, executeRange) {
this.id = ID; this.id = ID;
this.load = load; this.load = load;
this.warmup = warmup; this.warmup = warmup;
this.executeRange = executeRange; this.executeRange = executeRange;
this.cooldown = cooldown; this.cooldown = cooldown;
} }
TestPlanRequestModel = function(scriptList, ipList, testPlanName) { TestPlanRequestModel = function(scriptList, ipList, testPlanName) {
this.scriptList = scriptList; this.scriptList = scriptList;
this.ipList = ipList; this.ipList = ipList;
this.testPlanName = testPlanName; this.testPlanName = testPlanName;
}; };
function getIpList() { function getIpList() {
var inputNode = $("#ipConfig").find("input"); var inputNode = $("#ipConfig").find("input");
var length = inputNode.length; var length = inputNode.length;
var ipList = new Array(); var ipList = new Array();
for ( var i = 0; i < length; i++) for ( var i = 0; i < length; i++)
ipList.push(inputNode[i].value); ipList.push(inputNode[i].value);
return ipList; return ipList;
} }
function getScriptIdList() { function getScriptIdList() {
var select =$("#userScenarios").find("select"); var select =$("#userScenarios").find("select");
var scriptNameList = new Array(); var scriptNameList = new Array();
var scriptIdList = new Array(); var scriptIdList = new Array();
for ( var i = 0; i < select.length; i++) for ( var i = 0; i < select.length; i++)
scriptNameList.push(select[i].options[select[i].selectedIndex].value); scriptNameList.push(select[i].options[select[i].selectedIndex].value);
for ( var j = 0; j < select.length; j++) for ( var j = 0; j < select.length; j++)
scriptIdList.push(getScriptId(scriptNameList[j])); scriptIdList.push(getScriptId(scriptNameList[j]));
return scriptIdList; return scriptIdList;
} }
function start() { function start() {
var scriptList = new Array(); var scriptList = new Array();
var ipList = new Array(); var ipList = new Array();
ipList = getIpList(); ipList = getIpList();
var input = $("#userScenarios").find("input"); var input = $("#userScenarios").find("input");
var allocationList = new Array(); var allocationList = new Array();
var loadList = new Array(); var loadList = new Array();
var requireLoad = parseInt($("#RequireLoad").val()); var requireLoad = parseInt($("#RequireLoad").val());
var scriptList = new Array(); var scriptList = new Array();
var scriptIdList = new Array(); var scriptIdList = new Array();
var warmUp = parseInt($("#WarmUp").val()); var warmUp = parseInt($("#WarmUp").val());
var coolDown = parseInt($("#CoolDown").val()); var coolDown = parseInt($("#CoolDown").val());
var executeRange = parseInt($("#ExecuteRange").val()); var executeRange = parseInt($("#ExecuteRange").val());
for ( var i = 0; i < input.length; i++) for ( var i = 0; i < input.length; i++)
allocationList.push(parseInt(input[i].value)); allocationList.push(parseInt(input[i].value));
for ( var j = 0; j < input.length; j++) for ( var j = 0; j < input.length; j++)
loadList.push(parseInt(requireLoad * allocationList[j] / 100)); loadList.push(parseInt(requireLoad * allocationList[j] / 100));
scriptIdList = getScriptIdList(); scriptIdList = getScriptIdList();
for ( var k = 0; k < input.length; k++) for ( var k = 0; k < input.length; k++)
scriptList.push(new ScriptModel(scriptIdList[k], loadList[k], warmUp, scriptList.push(new ScriptModel(scriptIdList[k], loadList[k], warmUp,
coolDown, executeRange)); coolDown, executeRange));
var name = $("#testConfigurationName").val(); var name = $("#testConfigurationName").val();
var testPlan = new TestPlanRequestModel(scriptList, ipList, name); var testPlan = new TestPlanRequestModel(scriptList, ipList, name);
$.ajax({ $.ajax({
type : "POST", type : "POST",
url : "runTestPlan", url : "runTestPlan",
contentType : "application/json", contentType : "application/json",
data : JSON.stringify(testPlan), data : JSON.stringify(testPlan),
success : function(data) { success : function(data) {
if (data.success) if (data.success)
window.location.replace("testPlanTask.jsp"); window.location.replace("testPlanTask.jsp");
else else
alert(data.failedMessage); alert(data.failedMessage);
}, },
error : function(request, status, error) { error : function(request, status, error) {
} }
}); });
} }
function startTest() { function startTest() {
checkAllInpute(); checkAllInpute();
if ($("#nameMessage").attr("class") == "hide" if ($("#nameMessage").attr("class") == "hide"
&& $("#loadConfigMessage").attr( && $("#loadConfigMessage").attr(
"class") == "hide" "class") == "hide"
&& $("#alertMessage").attr("class") == "hide" && $("#alertMessage").attr("class") == "hide"
&& $("#userConfigMessage").attr( && $("#userConfigMessage").attr(
"class") == "hide" "class") == "hide"
&& $("#ipConfigMessage").attr("class") == "hide") && $("#ipConfigMessage").attr("class") == "hide")
start(); start();
} }
function createNewScript(){ function createNewScript(){
window.open("script.jsp"); window.open("script.jsp");
} }

View File

@ -1,32 +1,8 @@
var files; var files;
var file1; var file1;
var fileList = new Array(); var fileList = [];
var fileNames = [];
test("upload files and other data", function() {
uploadFilesAndScript();
});
// function submitFiles() {
// var formData = new FormData();
// var file1 = $('#id1').files[0];
// var file2 = $('#id2').files[0];
// var fileList = new Array();
// fileList.push(file1);
// fileList.push(file2);
// formData.append("script", file1.files[0]);
// formData.append("scriptName", "testUploadFiles");
// formData.append("paramFiles", fileList);
// $.ajax({
// url : "uploadScript",
// type : "POST",
// data : formData,
// processData : false, // tell jQuery not to process the data
// contentType : false, // tell jQuery not to set contentType
// success : function(data) {
// alert(data);
// }
// });
// }
$(function() { $(function() {
$("input[type=submit]").click(function() { $("input[type=submit]").click(function() {
submit(); submit();
@ -37,16 +13,25 @@ function submit() {
uploadFilesAndScript(); uploadFilesAndScript();
} }
function uploadFilesAndScript() { function uploadFilesAndScript() {
var form = document.createElement("form"); var formData=new FormData();
$(form).attr("name", "fileUpload"); var filesDiv=$("input[type=file]");
$("body").append($(form)); for(var i=0;i<filesDiv.length;i++){
$(form).append($("#param"));
var formData = new FormData(form); formData.append("paramFiles",filesDiv[i].files[0],filesDiv[i].files[0].name);
formData.append("content", ""); }
var oReq = new XMLHttpRequest();
oReq.open("POST", "../uploadEditScript"); formData.append("content","");
oReq.send(formData);
alert(oReq.responseText); $.ajax({
url : "/uploadEditedScipt",
type : "POST",
contentType:false,
processData:false,
data : formData,
success : function(data) {
alert(data);
}
});
} }
function createFileInput(fileList) { function createFileInput(fileList) {
@ -56,20 +41,7 @@ function createFileInput(fileList) {
lable.text("test"); lable.text("test");
input.attr("type", "file"); input.attr("type", "file");
input.attr("name", "file"); input.attr("name", "file");
input.attr("id","param"); input.attr("id", "param");
fileContainer.append(lable); fileContainer.append(lable);
fileContainer.append(input); fileContainer.append(input);
input.change(function(event) {
$.each(event.target.files, function(index, file) {
var reader = new FileReader();
reader.onload = function(event) {
object = new Object();
object.filename = file.name;
object.data = event.target.result;
fileList.push(object);
};
reader.readAsText(file);
console.log(file.name);
});
});
} }

View File

@ -0,0 +1,17 @@
function upload(){
var files= document.getElementById("file");
var file=files.files[0];
// var file=$("#file").files[0];
console.log("fileName: " + file.name);
var url="/upload";
$.post(url,{script:file},function(data){
alert(data);
}," multipart/form-data")
};
$(function(){
$("#upload").click(function(e){
upload();
});
});

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>upload file</title>
<link rel="stylesheet"
href="http://code.jquery.com/qunit/qunit-1.14.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div>
<input type="file" id="file"> <input type="submit"
value="Upload" id="upload">
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js"></script>
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
<script src="js/uploadFile.js"></script>
</body>
</html>