add test to testResult
This commit is contained in:
parent
6e7b6fbb8c
commit
4ca11db283
|
@ -1,5 +1,6 @@
|
|||
var intervalTime = 5000;
|
||||
var Chart=function(){};
|
||||
var Chart = function() {
|
||||
};
|
||||
Chart.prototype.createChart = function(container) {
|
||||
container.highcharts({
|
||||
chart : {
|
||||
|
@ -19,17 +20,16 @@ Chart.prototype.createChart = function(container) {
|
|||
});
|
||||
chart.xAxis[0].update({
|
||||
type : 'datetime',
|
||||
tickInterval : 1000*60,
|
||||
tickInterval : 1000 * 60,
|
||||
tickWidth : 0,
|
||||
gridLineWidth : 1,
|
||||
tickPixelInterval : 50
|
||||
});
|
||||
this.highChart=chart;
|
||||
this.modelArray=new Array();
|
||||
this.highChart = chart;
|
||||
this.modelArray = new Array();
|
||||
};
|
||||
|
||||
|
||||
Chart.prototype.addAxis=function(axis,seriesId,data){
|
||||
Chart.prototype.addAxis = function(axis, seriesId, data) {
|
||||
this.highChart.addAxis({ // Secondary yAxis
|
||||
id : axis,
|
||||
title : {
|
||||
|
@ -41,71 +41,66 @@ Chart.prototype.addAxis=function(axis,seriesId,data){
|
|||
this.addSeries(axis, seriesId, data);
|
||||
};
|
||||
|
||||
Chart.prototype.addSeries=function(axis,seriesId,data) {
|
||||
Chart.prototype.addSeries = function(axis, seriesId, data) {
|
||||
this.highChart.addSeries({
|
||||
id : seriesId,
|
||||
name : seriesId,
|
||||
yAxis : axis,
|
||||
data :data,
|
||||
data : data,
|
||||
marker : {
|
||||
enabled : true,
|
||||
radius : 3
|
||||
},
|
||||
showInLegend:true
|
||||
showInLegend : true
|
||||
}, true);
|
||||
};
|
||||
Chart.prototype.removeAxis=function(axisId) {
|
||||
Chart.prototype.removeAxis = function(axisId) {
|
||||
this.highChart.get(axisId).remove();
|
||||
};
|
||||
|
||||
Chart.prototype.addPoint=function(seriesId,point ) {
|
||||
if(point.y=="NaN")
|
||||
point.y=0;
|
||||
this.highChart.get(seriesId).addPoint([ point.x, point.y ]);
|
||||
Chart.prototype.addPoint = function(seriesId, point) {
|
||||
if (point.y == "NaN")
|
||||
point.y = 0;
|
||||
this.highChart.get(seriesId).addPoint([ point.x, point.y ]);
|
||||
};
|
||||
Chart.prototype.addPoints=function(seriesId,data ) {
|
||||
var chart=this;
|
||||
for(var i=0;i<data.length;i++){
|
||||
chart.addPoint(seriesId,data[i]);
|
||||
Chart.prototype.addPoints = function(seriesId, data) {
|
||||
var chart = this;
|
||||
for ( var i = 0; i < data.length; i++) {
|
||||
chart.addPoint(seriesId, data[i]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
var Point = function(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
Chart.prototype.addGraph = function(model) {
|
||||
|
||||
var chart=this;
|
||||
chart.addAxis(model.axis,model.series, []);
|
||||
|
||||
var chart = this;
|
||||
chart.addAxis(model.axis, model.series, []);
|
||||
|
||||
var intervalId = setInterval(function() {
|
||||
|
||||
$.post(model.url+"/"+model.time, {
|
||||
}, function(data) {
|
||||
if(!data.success){
|
||||
$.post(model.url + "/" + model.time, {}, function(data) {
|
||||
loadItems.scriptBriefStatusAve = true;
|
||||
if (!data.success) {
|
||||
alert(data.failedMessage);
|
||||
clearInterval(intervalId);
|
||||
|
||||
return;
|
||||
}
|
||||
/*if (data == null) {
|
||||
clearInterval(intervalId);
|
||||
return;
|
||||
}*/
|
||||
data=data.data;
|
||||
if(data instanceof Array) {
|
||||
|
||||
var points=new Array();
|
||||
for(var i=0;i<data.length;i++){
|
||||
chart.addDataToGraph(chart,model,intervalId,data[i]);
|
||||
data = data.data;
|
||||
if (data instanceof Array) {
|
||||
|
||||
var points = new Array();
|
||||
for ( var i = 0; i < data.length; i++) {
|
||||
chart.addDataToGraph(chart, model, intervalId, data[i]);
|
||||
}
|
||||
}
|
||||
else chart.addDataToGraph(chart,model,intervalId,data);
|
||||
|
||||
loadItems.scriptBriefStatusAve=true;
|
||||
} else
|
||||
chart.addDataToGraph(chart, model, intervalId, data);
|
||||
loadItems.scriptBriefStatusAve = true;
|
||||
|
||||
}, "json");
|
||||
|
||||
}, intervalTime);
|
||||
|
@ -113,22 +108,21 @@ Chart.prototype.addGraph = function(model) {
|
|||
this.modelArray.push(model);
|
||||
|
||||
};
|
||||
Chart.prototype.addDataToGraph=function(chart,model,intervalId,data){
|
||||
Chart.prototype.addDataToGraph = function(chart, model, intervalId, data) {
|
||||
|
||||
if (data.finished) {
|
||||
if (data.finished) {
|
||||
clearInterval(intervalId);
|
||||
return;
|
||||
}
|
||||
var point = new Point(data.time,data.data);
|
||||
if(data.time>model.time)
|
||||
model.time=data.time;
|
||||
chart.addPoint(model.series, point);
|
||||
|
||||
|
||||
var point = new Point(data.time, data.data);
|
||||
if (data.time > model.time)
|
||||
model.time = data.time;
|
||||
chart.addPoint(model.series, point);
|
||||
|
||||
};
|
||||
Chart.prototype.deleteGraph = function(model) {
|
||||
for (var i = 0; i < this.modelArray.length; i++) {
|
||||
if (model.series==this.modelArray[i].series) {
|
||||
for ( var i = 0; i < this.modelArray.length; i++) {
|
||||
if (model.series == this.modelArray[i].series) {
|
||||
clearInterval(this.modelArray[i].intervalId);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ function getScriptList(testPlanId) {
|
|||
else data=data.data;
|
||||
if (data.scriptIds.length <= 0)
|
||||
return null;
|
||||
alert(data.scriptIdNameMap.length);
|
||||
for ( var i = 0; i < data.scriptIdNameMap.length; i++) {
|
||||
scriptList.push(data.scriptIdNameMap[i]);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
package org.bench4q.web.api.test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.web.api.TestPlanActionController;
|
||||
import org.bench4q.web.api.TestPlanHistoryResult;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
import org.bench4q.web.model.BaseResponseModel;
|
||||
import org.bench4q.web.model.SutInfo;
|
||||
import org.bench4q.web.model.TestPlanListModel;
|
||||
import org.bench4q.web.model.WebTestPlanResultModel;
|
||||
import org.bench4q.web.tool.test.LoginHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" })
|
||||
public class TestResultTest {
|
||||
private LoginHelper loginHelper;
|
||||
|
||||
private TestPlanActionController testPlanActionController;
|
||||
|
||||
private TestPlanHistoryResult testPlanHistoryResult;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
public LoginHelper getLoginHelper() {
|
||||
return loginHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setLoginHelper(LoginHelper loginHelper) {
|
||||
this.loginHelper = loginHelper;
|
||||
}
|
||||
|
||||
public TestPlanActionController getTestPlanActionController() {
|
||||
return testPlanActionController;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanActionController(
|
||||
TestPlanActionController testPlanActionController) {
|
||||
this.testPlanActionController = testPlanActionController;
|
||||
}
|
||||
|
||||
public TestPlanHistoryResult getTestPlanHistoryResult() {
|
||||
return testPlanHistoryResult;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanHistoryResult(
|
||||
TestPlanHistoryResult testPlanHistoryResult) {
|
||||
this.testPlanHistoryResult = testPlanHistoryResult;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.accessToken = loginHelper.Login();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getReplaceList() throws CustomGenericException,
|
||||
JAXBException {
|
||||
if (getTestPlanId() == null)
|
||||
Assert.assertTrue(false);
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getTestPlanActionController().getReplaceList(
|
||||
loginHelper.Login(), getTestPlanId());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Integer> scriptIdMap = (Map<String, Integer>) baseResponseModel
|
||||
.getData();
|
||||
Assert.assertTrue(scriptIdMap.size() > 0);
|
||||
}
|
||||
|
||||
// this is important need to submit a testPlan later
|
||||
@Test
|
||||
public void test_getSutInfo() throws CustomGenericException, JAXBException {
|
||||
Assert.assertNotNull(this.getTestPlanIdWithMonitor());
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SutInfo> sutInfos = (List<SutInfo>) this
|
||||
.getTestPlanActionController()
|
||||
.getSutInfo(accessToken, this.getTestPlanIdWithMonitor())
|
||||
.getData();
|
||||
for (SutInfo sutInfo : sutInfos) {
|
||||
Assert.assertEquals("5556", sutInfo.getPort());
|
||||
Assert.assertEquals("133.133.12.3", sutInfo.getIp());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getScriptBehaviorBriefModel()
|
||||
throws CustomGenericException, JAXBException {
|
||||
WebTestPlanResultModel webTestPlanResultModel = getWebTestPlanResultModelWithMonitor();
|
||||
BaseResponseModel baseResponseModel = this
|
||||
.getTestPlanActionController().getScriptBehaviorBriefModel(
|
||||
accessToken,
|
||||
webTestPlanResultModel.getTestPlanId().toString(),
|
||||
new Integer(webTestPlanResultModel.getScriptIds()
|
||||
.get(0)).toString());
|
||||
ScriptBehaviorsBriefModel scriptBehaviorsBriefModel = (ScriptBehaviorsBriefModel) baseResponseModel
|
||||
.getData();
|
||||
Assert.assertNotNull(scriptBehaviorsBriefModel);
|
||||
Assert.assertNotNull(scriptBehaviorsBriefModel
|
||||
.getTestBehaviorsBriefModel());
|
||||
Assert.assertTrue(scriptBehaviorsBriefModel
|
||||
.getTestBehaviorsBriefModel().getBehaviorBriefModels().size() > 0);
|
||||
}
|
||||
|
||||
private String getTestPlanIdWithMonitor() throws CustomGenericException,
|
||||
JAXBException {
|
||||
WebTestPlanResultModel webTestPlanResultModel = getWebTestPlanResultModelWithMonitor();
|
||||
if (webTestPlanResultModel == null)
|
||||
return null;
|
||||
else
|
||||
return webTestPlanResultModel.getTestPlanId().toString();
|
||||
}
|
||||
|
||||
private WebTestPlanResultModel getWebTestPlanResultModelWithMonitor()
|
||||
throws CustomGenericException, JAXBException {
|
||||
for (TestPlanDBModel testPlanDBModel : ((TestPlanListModel) testPlanHistoryResult
|
||||
.loadTestPlans(accessToken).getData()).getList()) {
|
||||
if (testPlanDBModel.getCurrentStatus().equals(
|
||||
TestPlanStatus.Complete.name())) {
|
||||
WebTestPlanResultModel webTestPlanResultModel = (WebTestPlanResultModel) this
|
||||
.getTestPlanActionController()
|
||||
.queryTestPlan(accessToken,
|
||||
testPlanDBModel.getTestPlanRunId()).getData();
|
||||
if (webTestPlanResultModel.getMonitorModels().size() > 0)
|
||||
return webTestPlanResultModel;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getTestPlanId() throws CustomGenericException {
|
||||
for (TestPlanDBModel testPlanDBModel : ((TestPlanListModel) testPlanHistoryResult
|
||||
.loadTestPlans(accessToken).getData()).getList()) {
|
||||
if (testPlanDBModel.getCurrentStatus().equals(
|
||||
TestPlanStatus.Complete.name())) {
|
||||
return testPlanDBModel.getTestPlanRunId();
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue