refactor the test history and getdata and js

This commit is contained in:
wxr 2014-02-20 08:35:04 +08:00
parent 687e770416
commit f63a329dd1
19 changed files with 260 additions and 240 deletions

View File

@ -22,4 +22,4 @@
<outputDirectory>/</outputDirectory> <outputDirectory>/</outputDirectory>
</file> </file>
</files> </files>
</assembly> </assembly>

View File

@ -1,6 +1,5 @@
package org.bench4q.web.TestPlan; package org.bench4q.web.TestPlan;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -12,10 +11,11 @@ import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanResultModel; import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.web.exception.CustomGenericException; import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange; import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
import org.bench4q.web.model.RunningScriptInfoModel;
import org.bench4q.web.service.BaseService; import org.bench4q.web.service.BaseService;
import org.bench4q.web.service.CommunicateWithMaster; import org.bench4q.web.service.CommunicateWithMaster;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class TestPlanInfo { public class TestPlanInfo {
private CommunicateWithMaster communicateWithMaster; private CommunicateWithMaster communicateWithMaster;
private String baseUrl=BaseService.getMasterIP()+"testPlan"; private String baseUrl=BaseService.getMasterIP()+"testPlan";

View File

@ -7,33 +7,25 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel; import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanBusinessModel;
import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanResultModel; import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.TestScriptConfig;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel; import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
import org.bench4q.web.TestPlan.RunTestPlan; import org.bench4q.web.TestPlan.RunTestPlan;
import org.bench4q.web.TestPlan.TestPlanInfo; import org.bench4q.web.TestPlan.TestPlanInfo;
import org.bench4q.web.exception.CustomGenericException; import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
import org.bench4q.web.model.*; import org.bench4q.web.model.*;
import org.bench4q.web.service.CommunicateWithMaster; import org.bench4q.web.service.CommunicateWithMaster;
import org.bench4q.web.service.MonitorDescriptionInfoService; import org.bench4q.web.service.MonitorDescriptionInfoService;
import org.bench4q.web.service.TestPlanService; import org.bench4q.web.service.TestPlanService;
import org.eclipse.jetty.util.HttpCookieStore.Empty;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
@ -265,8 +257,8 @@ public class TestPlanActionController extends BaseControllerService {
throws CustomGenericException, NoSuchFieldException { throws CustomGenericException, NoSuchFieldException {
String caller = "TestPlanActionController:getScriptBriefStatus"; String caller = "TestPlanActionController:getScriptBriefStatus";
if (!validateInput(testPlanId) || !validateInput(scriptId)) { if (!validateInput(testPlanId) || !validateInput(scriptId)) {
throw new CustomGenericException("0", return new BaseResponseModel(false, caller
"invalidate scriptid or testplanid", caller); + "invalidate scriptid or testplanid");
} }
String url = this.getBaseUrl() + "/scriptBrief" + "/" + testPlanId String url = this.getBaseUrl() + "/scriptBrief" + "/" + testPlanId
+ "/" + scriptId + "/" + startTime; + "/" + scriptId + "/" + startTime;
@ -288,8 +280,8 @@ public class TestPlanActionController extends BaseControllerService {
String url = this.getBaseUrl() + "/getBehaviorsBrief" + "/" String url = this.getBaseUrl() + "/getBehaviorsBrief" + "/"
+ testPlanId + "/" + scriptId; + testPlanId + "/" + scriptId;
if (!validateInput(testPlanId) || !validateInput(scriptId)) { if (!validateInput(testPlanId) || !validateInput(scriptId)) {
throw new CustomGenericException("0", return new BaseResponseModel(false, caller
"invalidate scriptid or testplanid", caller); + ":invalidate scriptid or testplanid:");
} }
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = (ScriptBehaviorsBriefModel) this ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = (ScriptBehaviorsBriefModel) this
.getCommunicateWithMaster().getResponseModel(accessToken, url, .getCommunicateWithMaster().getResponseModel(accessToken, url,
@ -314,14 +306,16 @@ public class TestPlanActionController extends BaseControllerService {
return new BaseResponseModel(true, scriptPagesBriefModel); return new BaseResponseModel(true, scriptPagesBriefModel);
} }
@SuppressWarnings("unchecked")
@RequestMapping("/{testPlanId}/urlContentTypeDistribution") @RequestMapping("/{testPlanId}/urlContentTypeDistribution")
@ResponseBody @ResponseBody
public List<UrlContentTypeDistributionModel> getUrlContentTypeDistribution( public BaseResponseModel getUrlContentTypeDistribution(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@PathVariable String testPlanId) throws CustomGenericException { @PathVariable String testPlanId) throws CustomGenericException,
JAXBException {
List<UrlContentTypeDistributionModel> urlContentTypeDistributionModels = new ArrayList<UrlContentTypeDistributionModel>(); List<UrlContentTypeDistributionModel> urlContentTypeDistributionModels = new ArrayList<UrlContentTypeDistributionModel>();
Map<String, Long> urlContentTypeCountMap = getUrlContentTypeCount( Map<String, Long> urlContentTypeCountMap = (Map<String, Long>)getUrlContentTypeCount(
accessToken, testPlanId); accessToken, testPlanId).getData();
long totalCount = this.getTestPlanService().getTotalCount( long totalCount = this.getTestPlanService().getTotalCount(
urlContentTypeCountMap); urlContentTypeCountMap);
Map<String, Double> urlContentTypePercentMap = this Map<String, Double> urlContentTypePercentMap = this
@ -336,77 +330,80 @@ public class TestPlanActionController extends BaseControllerService {
urlContentTypeCountMap.get(key), urlContentTypeCountMap.get(key),
urlContentTypePercentMap.get(key))); urlContentTypePercentMap.get(key)));
} }
return urlContentTypeDistributionModels; return new BaseResponseModel(true, urlContentTypeDistributionModels);
} }
@SuppressWarnings("unchecked")
@RequestMapping("/{testPlanId}/urlContentTypePercent") @RequestMapping("/{testPlanId}/urlContentTypePercent")
@ResponseBody @ResponseBody
public Map<String, Double> getUrlContentTypePercent( public BaseResponseModel getUrlContentTypePercent(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@PathVariable String testPlanId) throws CustomGenericException { @PathVariable String testPlanId) throws CustomGenericException,
Map<String, Long> urlContentTypeCountMap = getUrlContentTypeCount( JAXBException {
accessToken, testPlanId); Map<String, Long> urlContentTypeCountMap =(Map<String, Long>) getUrlContentTypeCount(
accessToken, testPlanId).getData();
long totalCount = this.getTestPlanService().getTotalCount( long totalCount = this.getTestPlanService().getTotalCount(
urlContentTypeCountMap); urlContentTypeCountMap);
return this.getTestPlanService().getUrlContentTypePercent(
urlContentTypeCountMap, totalCount);
return new BaseResponseModel(true, this.getTestPlanService()
.getUrlContentTypePercent(urlContentTypeCountMap, totalCount));
} }
@RequestMapping("/{testPlanId}/urlContentTypeCount") @RequestMapping("/{testPlanId}/urlContentTypeCount")
@ResponseBody @ResponseBody
public Map<String, Long> getUrlContentTypeCount( public BaseResponseModel getUrlContentTypeCount(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@PathVariable String testPlanId) throws CustomGenericException { @PathVariable String testPlanId) throws CustomGenericException,
JAXBException {
Map<String, Long> urlContentCountMap = new HashMap<String, Long>(); Map<String, Long> urlContentCountMap = new HashMap<String, Long>();
try {
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : getBehaviorStatusCodeResultModels(
accessToken, testPlanId)) {
if (urlContentCountMap.get(behaviorStatusCodeResultModel
.getContentType()) == null)
urlContentCountMap.put(
behaviorStatusCodeResultModel.getContentType(),
behaviorStatusCodeResultModel.getCount());
else {
long originalValue = urlContentCountMap
.get(behaviorStatusCodeResultModel.getContentType());
urlContentCountMap.put(
behaviorStatusCodeResultModel.getContentType(),
originalValue
+ behaviorStatusCodeResultModel.getCount());
}
for (BehaviorStatusCodeResultModel behaviorStatusCodeResultModel : getBehaviorStatusCodeResultModels(
accessToken, testPlanId)) {
if (urlContentCountMap.get(behaviorStatusCodeResultModel
.getContentType()) == null)
urlContentCountMap.put(
behaviorStatusCodeResultModel.getContentType(),
behaviorStatusCodeResultModel.getCount());
else {
long originalValue = urlContentCountMap
.get(behaviorStatusCodeResultModel.getContentType());
urlContentCountMap.put(
behaviorStatusCodeResultModel.getContentType(),
originalValue
+ behaviorStatusCodeResultModel.getCount());
} }
return urlContentCountMap;
} catch (NullPointerException e) {
e.printStackTrace();
return null;
} }
return new BaseResponseModel(true, urlContentCountMap);
} }
@RequestMapping("/{testPlanId}/testBriefStatus/{startTime}") @RequestMapping("/{testPlanId}/testBriefStatus/{startTime}")
@ResponseBody @ResponseBody
public TestBriefStatusModel getTotalRequest( public BaseResponseModel getTotalRequest(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@PathVariable String testPlanId, @PathVariable String startTime) @PathVariable String testPlanId, @PathVariable String startTime)
throws CustomGenericException { throws CustomGenericException, JAXBException {
String caller = this.BASECALLER + "getTotalRequest";
if (!validateInput(testPlanId)) { if (!validateInput(testPlanId)) {
System.out.println("invalidate input testPlanId or scriptId"); return new BaseResponseModel(false, caller
return null; + " :testplanId is invalidate:" + testPlanId);
} }
TestBriefStatusModel testBriefStatusModel = new TestBriefStatusModel(); TestBriefStatusModel testBriefStatusModel = new TestBriefStatusModel();
long vus = 0; long vus = 0;
long requests = 0; long requests = 0;
Date time = new Date(0); Date time = new Date(0);
try { if (this.getTestPlanInfo()
for (RunningScriptInfoModel runningScriptInfoModel : this .getTestPlanInfoFromDB(accessToken, testPlanId, caller)
.getTestPlanScriptInfo(accessToken, testPlanId).getData()) { .getRunningScriptModels() == null)
throw new CustomGenericException("5", caller
+ " :scripts in testPlan is empty", caller);
for (RunningScriptModel runningScriptModel : this.getTestPlanInfo()
.getTestPlanInfoFromDB(accessToken, testPlanId, caller)
.getRunningScriptModels()) {
ScriptBriefResultModel lastScriptBriefResultModel = getLastScriptBriefModel( ScriptBriefResultModel lastScriptBriefResultModel = getLastScriptBriefModel(
accessToken, testPlanId, startTime, accessToken, testPlanId, startTime, runningScriptModel);
runningScriptInfoModel);
requests += lastScriptBriefResultModel requests += lastScriptBriefResultModel
.getTotalFailCountFromBegin() .getTotalFailCountFromBegin()
+ lastScriptBriefResultModel + lastScriptBriefResultModel
@ -418,42 +415,35 @@ public class TestPlanActionController extends BaseControllerService {
testBriefStatusModel.setRequests(requests); testBriefStatusModel.setRequests(requests);
testBriefStatusModel.setVus(vus); testBriefStatusModel.setVus(vus);
testBriefStatusModel.setTime(time); testBriefStatusModel.setTime(time);
return testBriefStatusModel; return new BaseResponseModel(true, testBriefStatusModel);
} catch (NullPointerException e) {
e.printStackTrace();
return null;
}
} }
private ScriptBriefResultModel getLastScriptBriefModel(String accessToken, private ScriptBriefResultModel getLastScriptBriefModel(String accessToken,
String testPlanId, String startTime, String testPlanId, String startTime,
RunningScriptInfoModel runningScriptInfoModel) RunningScriptModel runningScriptModel)
throws CustomGenericException { throws CustomGenericException {
String caller = "TestPlanActionController:getLastScriptBriefModel"; String caller = "TestPlanActionController:getLastScriptBriefModel";
try { String[] paths = new String[] { "scriptBrief", testPlanId,
String[] paths = new String[] { new Integer(runningScriptModel.getScriptId()).toString(),
"scriptBrief", startTime };
testPlanId,
new Integer(runningScriptInfoModel.getScriptId())
.toString(), startTime };
String url = generateUrl(this.getBaseUrl(), paths); String url = generateUrl(this.getBaseUrl(), paths);
TestPlanScriptBriefResultModel testPlanScriptBriefResultModel = (TestPlanScriptBriefResultModel) this TestPlanScriptBriefResultModel testPlanScriptBriefResultModel = (TestPlanScriptBriefResultModel) this
.getTestPlanService() .getTestPlanService()
.getCommunicateWithMaster() .getCommunicateWithMaster()
.getResponseModel(accessToken, url, .getResponseModel(accessToken, url,
TestPlanScriptBriefResultModel.class, null, caller); TestPlanScriptBriefResultModel.class, null, caller);
if(testPlanScriptBriefResultModel.getScriptBriefResultModels()==null)
throw new CustomGenericException("5", "script result empty", caller);
int lastScriptBriefResultIndex = testPlanScriptBriefResultModel int lastScriptBriefResultIndex = testPlanScriptBriefResultModel
.getScriptBriefResultModels().size(); .getScriptBriefResultModels().size();
if (lastScriptBriefResultIndex == 0) if (lastScriptBriefResultIndex == 0)
return null; throw new CustomGenericException("5", "script result empty", caller);
ScriptBriefResultModel lastScriptBriefResultModel = testPlanScriptBriefResultModel ScriptBriefResultModel lastScriptBriefResultModel = testPlanScriptBriefResultModel
.getScriptBriefResultModels().get( .getScriptBriefResultModels().get(
lastScriptBriefResultIndex - 1); lastScriptBriefResultIndex - 1);
return lastScriptBriefResultModel; return lastScriptBriefResultModel;
} catch (NullPointerException e) {
e.printStackTrace();
return null;
}
} }
private String generateUrl(String baseUrl, String[] paths) { private String generateUrl(String baseUrl, String[] paths) {
@ -466,30 +456,29 @@ public class TestPlanActionController extends BaseControllerService {
private List<BehaviorStatusCodeResultModel> getBehaviorStatusCodeResultModels( private List<BehaviorStatusCodeResultModel> getBehaviorStatusCodeResultModels(
String accessToken, String testPlanId) String accessToken, String testPlanId)
throws CustomGenericException { throws CustomGenericException, JAXBException {
String caller="getBehaviorStatusCodeResultModels"; String caller = "getBehaviorStatusCodeResultModels";
List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>(); List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>();
try { List<RunningScriptModel> runningScriptModels = this.getTestPlanInfo()
for (RunningScriptModel runningScriptModel : this .getTestPlanInfoFromDB(accessToken, testPlanId, caller)
.getTestPlanInfo().getTestPlanInfoFromDB(accessToken, .getRunningScriptModels();
testPlanId, caller).getRunningScriptModels()) { if (runningScriptModels == null)
ScriptBehaviorsBriefModel scriptBehaviorBriefModel = getScriptBehaviorBriefModel( throw new CustomGenericException("5",
accessToken, testPlanId, "scripts in testPlan is empty", caller);
runningScriptModel.getScriptId() for (RunningScriptModel runningScriptModel : this.getTestPlanInfo()
); .getTestPlanInfoFromDB(accessToken, testPlanId, caller)
if (this.getTestPlanService() .getRunningScriptModels()) {
.getBehaviorStatusCodeResultModels( ScriptBehaviorsBriefModel scriptBehaviorBriefModel = (ScriptBehaviorsBriefModel) getScriptBehaviorBriefModel(
scriptBehaviorBriefModel) != null) accessToken, testPlanId,
behaviorStatusCodeResultModels.addAll(this new Integer(runningScriptModel.getScriptId()).toString())
.getTestPlanService() .getData();
behaviorStatusCodeResultModels
.addAll(this.getTestPlanService()
.getBehaviorStatusCodeResultModels( .getBehaviorStatusCodeResultModels(
scriptBehaviorBriefModel)); scriptBehaviorBriefModel));
}
return behaviorStatusCodeResultModels;
} catch (NullPointerException e) {
e.printStackTrace();
return null;
} }
return behaviorStatusCodeResultModels;
} }
} }

View File

@ -9,10 +9,14 @@ import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.models.ErrorResponseModel;
import org.bench4q.share.models.master.TestPlanDBModel; import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanResponseModel; import org.bench4q.share.models.master.TestPlanResponseModel;
import org.bench4q.web.exception.CustomGenericException; import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
import org.bench4q.web.model.BaseResponseModel;
import org.bench4q.web.model.TestPlanListModel; import org.bench4q.web.model.TestPlanListModel;
import org.bench4q.web.service.CommunicateWithMaster;
import org.bench4q.web.service.TestPlanService; import org.bench4q.web.service.TestPlanService;
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;
@ -29,6 +33,14 @@ import org.springframework.web.bind.annotation.SessionAttributes;
public class TestPlanHistoryResult extends BaseControllerService { public class TestPlanHistoryResult extends BaseControllerService {
private String baseUrl = this.masterIP + "testPlan"; private String baseUrl = this.masterIP + "testPlan";
private TestPlanService testPlanService; private TestPlanService testPlanService;
private CommunicateWithMaster communicateWithMaster;
private CommunicateWithMaster getCommunicateWithMaster() {
return communicateWithMaster;
}
@Autowired
private void setCommunicateWithMaster(CommunicateWithMaster communicateWithMaster) {
this.communicateWithMaster = communicateWithMaster;
}
public String getBaseUrl() { public String getBaseUrl() {
return baseUrl; return baseUrl;
@ -50,7 +62,8 @@ public class TestPlanHistoryResult extends BaseControllerService {
@RequestMapping(value = "loadTestPlans", method = { RequestMethod.GET, @RequestMapping(value = "loadTestPlans", method = { RequestMethod.GET,
RequestMethod.POST }) RequestMethod.POST })
@ResponseBody @ResponseBody
public TestPlanListModel loadTestPlans( public BaseResponseModel
loadTestPlans(
@ModelAttribute("accessToken") String accessToken) @ModelAttribute("accessToken") String accessToken)
throws CustomGenericException { throws CustomGenericException {
System.out.println("enter loadTestPlans"); System.out.println("enter loadTestPlans");
@ -62,12 +75,10 @@ public class TestPlanHistoryResult extends BaseControllerService {
.getResponseModel(accessToken, url, .getResponseModel(accessToken, url,
TestPlanResponseModel.class, null, caller); TestPlanResponseModel.class, null, caller);
if (testPlanResponseModel.isSuccess()) { if (testPlanResponseModel.isSuccess()) {
System.out.println(SUCCESS); return new BaseResponseModel(true,buildTestPlanListModel(testPlanResponseModel
return buildTestPlanListModel(testPlanResponseModel .getTestPlanDBModels()));
.getTestPlanDBModels());
} else { } else {
System.err.println(FAIL); return new BaseResponseModel(false,testPlanResponseModel.getFailCause());
return null;
} }
} }
@ -79,22 +90,27 @@ public class TestPlanHistoryResult extends BaseControllerService {
@RequestMapping(value = "downloadReport", method = { RequestMethod.GET, @RequestMapping(value = "downloadReport", method = { RequestMethod.GET,
RequestMethod.POST }) RequestMethod.POST })
public void downloadReport(HttpServletResponse response, public BaseResponseModel downloadReport(HttpServletResponse response,
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@RequestParam String testPlanId) { @RequestParam String testPlanId) throws CustomGenericException {
String caller="TestPlanHistory:downloadReport";
try { try {
System.out.println("enter download report");
HttpResponse httpResponse = this.getHttpRequester().sendGet( HttpResponse httpResponse = this.getHttpRequester().sendGet(
this.getBaseUrl() + "/getTestPlanReport", this.getBaseUrl() + "/getTestPlanReport",
makeParamsMap("testPlanRunID", testPlanId), makeParamsMap("testPlanRunID", testPlanId),
this.makeAccessTockenMap(accessToken)); this.makeAccessTockenMap(accessToken));
if (httpResponse == null || httpResponse.getContent().isEmpty()) { if (httpResponse == null || httpResponse.getContent().isEmpty()) {
return; throw new CustomGenericException("1", "invalidate http response", caller);
} }
if (httpResponse.getCode() == HttpStatus.BAD_REQUEST_400) { if (httpResponse.getCode() == HttpStatus.BAD_REQUEST_400) {
this.getProcessHttpReponse().processBadRequest(httpResponse); ErrorResponseModel errorResponseModel = (ErrorResponseModel) ObjectXmlExchange
return; .fromXml(ErrorResponseModel.class,
httpResponse.getContent());
this.getCommunicateWithMaster().logException(errorResponseModel);
throw new CustomGenericException("2", FAIL_WITH_EXCEPTION + "_"
+ errorResponseModel.getMessage(), caller + "_"
+ errorResponseModel.getResource());
} }
byte[] pdfBuffer = httpResponse.getContent().getBytes(); byte[] pdfBuffer = httpResponse.getContent().getBytes();
ServletOutputStream outputStream = response.getOutputStream(); ServletOutputStream outputStream = response.getOutputStream();
@ -108,21 +124,19 @@ public class TestPlanHistoryResult extends BaseControllerService {
outputStream.write(pdfBuffer); outputStream.write(pdfBuffer);
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
System.out.println("finish download report"); return new BaseResponseModel(true);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); throw new CustomGenericException("1", "exception:io exception", caller);
return;
} catch (JAXBException e) { } catch (JAXBException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); throw new CustomGenericException("1", "exception:io exception", caller);
return;
} }
} }
@RequestMapping(value = "deleteTest", method = { RequestMethod.GET, @RequestMapping(value = "deleteTest", method = { RequestMethod.GET,
RequestMethod.POST }) RequestMethod.POST })
@ResponseBody @ResponseBody
public Boolean deleteTest(HttpServletResponse response, public BaseResponseModel deleteTest(HttpServletResponse response,
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@RequestParam String testPlanId) throws CustomGenericException { @RequestParam String testPlanId) throws CustomGenericException {
String url = this.getBaseUrl() + "/removeTestPlanFromPool"; String url = this.getBaseUrl() + "/removeTestPlanFromPool";
@ -134,14 +148,13 @@ public class TestPlanHistoryResult extends BaseControllerService {
.getCommunicateWithMaster() .getCommunicateWithMaster()
.getResponseModel(accessToken, url, .getResponseModel(accessToken, url,
TestPlanResponseModel.class, params, caller); TestPlanResponseModel.class, params, caller);
if (testPlanResponseModel == null)
return false;
if (testPlanResponseModel.isSuccess()) { if (testPlanResponseModel.isSuccess()) {
System.out.println(SUCCESS);
return true; return new BaseResponseModel(true);
} else { } else {
System.err.println(FAIL);
return false; return new BaseResponseModel(false,testPlanResponseModel.getFailCause());
} }
} }

View File

@ -12,7 +12,6 @@ import java.util.Properties;
import org.bench4q.web.api.BaseControllerService; import org.bench4q.web.api.BaseControllerService;
import org.bench4q.web.model.ResultInfoModel; import org.bench4q.web.model.ResultInfoModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component

View File

@ -159,7 +159,7 @@ public class CommunicateWithMaster {
return properties; return properties;
} }
private void logException(ErrorResponseModel errorResponseModel) { public void logException(ErrorResponseModel errorResponseModel) {
logger.info(FAIL_WITH_EXCEPTION); logger.info(FAIL_WITH_EXCEPTION);
logger.info("Exception code:" + errorResponseModel.getCode()); logger.info("Exception code:" + errorResponseModel.getCode());
logger.info("Exception message:" + errorResponseModel.getMessage()); logger.info("Exception message:" + errorResponseModel.getMessage());

View File

@ -15,7 +15,6 @@ import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel; import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
@ -30,19 +29,16 @@ import org.springframework.web.bind.annotation.SessionAttributes;
@Component @Component
@SessionAttributes({ "accessToken", "testPlanTaskList" }) @SessionAttributes({ "accessToken", "testPlanTaskList" })
public class TestPlanService extends BaseService { public class TestPlanService extends BaseService {
private final String baseUrl = BaseService.getMasterIP() + "testPlan";
/*private final String BASECALLER = "TestPlanService:";
private String getBaseUrl() { /*
return baseUrl; * private final String BASECALLER = "TestPlanService:";
} *
*/ * private String getBaseUrl() { return baseUrl; }
*/
public TestPlanService() { public TestPlanService() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public ResultInfoModel getScriptBriefStatusResultInfo() { public ResultInfoModel getScriptBriefStatusResultInfo() {
String result = "briefStatus"; String result = "briefStatus";
@ -354,22 +350,15 @@ public class TestPlanService extends BaseService {
public List<BehaviorStatusCodeResultModel> getBehaviorStatusCodeResultModels( public List<BehaviorStatusCodeResultModel> getBehaviorStatusCodeResultModels(
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel) { ScriptBehaviorsBriefModel scriptBehaviorsBriefModel) {
List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>(); List<BehaviorStatusCodeResultModel> behaviorStatusCodeResultModels = new ArrayList<BehaviorStatusCodeResultModel>();
if (scriptBehaviorsBriefModel == null) for (BehaviorBriefModel behaviorBriefModel : scriptBehaviorsBriefModel
return null; .getTestBehaviorsBriefModel().getBehaviorBriefModels()) {
try {
for (BehaviorBriefModel behaviorBriefModel : scriptBehaviorsBriefModel
.getTestBehaviorsBriefModel().getBehaviorBriefModels()) {
if (behaviorBriefModel.getDetailStatusCodeResultModels() != null) if (behaviorBriefModel.getDetailStatusCodeResultModels() != null)
behaviorStatusCodeResultModels.addAll(behaviorBriefModel behaviorStatusCodeResultModels.addAll(behaviorBriefModel
.getDetailStatusCodeResultModels()); .getDetailStatusCodeResultModels());
}
return behaviorStatusCodeResultModels;
} catch (NullPointerException e) {
return null;
} }
return behaviorStatusCodeResultModels;
} }

View File

@ -1 +1 @@
masterAddress=133.133.12.1:7979/ masterAddress=127.0.0.1:7979/

View File

@ -25,7 +25,7 @@ function getColumn(obj, columnIndex) {
} }
function extractRowData(data, tableModel, actionButton) { function extractRowData(data, tableModel, actionButton) {
var dataArray = new Array(); var dataArray = new Array();
dataArray=getRowData(data, tableModel,dataArray) dataArray=getRowData(data, tableModel,dataArray);
if (actionButton != null) if (actionButton != null)
dataArray.push(actionButton); dataArray.push(actionButton);
return dataArray; return dataArray;

View File

@ -19,7 +19,7 @@ ChartSelector.prototype.getExcessTree=function(allTree,pathValues){
excessTree.deleteFromTree(pathValues); excessTree.deleteFromTree(pathValues);
return excessTree; return excessTree;
} };
ChartSelector.prototype.addEventListener = function(chartSelector) { ChartSelector.prototype.addEventListener = function(chartSelector) {
this.addButton.click(function(e) { this.addButton.click(function(e) {
e.preventDefault(); e.preventDefault();
@ -46,7 +46,7 @@ ChartSelector.prototype.updateSelector = function(selectorId, updatedData, tree)
}; };
ChartSelector.prototype.deleteChildSelector=function(parentDomNode,updatedData){ ChartSelector.prototype.deleteChildSelector=function(parentDomNode,updatedData){
var selectArray=$("#"+parentDomNode.attr("id")+" select"); var selectArray=$("#"+parentDomNode.attr("id")+" select");
var divArray=$("#"+parentDomNode.attr("id")+" div") var divArray=$("#"+parentDomNode.attr("id")+" div");
parentDomNode.html(""); parentDomNode.html("");
for(var i=0;i<selectArray.length;i++){ for(var i=0;i<selectArray.length;i++){
parentDomNode.append(divArray[i]); parentDomNode.append(divArray[i]);
@ -57,14 +57,14 @@ ChartSelector.prototype.deleteChildSelector=function(parentDomNode,updatedData){
} }
} };;
ChartSelector.prototype.createSelectorByValues = function(parentDomNode, treeNode,pathValues) { ChartSelector.prototype.createSelectorByValues = function(parentDomNode, treeNode,pathValues) {
var currentNode = treeNode; var currentNode = treeNode;
if (currentNode == null) if (currentNode == null)
return ; return ;
var selectedNode; var selectedNode;
if (currentNode.children != null && currentNode.children.length > 0) { if (currentNode.children != null && currentNode.children.length > 0) {
selectedNode=this.getSelectNodeByValue(currentNode,pathValues) selectedNode=this.getSelectNodeByValue(currentNode,pathValues);
if(selectedNode==null) if(selectedNode==null)
selectedNode = currentNode.children[0]; selectedNode = currentNode.children[0];
var selectOptions = new Array(); var selectOptions = new Array();
@ -88,7 +88,7 @@ ChartSelector.prototype.addSelectlistEvent=function(){
chartSelector.updateSelector( chartSelector.addSelectorId, updatedData, chartSelector.excessTree); chartSelector.updateSelector( chartSelector.addSelectorId, updatedData, chartSelector.excessTree);
event.stopImmediatePropagation(); event.stopImmediatePropagation();
}); });
} };
ChartSelector.prototype.createSelector = function(parentDomNode, treeNode) { ChartSelector.prototype.createSelector = function(parentDomNode, treeNode) {
var currentNode = treeNode; var currentNode = treeNode;
if (currentNode == null) if (currentNode == null)
@ -115,15 +115,15 @@ ChartSelector.prototype.getSelectNodeByValue=function(parentNode,values){
} }
return null; return null;
} };
ChartSelector.prototype.createSingleListDom = function(lableText, options) { ChartSelector.prototype.createSingleListDom = function(lableText, options) {
var div = $("<div></div>"); var div = $("<div></div>");
div.addClass("control-group"); div.addClass("control-group");
var lable = $("<lable></lable>"); var lable = $("<lable></lable>");
lable.addClass("control-label") lable.addClass("control-label");
lable.text(lableText); lable.text(lableText);
div.append(lable); div.append(lable);
div.append("</br>") div.append("</br>");
var select = $("<select ></select>"); var select = $("<select ></select>");
select.addClass("form-control"); select.addClass("form-control");
for (var i = 0; i < options.length; i++) { for (var i = 0; i < options.length; i++) {
@ -176,7 +176,7 @@ ChartSelector.prototype.initChart=function(pathValues){
model.setUrl(this.getSlectedVluesArray(this.addSelectorId),this); model.setUrl(this.getSlectedVluesArray(this.addSelectorId),this);
model.axis=(model.series+"_Axis"); model.axis=(model.series+"_Axis");
this.chart.addGraph(model); this.chart.addGraph(model);
} };
ChartSelector.prototype.deleteGraph = function() { ChartSelector.prototype.deleteGraph = function() {
this.showTree=this.deleteGraphFromTree(this.showTree, this.deleteSelectorId); this.showTree=this.deleteGraphFromTree(this.showTree, this.deleteSelectorId);
this.excessTree=this.addGraphToTree(this.excessTree, this.deleteSelectorId); this.excessTree=this.addGraphToTree(this.excessTree, this.deleteSelectorId);
@ -224,7 +224,7 @@ Model.prototype.setIntervalId = function(intervalId) {
function getSubDataArray(indexData, dataArray) { function getSubDataArray(indexData, dataArray) {
var subDataArray = new Array(); var subDataArray = new Array();
for (var i = 0; i < dataArray.length; i++) { for (var i = 0; i < dataArray.length; i++) {
subDataArray.push(dataArray[i]) subDataArray.push(dataArray[i]);
if (dataArray[i] == indexData) { if (dataArray[i] == indexData) {
break; break;
} }

View File

@ -69,7 +69,7 @@ Chart.prototype.addPoints=function(seriesId,data ) {
chart.addPoint(seriesId,data[i]); chart.addPoint(seriesId,data[i]);
} }
} };
@ -87,7 +87,7 @@ Chart.prototype.addGraph = function(model) {
$.post(model.url+"/"+model.time, { $.post(model.url+"/"+model.time, {
}, function(data) { }, function(data) {
if(!data.success){ if(!data.success){
alert(data.failedMessage) alert(data.failedMessage);
clearInterval(intervalId); clearInterval(intervalId);
return; return;
} }
@ -125,7 +125,7 @@ Chart.prototype.addDataToGraph=function(chart,model,intervalId,data){
chart.addPoint(model.series, point); chart.addPoint(model.series, point);
} };
Chart.prototype.deleteGraph = function(model) { Chart.prototype.deleteGraph = function(model) {
for (var i = 0; i < this.modelArray.length; i++) { for (var i = 0; i < this.modelArray.length; i++) {
if (model.series==this.modelArray[i].series) { if (model.series==this.modelArray[i].series) {

View File

@ -15,7 +15,8 @@ function loadTests(table, model,loadLength,actionButton) {
table.dataTable().fnClearTable(); table.dataTable().fnClearTable();
$.post("loadTestPlans", {}, function(data) { $.post("loadTestPlans", {}, function(data) {
if (data != null) { if (data.success) {
data=data.data;
if (data.list != null){ if (data.list != null){
if(loadLength<0) if(loadLength<0)
loadLength=data.list.length; loadLength=data.list.length;
@ -38,9 +39,10 @@ function loadTests(table, model,loadLength,actionButton) {
testPlanIdColumn.html(href); testPlanIdColumn.html(href);
} }
} }
else else
alert("fail to load tests"); alert(data.failedMessage);
$('.download').click(function(e) { $('.download').click(function(e) {
e.preventDefault(); e.preventDefault();
@ -78,12 +80,12 @@ function deleteTest(obj) {
testPlanId : testPlanId testPlanId : testPlanId
}, function(data) { }, function(data) {
if (data) { if (data.success) {
var table = getTable(obj); var table = getTable(obj);
var row = getRow(obj); var row = getRow(obj);
$(table).dataTable().fnDeleteRow(row.rowIndex - 1); $(table).dataTable().fnDeleteRow(row.rowIndex - 1);
} else { } else {
alert("fail"); alert(data.failedMessage);
} }
}); });

View File

@ -41,15 +41,15 @@ function login() {
userName : userName, userName : userName,
password : password password : password
}, function(data) { }, function(data) {
if (data) {
if (data.success) {
$('#loginMsg').hide(); $('#loginMsg').hide();
window.location.replace("homepage.jsp"); window.location.replace("homepage.jsp");
} }
else { else {
$('#loginMsg').html($.i18n.prop('msgLogin')); alert(data.failedMessage);
$('#loginMsg').show();
} }
},"json"); },"json");
} }
@ -61,15 +61,14 @@ function adminLogin() {
userName : userName, userName : userName,
password : password password : password
}, function(data) { }, function(data) {
if (data) { if (data.success) {
$('#loginMsg').hide(); $('#loginMsg').hide();
window.location.replace("agentManage.jsp"); window.location.replace("agentManage.jsp");
} }
else { else {
$('#loginMsg').html($.i18n.prop('msgLogin')); alert(data.failedMessage);
$('#loginMsg').show();
} }
}); });
} }
@ -88,13 +87,14 @@ function register() {
password : password, password : password,
rePassword:rePassword rePassword:rePassword
}, function(data) { }, function(data) {
if (data) { if (data.success) {
$('#registerMsg').hide(); $('#registerMsg').hide();
window.location.replace("index.jsp"); window.location.replace("index.jsp");
} }
else { else {
alert(data.failedMessage);
// $('#registerMsg').html($.i18n.prop('msgRegister')); // $('#registerMsg').html($.i18n.prop('msgRegister'));
$('#registerMsg').show(); $('#registerMsg').show();
} }

View File

@ -47,12 +47,18 @@ var UrlContentTypeDistribution = function(containerId, testPlanId) {
$.post(url, "", function(data) { $.post(url, "", function(data) {
var dataArray = new Array(); var dataArray = new Array();
if (data != null) { if(!data.success){
alert(data.failedMessage);
return;
}
else data=data.data;
for(var key in data) for(var key in data)
dataArray.push([key,data[key]]); dataArray.push([key,data[key]]);
chart.series[0].setData(dataArray); chart.series[0].setData(dataArray);
}
loadItems.urlDistribution=true; loadItems.urlDistribution=true;
},"json"); },"json");

View File

@ -5,7 +5,7 @@ var loadItems=function(){
this.behavior=false; this.behavior=false;
this.urlDistribution=false; this.urlDistribution=false;
this.testBrief=false; this.testBrief=false;
} };
function SetProgress(progress) { function SetProgress(progress) {
if (progress) { if (progress) {
$("#" + progress_id + " > div").css("width", String(progress) + "%"); // 控制#loading $("#" + progress_id + " > div").css("width", String(progress) + "%"); // 控制#loading

View File

@ -17,12 +17,15 @@ function getScriptList(testPlanId) {
dataType : "json", dataType : "json",
async : false, async : false,
success : function(data) { success : function(data) {
if (data == null) if(!data.success){
return null; alert(data.failedMessage);
return;
}
else data=data.data;
if (data.runningScriptModels.length <= 0) if (data.runningScriptModels.length <= 0)
return null; return null;
for ( var i = 0; i < data.runningScriptModels.length; i++) { for ( var i = 0; i < data.runningScriptModels.length; i++) {
scriptList.push(data.runningScriptModels[i]) scriptList.push(data.runningScriptModels[i]);
} }
} }
@ -40,7 +43,7 @@ var PageResult = function() {
"averageResponseTimeThisTime", "latestResponseTime"); "averageResponseTimeThisTime", "latestResponseTime");
this.table = $("#page").dataTable(); this.table = $("#page").dataTable();
} };
PageResult.prototype.addResultToTable = function() { PageResult.prototype.addResultToTable = function() {
this.table.fnClearTable(); this.table.fnClearTable();
var result = this.result; var result = this.result;
@ -50,7 +53,7 @@ PageResult.prototype.addResultToTable = function() {
} }
loadItems.pageResult=true; loadItems.pageResult=true;
} };
var PageResultModel = function(page, scriptPageBriefModel, scriptName) { var PageResultModel = function(page, scriptPageBriefModel, scriptName) {
this.page = page; this.page = page;
this.countFromBegin = scriptPageBriefModel.countFromBegin; this.countFromBegin = scriptPageBriefModel.countFromBegin;
@ -59,7 +62,7 @@ var PageResultModel = function(page, scriptPageBriefModel, scriptName) {
this.averageResponseTimeThisTime = scriptPageBriefModel.averageResponseTimeThisTime; this.averageResponseTimeThisTime = scriptPageBriefModel.averageResponseTimeThisTime;
this.latestResponseTime = scriptPageBriefModel.latestResponseTime; this.latestResponseTime = scriptPageBriefModel.latestResponseTime;
this.scriptName = scriptName; this.scriptName = scriptName;
} };
PageResult.prototype.getResult = function(testPlanId, scriptList) { PageResult.prototype.getResult = function(testPlanId, scriptList) {
var pageResult = this; var pageResult = this;
@ -89,16 +92,18 @@ PageResult.prototype.getResult = function(testPlanId, scriptList) {
} }
}, this.intevalTime); }, this.intevalTime);
} };
PageResult.prototype.getSinglePageResult = function(pageResult, intervalId, PageResult.prototype.getSinglePageResult = function(pageResult, intervalId,
finishedCount, script) { finishedCount, script) {
var urlPath = [ testPlanId, "script", script.scriptId, "page" ]; var urlPath = [ testPlanId, "script", script.scriptId, "page" ];
var url = generateUrl(urlPath); var url = generateUrl(urlPath);
$.post(url, {}, function(data) { $.post(url, {}, function(data) {
if (data == null || data.scriptPageBriefModels == null) { if(!data.success){
clearInterval(intervalId); clearInterval(intervalId);
return; return;
} }
else data=data.data;
data = data.scriptPageBriefModels; data = data.scriptPageBriefModels;
var scriptPagesFinished = true; var scriptPagesFinished = true;
for ( var i = 0; i < data.length; i++) { for ( var i = 0; i < data.length; i++) {
@ -113,7 +118,7 @@ PageResult.prototype.getSinglePageResult = function(pageResult, intervalId,
finishedCount++; finishedCount++;
}, "json"); }, "json");
} };
// Behavior------------------------------------------------------- // Behavior-------------------------------------------------------
var BehaviorResult = function() { var BehaviorResult = function() {
@ -155,7 +160,7 @@ BehaviorResult.prototype.getResult = function(testPlanId, scriptList) {
}, this.intevalTime); }, this.intevalTime);
} };
function generateUrl(urlPath) { function generateUrl(urlPath) {
var url = urlPath[0]; var url = urlPath[0];
for ( var i = 1; i < urlPath.length; i++) for ( var i = 1; i < urlPath.length; i++)
@ -168,10 +173,11 @@ BehaviorResult.prototype.getSingleBehaviorResult = function(behaviorResult,
var urlPath = [ testPlanId, "script", script.scriptId, "behaviors" ]; var urlPath = [ testPlanId, "script", script.scriptId, "behaviors" ];
var url = generateUrl(urlPath); var url = generateUrl(urlPath);
$.post(url, {}, function(data) { $.post(url, {}, function(data) {
if (data == null) { if (!data.success) {
clearInterval(intervalId); clearInterval(intervalId);
return; return;
} }
data=data.data;
if (data.finished || data.testBehaviorsBriefModel == null) { if (data.finished || data.testBehaviorsBriefModel == null) {
finishedCount++; finishedCount++;
} }
@ -182,11 +188,11 @@ BehaviorResult.prototype.getSingleBehaviorResult = function(behaviorResult,
script.scriptName)); script.scriptName));
}, "json"); }, "json");
} };
var Behavior = function(behaviorBriefModel, scriptName) { var Behavior = function(behaviorBriefModel, scriptName) {
this.behaviorBriefModel = behaviorBriefModel; this.behaviorBriefModel = behaviorBriefModel;
this.scriptName = scriptName; this.scriptName = scriptName;
} };
BehaviorResult.prototype.getBehaviorsList = function(behaviorBriefModels, BehaviorResult.prototype.getBehaviorsList = function(behaviorBriefModels,
scriptName) { scriptName) {
var behaviors = new Array(); var behaviors = new Array();
@ -194,7 +200,7 @@ BehaviorResult.prototype.getBehaviorsList = function(behaviorBriefModels,
behaviors.push(new Behavior(behaviorBriefModels[i], scriptName)); behaviors.push(new Behavior(behaviorBriefModels[i], scriptName));
} }
return behaviors; return behaviors;
} };
BehaviorResult.prototype.addBehaviorsToTable = function() { BehaviorResult.prototype.addBehaviorsToTable = function() {
this.table.fnClearTable(); this.table.fnClearTable();
@ -206,7 +212,7 @@ BehaviorResult.prototype.addBehaviorsToTable = function() {
this.table.fnAddData(row); this.table.fnAddData(row);
} }
loadItems.behaviorResult=true; loadItems.behaviorResult=true;
} };
BehaviorResult.prototype.DetailAddListener = function() { BehaviorResult.prototype.DetailAddListener = function() {
var behaviorResult = this; var behaviorResult = this;
$(".show-detail-picture") $(".show-detail-picture")
@ -237,7 +243,7 @@ BehaviorResult.prototype.DetailAddListener = function() {
} }
}); });
} };;
BehaviorResult.prototype.showUrlDetailResult = function(brotherDom, url) { BehaviorResult.prototype.showUrlDetailResult = function(brotherDom, url) {
var theader = [ "url", "statusCode", "count", "contentLength", var theader = [ "url", "statusCode", "count", "contentLength",
"minResponseTime", "maxResponseTime", "totalResponseTimeThisTime" ]; "minResponseTime", "maxResponseTime", "totalResponseTimeThisTime" ];
@ -257,7 +263,7 @@ BehaviorResult.prototype.showUrlDetailResult = function(brotherDom, url) {
this.addDataToDetailTable($(table.children("tbody")[0]), dataRows[i]); this.addDataToDetailTable($(table.children("tbody")[0]), dataRows[i]);
} }
} };
BehaviorResult.prototype.addDataToDetailTable = function(tbody, dataRow) { BehaviorResult.prototype.addDataToDetailTable = function(tbody, dataRow) {
var tr = $("<tr></tr>"); var tr = $("<tr></tr>");
for ( var i = 0; i < dataRow.length; i++) { for ( var i = 0; i < dataRow.length; i++) {
@ -266,9 +272,9 @@ BehaviorResult.prototype.addDataToDetailTable = function(tbody, dataRow) {
tr.append(td); tr.append(td);
} }
tbody.append(tr); tbody.append(tr);
} };
BehaviorResult.prototype.drawUrlDetailResult = function(theader) { BehaviorResult.prototype.drawUrlDetailResult = function(theader) {
var table = this.getDetaileTable(theader) var table = this.getDetaileTable(theader);
var div = $("<div></div>"); var div = $("<div></div>");
div.append(table); div.append(table);
var td = $("<td colspan='5'></td>"); var td = $("<td colspan='5'></td>");
@ -277,7 +283,7 @@ BehaviorResult.prototype.drawUrlDetailResult = function(theader) {
tr.append(td); tr.append(td);
return tr; return tr;
} };
BehaviorResult.prototype.getDetaileTable = function(theader) { BehaviorResult.prototype.getDetaileTable = function(theader) {
var table = $("<table></table>"); var table = $("<table></table>");
table.addClass("innerTable"); table.addClass("innerTable");
@ -293,7 +299,7 @@ BehaviorResult.prototype.getDetaileTable = function(theader) {
return table; return table;
} };
BehaviorResult.prototype.searchBehaviorByUrl = function(url) { BehaviorResult.prototype.searchBehaviorByUrl = function(url) {
var behaviors = this.behaviors; var behaviors = this.behaviors;
@ -303,7 +309,7 @@ BehaviorResult.prototype.searchBehaviorByUrl = function(url) {
} }
} }
return null; return null;
} };
var BehaviorModel = function(behavior, scriptName) { var BehaviorModel = function(behavior, scriptName) {
this.Url = behavior.behaviorUrl; this.Url = behavior.behaviorUrl;
@ -311,14 +317,14 @@ var BehaviorModel = function(behavior, scriptName) {
this.Successful = this.getStatusCount( this.Successful = this.getStatusCount(
behavior.detailStatusCodeResultModels, 200); behavior.detailStatusCodeResultModels, 200);
this.Total = this.getTotalCount(behavior.detailStatusCodeResultModels); this.Total = this.getTotalCount(behavior.detailStatusCodeResultModels);
} };
var BehaviorDetailModel = function(url, behaviorDetaile) { var BehaviorDetailModel = function(url, behaviorDetaile) {
this.url = url; this.url = url;
for ( var key in behaviorDetaile) { for ( var key in behaviorDetaile) {
if (key.indexOf("contentType") < 0) if (key.indexOf("contentType") < 0)
this[key] = behaviorDetaile[key]; this[key] = behaviorDetaile[key];
} }
} };
BehaviorModel.prototype.getStatusCount = function(behaviorStatusResultList, BehaviorModel.prototype.getStatusCount = function(behaviorStatusResultList,
statusCode) { statusCode) {
if (behaviorStatusResultList == null) if (behaviorStatusResultList == null)
@ -329,7 +335,7 @@ BehaviorModel.prototype.getStatusCount = function(behaviorStatusResultList,
count += behaviorStatusResultList[i].count; count += behaviorStatusResultList[i].count;
} }
return count; return count;
} };
BehaviorModel.prototype.getTotalCount = function(behaviorStatusResultList) { BehaviorModel.prototype.getTotalCount = function(behaviorStatusResultList) {
if (behaviorStatusResultList == null) if (behaviorStatusResultList == null)
return 0; return 0;
@ -338,7 +344,7 @@ BehaviorModel.prototype.getTotalCount = function(behaviorStatusResultList) {
count += behaviorStatusResultList[i].count; count += behaviorStatusResultList[i].count;
} }
return count; return count;
} };
// need to abstract the tow // need to abstract the tow
// part---------------------------------------------------- // part----------------------------------------------------

View File

@ -12,8 +12,12 @@ function showTestPlanStatusAsync(testPlanId){
/* var urlAddress= "/" + testPlanId + "/queryTestPlan";*/ /* var urlAddress= "/" + testPlanId + "/queryTestPlan";*/
var urlAddress= testPlanId + "/queryTestPlan"; var urlAddress= testPlanId + "/queryTestPlan";
$.post(urlAddress,{},function(data){ $.post(urlAddress,{},function(data){
if(data==null) if(!data.success){
alert(data.failedMessage);
return; return;
}
else data=data.data;
testStatus=data.currentStatus; testStatus=data.currentStatus;
$('#status').html('Test Status<br/><br><h4>'+testStatus+'</h4>'); $('#status').html('Test Status<br/><br><h4>'+testStatus+'</h4>');
},"json"); },"json");
@ -21,8 +25,12 @@ function showTestPlanStatusAsync(testPlanId){
function showTestBriefStatus(startTime){ function showTestBriefStatus(startTime){
var urlAddress= testPlanId + "/testBriefStatus"+"/"+startTime; var urlAddress= testPlanId + "/testBriefStatus"+"/"+startTime;
$.post(urlAddress,{},function(data){ $.post(urlAddress,{},function(data){
if(data==null) if(!data.success){
alert(data.failedMessage);
return; return;
}
else data=data.data;
startTime=data.time; startTime=data.time;
$("#vu").html('VUs active<br/><br><h4>'+data.vus+'</h4>'); $("#vu").html('VUs active<br/><br><h4>'+data.vus+'</h4>');
$("#request").html('Requests<br/><br><h4>'+data.requests+'</h4>'); $("#request").html('Requests<br/><br><h4>'+data.requests+'</h4>');
@ -37,10 +45,12 @@ function getTestPlanStatus(testPlanId) {
dataType : "json", dataType : "json",
async : false, async : false,
success : function(data) { success : function(data) {
if (data == null) { if(!data.success){
flag = false; flag=false;
return; return;
} }
else data=data.data;
testStatus = data.currentStatus; testStatus = data.currentStatus;
if (data.currentStatus == "Complete" if (data.currentStatus == "Complete"
|| data.currentStatus == "InRunning") { || data.currentStatus == "InRunning") {

View File

@ -22,7 +22,7 @@ TreeNode.prototype.insertNodes = function(childNodes) {
this.children.push(childNodes[i]); this.children.push(childNodes[i]);
} }
} };
var Tree = function() { var Tree = function() {
this.root = null; this.root = null;
}; };
@ -42,7 +42,7 @@ Tree.prototype.getClondSubTreeByValue = function(value) {
clonedTree.root.childClassName = parentNode.childClassName; clonedTree.root.childClassName = parentNode.childClassName;
this.getClonedSubTree(parentNode, clonedTree.root);// 这个就把引用传递过去了,应该没什么影响,我再看看吧 this.getClonedSubTree(parentNode, clonedTree.root);// 这个就把引用传递过去了,应该没什么影响,我再看看吧
return clonedTree; return clonedTree;
} };
Tree.prototype.searchTreeNodeByValue = function(parentNode, value) { Tree.prototype.searchTreeNodeByValue = function(parentNode, value) {
@ -53,7 +53,7 @@ Tree.prototype.searchTreeNodeByValue = function(parentNode, value) {
if (value == parentNode.children[i].value) { if (value == parentNode.children[i].value) {
return parentNode.children[i]; return parentNode.children[i];
} }
var node = this.searchTreeNodeByValue(parentNode.children[i], value) var node = this.searchTreeNodeByValue(parentNode.children[i], value);
if (node != null) if (node != null)
return node; return node;
} }
@ -195,7 +195,7 @@ Tree.prototype.getClonedTree = function(tree) {
clonedTree.root = this.getClonedNode(tree.root); clonedTree.root = this.getClonedNode(tree.root);
return clonedTree; return clonedTree;
} };
Tree.prototype.getClonedNode = function(node) { Tree.prototype.getClonedNode = function(node) {
if (node == null) if (node == null)
return null; return null;
@ -208,7 +208,7 @@ Tree.prototype.getClonedNode = function(node) {
} }
} }
return clonedNode; return clonedNode;
} };
/* /*
* Tree.prototype.getExcessTreeNodes = function(allTreeNode, showTreeNode) { var * Tree.prototype.getExcessTreeNodes = function(allTreeNode, showTreeNode) { var
* tree=this; if (allTreeNode == null) return null; * tree=this; if (allTreeNode == null) return null;

View File

@ -1,11 +1,11 @@
var LoadItems=function(){ var LoadItems = function() {
this.scriptBriefStatusAve=false; this.scriptBriefStatusAve = false;
this.pageResult=false; this.pageResult = false;
this.behaviorResult=false; this.behaviorResult = false;
this.urlDistribution=false; this.urlDistribution = false;
this.testBrief=false; this.testBrief = false;
}; };
var loadItems=new LoadItems(); var loadItems = new LoadItems();
var testStatus; var testStatus;
$(document).ready( $(document).ready(
function() { function() {
@ -18,8 +18,9 @@ $(document).ready(
var replaceArray = createUrlReplaceArray(testPlanId); var replaceArray = createUrlReplaceArray(testPlanId);
var chart = new Chart(); var chart = new Chart();
chart.createChart($("#chart")); chart.createChart($("#chart"));
var chartSelector = createChartSelector(tree, chart, replaceArray,getShowTreePathValues(tree)); var chartSelector = createChartSelector(tree, chart, replaceArray,
chartSelector.initChart(getShowTreePathValues(tree),this); getShowTreePathValues(tree));
chartSelector.initChart(getShowTreePathValues(tree), this);
graphButtonListener(chartSelector); graphButtonListener(chartSelector);
var behaviorResult = new BehaviorResult(); var behaviorResult = new BehaviorResult();
behaviorResult.getResult(testPlanId, getScriptList(testPlanId)); behaviorResult.getResult(testPlanId, getScriptList(testPlanId));
@ -29,10 +30,9 @@ $(document).ready(
"url-distribution", testPlanId); "url-distribution", testPlanId);
}); });
function replace(keyArray, replaceArray) { function replace(keyArray, replaceArray) {
for ( var i = 0; i < keyArray.length; i++) { for (var i = 0; i < keyArray.length; i++) {
for ( var j = 0; j < replaceArray.length; j++) { for (var j = 0; j < replaceArray.length; j++) {
if (keyArray[i] == replaceArray[j].oldWord) if (keyArray[i] == replaceArray[j].oldWord)
keyArray[i] = replaceArray[j].newWord keyArray[i] = replaceArray[j].newWord
} }
@ -61,7 +61,7 @@ function graphButtonListener(chartSelector) {
if (chartSelector.excessTree.root != null) if (chartSelector.excessTree.root != null)
chartSelector.createSelector($("#" chartSelector.createSelector($("#"
+ chartSelector.addSelectorId), + chartSelector.addSelectorId),
chartSelector.excessTree.root) chartSelector.excessTree.root);
} }
chartSelector.addSelectlistEvent(); chartSelector.addSelectlistEvent();
@ -69,51 +69,57 @@ function graphButtonListener(chartSelector) {
}); });
} }
function createChartSelector(tree, chart, replaceArray,showTreePathValues) { function createChartSelector(tree, chart, replaceArray, showTreePathValues) {
var addSelectorId = "add-graph-list"; var addSelectorId = "add-graph-list";
var deleteSelectorId = "del-graph-list"; var deleteSelectorId = "del-graph-list";
var addButton = $("#add-graph-add"); var addButton = $("#add-graph-add");
var deleteButton = $("#del-graph-del"); var deleteButton = $("#del-graph-del");
var showTree=initShowTree(tree); var showTree = initShowTree(tree);
var chartSelector = new ChartSelector(tree, showTree, chart, addSelectorId, var chartSelector = new ChartSelector(tree, showTree, chart, addSelectorId,
deleteSelectorId, addButton, deleteButton, replaceArray,showTreePathValues); deleteSelectorId, addButton, deleteButton, replaceArray,
showTreePathValues);
return chartSelector; return chartSelector;
} }
function getShowTreePathValues(tree){ function getShowTreePathValues(tree) {
var currentNode = tree.root.children[0]; var currentNode = tree.root.children[0];
var pathValues = new Array(); var pathValues = new Array();
while (currentNode != null) { while (currentNode != null) {
pathValues.push(currentNode.value) pathValues.push(currentNode.value);
if(currentNode.children!==null) if (currentNode.children !== null)
currentNode = currentNode.children[0]; currentNode = currentNode.children[0];
else currentNode=null; else
currentNode = null;
} }
return pathValues; return pathValues;
} }
function initShowTree(tree) { function initShowTree(tree) {
var pathValues=getShowTreePathValues(tree); var pathValues = getShowTreePathValues(tree);
return tree.getCloneTreeFromVlaue(pathValues); return tree.getCloneTreeFromVlaue(pathValues);
} }
var ReplaceNode = function(oldWord, newWord) { var ReplaceNode = function(oldWord, newWord) {
this.oldWord = oldWord; this.oldWord = oldWord;
this.newWord = newWord; this.newWord = newWord;
} };
function createUrlReplaceArray(testPlanId) { function createUrlReplaceArray(testPlanId) {
var replaceArray = new Array(); var replaceArray = new Array();
$.ajax({ $.ajax({
type : "POST", type : "POST",
/* url : "/" + testPlanId + "/mapInfo",*/ /* url : "/" + testPlanId + "/mapInfo", */
url :testPlanId + "/mapInfo", url : testPlanId + "/mapInfo",
dataType : "json", dataType : "json",
async : false, async : false,
success : function(data) { success : function(data) {
if (data == null) if(!data.success){
return null; alert(data.failedMessage);
return;
}
else data=data.data;
for ( var key in data) { for ( var key in data) {
var replaceNode = new ReplaceNode(key, data[key]); var replaceNode = new ReplaceNode(key, data[key]);
replaceArray.push(replaceNode); replaceArray.push(replaceNode);
@ -129,7 +135,7 @@ function getvars() {
var vars = [], hash; var vars = [], hash;
var hashes = window.location.href.slice( var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&'); window.location.href.indexOf('?') + 1).split('&');
for ( var i = 0; i < hashes.length; i++) { for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('='); hash = hashes[i].split('=');
vars.push(hash[0]); vars.push(hash[0]);
vars[hash[0]] = hash[1]; vars[hash[0]] = hash[1];