refactor MarshalHelper to generic

refactor MarshalHelper to generic
This commit is contained in:
coderfengyun 2014-09-15 21:46:03 +08:00
parent 7d7d8c7837
commit b1d0f3eb1d
40 changed files with 184 additions and 205 deletions

View File

@ -86,11 +86,11 @@ public class TestController {
try { try {
this.getParamFileCollector().collectParamFiles(files, runId); this.getParamFileCollector().collectParamFiles(files, runId);
System.out.println(scenarioModel); System.out.println(scenarioModel);
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper.unmarshal(
.unmarshal(RunScenarioModel.class, scenarioModel); RunScenarioModel.class, scenarioModel);
System.out.println(scheduleContent); System.out.println(scheduleContent);
this.logger.info(scheduleContent); this.logger.info(scheduleContent);
ScheduleModel scheduleModel = (ScheduleModel) MarshalHelper ScheduleModel scheduleModel = MarshalHelper
.unmarshal(ScheduleModel.class, scheduleContent); .unmarshal(ScheduleModel.class, scheduleContent);
this.getScenarioEngine().submitScenario(runId, this.getScenarioEngine().submitScenario(runId,
Scenario.scenarioCompiler(runScenarioModel), Scenario.scenarioCompiler(runScenarioModel),

View File

@ -67,12 +67,11 @@ public class Scenario {
} }
public static Scenario scenarioBuilderWithCompile(String scenarioContent) { public static Scenario scenarioBuilderWithCompile(String scenarioContent) {
return scenarioCompiler((RunScenarioModel) MarshalHelper return scenarioCompiler(MarshalHelper.tryUnmarshal(
.tryUnmarshal(RunScenarioModel.class, scenarioContent)); RunScenarioModel.class, scenarioContent));
} }
public static Scenario scenarioCompiler( public static Scenario scenarioCompiler(RunScenarioModel scenarioModel) {
RunScenarioModel scenarioModel) {
if (scenarioModel == null) { if (scenarioModel == null) {
throw new NullPointerException(); throw new NullPointerException();
} }

View File

@ -17,7 +17,7 @@ public class ExtractScenarioTest {
@Test @Test
public void test() throws JAXBException, IOException { public void test() throws JAXBException, IOException {
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper
.unmarshal(RunScenarioModel.class, FileUtils .unmarshal(RunScenarioModel.class, FileUtils
.readFileToString(new File("Scripts/goodForPage.xml"))); .readFileToString(new File("Scripts/goodForPage.xml")));
Scenario scenario = Scenario.scenarioCompiler(runScenarioModel); Scenario scenario = Scenario.scenarioCompiler(runScenarioModel);

View File

@ -82,9 +82,8 @@ public class TestWithScriptFile extends TestBase {
HttpResponse httpResponse = this.getHttpRequester().sendPostXml( HttpResponse httpResponse = this.getHttpRequester().sendPostXml(
this.url + "/runWithoutParams", this.url + "/runWithoutParams",
marshalRunScenarioModel(runScenarioModel), null); marshalRunScenarioModel(runScenarioModel), null);
RunScenarioResultModel resultModel = (RunScenarioResultModel) MarshalHelper RunScenarioResultModel resultModel = MarshalHelper.unmarshal(
.unmarshal(RunScenarioResultModel.class, RunScenarioResultModel.class, httpResponse.getContent());
httpResponse.getContent());
this.setTestId(resultModel.getRunId()); this.setTestId(resultModel.getRunId());
} catch (IOException e) { } catch (IOException e) {
System.out.println("IO exception!"); System.out.println("IO exception!");
@ -138,9 +137,8 @@ public class TestWithScriptFile extends TestBase {
HttpResponse httpResponse = this.getHttpRequester().sendGet( HttpResponse httpResponse = this.getHttpRequester().sendGet(
this.url + "/brief/" + this.getTestId().toString(), null, null); this.url + "/brief/" + this.getTestId().toString(), null, null);
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
AgentBriefStatusModel briefModel = (AgentBriefStatusModel) MarshalHelper AgentBriefStatusModel briefModel = MarshalHelper.unmarshal(
.unmarshal(AgentBriefStatusModel.class, AgentBriefStatusModel.class, httpResponse.getContent());
httpResponse.getContent());
assertTrue(briefModel.getTimeFrame() > 0); assertTrue(briefModel.getTimeFrame() > 0);
} }
@ -150,9 +148,8 @@ public class TestWithScriptFile extends TestBase {
this.url + "/behaviorsBrief/" + this.getTestId().toString(), this.url + "/behaviorsBrief/" + this.getTestId().toString(),
null, null); null, null);
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
AgentBehaviorsBriefModel behaviorsBriefModel = (AgentBehaviorsBriefModel) MarshalHelper AgentBehaviorsBriefModel behaviorsBriefModel = MarshalHelper.unmarshal(
.unmarshal(AgentBehaviorsBriefModel.class, AgentBehaviorsBriefModel.class, httpResponse.getContent());
httpResponse.getContent());
assertTrue(behaviorsBriefModel.getBehaviorBriefModels().size() > 0); assertTrue(behaviorsBriefModel.getBehaviorBriefModels().size() > 0);
} }
@ -161,8 +158,8 @@ public class TestWithScriptFile extends TestBase {
HttpResponse httpResponse = this.getHttpRequester().sendGet( HttpResponse httpResponse = this.getHttpRequester().sendGet(
this.url + "/brief/" + this.getTestId().toString() + "/0", this.url + "/brief/" + this.getTestId().toString() + "/0",
null, null); null, null);
BehaviorBriefModel behaviorBriefModel = (BehaviorBriefModel) MarshalHelper BehaviorBriefModel behaviorBriefModel = MarshalHelper.unmarshal(
.unmarshal(BehaviorBriefModel.class, httpResponse.getContent()); BehaviorBriefModel.class, httpResponse.getContent());
assertTrue(behaviorBriefModel.getDetailStatusCodeResultModels().size() > 0); assertTrue(behaviorBriefModel.getDetailStatusCodeResultModels().size() > 0);
} }
@ -196,7 +193,7 @@ public class TestWithScriptFile extends TestBase {
+ "testJD.xml")); + "testJD.xml"));
HttpResponse httpResponse1 = this.getHttpRequester().sendPost( HttpResponse httpResponse1 = this.getHttpRequester().sendPost(
url + "/bookTest/20", null, null); url + "/bookTest/20", null, null);
RunScenarioResultModel bookResponse = (RunScenarioResultModel) MarshalHelper RunScenarioResultModel bookResponse = MarshalHelper
.tryUnmarshal(RunScenarioResultModel.class, .tryUnmarshal(RunScenarioResultModel.class,
httpResponse1.getContent()); httpResponse1.getContent());
assertNotNull(bookResponse); assertNotNull(bookResponse);
@ -216,7 +213,7 @@ public class TestWithScriptFile extends TestBase {
assertNotNull(httpResponse); assertNotNull(httpResponse);
assertNotNull(httpResponse.getContent()); assertNotNull(httpResponse.getContent());
assertEquals(200, httpResponse.getCode()); assertEquals(200, httpResponse.getCode());
RunScenarioResultModel resultModel = (RunScenarioResultModel) MarshalHelper RunScenarioResultModel resultModel = MarshalHelper
.tryUnmarshal(RunScenarioResultModel.class, .tryUnmarshal(RunScenarioResultModel.class,
httpResponse.getContent()); httpResponse.getContent());
String dirPath = (String) TestHelper.invokePrivate( String dirPath = (String) TestHelper.invokePrivate(
@ -244,9 +241,8 @@ public class TestWithScriptFile extends TestBase {
fail(); fail();
} }
System.out.println(httpResponse); System.out.println(httpResponse);
AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) MarshalHelper AgentPageBriefModel pageBriefModel = MarshalHelper.unmarshal(
.unmarshal(AgentPageBriefModel.class, AgentPageBriefModel.class, httpResponse.getContent());
httpResponse.getContent());
assertTrue(pageBriefModel.getCountFromBegin() > 0); assertTrue(pageBriefModel.getCountFromBegin() > 0);
} catch (Exception e) { } catch (Exception e) {
this.stopTest(); this.stopTest();

View File

@ -149,7 +149,7 @@ public class Test_HttpPlugin extends TestBase {
@Test @Test
public void buildAScenario() throws IOException { public void buildAScenario() throws IOException {
RunScenarioModel scenarioMode = (RunScenarioModel) MarshalHelper RunScenarioModel scenarioMode = MarshalHelper
.tryUnmarshal(RunScenarioModel.class, FileUtils .tryUnmarshal(RunScenarioModel.class, FileUtils
.readFileToString(new File( .readFileToString(new File(
"Scripts/httpWithoutTimer.xml"))); "Scripts/httpWithoutTimer.xml")));

View File

@ -178,11 +178,11 @@ public class RunningAgentDB implements RunningAgentInterface {
public boolean distributeScriptAndParams() { public boolean distributeScriptAndParams() {
Script script2 = this.getTestPlanScript().getScript(); Script script2 = this.getTestPlanScript().getScript();
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper.tryUnmarshal(
.tryUnmarshal(RunScenarioModel.class, this.getTestPlanScript() RunScenarioModel.class, this.getTestPlanScript()
.getFilteredScriptCnt()); .getFilteredScriptCnt());
runScenarioModel.setPoolSize(getLoadInUse()); runScenarioModel.setPoolSize(getLoadInUse());
ScheduleModel scheduleModel = generateScheduleModelWithRatio((ScheduleModel) MarshalHelper ScheduleModel scheduleModel = generateScheduleModelWithRatio(MarshalHelper
.tryUnmarshal(ScheduleModel.class, this.getTestPlanScript() .tryUnmarshal(ScheduleModel.class, this.getTestPlanScript()
.getScheduleContent())); .getScheduleContent()));
RunScenarioResultModel runScenarioResultModel = this RunScenarioResultModel runScenarioResultModel = this

View File

@ -147,9 +147,8 @@ public class TestPlanScript implements RunningScriptInterface {
@Transient @Transient
public RunScenarioModel getScenario() { public RunScenarioModel getScenario() {
try { try {
return (RunScenarioModel) MarshalHelper return MarshalHelper.unmarshal(RunScenarioModel.class, this
.unmarshal(RunScenarioModel.class, this.getScript() .getScript().getScriptContent());
.getScriptContent());
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(TestPlanScript.class).error( Logger.getLogger(TestPlanScript.class).error(
ExceptionLog.getStackTrace(e)); ExceptionLog.getStackTrace(e));

View File

@ -18,8 +18,8 @@ import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
@Entity @Entity
@Table(name = "TestPlanScriptResult") @Table(name = "TestPlanScriptResult")
public class TestPlanScriptResult { public class TestPlanScriptResult {
// private int testPlanId; // private int testPlanId;
// private int scriptId, // private int scriptId,
private int id; private int id;
private TestPlanScript testPlanScript; private TestPlanScript testPlanScript;
private String resultContent; private String resultContent;
@ -76,8 +76,8 @@ public class TestPlanScriptResult {
public ScriptBriefResultModel extractScriptBriefResultModel() { public ScriptBriefResultModel extractScriptBriefResultModel() {
try { try {
return (ScriptBriefResultModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(ScriptBriefResultModel.class,
ScriptBriefResultModel.class, this.getResultContent()); this.getResultContent());
} catch (JAXBException e) { } catch (JAXBException e) {
return null; return null;
} }

View File

@ -172,7 +172,7 @@ public class TestPlanFactory {
if (scriptFilterOptionsModel == null) { if (scriptFilterOptionsModel == null) {
return scriptContent; return scriptContent;
} }
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper
.tryUnmarshal(RunScenarioModel.class, scriptContent); .tryUnmarshal(RunScenarioModel.class, scriptContent);
List<String> filterPluginId = new ArrayList<String>(); List<String> filterPluginId = new ArrayList<String>();
if (scriptFilterOptionsModel.isFilterTimer()) { if (scriptFilterOptionsModel.isFilterTimer()) {

View File

@ -129,7 +129,6 @@ public class MonitorResultService {
} }
} }
@SuppressWarnings("unchecked")
private <T1 extends SampleModel, T2 extends MonitorResultBase> T2 loadMonitorResultModel( private <T1 extends SampleModel, T2 extends MonitorResultBase> T2 loadMonitorResultModel(
UUID testPlanRunId, String hostName, long beginTime, UUID testPlanRunId, String hostName, long beginTime,
Class<T1> fromMonitorClass, Class<T2> resultClass) throws Exception { Class<T1> fromMonitorClass, Class<T2> resultClass) throws Exception {
@ -143,7 +142,7 @@ public class MonitorResultService {
assert (fromMonitorClass.getName().equals(monitorResult assert (fromMonitorClass.getName().equals(monitorResult
.getType())); .getType()));
T1 result = (T1) MarshalHelper.unmarshal(fromMonitorClass, T1 result = MarshalHelper.unmarshal(fromMonitorClass,
monitorResult.getContent()); monitorResult.getContent());
ret.add(result); ret.add(result);

View File

@ -94,8 +94,7 @@ public class ScriptService {
return null; return null;
} }
try { try {
return (RunScenarioModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(RunScenarioModel.class, content);
RunScenarioModel.class, content);
} catch (JAXBException e) { } catch (JAXBException e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
return null; return null;

View File

@ -58,7 +58,7 @@ public class TestPlanScriptResultService {
System.out.println("Script Result Size from DB : " System.out.println("Script Result Size from DB : "
+ scriptResults.size()); + scriptResults.size());
for (TestPlanScriptResult testPlanScriptResult : scriptResults) { for (TestPlanScriptResult testPlanScriptResult : scriptResults) {
result.add((ScriptBriefResultModel) MarshalHelper.unmarshal( result.add(MarshalHelper.unmarshal(
ScriptBriefResultModel.class, ScriptBriefResultModel.class,
testPlanScriptResult.getResultContent())); testPlanScriptResult.getResultContent()));
} }
@ -98,8 +98,7 @@ public class TestPlanScriptResultService {
if (testPlanScriptResult == null) { if (testPlanScriptResult == null) {
return new ScriptBehaviorsBriefModel(); return new ScriptBehaviorsBriefModel();
} }
return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(ScriptBehaviorsBriefModel.class,
ScriptBehaviorsBriefModel.class,
testPlanScriptResult.getResultContent()); testPlanScriptResult.getResultContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
@ -138,8 +137,7 @@ public class TestPlanScriptResultService {
if (testPlanScriptResult == null) { if (testPlanScriptResult == null) {
return result; return result;
} }
result = (ScriptPagesBriefModel) MarshalHelper.unmarshal( result = MarshalHelper.unmarshal(ScriptPagesBriefModel.class,
ScriptPagesBriefModel.class,
testPlanScriptResult.getResultContent()); testPlanScriptResult.getResultContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
@ -159,7 +157,7 @@ public class TestPlanScriptResultService {
if (testPlanScriptResult == null) { if (testPlanScriptResult == null) {
return null; return null;
} }
return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal( return MarshalHelper.tryUnmarshal(
ScriptBriefResultModel.class, ScriptBriefResultModel.class,
testPlanScriptResult.getResultContent()); testPlanScriptResult.getResultContent());
} }

View File

@ -62,7 +62,8 @@ public class MonitorReportService {
this.monitorResultService = monitorResultService; this.monitorResultService = monitorResultService;
} }
void createMonitorResultImages(UUID testPlanRunID, Document document) throws Bench4QException { void createMonitorResultImages(UUID testPlanRunID, Document document)
throws Bench4QException {
Map<String, MonitorResultContainerModel> SUTResultMap = new HashMap<String, MonitorResultContainerModel>(); Map<String, MonitorResultContainerModel> SUTResultMap = new HashMap<String, MonitorResultContainerModel>();
List<MonitorResult> results = this.getMonitorResultService() List<MonitorResult> results = this.getMonitorResultService()
.queryMonitorResults(testPlanRunID); .queryMonitorResults(testPlanRunID);
@ -98,23 +99,23 @@ public class MonitorReportService {
try { try {
if (Class.forName(result.getType()).equals(PhysicalDiskModel.class)) { if (Class.forName(result.getType()).equals(PhysicalDiskModel.class)) {
container.getLogicalDiskModels().add( container.getLogicalDiskModels().add(
(PhysicalDiskModel) MarshalHelper.unmarshal( MarshalHelper.unmarshal(PhysicalDiskModel.class,
PhysicalDiskModel.class, result.getContent())); result.getContent()));
} else if (Class.forName(result.getType()) } else if (Class.forName(result.getType())
.equals(MemoryModel.class)) { .equals(MemoryModel.class)) {
container.getMemoryModels().add( container.getMemoryModels().add(
(MemoryModel) MarshalHelper.unmarshal( MarshalHelper.unmarshal(
MemoryModel.class, result.getContent())); MemoryModel.class, result.getContent()));
} else if (Class.forName(result.getType()).equals( } else if (Class.forName(result.getType()).equals(
NetworkInterfaceModel.class)) { NetworkInterfaceModel.class)) {
container.getNetWorkModels().add( container.getNetWorkModels().add(
(NetworkInterfaceModel) MarshalHelper.unmarshal( MarshalHelper.unmarshal(
NetworkInterfaceModel.class, NetworkInterfaceModel.class,
result.getContent())); result.getContent()));
} else if (Class.forName(result.getType()).equals( } else if (Class.forName(result.getType()).equals(
ProcessorModel.class)) { ProcessorModel.class)) {
container.getProcessorModels().add( container.getProcessorModels().add(
(ProcessorModel) MarshalHelper.unmarshal( MarshalHelper.unmarshal(
ProcessorModel.class, result.getContent())); ProcessorModel.class, result.getContent()));
} }
} catch (Exception e) { } catch (Exception e) {
@ -131,7 +132,7 @@ public class MonitorReportService {
ReportService.addParagraph(Memory, document); ReportService.addParagraph(Memory, document);
createMemoryImage(container.getMemoryModels(), document); createMemoryImage(container.getMemoryModels(), document);
ReportService.addParagraph(network_Interface, document); ReportService.addParagraph(network_Interface, document);
// createNetworkImage(container.getNetWorkModels(), document); // createNetworkImage(container.getNetWorkModels(), document);
ReportService.addParagraph(Processor, document); ReportService.addParagraph(Processor, document);
createProcessorImage(container.getProcessorModels(), document); createProcessorImage(container.getProcessorModels(), document);
} catch (Exception e) { } catch (Exception e) {
@ -212,7 +213,6 @@ public class MonitorReportService {
ReportService.buildChartStream(document, seriesCount, ReportService.buildChartStream(document, seriesCount,
timeSeriesArray, logical_Disk).toByteArray(), document); timeSeriesArray, logical_Disk).toByteArray(), document);
} }
/** /**
* refactor this kind of use * refactor this kind of use
@ -222,25 +222,25 @@ public class MonitorReportService {
* @throws Exception * @throws Exception
*/ */
// private void createNetworkImage(List<NetworkInterfaceModel> list, // private void createNetworkImage(List<NetworkInterfaceModel> list,
// Document document) throws Exception { // Document document) throws Exception {
// if (list == null || list.size() == 0) { // if (list == null || list.size() == 0) {
// return; // return;
// } // }
// int seriesCount = list.get(0).getNetworkList().size(); // int seriesCount = list.get(0).getNetworkList().size();
// List<TimeSeries> timeSeriesArray = ReportService.buildSeries( // List<TimeSeries> timeSeriesArray = ReportService.buildSeries(
// seriesCount, network_Interface); // seriesCount, network_Interface);
// for (NetworkInterfaceModel model : list) { // for (NetworkInterfaceModel model : list) {
// for (int i = 0; i < timeSeriesArray.size(); i++) { // for (int i = 0; i < timeSeriesArray.size(); i++) {
// timeSeriesArray.get(i).addOrUpdate( // timeSeriesArray.get(i).addOrUpdate(
// new Second(model.getSamplingTime()), // new Second(model.getSamplingTime()),
// model.getNetworkList().get(i).getBytesTotalPerSecond()); // model.getNetworkList().get(i).getBytesTotalPerSecond());
// } // }
// } // }
// ReportService.writeImageIntoPdf( // ReportService.writeImageIntoPdf(
// ReportService.buildChartStream(document, seriesCount, // ReportService.buildChartStream(document, seriesCount,
// timeSeriesArray, network_Interface).toByteArray(), // timeSeriesArray, network_Interface).toByteArray(),
// document); // document);
// } // }
//} // }
} }

View File

@ -55,8 +55,8 @@ public class AgentMessengerImpl implements AgentMessenger {
null, null); null, null);
System.out.println(buildBaseUrl(agent) + "/test/bookTest/" System.out.println(buildBaseUrl(agent) + "/test/bookTest/"
+ requireLoad); + requireLoad);
return (RunScenarioResultModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(RunScenarioResultModel.class,
RunScenarioResultModel.class, httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(httpResponse.getContent(), e); logger.error(httpResponse.getContent(), e);
return null; return null;
@ -90,8 +90,8 @@ public class AgentMessengerImpl implements AgentMessenger {
buildBaseUrl(agent) + "/test/submitScenarioWithParams/" buildBaseUrl(agent) + "/test/submitScenarioWithParams/"
+ agentRunId + "/" + realStartDate.getTime(), + agentRunId + "/" + realStartDate.getTime(),
"files[]", paramFiles, stringParts); "files[]", paramFiles, stringParts);
return (RunScenarioResultModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(RunScenarioResultModel.class,
RunScenarioResultModel.class, httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logIt(httpResponse, e); logIt(httpResponse, e);
return null; return null;
@ -126,8 +126,8 @@ public class AgentMessengerImpl implements AgentMessenger {
logger.error("the response is not valid"); logger.error("the response is not valid");
return null; return null;
} }
return (RunScenarioResultModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(RunScenarioResultModel.class,
RunScenarioResultModel.class, httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logIt(httpResponse, e); logIt(httpResponse, e);
return null; return null;
@ -157,8 +157,8 @@ public class AgentMessengerImpl implements AgentMessenger {
return null; return null;
} }
logger.info(httpResponse.getContent()); logger.info(httpResponse.getContent());
return (TestBriefStatusModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(TestBriefStatusModel.class,
TestBriefStatusModel.class, httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logIt(httpResponse, e); logIt(httpResponse, e);
logger.error(e.toString() logger.error(e.toString()
@ -191,7 +191,7 @@ public class AgentMessengerImpl implements AgentMessenger {
if (HttpRequester.isInvalidResponse(httpResponse)) { if (HttpRequester.isInvalidResponse(httpResponse)) {
return null; return null;
} }
return (StopTestModel) MarshalHelper.unmarshal(StopTestModel.class, return MarshalHelper.unmarshal(StopTestModel.class,
httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString() + " when stop the agent with hostName " logger.error(e.toString() + " when stop the agent with hostName "
@ -222,8 +222,8 @@ public class AgentMessengerImpl implements AgentMessenger {
if (HttpRequester.isInvalidResponse(httpResponse)) { if (HttpRequester.isInvalidResponse(httpResponse)) {
return null; return null;
} }
return (ServerStatusModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(ServerStatusModel.class,
ServerStatusModel.class, httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.error("agent :" + agent.getHostName() + " break down!"); logger.error("agent :" + agent.getHostName() + " break down!");
return null; return null;

View File

@ -1,10 +1,7 @@
package org.bench4q.master.infrastructure.communication.impl; package org.bench4q.master.infrastructure.communication.impl;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.infrastructure.communication.MonitorMessenger; import org.bench4q.master.infrastructure.communication.MonitorMessenger;
@ -55,19 +52,10 @@ public class MonitorMessengerImpl implements MonitorMessenger {
logger.info("The httpResponse is invalid "); logger.info("The httpResponse is invalid ");
return null; return null;
} }
@SuppressWarnings("unchecked") T model = MarshalHelper.unmarshal(resultClass,
T model = (T) MarshalHelper.unmarshal(resultClass,
httpResponse.getContent()); httpResponse.getContent());
model.setSamplingTime(sampleDate); model.setSamplingTime(sampleDate);
return model; return model;
} catch (IOException e) {
logger.error(ExceptionLog.getStackTrace(e));
return null;
} catch (JAXBException e) {
logger.error(ExceptionLog.getStackTrace(e));
return null;
} catch (Exception e) { } catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
return null; return null;

View File

@ -22,7 +22,7 @@ public class MarshallerTest {
public void testUnmarshal() throws JAXBException { public void testUnmarshal() throws JAXBException {
RunningAgentModel input = new RunningAgentModel(); RunningAgentModel input = new RunningAgentModel();
String content = MarshalHelper.marshal(RunningAgentModel.class, input); String content = MarshalHelper.marshal(RunningAgentModel.class, input);
RunningAgentModel output = (RunningAgentModel) MarshalHelper.unmarshal( RunningAgentModel output = MarshalHelper.unmarshal(
RunningAgentModel.class, content); RunningAgentModel.class, content);
System.out.println(input.getLoadInUse()); System.out.println(input.getLoadInUse());
assertTrue(input.getLoadInUse() == output.getLoadInUse()); assertTrue(input.getLoadInUse() == output.getLoadInUse());

View File

@ -64,9 +64,9 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan {
File scenarioFile = new File("Scripts" + FILE_SEPARATOR File scenarioFile = new File("Scripts" + FILE_SEPARATOR
+ "homepage.xml"); + "homepage.xml");
assertTrue(scenarioFile.exists()); assertTrue(scenarioFile.exists());
RunScenarioModel inputModel = (RunScenarioModel) MarshalHelper RunScenarioModel inputModel = MarshalHelper.unmarshal(
.unmarshal(RunScenarioModel.class, RunScenarioModel.class,
FileUtils.readFileToString(scenarioFile)); FileUtils.readFileToString(scenarioFile));
inputModel.setPoolSize(20); inputModel.setPoolSize(20);
Agent agent = Agent Agent agent = Agent

View File

@ -47,8 +47,8 @@ public class AgentPoolControllerTest extends TestBase {
MarshalHelper.marshal(AgentModel.class, agent), MarshalHelper.marshal(AgentModel.class, agent),
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
agentResponseModel = (AgentResponseModel) MarshalHelper.unmarshal( agentResponseModel = MarshalHelper.unmarshal(AgentResponseModel.class,
AgentResponseModel.class, httpResponse.getContent()); httpResponse.getContent());
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
System.out.println(agentResponseModel.isSuccess()); System.out.println(agentResponseModel.isSuccess());

View File

@ -78,7 +78,7 @@ public class PluginControllerTest extends TestBase {
String pluginContent = FileUtils.readFileToString(file); String pluginContent = FileUtils.readFileToString(file);
HttpResponse httpResponse = this.httpRequester.sendPutXml(url, HttpResponse httpResponse = this.httpRequester.sendPutXml(url,
pluginContent, makeAccessTockenMap(this.getAccessTocken())); pluginContent, makeAccessTockenMap(this.getAccessTocken()));
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = MarshalHelper
.tryUnmarshal(PluginResponseModel.class, .tryUnmarshal(PluginResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
Assert.assertNotNull(pluginResponseModel); Assert.assertNotNull(pluginResponseModel);
@ -94,7 +94,7 @@ public class PluginControllerTest extends TestBase {
this.test_PluginHelper.addPlugin(fileName, pluginService, pluginName); this.test_PluginHelper.addPlugin(fileName, pluginService, pluginName);
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = MarshalHelper
.tryUnmarshal(PluginResponseModel.class, .tryUnmarshal(PluginResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
@ -116,7 +116,7 @@ public class PluginControllerTest extends TestBase {
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = MarshalHelper
.tryUnmarshal(PluginResponseModel.class, .tryUnmarshal(PluginResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertNotNull(pluginResponseModel); assertNotNull(pluginResponseModel);
@ -133,7 +133,7 @@ public class PluginControllerTest extends TestBase {
String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName; String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName;
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = MarshalHelper
.tryUnmarshal(PluginResponseModel.class, .tryUnmarshal(PluginResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertNotNull(pluginResponseModel); assertNotNull(pluginResponseModel);
@ -148,7 +148,7 @@ public class PluginControllerTest extends TestBase {
String url = URLSTRING + "/loadBehaviors/" + this.pluginName; String url = URLSTRING + "/loadBehaviors/" + this.pluginName;
HttpResponse httpResponse = this.httpRequester.sendPost(url, null, HttpResponse httpResponse = this.httpRequester.sendPost(url, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = MarshalHelper
.tryUnmarshal(PluginResponseModel.class, .tryUnmarshal(PluginResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertNotNull(pluginResponseModel); assertNotNull(pluginResponseModel);
@ -170,9 +170,8 @@ public class PluginControllerTest extends TestBase {
properties); properties);
PluginResponseModel pluginResponseModel = null; PluginResponseModel pluginResponseModel = null;
try { try {
pluginResponseModel = (PluginResponseModel) MarshalHelper pluginResponseModel = MarshalHelper.unmarshal(
.unmarshal(PluginResponseModel.class, PluginResponseModel.class, httpResponse.getContent());
httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.info(ExceptionLog.getStackTrace(e)); logger.info(ExceptionLog.getStackTrace(e));
} }

View File

@ -31,9 +31,9 @@ public class RecordScriptControllerTest extends TestBase {
+ "/startScriptRecordServer", null, + "/startScriptRecordServer", null,
this.makeAccessTockenMap(this.getAccessTocken())); this.makeAccessTockenMap(this.getAccessTocken()));
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper OperateScriptServerResponseModel ret = MarshalHelper.unmarshal(
.unmarshal(OperateScriptServerResponseModel.class, OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertTrue(ret.isSuccess()); assertTrue(ret.isSuccess());
return ret; return ret;
} }
@ -46,9 +46,9 @@ public class RecordScriptControllerTest extends TestBase {
HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL
+ "/stopScriptRecordServer", paramsMap, + "/stopScriptRecordServer", paramsMap,
this.makeAccessTockenMap(this.accessTocken)); this.makeAccessTockenMap(this.accessTocken));
OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper OperateScriptServerResponseModel ret = MarshalHelper.unmarshal(
.unmarshal(OperateScriptServerResponseModel.class, OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertTrue(ret.isSuccess()); assertTrue(ret.isSuccess());
} }
@ -67,9 +67,9 @@ public class RecordScriptControllerTest extends TestBase {
HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL
+ "/saveScriptToDB", params, + "/saveScriptToDB", params,
this.makeAccessTockenMap(this.getAccessTocken())); this.makeAccessTockenMap(this.getAccessTocken()));
OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper OperateScriptServerResponseModel ret = MarshalHelper.unmarshal(
.unmarshal(OperateScriptServerResponseModel.class, OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertTrue(ret.isSuccess()); assertTrue(ret.isSuccess());
assertNotNull(ret.getScriptModels()); assertNotNull(ret.getScriptModels());
assertNotNull(ret.getScriptModels().get(0)); assertNotNull(ret.getScriptModels().get(0));
@ -88,7 +88,7 @@ public class RecordScriptControllerTest extends TestBase {
test.stopRecord(model); test.stopRecord(model);
ScriptModel scriptModel = test.saveScriptToDB(model, "chen2"); ScriptModel scriptModel = test.saveScriptToDB(model, "chen2");
assertNotNull(scriptModel.getScriptContent()); assertNotNull(scriptModel.getScriptContent());
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper
.unmarshal(RunScenarioModel.class, .unmarshal(RunScenarioModel.class,
scriptModel.getScriptContent()); scriptModel.getScriptContent());
assertNotNull(runScenarioModel); assertNotNull(runScenarioModel);

View File

@ -28,7 +28,7 @@ public class ScriptControllerTest extends TestBase {
String url = this.controllerUrl + "/loadScriptList"; String url = this.controllerUrl + "/loadScriptList";
HttpResponse httpResponse = this.httpRequester.sendGet(url, null, HttpResponse httpResponse = this.httpRequester.sendGet(url, null,
this.makeAccessTockenMap(this.login())); this.makeAccessTockenMap(this.login()));
OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper OperateScriptServerResponseModel ret = MarshalHelper
.unmarshal(OperateScriptServerResponseModel.class, .unmarshal(OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertTrue(ret.getScriptModels().size() > 0); assertTrue(ret.getScriptModels().size() > 0);

View File

@ -39,9 +39,8 @@ public class TestBase {
try { try {
httpResponse = this.httpRequester.sendGet(urlString, map, null); httpResponse = this.httpRequester.sendGet(urlString, map, null);
System.out.println("http content:" + httpResponse.getContent()); System.out.println("http content:" + httpResponse.getContent());
return ((AuthorizeResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(AuthorizeResponseModel.class,
AuthorizeResponseModel.class, httpResponse.getContent())) httpResponse.getContent()).getAccessToken();
.getAccessToken();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

View File

@ -38,7 +38,7 @@ public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan
+ "/loadScriptBirefResults/" + this.getScriptId() + "/loadScriptBirefResults/" + this.getScriptId()
+ "/averageResponseTime", null, + "/averageResponseTime", null,
this.makeAccessTockenMap(this.getAccessTocken())); this.makeAccessTockenMap(this.getAccessTocken()));
ResultLoadModel loadModel = (ResultLoadModel) MarshalHelper.unmarshal( ResultLoadModel loadModel = MarshalHelper.unmarshal(
ResultLoadModel.class, httpResponse.getContent()); ResultLoadModel.class, httpResponse.getContent());
assertEquals(3, loadModel.getValueTimeModels().size()); assertEquals(3, loadModel.getValueTimeModels().size());
} }

View File

@ -35,7 +35,7 @@ public class Test_MonitorController extends TestBase {
if (HttpRequester.isInvalidResponse(httpResponse)) { if (HttpRequester.isInvalidResponse(httpResponse)) {
fail("not valid response!"); fail("not valid response!");
} }
MonitorMemoryResponseModel memoryResponseModel = (MonitorMemoryResponseModel) MarshalHelper MonitorMemoryResponseModel memoryResponseModel = MarshalHelper
.unmarshal(MonitorMemoryResponseModel.class, .unmarshal(MonitorMemoryResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertEquals(3, memoryResponseModel.getMemoryModels().size()); assertEquals(3, memoryResponseModel.getMemoryModels().size());

View File

@ -143,7 +143,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan {
+ "/runTestPlanWithTestPlanModel", content, + "/runTestPlanWithTestPlanModel", content,
this.makeAccessTockenMap(this.accessTocken)); this.makeAccessTockenMap(this.accessTocken));
result = (TestPlanResultModel) MarshalHelper.unmarshal( result = MarshalHelper.unmarshal(
TestPlanResultModel.class, httpResponse.getContent()); TestPlanResultModel.class, httpResponse.getContent());
System.out.println(result.getCurrentStatus()); System.out.println(result.getCurrentStatus());
return result.getTestPlanId(); return result.getTestPlanId();
@ -182,7 +182,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan {
HttpResponse httpResponse = this.httpRequester.sendGet(this._url HttpResponse httpResponse = this.httpRequester.sendGet(this._url
+ "/getRunningInfo", params, + "/getRunningInfo", params,
this.makeAccessTockenMap(this.getAccessTocken())); this.makeAccessTockenMap(this.getAccessTocken()));
TestPlanResultModel ret = (TestPlanResultModel) MarshalHelper TestPlanResultModel ret = MarshalHelper
.unmarshal(TestPlanResultModel.class, httpResponse.getContent()); .unmarshal(TestPlanResultModel.class, httpResponse.getContent());
System.out.println(ret.getCurrentStatus()); System.out.println(ret.getCurrentStatus());
return ret; return ret;
@ -194,7 +194,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan {
+ "/scriptBrief/" + testPlanId.toString() + "/" + scriptId + "/scriptBrief/" + testPlanId.toString() + "/" + scriptId
+ "/" + 0, null, createAccessTokenMap()); + "/" + 0, null, createAccessTokenMap());
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
TestPlanScriptBriefResultModel ret = (TestPlanScriptBriefResultModel) MarshalHelper TestPlanScriptBriefResultModel ret = MarshalHelper
.unmarshal(TestPlanScriptBriefResultModel.class, .unmarshal(TestPlanScriptBriefResultModel.class,
httpResponse.getContent()); httpResponse.getContent());
for (ScriptBriefResultModel scriptBriefResultModel : ret for (ScriptBriefResultModel scriptBriefResultModel : ret
@ -210,7 +210,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan {
+ "/pagesBrief/" + testPlanId.toString() + "/" + scriptId, + "/pagesBrief/" + testPlanId.toString() + "/" + scriptId,
null, createAccessTokenMap()); null, createAccessTokenMap());
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
ScriptPagesBriefModel ret = (ScriptPagesBriefModel) MarshalHelper ScriptPagesBriefModel ret = MarshalHelper
.unmarshal(ScriptPagesBriefModel.class, .unmarshal(ScriptPagesBriefModel.class,
httpResponse.getContent()); httpResponse.getContent());
return ret; return ret;
@ -254,7 +254,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan {
+ testPlanID.toString() + "/" + hostName + "/6565/0", + testPlanID.toString() + "/" + hostName + "/6565/0",
null, this.createAccessTokenMap()); null, this.createAccessTokenMap());
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
MonitorPhysicalDiskResponseModel logicalDiskResponseModel = (MonitorPhysicalDiskResponseModel) MarshalHelper MonitorPhysicalDiskResponseModel logicalDiskResponseModel = MarshalHelper
.unmarshal(MonitorPhysicalDiskResponseModel.class, .unmarshal(MonitorPhysicalDiskResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertNotNull(logicalDiskResponseModel); assertNotNull(logicalDiskResponseModel);

View File

@ -31,7 +31,7 @@ public class Test_TestPlanResultController extends TestBase {
+ testPlanRunId, null, + testPlanRunId, null,
makeAccessTockenMap(this.getAccessTocken())); makeAccessTockenMap(this.getAccessTocken()));
assertTrue(httpResponse != null); assertTrue(httpResponse != null);
ResultLoadModel resultModel = (ResultLoadModel) MarshalHelper ResultLoadModel resultModel = MarshalHelper
.unmarshal(ResultLoadModel.class, httpResponse.getContent()); .unmarshal(ResultLoadModel.class, httpResponse.getContent());
assertTrue(resultModel.getValueTimeModels().size() > 0); assertTrue(resultModel.getValueTimeModels().size() > 0);
} }

View File

@ -27,7 +27,7 @@ public class UserControllerTest extends TestBase {
+ "/user/normalAuthorize?userName=chen&password=123"; + "/user/normalAuthorize?userName=chen&password=123";
HttpResponse httpResponse = this.httpRequester.sendGet(urlString, null, HttpResponse httpResponse = this.httpRequester.sendGet(urlString, null,
null); null);
AuthorizeResponseModel ret = (AuthorizeResponseModel) MarshalHelper AuthorizeResponseModel ret = MarshalHelper
.unmarshal(AuthorizeResponseModel.class, .unmarshal(AuthorizeResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertTrue(ret.isSuccess()); assertTrue(ret.isSuccess());
@ -38,7 +38,7 @@ public class UserControllerTest extends TestBase {
String url = BASE_URL String url = BASE_URL
+ "/user/adminAuthorize?userName=chen&password=123"; + "/user/adminAuthorize?userName=chen&password=123";
HttpResponse httpResponse = this.httpRequester.sendGet(url, null, null); HttpResponse httpResponse = this.httpRequester.sendGet(url, null, null);
AuthorizeResponseModel ret = (AuthorizeResponseModel) MarshalHelper AuthorizeResponseModel ret = MarshalHelper
.unmarshal(AuthorizeResponseModel.class, .unmarshal(AuthorizeResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertTrue(ret.isSuccess()); assertTrue(ret.isSuccess());
@ -56,7 +56,7 @@ public class UserControllerTest extends TestBase {
params.put("scope", "1"); params.put("scope", "1");
HttpResponse httpResponse = this.httpRequester.sendGet(url, params, HttpResponse httpResponse = this.httpRequester.sendGet(url, params,
null); null);
RegisterResponseModel registerResponseModel = (RegisterResponseModel) MarshalHelper RegisterResponseModel registerResponseModel = MarshalHelper
.tryUnmarshal(RegisterResponseModel.class, .tryUnmarshal(RegisterResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
assertNotNull(registerResponseModel); assertNotNull(registerResponseModel);
@ -70,7 +70,7 @@ public class UserControllerTest extends TestBase {
String url = BASE_URL + "/user/deleteUser" + "/" + userName; String url = BASE_URL + "/user/deleteUser" + "/" + userName;
HttpResponse httpResponse = this.httpRequester.sendGet(url, null, null); HttpResponse httpResponse = this.httpRequester.sendGet(url, null, null);
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
AuthorizeResponseModel authorizeResponseModel = (AuthorizeResponseModel) MarshalHelper AuthorizeResponseModel authorizeResponseModel = MarshalHelper
.tryUnmarshal(AuthorizeResponseModel.class, .tryUnmarshal(AuthorizeResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());

View File

@ -82,7 +82,7 @@ public class Test_Agent {
assertEquals(AgentStatus.InIdle, agentModel.getCurrentEnumStatus()); assertEquals(AgentStatus.InIdle, agentModel.getCurrentEnumStatus());
String content = MarshalHelper.tryMarshal(agentModel); String content = MarshalHelper.tryMarshal(agentModel);
System.out.println(content); System.out.println(content);
AgentModel modelAfterUnMarshal = (AgentModel) MarshalHelper AgentModel modelAfterUnMarshal = MarshalHelper
.tryUnmarshal(AgentModel.class, content); .tryUnmarshal(AgentModel.class, content);
assertEquals(modelAfterUnMarshal.getCurrentEnumStatus(), assertEquals(modelAfterUnMarshal.getCurrentEnumStatus(),
AgentStatus.InIdle); AgentStatus.InIdle);

View File

@ -92,9 +92,9 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
double ratio = (double) runningAgentDB.getLoadInUse() double ratio = (double) runningAgentDB.getLoadInUse()
/ (double) testPlanScript.getRequireLoad(); / (double) testPlanScript.getRequireLoad();
ScheduleModel scheduleModelInRunningAgent = runningAgentDB ScheduleModel scheduleModelInRunningAgent = runningAgentDB
.generateScheduleModelWithRatio((ScheduleModel) MarshalHelper .generateScheduleModelWithRatio(MarshalHelper.tryUnmarshal(
.tryUnmarshal(ScheduleModel.class, ScheduleModel.class,
testPlanScript.getScheduleContent())); testPlanScript.getScheduleContent()));
assertEquals(Math.round(ratio * testPlanScript.getRequireLoad()), assertEquals(Math.round(ratio * testPlanScript.getRequireLoad()),
scheduleModelInRunningAgent.getMaxLoad()); scheduleModelInRunningAgent.getMaxLoad());
System.out.println(scheduleModelInRunningAgent.getMaxLoad()); System.out.println(scheduleModelInRunningAgent.getMaxLoad());

View File

@ -158,7 +158,7 @@ public class Test_ScriptService {
String content = this.getScriptService() String content = this.getScriptService()
.getScript(getUploadScriptId(getUserForTest())) .getScript(getUploadScriptId(getUserForTest()))
.getScriptContent(); .getScriptContent();
RunScenarioModel afterUpdate = (RunScenarioModel) MarshalHelper RunScenarioModel afterUpdate = MarshalHelper
.unmarshal(RunScenarioModel.class, content); .unmarshal(RunScenarioModel.class, content);
assertEquals(1, afterUpdate.getPages().size()); assertEquals(1, afterUpdate.getPages().size());
} }

View File

@ -20,11 +20,10 @@ import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
public class Bench4qTestScriptAdapter implements IScriptAdapter { public class Bench4qTestScriptAdapter implements IScriptAdapter {
private int idGenerator =1; private int idGenerator = 1;
private int pageCount; private int pageCount;
private RunScenarioModel runScenarioModel; private RunScenarioModel runScenarioModel;
private List<ChildrenUrl> childrenUrls = new ArrayList<ChildrenUrl>(); private List<ChildrenUrl> childrenUrls = new ArrayList<ChildrenUrl>();
private BehaviorModel preTimerBehavior = null;
private static Logger logger = Logger private static Logger logger = Logger
.getLogger(Bench4qTestScriptAdapter.class); .getLogger(Bench4qTestScriptAdapter.class);
@ -72,7 +71,7 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
this.getRunScenarioModel().getPages().add(new PageModel(idGenerator++)); this.getRunScenarioModel().getPages().add(new PageModel(idGenerator++));
assert (pageCountEqualWithPageSizeInScenario()); assert (pageCountEqualWithPageSizeInScenario());
} }
public void insertUserBehaviorsToScenario(BehaviorModel model) { public void insertUserBehaviorsToScenario(BehaviorModel model) {
List<BatchModel> batches = this.getCurrentPage().getBatches(); List<BatchModel> batches = this.getCurrentPage().getBatches();
model.setId(idGenerator++); model.setId(idGenerator++);
@ -86,29 +85,31 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
return; return;
} }
guardChildBatchExist(batches, parentBatchId); guardChildBatchExist(batches, parentBatchId);
getBatchById(batches, getBatchById(batches, parentBatchId).getChildId()).getBehaviors() getBatchById(batches, getBatchById(batches, parentBatchId).getChildId())
.add(model); .getBehaviors().add(model);
} }
private BatchModel getBatchById(List<BatchModel> batches, int batchId){
for(BatchModel batchModel : batches){ private BatchModel getBatchById(List<BatchModel> batches, int batchId) {
if(batchModel.getId() == batchId){ for (BatchModel batchModel : batches) {
if (batchModel.getId() == batchId) {
return batchModel; return batchModel;
} }
} }
return null; return null;
} }
private boolean guardChildBatchExist(List<BatchModel> batches, private boolean guardChildBatchExist(List<BatchModel> batches,
int parentBatchId) { int parentBatchId) {
if (isChildBatchAbsent(batches, parentBatchId)) { if (isChildBatchAbsent(batches, parentBatchId)) {
BatchModel batchBehavior = createBatchBehaviorWithProperBatchId(); BatchModel batchBehavior = createBatchBehaviorWithProperBatchId();
batchBehavior.setParentId(parentBatchId); batchBehavior.setParentId(parentBatchId);
batches.add(batchBehavior); batches.add(batchBehavior);
BatchModel parentBatch = getBatchById(batches,parentBatchId); BatchModel parentBatch = getBatchById(batches, parentBatchId);
if(parentBatch != null){ if (parentBatch != null) {
parentBatch.setChildId(batchBehavior.getId()); parentBatch.setChildId(batchBehavior.getId());
} }
return false; return false;
}else{ } else {
return true; return true;
} }
} }
@ -132,22 +133,22 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
private BatchModel createBatchBehaviorWithProperBatchId() { private BatchModel createBatchBehaviorWithProperBatchId() {
BatchModel batchBehavior = new BatchModel(idGenerator++); BatchModel batchBehavior = new BatchModel(idGenerator++);
// batchBehavior.setId(RunScenarioModelHelper.getBatches( // batchBehavior.setId(RunScenarioModelHelper.getBatches(
// this.runScenarioModel).size()); // this.runScenarioModel).size());
batchBehavior.setParentId(-1); batchBehavior.setParentId(-1);
batchBehavior.setChildId(-1); batchBehavior.setChildId(-1);
// List<BehaviorModel> behaviors = new ArrayList<BehaviorModel>(); // List<BehaviorModel> behaviors = new ArrayList<BehaviorModel>();
// batchBehavior.setBehaviors(behaviors); // batchBehavior.setBehaviors(behaviors);
return batchBehavior; return batchBehavior;
} }
private boolean isChildBatchAbsent(List<BatchModel> batches, private boolean isChildBatchAbsent(List<BatchModel> batches,
int parentBatchId) { int parentBatchId) {
// if (parentBatchId >= batches.size()) { // if (parentBatchId >= batches.size()) {
// return false; // return false;
// } // }
BatchModel batchModel = getBatchById(batches, parentBatchId); BatchModel batchModel = getBatchById(batches, parentBatchId);
if(batchModel != null){ if (batchModel != null) {
return batchModel.getChildId() < 0; return batchModel.getChildId() < 0;
} }
return false; return false;
@ -189,17 +190,18 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
public int getParentBatchIdWithParentUrl(String url) { public int getParentBatchIdWithParentUrl(String url) {
List<BatchModel> batchesInScenario = RunScenarioModelHelper List<BatchModel> batchesInScenario = RunScenarioModelHelper
.getBatches(this.getRunScenarioModel()); .getBatches(this.getRunScenarioModel());
// for (int batchId = 0; batchId < batchesInScenario.size(); batchId++) { // for (int batchId = 0; batchId < batchesInScenario.size(); batchId++)
// BatchModel batch = batchesInScenario.get(batchId); // {
// for (BehaviorModel behavior : batch.getBehaviors()) { // BatchModel batch = batchesInScenario.get(batchId);
// for (ParameterModel parameter : behavior.getParameters()) { // for (BehaviorModel behavior : batch.getBehaviors()) {
// if (parameter.getKey().equals("url") // for (ParameterModel parameter : behavior.getParameters()) {
// && parameter.getValue().equals(url)) { // if (parameter.getKey().equals("url")
// return batchId; // && parameter.getValue().equals(url)) {
// } // return batchId;
// } // }
// } // }
// } // }
// }
for (int i = 0; i < batchesInScenario.size(); i++) { for (int i = 0; i < batchesInScenario.size(); i++) {
BatchModel batch = batchesInScenario.get(i); BatchModel batch = batchesInScenario.get(i);
for (BehaviorModel behavior : batch.getBehaviors()) { for (BehaviorModel behavior : batch.getBehaviors()) {
@ -238,8 +240,8 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
return; return;
} }
try { try {
this.setRunScenarioModel((RunScenarioModel) MarshalHelper this.setRunScenarioModel(MarshalHelper.unmarshal(
.unmarshal(RunScenarioModel.class, text)); RunScenarioModel.class, text));
} catch (JAXBException e) { } catch (JAXBException e) {
logger.error(e, e); logger.error(e, e);
this.setRunScenarioModel(new RunScenarioModel()); this.setRunScenarioModel(new RunScenarioModel());

View File

@ -28,14 +28,15 @@ public class MarshalHelper {
} }
} }
public static Object unmarshal(Class<?> classToUnmarshal, String input) @SuppressWarnings("unchecked")
public static <T> T unmarshal(Class<T> classToUnmarshal, String input)
throws JAXBException { throws JAXBException {
try { try {
Unmarshaller unmarshaller; Unmarshaller unmarshaller;
unmarshaller = JAXBContext.newInstance(classToUnmarshal) unmarshaller = JAXBContext.newInstance(classToUnmarshal)
.createUnmarshaller(); .createUnmarshaller();
return unmarshaller.unmarshal(new ByteArrayInputStream(input return (T) unmarshaller.unmarshal(new ByteArrayInputStream(input
.getBytes("utf-8"))); .getBytes("utf-8")));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -53,9 +54,9 @@ public class MarshalHelper {
* @param input * @param input
* @return null if there is an exception happened. * @return null if there is an exception happened.
*/ */
public static Object tryUnmarshal(Class<?> classToUnmarshal, String input) { public static <T> T tryUnmarshal(Class<T> classToUnmarshal, String input) {
try { try {
return unmarshal(classToUnmarshal, input); return (T) unmarshal(classToUnmarshal, input);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;

View File

@ -105,7 +105,7 @@ public class ScriptController extends BaseController {
if (operateScriptServerResponseModel.isSuccess()) { if (operateScriptServerResponseModel.isSuccess()) {
ScriptModel scriptModel = operateScriptServerResponseModel ScriptModel scriptModel = operateScriptServerResponseModel
.getScriptModels().get(0); .getScriptModels().get(0);
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper
.tryUnmarshal(RunScenarioModel.class, .tryUnmarshal(RunScenarioModel.class,
scriptModel.getScriptContent()); scriptModel.getScriptContent());
if (runScenarioModel == null) { if (runScenarioModel == null) {
@ -135,7 +135,7 @@ public class ScriptController extends BaseController {
if (operateScriptServerResponseModel.isSuccess()) { if (operateScriptServerResponseModel.isSuccess()) {
ScriptModel scriptModel = operateScriptServerResponseModel ScriptModel scriptModel = operateScriptServerResponseModel
.getScriptModels().get(0); .getScriptModels().get(0);
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper
.tryUnmarshal(RunScenarioModel.class, .tryUnmarshal(RunScenarioModel.class,
scriptModel.getScriptContent()); scriptModel.getScriptContent());
if (runScenarioModel == null) { if (runScenarioModel == null) {
@ -362,7 +362,7 @@ public class ScriptController extends BaseController {
return fail(map, ""); return fail(map, "");
} }
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = MarshalHelper
.tryUnmarshal( .tryUnmarshal(
RunScenarioModel.class, RunScenarioModel.class,
operateScriptServerResponseModel.getScriptModels() operateScriptServerResponseModel.getScriptModels()

View File

@ -30,7 +30,7 @@ public class AgentManagerMessager extends MasterMessager {
createFaliAgentResponseModel(); createFaliAgentResponseModel();
} }
return (AgentResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
AgentResponseModel.class, httpResponse.getContent()); AgentResponseModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
this.handleException(httpResponse, e); this.handleException(httpResponse, e);
@ -71,7 +71,7 @@ public class AgentManagerMessager extends MasterMessager {
return createFaliAgentResponseModel(); return createFaliAgentResponseModel();
} }
return (AgentResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
AgentResponseModel.class, httpResponse.getContent()); AgentResponseModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
this.handleException(httpResponse, e); this.handleException(httpResponse, e);

View File

@ -35,7 +35,7 @@ public class MonitorMessager extends MasterMessager {
return null; return null;
} }
MonitorMemoryResponseModel memoryResponseModel = (MonitorMemoryResponseModel) MarshalHelper MonitorMemoryResponseModel memoryResponseModel = MarshalHelper
.unmarshal(MonitorMemoryResponseModel.class, .unmarshal(MonitorMemoryResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
return memoryResponseModel; return memoryResponseModel;
@ -61,7 +61,7 @@ public class MonitorMessager extends MasterMessager {
return null; return null;
} }
MonitorProcessorResponseModel monitorProcessorResponseModel = (MonitorProcessorResponseModel) MarshalHelper MonitorProcessorResponseModel monitorProcessorResponseModel = MarshalHelper
.unmarshal(MonitorProcessorResponseModel.class, .unmarshal(MonitorProcessorResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
return monitorProcessorResponseModel; return monitorProcessorResponseModel;
@ -85,7 +85,7 @@ public class MonitorMessager extends MasterMessager {
handleInvalidatedResponse(url); handleInvalidatedResponse(url);
return null; return null;
} }
MonitorNetworkReponseModel networkInterfaceModel = (MonitorNetworkReponseModel) MarshalHelper MonitorNetworkReponseModel networkInterfaceModel = MarshalHelper
.unmarshal(MonitorNetworkReponseModel.class, .unmarshal(MonitorNetworkReponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
return networkInterfaceModel; return networkInterfaceModel;
@ -110,7 +110,7 @@ public class MonitorMessager extends MasterMessager {
this.handleInvalidatedResponse(url); this.handleInvalidatedResponse(url);
return null; return null;
} }
MonitorPhysicalDiskResponseModel monitorPhysicalDiskResponseModel = (MonitorPhysicalDiskResponseModel) MarshalHelper MonitorPhysicalDiskResponseModel monitorPhysicalDiskResponseModel = MarshalHelper
.unmarshal(MonitorPhysicalDiskResponseModel.class, .unmarshal(MonitorPhysicalDiskResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
return monitorPhysicalDiskResponseModel; return monitorPhysicalDiskResponseModel;

View File

@ -112,7 +112,7 @@ public class PluginMessager extends MasterMessager {
private PluginResponseModel extractPluginResponseModel( private PluginResponseModel extractPluginResponseModel(
HttpResponse httpResponse) throws JAXBException { HttpResponse httpResponse) throws JAXBException {
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper PluginResponseModel pluginResponseModel = MarshalHelper
.unmarshal(PluginResponseModel.class, httpResponse.getContent()); .unmarshal(PluginResponseModel.class, httpResponse.getContent());
if (!pluginResponseModel.isSuccess()) { if (!pluginResponseModel.isSuccess()) {
logger.info(pluginResponseModel.getFailMessage()); logger.info(pluginResponseModel.getFailMessage());

View File

@ -68,7 +68,7 @@ public class RecordPortMessager extends MasterMessager {
private OrganizeRecordPortResponseModel extractOrganizeRecordPortResponseModel( private OrganizeRecordPortResponseModel extractOrganizeRecordPortResponseModel(
HttpResponse httpResponse) throws JAXBException { HttpResponse httpResponse) throws JAXBException {
OrganizeRecordPortResponseModel organizeRecordPortResponseModel = (OrganizeRecordPortResponseModel) MarshalHelper OrganizeRecordPortResponseModel organizeRecordPortResponseModel = MarshalHelper
.unmarshal(OrganizeRecordPortResponseModel.class, .unmarshal(OrganizeRecordPortResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
if (organizeRecordPortResponseModel.getPortModels() == null) { if (organizeRecordPortResponseModel.getPortModels() == null) {

View File

@ -84,7 +84,7 @@ public class ScriptMessager extends MasterMessager {
System.out.println(httpResponse.getContent()); System.out.println(httpResponse.getContent());
if (!validateHttpResponse(httpResponse)) if (!validateHttpResponse(httpResponse))
return null; return null;
return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
OperateScriptServerResponseModel.class, OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
@ -108,7 +108,7 @@ public class ScriptMessager extends MasterMessager {
paramFiles, stringParts); paramFiles, stringParts);
if (!validateHttpResponse(httpResponse)) if (!validateHttpResponse(httpResponse))
return null; return null;
return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
OperateScriptServerResponseModel.class, OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
@ -154,7 +154,7 @@ public class ScriptMessager extends MasterMessager {
// paramFiles, "paramContents[]", stringPart); // paramFiles, "paramContents[]", stringPart);
// if (!validateHttpResponse(httpResponse)) // if (!validateHttpResponse(httpResponse))
// return null; // return null;
// return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( // return MarshalHelper.unmarshal(
// OperateScriptServerResponseModel.class, // OperateScriptServerResponseModel.class,
// httpResponse.getContent()); // httpResponse.getContent());
// //
@ -224,7 +224,7 @@ public class ScriptMessager extends MasterMessager {
private OperateScriptServerResponseModel extractOperateScriptServerResponseModel( private OperateScriptServerResponseModel extractOperateScriptServerResponseModel(
HttpResponse httpResponse) throws JAXBException { HttpResponse httpResponse) throws JAXBException {
return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
OperateScriptServerResponseModel.class, OperateScriptServerResponseModel.class,
httpResponse.getContent()); httpResponse.getContent());
} }
@ -239,7 +239,7 @@ public class ScriptMessager extends MasterMessager {
handleInvalidatedResponse(url); handleInvalidatedResponse(url);
return null; return null;
} }
return (ScriptFilterModel) MarshalHelper.tryUnmarshal( return MarshalHelper.tryUnmarshal(
ScriptFilterModel.class, httpResponse.getContent()); ScriptFilterModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
this.handleException(httpResponse, e); this.handleException(httpResponse, e);

View File

@ -92,7 +92,7 @@ public class TestPlanMessager extends MasterMessager {
return null; return null;
} }
return (TestPlanScriptBriefResultModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
TestPlanScriptBriefResultModel.class, TestPlanScriptBriefResultModel.class,
httpResponse.getContent()); httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
@ -111,7 +111,7 @@ public class TestPlanMessager extends MasterMessager {
makeAccessTockenMap(accessToken)); makeAccessTockenMap(accessToken));
if (!validateHttpResponse(httpResponse)) if (!validateHttpResponse(httpResponse))
return null; return null;
return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
ScriptBehaviorsBriefModel.class, httpResponse.getContent()); ScriptBehaviorsBriefModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
this.handleException(httpResponse, e); this.handleException(httpResponse, e);
@ -131,7 +131,7 @@ public class TestPlanMessager extends MasterMessager {
handleInvalidatedResponse(url); handleInvalidatedResponse(url);
return null; return null;
} }
return (TestPlanDBModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
TestPlanDBModel.class, httpResponse.getContent()); TestPlanDBModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
handleException(httpResponse, e); handleException(httpResponse, e);
@ -205,14 +205,14 @@ public class TestPlanMessager extends MasterMessager {
private TestPlanResponseModel extractTestPlanResponseModel( private TestPlanResponseModel extractTestPlanResponseModel(
HttpResponse httpResponse) throws JAXBException, HttpResponse httpResponse) throws JAXBException,
UnsupportedEncodingException { UnsupportedEncodingException {
return (TestPlanResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
TestPlanResponseModel.class, httpResponse.getContent()); TestPlanResponseModel.class, httpResponse.getContent());
} }
private TestPlanResultModel extractTestPlanResultModel( private TestPlanResultModel extractTestPlanResultModel(
HttpResponse httpResponse) throws JAXBException, HttpResponse httpResponse) throws JAXBException,
UnsupportedEncodingException { UnsupportedEncodingException {
return (TestPlanResultModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
TestPlanResultModel.class, httpResponse.getContent()); TestPlanResultModel.class, httpResponse.getContent());
} }
@ -231,7 +231,7 @@ public class TestPlanMessager extends MasterMessager {
} }
System.out.println("getLatestScriptBriefResult:\r\n" System.out.println("getLatestScriptBriefResult:\r\n"
+ httpResponse.getContent()); + httpResponse.getContent());
return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal( return MarshalHelper.tryUnmarshal(
ScriptBriefResultModel.class, httpResponse.getContent()); ScriptBriefResultModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
@ -252,7 +252,7 @@ public class TestPlanMessager extends MasterMessager {
handleInvalidatedResponse(url); handleInvalidatedResponse(url);
return null; return null;
} }
return (ScriptPagesBriefModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
ScriptPagesBriefModel.class, httpResponse.getContent()); ScriptPagesBriefModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {

View File

@ -28,7 +28,7 @@ public class UserMessager extends MasterMessager {
if (!validateHttpResponse(httpResponse)) { if (!validateHttpResponse(httpResponse)) {
return null; return null;
} }
return (RegisterResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
RegisterResponseModel.class, httpResponse.getContent()); RegisterResponseModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
@ -69,7 +69,7 @@ public class UserMessager extends MasterMessager {
httpResponse = this.getHttpRequester().sendGet(url, params, null); httpResponse = this.getHttpRequester().sendGet(url, params, null);
if (!validateHttpResponse(httpResponse)) if (!validateHttpResponse(httpResponse))
return null; return null;
return (AuthorizeResponseModel) MarshalHelper.unmarshal( return MarshalHelper.unmarshal(
AuthorizeResponseModel.class, httpResponse.getContent()); AuthorizeResponseModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {