add test about load result data from database, until now, i just finish
the scriptBriefResultMOdel part
This commit is contained in:
parent
b76c138f6e
commit
14c8800a99
|
@ -3,9 +3,9 @@ package org.bench4q.master.api;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.master.service.db.TestPlanScriptService;
|
||||
import org.bench4q.master.service.db.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.db.UserService;
|
||||
import org.bench4q.share.models.master.ScriptProcessModel;
|
||||
import org.bench4q.share.models.master.ResultLoadModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
@ -14,31 +14,33 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/TestPlanResult")
|
||||
@RequestMapping("/testPlanResult")
|
||||
public class TestPlanResulController extends BaseController {
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
|
||||
public TestPlanScriptService getTestPlanScriptService() {
|
||||
return testPlanScriptService;
|
||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanScriptService(
|
||||
TestPlanScriptService testPlanScriptService) {
|
||||
this.testPlanScriptService = testPlanScriptService;
|
||||
public void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanRunId}/script/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/{testPlanRunId}/loadScriptBirefResults/{scriptId}/{fieldName}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ScriptProcessModel getScriptResults(
|
||||
public ResultLoadModel loadScriptBirefResults(
|
||||
@PathVariable UUID testPlanRunId, @PathVariable int scriptId,
|
||||
@PathVariable String fieldName) throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/{testPlanRunId}/script/{scriptId}/{fieldName}");
|
||||
}
|
||||
ScriptProcessModel ret = new ScriptProcessModel();
|
||||
|
||||
ResultLoadModel ret = new ResultLoadModel();
|
||||
ret.setValueTimeModels(this.getTestPlanScriptResultService()
|
||||
.loadScriptBriefSpecificField(testPlanRunId, scriptId,
|
||||
fieldName));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class Bench4QException extends Exception {
|
|||
this.resource = resource;
|
||||
}
|
||||
|
||||
public Bench4QException(String code, String message,
|
||||
String resource) {
|
||||
public Bench4QException(String code, String message, String resource) {
|
||||
this.setCode(code);
|
||||
this.setMessage(message);
|
||||
this.setResource(resource);
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ScriptReportService {
|
|||
}
|
||||
for (TestPlanScript testPlanScript : scripts) {
|
||||
createScriptImage(this.getTestPlanScriptService()
|
||||
.queryTestPlanScriptResult(testPlanScript), document);
|
||||
.queryScriptBriefResults(testPlanScript), document);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package org.bench4q.master.service.db;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.db.TestPlanScriptResult;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.ValueTimeModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestPlanScriptResultService {
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private static Logger logger = Logger
|
||||
.getLogger(TestPlanScriptResultService.class);
|
||||
|
||||
private TestPlanScriptService getTestPlanScriptService() {
|
||||
return testPlanScriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanScriptService(
|
||||
TestPlanScriptService testPlanScriptService) {
|
||||
this.testPlanScriptService = testPlanScriptService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Here I just use the Time that createDateTime in testplanscriptResult
|
||||
*
|
||||
* @param testPlanId
|
||||
* @param scriptId
|
||||
* @return
|
||||
*/
|
||||
public List<ValueTimeModel> loadScriptBriefSpecificField(UUID testPlanId,
|
||||
int scriptId, String fieldName) {
|
||||
List<TestPlanScriptResult> scriptBriefresults = this
|
||||
.getTestPlanScriptService().queryScriptBriefResults(testPlanId,
|
||||
scriptId);
|
||||
List<ValueTimeModel> ret = new ArrayList<ValueTimeModel>();
|
||||
for (TestPlanScriptResult result : scriptBriefresults) {
|
||||
try {
|
||||
ScriptBriefResultModel briefModel = (ScriptBriefResultModel) MarshalHelper
|
||||
.unmarshal(ScriptBriefResultModel.class,
|
||||
result.getResultContent());
|
||||
ret.add(ValueTimeModel.buildValueTimeModel(
|
||||
getSpecificFieldValue(briefModel, fieldName),
|
||||
result.getCreateDatetime()));
|
||||
} catch (JAXBException e) {
|
||||
logger.info(ExceptionLog.getExceptionStackTrace(e)
|
||||
+ " When unmarshal the model from ResultCOntent");
|
||||
continue;
|
||||
} catch (NoSuchFieldException e) {
|
||||
logger.info(ExceptionLog.getExceptionStackTrace(e)
|
||||
+ " When get Field from the model from ResultCOntent");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public long getSpecificFieldValue(ScriptBriefResultModel briefModel,
|
||||
String fieldName) throws NoSuchFieldException {
|
||||
try {
|
||||
Field field = getFieldAndSetAccessible(briefModel, fieldName);
|
||||
return (Long) field.get(briefModel);
|
||||
} catch (Exception e) {
|
||||
throw new NoSuchFieldException();
|
||||
}
|
||||
}
|
||||
|
||||
private Field getFieldAndSetAccessible(ScriptBriefResultModel briefModel,
|
||||
String fieldName) throws NoSuchFieldException, SecurityException {
|
||||
Field field = briefModel.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
}
|
|
@ -79,19 +79,20 @@ public class TestPlanScriptService {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean saveScriptBriefResult(final UUID testPlanRunId, final int scriptId,
|
||||
final ScriptBriefResultModel resultModel) {
|
||||
public boolean saveScriptBriefResult(final UUID testPlanRunId,
|
||||
final int scriptId, final ScriptBriefResultModel resultModel) {
|
||||
return saveResultPrivate(testPlanRunId, scriptId, resultModel);
|
||||
}
|
||||
|
||||
public boolean saveBehaviorsBriefResult(final UUID testPlanRunId, final int scriptId,
|
||||
public boolean saveBehaviorsBriefResult(final UUID testPlanRunId,
|
||||
final int scriptId,
|
||||
final ScriptBehaviorsBriefModel scriptBehaviorsBriefModel) {
|
||||
return saveResultPrivate(testPlanRunId, scriptId,
|
||||
scriptBehaviorsBriefModel);
|
||||
}
|
||||
|
||||
public boolean savePageBriefResult(final UUID testPlanRunId, final int scriptId,
|
||||
final ScriptPageBriefModel pageBriefModel) {
|
||||
public boolean savePageBriefResult(final UUID testPlanRunId,
|
||||
final int scriptId, final ScriptPageBriefModel pageBriefModel) {
|
||||
return saveResultPrivate(testPlanRunId, scriptId, pageBriefModel);
|
||||
}
|
||||
|
||||
|
@ -181,15 +182,27 @@ public class TestPlanScriptService {
|
|||
}
|
||||
}
|
||||
|
||||
public List<TestPlanScriptResult> queryTestPlanScriptResult(
|
||||
public List<TestPlanScriptResult> queryScriptBriefResults(UUID testPlanId,
|
||||
int scriptId) {
|
||||
return queryScriptBriefResults(this.getTestPlanScript(scriptId,
|
||||
testPlanId));
|
||||
}
|
||||
|
||||
public List<TestPlanScriptResult> queryScriptBriefResults(
|
||||
TestPlanScript testPlanScript) {
|
||||
return queryScriptResultsByType(testPlanScript,
|
||||
ScriptBriefResultModel.class.getName());
|
||||
}
|
||||
|
||||
private List<TestPlanScriptResult> queryScriptResultsByType(
|
||||
TestPlanScript testPlanScript, String type) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TestPlanScriptResult> resultList = session
|
||||
.createCriteria(TestPlanScriptResult.class)
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.list();
|
||||
.add(Restrictions.eq("resultType", type)).list();
|
||||
return resultList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -192,7 +192,7 @@ public class TestPlanService {
|
|||
@SuppressWarnings("unchecked")
|
||||
List<PlanedConfig> configs = session
|
||||
.createCriteria(PlanedConfig.class)
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScripts))
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.list();
|
||||
if (configs == null) {
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package org.bench4q.master.test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.service.db.ScriptService;
|
||||
import org.bench4q.master.service.db.TestPlanScriptResultService;
|
||||
import org.bench4q.master.service.db.TestPlanScriptService;
|
||||
import org.bench4q.master.service.db.TestPlanService;
|
||||
import org.bench4q.master.service.db.UserService;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.models.master.ScriptBriefResultModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class TestBase_MakeUpTestPlan extends TestBase {
|
||||
private TestPlanScriptResultService testPlanScriptResultService;
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanService testPlanService;
|
||||
private UserService userService;
|
||||
private ScriptService scriptService;
|
||||
private UUID testPlanRunIdUuid;
|
||||
private int scriptId;
|
||||
|
||||
public TestPlanScriptResultService getTestPlanScriptResultService() {
|
||||
return testPlanScriptResultService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptResultService(
|
||||
TestPlanScriptResultService testPlanScriptResultService) {
|
||||
this.testPlanScriptResultService = testPlanScriptResultService;
|
||||
}
|
||||
|
||||
public TestPlanScriptService getTestPlanScriptService() {
|
||||
return testPlanScriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanScriptService(
|
||||
TestPlanScriptService testPlanScriptService) {
|
||||
this.testPlanScriptService = testPlanScriptService;
|
||||
}
|
||||
|
||||
public TestPlanService getTestPlanService() {
|
||||
return testPlanService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTestPlanService(TestPlanService testPlanService) {
|
||||
this.testPlanService = testPlanService;
|
||||
}
|
||||
|
||||
public UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public UUID getTestPlanRunIdUuid() {
|
||||
return testPlanRunIdUuid;
|
||||
}
|
||||
|
||||
public void setTestPlanRunIdUuid(UUID testPlanRunIdUuid) {
|
||||
this.testPlanRunIdUuid = testPlanRunIdUuid;
|
||||
}
|
||||
|
||||
public int getScriptId() {
|
||||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
protected ScriptBriefResultModel buildScriptBriefResultModel(int i) {
|
||||
ScriptBriefResultModel resultModel = new ScriptBriefResultModel();
|
||||
resultModel.setAverageElapsedTime(100 * i);
|
||||
resultModel.setAverageResponseTime(100 * i);
|
||||
resultModel.setFailRateThisTime(10 * i);
|
||||
return resultModel;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.bench4q.master.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserTest extends TestCase {
|
||||
private HttpRequester httpRequester = new HttpRequester();
|
||||
|
||||
@Test
|
||||
public void authorizeTest() throws IOException {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("userName", "chen");
|
||||
map.put("password", "123");
|
||||
|
||||
HttpRequester.HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
"http://localhost:8080/user/authorize", map, null);
|
||||
assertEquals(true, httpResponse != null);
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
UserTest userTest = new UserTest();
|
||||
userTest.authorizeTest();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test.recordscript;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
@ -8,7 +8,6 @@ import javax.xml.bind.JAXBException;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.bench4q.master.test.TestBase;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
|
@ -1,8 +1,10 @@
|
|||
package org.bench4q.master.test;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
|
@ -25,4 +27,16 @@ public class ScriptControllerTest extends TestBase {
|
|||
httpResponse.getContent());
|
||||
assertTrue(ret.getScriptModels().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteScript(int scriptId) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("scriptId", scriptId + "");
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER
|
||||
+ this.accessTocken);
|
||||
HttpResponse httpResponse = this.httpRequester.sendPost(
|
||||
this.controllerUrl + "/deleteScript", params, properties);
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bench4q.master.test;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -1,13 +1,15 @@
|
|||
package org.bench4q.master.test.testplan;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.test.TestBase;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestPlanControllerTest extends TestBase {
|
||||
|
@ -18,11 +20,17 @@ public class TestPlanControllerTest extends TestBase {
|
|||
|
||||
@Test
|
||||
public void runTestPlanWithoutLogOn() throws JAXBException, IOException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendPostXml(this.url
|
||||
+ "/runTestPlanWithTestPlanModel", MarshalHelper.marshal(
|
||||
TestPlanBusinessModel.class, TestPlanTester.createATestPlan()),
|
||||
null);
|
||||
HttpResponse httpResponse = this.httpRequester
|
||||
.sendPostXml(
|
||||
this.url + "/runTestPlanWithTestPlanModel",
|
||||
MarshalHelper
|
||||
.marshal(
|
||||
TestPlanBusinessModel.class,
|
||||
TestPlanTester
|
||||
.createATestPlan(TestPlanTester.SCRIPTID1)),
|
||||
null);
|
||||
System.out.println(httpResponse.getContent());
|
||||
assertEquals(400, httpResponse.getCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package org.bench4q.master.test.controller;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.entity.db.User;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.master.testplan.entity.TestPlanInBusiness;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.ResultLoadModel;
|
||||
import org.bench4q.share.models.master.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.ScriptPageBriefModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
||||
public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan {
|
||||
private String urlString = BASE_URL + "/testPlanResult";
|
||||
|
||||
@Test
|
||||
public void testGetScriptResults() throws IOException, JAXBException {
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(urlString + "/"
|
||||
+ this.getTestPlanRunIdUuid().toString()
|
||||
+ "/loadScriptBirefResults/" + this.getScriptId()
|
||||
+ "/averageResponseTime", null,
|
||||
this.makeAccessTockenMap(this.getAccessTocken()));
|
||||
ResultLoadModel loadModel = (ResultLoadModel) MarshalHelper.unmarshal(
|
||||
ResultLoadModel.class, httpResponse.getContent());
|
||||
assertEquals(3, loadModel.getValueTimeModels().size());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult() {
|
||||
UUID testPlanRunId = UUID.randomUUID();
|
||||
User user = this.getUserService().getUserByName("admin");
|
||||
this.setScriptId(this.getScriptService().loadScripts(user).get(0)
|
||||
.getId());
|
||||
TestPlanBusinessModel model = TestPlanTester.createATestPlan(this
|
||||
.getScriptId());
|
||||
TestPlanInBusiness testPlan = BusinessModelMapFactory.toBusiness(model);
|
||||
this.getTestPlanService().saveTestPlanToDB(testPlan, user,
|
||||
testPlanRunId, testPlan.getRunningScripts());
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.getTestPlanScriptService().saveScriptBriefResult(
|
||||
testPlanRunId, this.getScriptId(),
|
||||
buildScriptBriefResultModel(i));
|
||||
this.getTestPlanScriptService().saveBehaviorsBriefResult(
|
||||
testPlanRunId, this.getScriptId(),
|
||||
new ScriptBehaviorsBriefModel());
|
||||
this.getTestPlanScriptService().savePageBriefResult(testPlanRunId,
|
||||
this.getScriptId(), new ScriptPageBriefModel());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
this.getTestPlanService().removeTestPlanInDB(
|
||||
this.getTestPlanService()
|
||||
.getTestPlan(this.getTestPlanRunIdUuid()).getId());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package org.bench4q.master.test;
|
||||
package org.bench4q.master.test.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
|
@ -11,7 +10,7 @@ import org.junit.Test;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AuthTest extends TestBase {
|
||||
public class UserControllerTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testNormalAuth() throws IOException, JAXBException {
|
||||
|
@ -35,4 +34,5 @@ public class AuthTest extends TestBase {
|
|||
httpResponse.getContent());
|
||||
assertTrue(ret.isSuccess());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package org.bench4q.master.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
|
||||
public class scriptOperateTest extends TestBase {
|
||||
private final String _url = TestBase.BASE_URL + "/RecordScript";
|
||||
|
||||
public void deleteScript(int scriptId) throws IOException {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("scriptId", scriptId + "");
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER
|
||||
+ this.accessTocken);
|
||||
HttpResponse httpResponse = this.httpRequester.sendPost(this._url
|
||||
+ "/deleteScript", params, properties);
|
||||
System.out.println(httpResponse.getContent());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, JAXBException {
|
||||
scriptOperateTest test = new scriptOperateTest();
|
||||
test.accessTocken = test.login();
|
||||
test.deleteScript(2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package org.bench4q.master.test.service;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.entity.db.User;
|
||||
import org.bench4q.master.test.TestBase_MakeUpTestPlan;
|
||||
import org.bench4q.master.test.testplan.TestPlanTester;
|
||||
import org.bench4q.master.testplan.entity.TestPlanInBusiness;
|
||||
import org.bench4q.share.models.master.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.ScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.ScriptPageBriefModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.bench4q.share.models.master.ValueTimeModel;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
|
||||
public class TestTestPlanScriptResultService extends TestBase_MakeUpTestPlan {
|
||||
|
||||
@Test
|
||||
public void testGetSpecficFieldValue() throws NoSuchFieldException {
|
||||
long averageResponseTime = this.getTestPlanScriptResultService()
|
||||
.getSpecificFieldValue(buildScriptBriefResultModel(0),
|
||||
"averageResponseTime");
|
||||
assertEquals(0, averageResponseTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAvgFromScriptBriefResultWithWrongTestPlanID()
|
||||
throws NoSuchFieldException, SecurityException {
|
||||
List<ValueTimeModel> results = this
|
||||
.getTestPlanScriptResultService()
|
||||
.loadScriptBriefSpecificField(
|
||||
UUID.fromString("af67ccd7-ca7b-4dbf-9544-8ffe81b3af2d"),
|
||||
61,
|
||||
ScriptBriefResultModel.class.getDeclaredField(
|
||||
"averageResponseTime").getName());
|
||||
assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAvgFromScriptBriefResult() throws NoSuchFieldException,
|
||||
SecurityException {
|
||||
List<ValueTimeModel> results = this.getTestPlanScriptResultService()
|
||||
.loadScriptBriefSpecificField(
|
||||
this.getTestPlanRunIdUuid(),
|
||||
this.getScriptId(),
|
||||
ScriptBriefResultModel.class.getDeclaredField(
|
||||
"averageResponseTime").getName());
|
||||
System.out.println(results.size());
|
||||
assertTrue(results.size() > 0);
|
||||
assertTrue(results.get(1).getValue() % 100 == 0);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void makeUpTestPlanAndTestPlanScriptAndTestPlanScriptResult() {
|
||||
UUID testPlanRunId = UUID.randomUUID();
|
||||
User user = this.getUserService().getUserByName("admin");
|
||||
this.setScriptId(this.getScriptService().loadScripts(user).get(0)
|
||||
.getId());
|
||||
TestPlanBusinessModel model = TestPlanTester.createATestPlan(this
|
||||
.getScriptId());
|
||||
TestPlanInBusiness testPlan = BusinessModelMapFactory.toBusiness(model);
|
||||
this.getTestPlanService().saveTestPlanToDB(testPlan, user,
|
||||
testPlanRunId, testPlan.getRunningScripts());
|
||||
this.setTestPlanRunIdUuid(testPlanRunId);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.getTestPlanScriptService().saveScriptBriefResult(
|
||||
testPlanRunId, this.getScriptId(),
|
||||
buildScriptBriefResultModel(i));
|
||||
this.getTestPlanScriptService().saveBehaviorsBriefResult(
|
||||
testPlanRunId, this.getScriptId(),
|
||||
new ScriptBehaviorsBriefModel());
|
||||
this.getTestPlanScriptService().savePageBriefResult(testPlanRunId,
|
||||
this.getScriptId(), new ScriptPageBriefModel());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
this.getTestPlanService().removeTestPlanInDB(
|
||||
this.getTestPlanService()
|
||||
.getTestPlan(this.getTestPlanRunIdUuid()).getId());
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ public class TestTestPlanScriptService {
|
|||
.getTestPlanScript(WRONG_SCRIPT_ID,
|
||||
UUID.fromString(WRONG_TEST_PLAN_RUN_ID));
|
||||
List<TestPlanScriptResult> scriptBriefResultModels = this
|
||||
.getTestPlanScriptService().queryTestPlanScriptResult(
|
||||
.getTestPlanScriptService().queryScriptBriefResults(
|
||||
testPlanScript);
|
||||
assertTrue(scriptBriefResultModels.size() == 0);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class TestTestPlanScriptService {
|
|||
.getTestPlanScript(PROPER_SCRIPT_ID,
|
||||
UUID.fromString(TEST_PLAN_RUN_ID));
|
||||
List<TestPlanScriptResult> scriptBriefList = this
|
||||
.getTestPlanScriptService().queryTestPlanScriptResult(
|
||||
.getTestPlanScriptService().queryScriptBriefResults(
|
||||
testPlanScript);
|
||||
assertTrue(scriptBriefList.size() > 0);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class TestTestPlanScriptService {
|
|||
.getTestPlanScript(WRONG_SCRIPT_ID,
|
||||
UUID.fromString(WRONG_TEST_PLAN_RUN_ID));
|
||||
assertTrue(this.getTestPlanScriptService()
|
||||
.queryTestPlanScriptResult(testPlanScript).size() == 0);
|
||||
.queryScriptBriefResults(testPlanScript).size() == 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import javax.xml.bind.JAXBContext;
|
|||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.bench4q.master.test.TestBase;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
|
@ -30,7 +30,7 @@ public class TestPlanTester extends TestBase {
|
|||
private TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
private String _url = TestBase.BASE_URL + "/testPlan";
|
||||
private int scriptSumNum;
|
||||
private static int SCRIPTID1 = 61;
|
||||
public static int SCRIPTID1 = 61;
|
||||
private static int SCRIPTID2 = 2;
|
||||
// private static int EACH_SCRIPT_LOAD_LargeSCALE = 12000;
|
||||
private static int EACH_SCRIPT_LOAD_SMALLSCALE = 40;
|
||||
|
@ -144,17 +144,18 @@ public class TestPlanTester extends TestBase {
|
|||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
public static TestPlanBusinessModel createATestPlan() {
|
||||
public static TestPlanBusinessModel createATestPlan(int scriptId) {
|
||||
TestPlanBusinessModel testPlanBusinessModel = new TestPlanBusinessModel();
|
||||
testPlanBusinessModel.setMonitorModels(createOneMonitorList());
|
||||
testPlanBusinessModel.setRunningScriptModels(createOneScriptList());
|
||||
testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
return testPlanBusinessModel;
|
||||
}
|
||||
|
||||
public TestPlanBusinessModel _createATestPlan() {
|
||||
if (this.getScriptSumNum() == 1) {
|
||||
this.testPlanBusinessModel
|
||||
.setRunningScriptModels(createOneScriptList());
|
||||
.setRunningScriptModels(createOneScriptList(SCRIPTID1));
|
||||
} else if (getScriptSumNum() == 2) {
|
||||
this.testPlanBusinessModel
|
||||
.setRunningScriptModels(createTowScriptList());
|
||||
|
@ -171,9 +172,9 @@ public class TestPlanTester extends TestBase {
|
|||
return monitors;
|
||||
}
|
||||
|
||||
private static List<RunningScriptModel> createOneScriptList() {
|
||||
private static List<RunningScriptModel> createOneScriptList(int scriptId) {
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
list.add(buildScriptModel(SCRIPTID1));
|
||||
list.add(buildScriptModel(scriptId));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ import java.io.IOException;
|
|||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.master.test.TestBase;
|
||||
import org.bench4q.master.test.controller.TestBase;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.ScriptProcessModel;
|
||||
import org.bench4q.share.models.master.ResultLoadModel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestTestPlanResult extends TestBase {
|
||||
|
@ -26,8 +26,8 @@ public class TestTestPlanResult extends TestBase {
|
|||
+ testPlanRunId, null,
|
||||
makeAccessTockenMap(this.getAccessTocken()));
|
||||
assertTrue(httpResponse != null);
|
||||
ScriptProcessModel resultModel = (ScriptProcessModel) MarshalHelper
|
||||
.unmarshal(ScriptProcessModel.class, httpResponse.getContent());
|
||||
assertTrue(resultModel.getScriptBriefResultModels().size() > 0);
|
||||
ResultLoadModel resultModel = (ResultLoadModel) MarshalHelper
|
||||
.unmarshal(ResultLoadModel.class, httpResponse.getContent());
|
||||
assertTrue(resultModel.getValueTimeModels().size() > 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue