From b1d0f3eb1d1de27f88895504179828233d568374 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Mon, 15 Sep 2014 21:46:03 +0800 Subject: [PATCH] refactor MarshalHelper to generic refactor MarshalHelper to generic --- .../org/bench4q/agent/api/TestController.java | 6 +- .../org/bench4q/agent/scenario/Scenario.java | 7 +- .../agent/test/ExtractScenarioTest.java | 2 +- .../agent/test/TestWithScriptFile.java | 28 ++++---- .../agent/test/plugin/Test_HttpPlugin.java | 2 +- .../master/domain/entity/RunningAgentDB.java | 6 +- .../master/domain/entity/TestPlanScript.java | 5 +- .../domain/entity/TestPlanScriptResult.java | 8 +-- .../domain/factory/TestPlanFactory.java | 2 +- .../domain/service/MonitorResultService.java | 3 +- .../master/domain/service/ScriptService.java | 3 +- .../service/TestPlanScriptResultService.java | 10 ++- .../service/report/MonitorReportService.java | 58 ++++++++-------- .../impl/AgentMessengerImpl.java | 22 +++---- .../impl/MonitorMessengerImpl.java | 14 +--- .../test/java/ModelTest/MarshallerTest.java | 2 +- .../communication/Test_AgentMessenger.java | 6 +- .../controller/AgentPoolControllerTest.java | 4 +- .../controller/PluginControllerTest.java | 15 ++--- .../RecordScriptControllerTest.java | 20 +++--- .../controller/ScriptControllerTest.java | 2 +- .../master/unitTest/controller/TestBase.java | 5 +- .../TestPlanScriptResultControllerTest.java | 2 +- .../controller/Test_MonitorController.java | 2 +- .../controller/Test_TestPlanController.java | 10 +-- .../Test_TestPlanResultController.java | 2 +- .../controller/UserControllerTest.java | 8 +-- .../master/unitTest/entity/Test_Agent.java | 2 +- .../unitTest/entity/Test_RunningScript.java | 6 +- .../unitTest/service/Test_ScriptService.java | 2 +- .../httpcapture/Bench4qTestScriptAdapter.java | 66 ++++++++++--------- .../bench4q/share/helper/MarshalHelper.java | 9 +-- .../org/bench4q/web/api/ScriptController.java | 6 +- .../masterMessager/AgentManagerMessager.java | 4 +- .../web/masterMessager/MonitorMessager.java | 8 +-- .../web/masterMessager/PluginMessager.java | 2 +- .../masterMessager/RecordPortMessager.java | 2 +- .../web/masterMessager/ScriptMessager.java | 10 +-- .../web/masterMessager/TestPlanMessager.java | 14 ++-- .../web/masterMessager/UserMessager.java | 4 +- 40 files changed, 184 insertions(+), 205 deletions(-) diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java index bd459350..a2bdab4c 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/api/TestController.java @@ -86,11 +86,11 @@ public class TestController { try { this.getParamFileCollector().collectParamFiles(files, runId); System.out.println(scenarioModel); - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper - .unmarshal(RunScenarioModel.class, scenarioModel); + RunScenarioModel runScenarioModel = MarshalHelper.unmarshal( + RunScenarioModel.class, scenarioModel); System.out.println(scheduleContent); this.logger.info(scheduleContent); - ScheduleModel scheduleModel = (ScheduleModel) MarshalHelper + ScheduleModel scheduleModel = MarshalHelper .unmarshal(ScheduleModel.class, scheduleContent); this.getScenarioEngine().submitScenario(runId, Scenario.scenarioCompiler(runScenarioModel), diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java index d9677a41..1bc2ea1a 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/Scenario.java @@ -67,12 +67,11 @@ public class Scenario { } public static Scenario scenarioBuilderWithCompile(String scenarioContent) { - return scenarioCompiler((RunScenarioModel) MarshalHelper - .tryUnmarshal(RunScenarioModel.class, scenarioContent)); + return scenarioCompiler(MarshalHelper.tryUnmarshal( + RunScenarioModel.class, scenarioContent)); } - public static Scenario scenarioCompiler( - RunScenarioModel scenarioModel) { + public static Scenario scenarioCompiler(RunScenarioModel scenarioModel) { if (scenarioModel == null) { throw new NullPointerException(); } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/ExtractScenarioTest.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/ExtractScenarioTest.java index e6262e0a..b2875acf 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/ExtractScenarioTest.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/ExtractScenarioTest.java @@ -17,7 +17,7 @@ public class ExtractScenarioTest { @Test public void test() throws JAXBException, IOException { - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper + RunScenarioModel runScenarioModel = MarshalHelper .unmarshal(RunScenarioModel.class, FileUtils .readFileToString(new File("Scripts/goodForPage.xml"))); Scenario scenario = Scenario.scenarioCompiler(runScenarioModel); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java index e88847f8..834cf65b 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/TestWithScriptFile.java @@ -82,9 +82,8 @@ public class TestWithScriptFile extends TestBase { HttpResponse httpResponse = this.getHttpRequester().sendPostXml( this.url + "/runWithoutParams", marshalRunScenarioModel(runScenarioModel), null); - RunScenarioResultModel resultModel = (RunScenarioResultModel) MarshalHelper - .unmarshal(RunScenarioResultModel.class, - httpResponse.getContent()); + RunScenarioResultModel resultModel = MarshalHelper.unmarshal( + RunScenarioResultModel.class, httpResponse.getContent()); this.setTestId(resultModel.getRunId()); } catch (IOException e) { System.out.println("IO exception!"); @@ -138,9 +137,8 @@ public class TestWithScriptFile extends TestBase { HttpResponse httpResponse = this.getHttpRequester().sendGet( this.url + "/brief/" + this.getTestId().toString(), null, null); System.out.println(httpResponse.getContent()); - AgentBriefStatusModel briefModel = (AgentBriefStatusModel) MarshalHelper - .unmarshal(AgentBriefStatusModel.class, - httpResponse.getContent()); + AgentBriefStatusModel briefModel = MarshalHelper.unmarshal( + AgentBriefStatusModel.class, httpResponse.getContent()); assertTrue(briefModel.getTimeFrame() > 0); } @@ -150,9 +148,8 @@ public class TestWithScriptFile extends TestBase { this.url + "/behaviorsBrief/" + this.getTestId().toString(), null, null); System.out.println(httpResponse.getContent()); - AgentBehaviorsBriefModel behaviorsBriefModel = (AgentBehaviorsBriefModel) MarshalHelper - .unmarshal(AgentBehaviorsBriefModel.class, - httpResponse.getContent()); + AgentBehaviorsBriefModel behaviorsBriefModel = MarshalHelper.unmarshal( + AgentBehaviorsBriefModel.class, httpResponse.getContent()); assertTrue(behaviorsBriefModel.getBehaviorBriefModels().size() > 0); } @@ -161,8 +158,8 @@ public class TestWithScriptFile extends TestBase { HttpResponse httpResponse = this.getHttpRequester().sendGet( this.url + "/brief/" + this.getTestId().toString() + "/0", null, null); - BehaviorBriefModel behaviorBriefModel = (BehaviorBriefModel) MarshalHelper - .unmarshal(BehaviorBriefModel.class, httpResponse.getContent()); + BehaviorBriefModel behaviorBriefModel = MarshalHelper.unmarshal( + BehaviorBriefModel.class, httpResponse.getContent()); assertTrue(behaviorBriefModel.getDetailStatusCodeResultModels().size() > 0); } @@ -196,7 +193,7 @@ public class TestWithScriptFile extends TestBase { + "testJD.xml")); HttpResponse httpResponse1 = this.getHttpRequester().sendPost( url + "/bookTest/20", null, null); - RunScenarioResultModel bookResponse = (RunScenarioResultModel) MarshalHelper + RunScenarioResultModel bookResponse = MarshalHelper .tryUnmarshal(RunScenarioResultModel.class, httpResponse1.getContent()); assertNotNull(bookResponse); @@ -216,7 +213,7 @@ public class TestWithScriptFile extends TestBase { assertNotNull(httpResponse); assertNotNull(httpResponse.getContent()); assertEquals(200, httpResponse.getCode()); - RunScenarioResultModel resultModel = (RunScenarioResultModel) MarshalHelper + RunScenarioResultModel resultModel = MarshalHelper .tryUnmarshal(RunScenarioResultModel.class, httpResponse.getContent()); String dirPath = (String) TestHelper.invokePrivate( @@ -244,9 +241,8 @@ public class TestWithScriptFile extends TestBase { fail(); } System.out.println(httpResponse); - AgentPageBriefModel pageBriefModel = (AgentPageBriefModel) MarshalHelper - .unmarshal(AgentPageBriefModel.class, - httpResponse.getContent()); + AgentPageBriefModel pageBriefModel = MarshalHelper.unmarshal( + AgentPageBriefModel.class, httpResponse.getContent()); assertTrue(pageBriefModel.getCountFromBegin() > 0); } catch (Exception e) { this.stopTest(); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java index 8a33e32b..5bfb7a22 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HttpPlugin.java @@ -149,7 +149,7 @@ public class Test_HttpPlugin extends TestBase { @Test public void buildAScenario() throws IOException { - RunScenarioModel scenarioMode = (RunScenarioModel) MarshalHelper + RunScenarioModel scenarioMode = MarshalHelper .tryUnmarshal(RunScenarioModel.class, FileUtils .readFileToString(new File( "Scripts/httpWithoutTimer.xml"))); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java index 7b76e063..a53404f8 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/RunningAgentDB.java @@ -178,11 +178,11 @@ public class RunningAgentDB implements RunningAgentInterface { public boolean distributeScriptAndParams() { Script script2 = this.getTestPlanScript().getScript(); - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper - .tryUnmarshal(RunScenarioModel.class, this.getTestPlanScript() + RunScenarioModel runScenarioModel = MarshalHelper.tryUnmarshal( + RunScenarioModel.class, this.getTestPlanScript() .getFilteredScriptCnt()); runScenarioModel.setPoolSize(getLoadInUse()); - ScheduleModel scheduleModel = generateScheduleModelWithRatio((ScheduleModel) MarshalHelper + ScheduleModel scheduleModel = generateScheduleModelWithRatio(MarshalHelper .tryUnmarshal(ScheduleModel.class, this.getTestPlanScript() .getScheduleContent())); RunScenarioResultModel runScenarioResultModel = this diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java index 10a79ba2..3e149be3 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScript.java @@ -147,9 +147,8 @@ public class TestPlanScript implements RunningScriptInterface { @Transient public RunScenarioModel getScenario() { try { - return (RunScenarioModel) MarshalHelper - .unmarshal(RunScenarioModel.class, this.getScript() - .getScriptContent()); + return MarshalHelper.unmarshal(RunScenarioModel.class, this + .getScript().getScriptContent()); } catch (Exception e) { Logger.getLogger(TestPlanScript.class).error( ExceptionLog.getStackTrace(e)); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScriptResult.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScriptResult.java index bb6f9c5e..8c6baef7 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScriptResult.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlanScriptResult.java @@ -18,8 +18,8 @@ import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; @Entity @Table(name = "TestPlanScriptResult") public class TestPlanScriptResult { -// private int testPlanId; -// private int scriptId, + // private int testPlanId; + // private int scriptId, private int id; private TestPlanScript testPlanScript; private String resultContent; @@ -76,8 +76,8 @@ public class TestPlanScriptResult { public ScriptBriefResultModel extractScriptBriefResultModel() { try { - return (ScriptBriefResultModel) MarshalHelper.unmarshal( - ScriptBriefResultModel.class, this.getResultContent()); + return MarshalHelper.unmarshal(ScriptBriefResultModel.class, + this.getResultContent()); } catch (JAXBException e) { return null; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java index a11a8c5e..be883eac 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java @@ -172,7 +172,7 @@ public class TestPlanFactory { if (scriptFilterOptionsModel == null) { return scriptContent; } - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper + RunScenarioModel runScenarioModel = MarshalHelper .tryUnmarshal(RunScenarioModel.class, scriptContent); List filterPluginId = new ArrayList(); if (scriptFilterOptionsModel.isFilterTimer()) { diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java index 4da5560d..64ec752e 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/MonitorResultService.java @@ -129,7 +129,6 @@ public class MonitorResultService { } } - @SuppressWarnings("unchecked") private T2 loadMonitorResultModel( UUID testPlanRunId, String hostName, long beginTime, Class fromMonitorClass, Class resultClass) throws Exception { @@ -143,7 +142,7 @@ public class MonitorResultService { assert (fromMonitorClass.getName().equals(monitorResult .getType())); - T1 result = (T1) MarshalHelper.unmarshal(fromMonitorClass, + T1 result = MarshalHelper.unmarshal(fromMonitorClass, monitorResult.getContent()); ret.add(result); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java index 885f3e6e..d6e804de 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/ScriptService.java @@ -94,8 +94,7 @@ public class ScriptService { return null; } try { - return (RunScenarioModel) MarshalHelper.unmarshal( - RunScenarioModel.class, content); + return MarshalHelper.unmarshal(RunScenarioModel.class, content); } catch (JAXBException e) { logger.error(ExceptionLog.getStackTrace(e)); return null; diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java index 77e413ed..825f1770 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanScriptResultService.java @@ -58,7 +58,7 @@ public class TestPlanScriptResultService { System.out.println("Script Result Size from DB : " + scriptResults.size()); for (TestPlanScriptResult testPlanScriptResult : scriptResults) { - result.add((ScriptBriefResultModel) MarshalHelper.unmarshal( + result.add(MarshalHelper.unmarshal( ScriptBriefResultModel.class, testPlanScriptResult.getResultContent())); } @@ -98,8 +98,7 @@ public class TestPlanScriptResultService { if (testPlanScriptResult == null) { return new ScriptBehaviorsBriefModel(); } - return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal( - ScriptBehaviorsBriefModel.class, + return MarshalHelper.unmarshal(ScriptBehaviorsBriefModel.class, testPlanScriptResult.getResultContent()); } catch (Exception e) { logger.error(ExceptionLog.getStackTrace(e)); @@ -138,8 +137,7 @@ public class TestPlanScriptResultService { if (testPlanScriptResult == null) { return result; } - result = (ScriptPagesBriefModel) MarshalHelper.unmarshal( - ScriptPagesBriefModel.class, + result = MarshalHelper.unmarshal(ScriptPagesBriefModel.class, testPlanScriptResult.getResultContent()); } catch (Exception e) { logger.error(ExceptionLog.getStackTrace(e)); @@ -159,7 +157,7 @@ public class TestPlanScriptResultService { if (testPlanScriptResult == null) { return null; } - return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal( + return MarshalHelper.tryUnmarshal( ScriptBriefResultModel.class, testPlanScriptResult.getResultContent()); } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/report/MonitorReportService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/report/MonitorReportService.java index cd849fef..a42226ab 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/report/MonitorReportService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/report/MonitorReportService.java @@ -62,7 +62,8 @@ public class MonitorReportService { this.monitorResultService = monitorResultService; } - void createMonitorResultImages(UUID testPlanRunID, Document document) throws Bench4QException { + void createMonitorResultImages(UUID testPlanRunID, Document document) + throws Bench4QException { Map SUTResultMap = new HashMap(); List results = this.getMonitorResultService() .queryMonitorResults(testPlanRunID); @@ -98,23 +99,23 @@ public class MonitorReportService { try { if (Class.forName(result.getType()).equals(PhysicalDiskModel.class)) { container.getLogicalDiskModels().add( - (PhysicalDiskModel) MarshalHelper.unmarshal( - PhysicalDiskModel.class, result.getContent())); + MarshalHelper.unmarshal(PhysicalDiskModel.class, + result.getContent())); } else if (Class.forName(result.getType()) .equals(MemoryModel.class)) { container.getMemoryModels().add( - (MemoryModel) MarshalHelper.unmarshal( + MarshalHelper.unmarshal( MemoryModel.class, result.getContent())); } else if (Class.forName(result.getType()).equals( NetworkInterfaceModel.class)) { container.getNetWorkModels().add( - (NetworkInterfaceModel) MarshalHelper.unmarshal( + MarshalHelper.unmarshal( NetworkInterfaceModel.class, result.getContent())); } else if (Class.forName(result.getType()).equals( ProcessorModel.class)) { container.getProcessorModels().add( - (ProcessorModel) MarshalHelper.unmarshal( + MarshalHelper.unmarshal( ProcessorModel.class, result.getContent())); } } catch (Exception e) { @@ -131,7 +132,7 @@ public class MonitorReportService { ReportService.addParagraph(Memory, document); createMemoryImage(container.getMemoryModels(), document); ReportService.addParagraph(network_Interface, document); -// createNetworkImage(container.getNetWorkModels(), document); + // createNetworkImage(container.getNetWorkModels(), document); ReportService.addParagraph(Processor, document); createProcessorImage(container.getProcessorModels(), document); } catch (Exception e) { @@ -212,7 +213,6 @@ public class MonitorReportService { ReportService.buildChartStream(document, seriesCount, timeSeriesArray, logical_Disk).toByteArray(), document); } - /** * refactor this kind of use @@ -222,25 +222,25 @@ public class MonitorReportService { * @throws Exception */ -// private void createNetworkImage(List list, -// Document document) throws Exception { -// if (list == null || list.size() == 0) { -// return; -// } -// int seriesCount = list.get(0).getNetworkList().size(); -// List timeSeriesArray = ReportService.buildSeries( -// seriesCount, network_Interface); -// for (NetworkInterfaceModel model : list) { -// for (int i = 0; i < timeSeriesArray.size(); i++) { -// timeSeriesArray.get(i).addOrUpdate( -// new Second(model.getSamplingTime()), -// model.getNetworkList().get(i).getBytesTotalPerSecond()); -// } -// } -// ReportService.writeImageIntoPdf( -// ReportService.buildChartStream(document, seriesCount, -// timeSeriesArray, network_Interface).toByteArray(), -// document); -// } -//} + // private void createNetworkImage(List list, + // Document document) throws Exception { + // if (list == null || list.size() == 0) { + // return; + // } + // int seriesCount = list.get(0).getNetworkList().size(); + // List timeSeriesArray = ReportService.buildSeries( + // seriesCount, network_Interface); + // for (NetworkInterfaceModel model : list) { + // for (int i = 0; i < timeSeriesArray.size(); i++) { + // timeSeriesArray.get(i).addOrUpdate( + // new Second(model.getSamplingTime()), + // model.getNetworkList().get(i).getBytesTotalPerSecond()); + // } + // } + // ReportService.writeImageIntoPdf( + // ReportService.buildChartStream(document, seriesCount, + // timeSeriesArray, network_Interface).toByteArray(), + // document); + // } + // } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java index 3d2cadf2..3e2e9738 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/AgentMessengerImpl.java @@ -55,8 +55,8 @@ public class AgentMessengerImpl implements AgentMessenger { null, null); System.out.println(buildBaseUrl(agent) + "/test/bookTest/" + requireLoad); - return (RunScenarioResultModel) MarshalHelper.unmarshal( - RunScenarioResultModel.class, httpResponse.getContent()); + return MarshalHelper.unmarshal(RunScenarioResultModel.class, + httpResponse.getContent()); } catch (Exception e) { logger.error(httpResponse.getContent(), e); return null; @@ -90,8 +90,8 @@ public class AgentMessengerImpl implements AgentMessenger { buildBaseUrl(agent) + "/test/submitScenarioWithParams/" + agentRunId + "/" + realStartDate.getTime(), "files[]", paramFiles, stringParts); - return (RunScenarioResultModel) MarshalHelper.unmarshal( - RunScenarioResultModel.class, httpResponse.getContent()); + return MarshalHelper.unmarshal(RunScenarioResultModel.class, + httpResponse.getContent()); } catch (Exception e) { logIt(httpResponse, e); return null; @@ -126,8 +126,8 @@ public class AgentMessengerImpl implements AgentMessenger { logger.error("the response is not valid"); return null; } - return (RunScenarioResultModel) MarshalHelper.unmarshal( - RunScenarioResultModel.class, httpResponse.getContent()); + return MarshalHelper.unmarshal(RunScenarioResultModel.class, + httpResponse.getContent()); } catch (Exception e) { logIt(httpResponse, e); return null; @@ -157,8 +157,8 @@ public class AgentMessengerImpl implements AgentMessenger { return null; } logger.info(httpResponse.getContent()); - return (TestBriefStatusModel) MarshalHelper.unmarshal( - TestBriefStatusModel.class, httpResponse.getContent()); + return MarshalHelper.unmarshal(TestBriefStatusModel.class, + httpResponse.getContent()); } catch (Exception e) { logIt(httpResponse, e); logger.error(e.toString() @@ -191,7 +191,7 @@ public class AgentMessengerImpl implements AgentMessenger { if (HttpRequester.isInvalidResponse(httpResponse)) { return null; } - return (StopTestModel) MarshalHelper.unmarshal(StopTestModel.class, + return MarshalHelper.unmarshal(StopTestModel.class, httpResponse.getContent()); } catch (Exception e) { logger.error(e.toString() + " when stop the agent with hostName " @@ -222,8 +222,8 @@ public class AgentMessengerImpl implements AgentMessenger { if (HttpRequester.isInvalidResponse(httpResponse)) { return null; } - return (ServerStatusModel) MarshalHelper.unmarshal( - ServerStatusModel.class, httpResponse.getContent()); + return MarshalHelper.unmarshal(ServerStatusModel.class, + httpResponse.getContent()); } catch (Exception e) { logger.error("agent :" + agent.getHostName() + " break down!"); return null; diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java index c5f87cee..ea598b9f 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/infrastructure/communication/impl/MonitorMessengerImpl.java @@ -1,10 +1,7 @@ package org.bench4q.master.infrastructure.communication.impl; -import java.io.IOException; import java.util.Date; -import javax.xml.bind.JAXBException; - import org.apache.log4j.Logger; import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.infrastructure.communication.MonitorMessenger; @@ -55,19 +52,10 @@ public class MonitorMessengerImpl implements MonitorMessenger { logger.info("The httpResponse is invalid "); return null; } - @SuppressWarnings("unchecked") - T model = (T) MarshalHelper.unmarshal(resultClass, + T model = MarshalHelper.unmarshal(resultClass, httpResponse.getContent()); model.setSamplingTime(sampleDate); - 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) { logger.error(ExceptionLog.getStackTrace(e)); return null; diff --git a/Bench4Q-Master/src/test/java/ModelTest/MarshallerTest.java b/Bench4Q-Master/src/test/java/ModelTest/MarshallerTest.java index 7bf98110..e8f367b4 100644 --- a/Bench4Q-Master/src/test/java/ModelTest/MarshallerTest.java +++ b/Bench4Q-Master/src/test/java/ModelTest/MarshallerTest.java @@ -22,7 +22,7 @@ public class MarshallerTest { public void testUnmarshal() throws JAXBException { RunningAgentModel input = new RunningAgentModel(); String content = MarshalHelper.marshal(RunningAgentModel.class, input); - RunningAgentModel output = (RunningAgentModel) MarshalHelper.unmarshal( + RunningAgentModel output = MarshalHelper.unmarshal( RunningAgentModel.class, content); System.out.println(input.getLoadInUse()); assertTrue(input.getLoadInUse() == output.getLoadInUse()); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java index e198a029..0bec4b2a 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/integrated/communication/Test_AgentMessenger.java @@ -64,9 +64,9 @@ public class Test_AgentMessenger extends TestBase_MakeUpTestPlan { File scenarioFile = new File("Scripts" + FILE_SEPARATOR + "homepage.xml"); assertTrue(scenarioFile.exists()); - RunScenarioModel inputModel = (RunScenarioModel) MarshalHelper - .unmarshal(RunScenarioModel.class, - FileUtils.readFileToString(scenarioFile)); + RunScenarioModel inputModel = MarshalHelper.unmarshal( + RunScenarioModel.class, + FileUtils.readFileToString(scenarioFile)); inputModel.setPoolSize(20); Agent agent = Agent diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/AgentPoolControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/AgentPoolControllerTest.java index 28dfd7c4..97c09540 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/AgentPoolControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/AgentPoolControllerTest.java @@ -47,8 +47,8 @@ public class AgentPoolControllerTest extends TestBase { MarshalHelper.marshal(AgentModel.class, agent), makeAccessTockenMap(this.getAccessTocken())); - agentResponseModel = (AgentResponseModel) MarshalHelper.unmarshal( - AgentResponseModel.class, httpResponse.getContent()); + agentResponseModel = MarshalHelper.unmarshal(AgentResponseModel.class, + httpResponse.getContent()); System.out.println(httpResponse.getContent()); System.out.println(agentResponseModel.isSuccess()); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/PluginControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/PluginControllerTest.java index 11e59ba0..6513c17e 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/PluginControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/PluginControllerTest.java @@ -78,7 +78,7 @@ public class PluginControllerTest extends TestBase { String pluginContent = FileUtils.readFileToString(file); HttpResponse httpResponse = this.httpRequester.sendPutXml(url, pluginContent, makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper + PluginResponseModel pluginResponseModel = MarshalHelper .tryUnmarshal(PluginResponseModel.class, httpResponse.getContent()); Assert.assertNotNull(pluginResponseModel); @@ -94,7 +94,7 @@ public class PluginControllerTest extends TestBase { this.test_PluginHelper.addPlugin(fileName, pluginService, pluginName); HttpResponse httpResponse = this.httpRequester.sendPost(url, null, makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper + PluginResponseModel pluginResponseModel = MarshalHelper .tryUnmarshal(PluginResponseModel.class, httpResponse.getContent()); System.out.println(httpResponse.getContent()); @@ -116,7 +116,7 @@ public class PluginControllerTest extends TestBase { HttpResponse httpResponse = this.httpRequester.sendPost(url, null, makeAccessTockenMap(this.getAccessTocken())); System.out.println(httpResponse.getContent()); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper + PluginResponseModel pluginResponseModel = MarshalHelper .tryUnmarshal(PluginResponseModel.class, httpResponse.getContent()); assertNotNull(pluginResponseModel); @@ -133,7 +133,7 @@ public class PluginControllerTest extends TestBase { String url = URLSTRING + "/deletePlugin" + "/" + this.pluginName; HttpResponse httpResponse = this.httpRequester.sendPost(url, null, makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper + PluginResponseModel pluginResponseModel = MarshalHelper .tryUnmarshal(PluginResponseModel.class, httpResponse.getContent()); assertNotNull(pluginResponseModel); @@ -148,7 +148,7 @@ public class PluginControllerTest extends TestBase { String url = URLSTRING + "/loadBehaviors/" + this.pluginName; HttpResponse httpResponse = this.httpRequester.sendPost(url, null, makeAccessTockenMap(this.getAccessTocken())); - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper + PluginResponseModel pluginResponseModel = MarshalHelper .tryUnmarshal(PluginResponseModel.class, httpResponse.getContent()); assertNotNull(pluginResponseModel); @@ -170,9 +170,8 @@ public class PluginControllerTest extends TestBase { properties); PluginResponseModel pluginResponseModel = null; try { - pluginResponseModel = (PluginResponseModel) MarshalHelper - .unmarshal(PluginResponseModel.class, - httpResponse.getContent()); + pluginResponseModel = MarshalHelper.unmarshal( + PluginResponseModel.class, httpResponse.getContent()); } catch (Exception e) { logger.info(ExceptionLog.getStackTrace(e)); } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/RecordScriptControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/RecordScriptControllerTest.java index 30748eb9..47eab52e 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/RecordScriptControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/RecordScriptControllerTest.java @@ -31,9 +31,9 @@ public class RecordScriptControllerTest extends TestBase { + "/startScriptRecordServer", null, this.makeAccessTockenMap(this.getAccessTocken())); System.out.println(httpResponse.getContent()); - OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper - .unmarshal(OperateScriptServerResponseModel.class, - httpResponse.getContent()); + OperateScriptServerResponseModel ret = MarshalHelper.unmarshal( + OperateScriptServerResponseModel.class, + httpResponse.getContent()); assertTrue(ret.isSuccess()); return ret; } @@ -46,9 +46,9 @@ public class RecordScriptControllerTest extends TestBase { HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL + "/stopScriptRecordServer", paramsMap, this.makeAccessTockenMap(this.accessTocken)); - OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper - .unmarshal(OperateScriptServerResponseModel.class, - httpResponse.getContent()); + OperateScriptServerResponseModel ret = MarshalHelper.unmarshal( + OperateScriptServerResponseModel.class, + httpResponse.getContent()); assertTrue(ret.isSuccess()); } @@ -67,9 +67,9 @@ public class RecordScriptControllerTest extends TestBase { HttpResponse httpResponse = this.httpRequester.sendPost(this.SCRIPT_URL + "/saveScriptToDB", params, this.makeAccessTockenMap(this.getAccessTocken())); - OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper - .unmarshal(OperateScriptServerResponseModel.class, - httpResponse.getContent()); + OperateScriptServerResponseModel ret = MarshalHelper.unmarshal( + OperateScriptServerResponseModel.class, + httpResponse.getContent()); assertTrue(ret.isSuccess()); assertNotNull(ret.getScriptModels()); assertNotNull(ret.getScriptModels().get(0)); @@ -88,7 +88,7 @@ public class RecordScriptControllerTest extends TestBase { test.stopRecord(model); ScriptModel scriptModel = test.saveScriptToDB(model, "chen2"); assertNotNull(scriptModel.getScriptContent()); - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper + RunScenarioModel runScenarioModel = MarshalHelper .unmarshal(RunScenarioModel.class, scriptModel.getScriptContent()); assertNotNull(runScenarioModel); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/ScriptControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/ScriptControllerTest.java index 6ada97fd..9119411f 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/ScriptControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/ScriptControllerTest.java @@ -28,7 +28,7 @@ public class ScriptControllerTest extends TestBase { String url = this.controllerUrl + "/loadScriptList"; HttpResponse httpResponse = this.httpRequester.sendGet(url, null, this.makeAccessTockenMap(this.login())); - OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper + OperateScriptServerResponseModel ret = MarshalHelper .unmarshal(OperateScriptServerResponseModel.class, httpResponse.getContent()); assertTrue(ret.getScriptModels().size() > 0); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestBase.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestBase.java index c2a1754f..7edddb8b 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestBase.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestBase.java @@ -39,9 +39,8 @@ public class TestBase { try { httpResponse = this.httpRequester.sendGet(urlString, map, null); System.out.println("http content:" + httpResponse.getContent()); - return ((AuthorizeResponseModel) MarshalHelper.unmarshal( - AuthorizeResponseModel.class, httpResponse.getContent())) - .getAccessToken(); + return MarshalHelper.unmarshal(AuthorizeResponseModel.class, + httpResponse.getContent()).getAccessToken(); } catch (Exception e) { e.printStackTrace(); return null; diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java index 7391ea2e..bf52a90d 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/TestPlanScriptResultControllerTest.java @@ -38,7 +38,7 @@ public class TestPlanScriptResultControllerTest extends TestBase_MakeUpTestPlan + "/loadScriptBirefResults/" + this.getScriptId() + "/averageResponseTime", null, this.makeAccessTockenMap(this.getAccessTocken())); - ResultLoadModel loadModel = (ResultLoadModel) MarshalHelper.unmarshal( + ResultLoadModel loadModel = MarshalHelper.unmarshal( ResultLoadModel.class, httpResponse.getContent()); assertEquals(3, loadModel.getValueTimeModels().size()); } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_MonitorController.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_MonitorController.java index 1bf8164f..5aac5d46 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_MonitorController.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_MonitorController.java @@ -35,7 +35,7 @@ public class Test_MonitorController extends TestBase { if (HttpRequester.isInvalidResponse(httpResponse)) { fail("not valid response!"); } - MonitorMemoryResponseModel memoryResponseModel = (MonitorMemoryResponseModel) MarshalHelper + MonitorMemoryResponseModel memoryResponseModel = MarshalHelper .unmarshal(MonitorMemoryResponseModel.class, httpResponse.getContent()); assertEquals(3, memoryResponseModel.getMemoryModels().size()); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanController.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanController.java index b6c7b025..bb0451fc 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanController.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanController.java @@ -143,7 +143,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan { + "/runTestPlanWithTestPlanModel", content, this.makeAccessTockenMap(this.accessTocken)); - result = (TestPlanResultModel) MarshalHelper.unmarshal( + result = MarshalHelper.unmarshal( TestPlanResultModel.class, httpResponse.getContent()); System.out.println(result.getCurrentStatus()); return result.getTestPlanId(); @@ -182,7 +182,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan { HttpResponse httpResponse = this.httpRequester.sendGet(this._url + "/getRunningInfo", params, this.makeAccessTockenMap(this.getAccessTocken())); - TestPlanResultModel ret = (TestPlanResultModel) MarshalHelper + TestPlanResultModel ret = MarshalHelper .unmarshal(TestPlanResultModel.class, httpResponse.getContent()); System.out.println(ret.getCurrentStatus()); return ret; @@ -194,7 +194,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan { + "/scriptBrief/" + testPlanId.toString() + "/" + scriptId + "/" + 0, null, createAccessTokenMap()); System.out.println(httpResponse.getContent()); - TestPlanScriptBriefResultModel ret = (TestPlanScriptBriefResultModel) MarshalHelper + TestPlanScriptBriefResultModel ret = MarshalHelper .unmarshal(TestPlanScriptBriefResultModel.class, httpResponse.getContent()); for (ScriptBriefResultModel scriptBriefResultModel : ret @@ -210,7 +210,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan { + "/pagesBrief/" + testPlanId.toString() + "/" + scriptId, null, createAccessTokenMap()); System.out.println(httpResponse.getContent()); - ScriptPagesBriefModel ret = (ScriptPagesBriefModel) MarshalHelper + ScriptPagesBriefModel ret = MarshalHelper .unmarshal(ScriptPagesBriefModel.class, httpResponse.getContent()); return ret; @@ -254,7 +254,7 @@ public class Test_TestPlanController extends TestBase_MakeUpTestPlan { + testPlanID.toString() + "/" + hostName + "/6565/0", null, this.createAccessTokenMap()); System.out.println(httpResponse.getContent()); - MonitorPhysicalDiskResponseModel logicalDiskResponseModel = (MonitorPhysicalDiskResponseModel) MarshalHelper + MonitorPhysicalDiskResponseModel logicalDiskResponseModel = MarshalHelper .unmarshal(MonitorPhysicalDiskResponseModel.class, httpResponse.getContent()); assertNotNull(logicalDiskResponseModel); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanResultController.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanResultController.java index 7f83970e..8d44725c 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanResultController.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/Test_TestPlanResultController.java @@ -31,7 +31,7 @@ public class Test_TestPlanResultController extends TestBase { + testPlanRunId, null, makeAccessTockenMap(this.getAccessTocken())); assertTrue(httpResponse != null); - ResultLoadModel resultModel = (ResultLoadModel) MarshalHelper + ResultLoadModel resultModel = MarshalHelper .unmarshal(ResultLoadModel.class, httpResponse.getContent()); assertTrue(resultModel.getValueTimeModels().size() > 0); } diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/UserControllerTest.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/UserControllerTest.java index 3a3a11cf..b0ae7bdf 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/UserControllerTest.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/controller/UserControllerTest.java @@ -27,7 +27,7 @@ public class UserControllerTest extends TestBase { + "/user/normalAuthorize?userName=chen&password=123"; HttpResponse httpResponse = this.httpRequester.sendGet(urlString, null, null); - AuthorizeResponseModel ret = (AuthorizeResponseModel) MarshalHelper + AuthorizeResponseModel ret = MarshalHelper .unmarshal(AuthorizeResponseModel.class, httpResponse.getContent()); assertTrue(ret.isSuccess()); @@ -38,7 +38,7 @@ public class UserControllerTest extends TestBase { String url = BASE_URL + "/user/adminAuthorize?userName=chen&password=123"; HttpResponse httpResponse = this.httpRequester.sendGet(url, null, null); - AuthorizeResponseModel ret = (AuthorizeResponseModel) MarshalHelper + AuthorizeResponseModel ret = MarshalHelper .unmarshal(AuthorizeResponseModel.class, httpResponse.getContent()); assertTrue(ret.isSuccess()); @@ -56,7 +56,7 @@ public class UserControllerTest extends TestBase { params.put("scope", "1"); HttpResponse httpResponse = this.httpRequester.sendGet(url, params, null); - RegisterResponseModel registerResponseModel = (RegisterResponseModel) MarshalHelper + RegisterResponseModel registerResponseModel = MarshalHelper .tryUnmarshal(RegisterResponseModel.class, httpResponse.getContent()); assertNotNull(registerResponseModel); @@ -70,7 +70,7 @@ public class UserControllerTest extends TestBase { String url = BASE_URL + "/user/deleteUser" + "/" + userName; HttpResponse httpResponse = this.httpRequester.sendGet(url, null, null); System.out.println(httpResponse.getContent()); - AuthorizeResponseModel authorizeResponseModel = (AuthorizeResponseModel) MarshalHelper + AuthorizeResponseModel authorizeResponseModel = MarshalHelper .tryUnmarshal(AuthorizeResponseModel.class, httpResponse.getContent()); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_Agent.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_Agent.java index e0b773ad..0429b3b3 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_Agent.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_Agent.java @@ -82,7 +82,7 @@ public class Test_Agent { assertEquals(AgentStatus.InIdle, agentModel.getCurrentEnumStatus()); String content = MarshalHelper.tryMarshal(agentModel); System.out.println(content); - AgentModel modelAfterUnMarshal = (AgentModel) MarshalHelper + AgentModel modelAfterUnMarshal = MarshalHelper .tryUnmarshal(AgentModel.class, content); assertEquals(modelAfterUnMarshal.getCurrentEnumStatus(), AgentStatus.InIdle); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningScript.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningScript.java index c7bf778b..bf68a244 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningScript.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/entity/Test_RunningScript.java @@ -92,9 +92,9 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan { double ratio = (double) runningAgentDB.getLoadInUse() / (double) testPlanScript.getRequireLoad(); ScheduleModel scheduleModelInRunningAgent = runningAgentDB - .generateScheduleModelWithRatio((ScheduleModel) MarshalHelper - .tryUnmarshal(ScheduleModel.class, - testPlanScript.getScheduleContent())); + .generateScheduleModelWithRatio(MarshalHelper.tryUnmarshal( + ScheduleModel.class, + testPlanScript.getScheduleContent())); assertEquals(Math.round(ratio * testPlanScript.getRequireLoad()), scheduleModelInRunningAgent.getMaxLoad()); System.out.println(scheduleModelInRunningAgent.getMaxLoad()); diff --git a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_ScriptService.java b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_ScriptService.java index 62be1098..a7095ea1 100644 --- a/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_ScriptService.java +++ b/Bench4Q-Master/src/test/java/org/bench4q/master/unitTest/service/Test_ScriptService.java @@ -158,7 +158,7 @@ public class Test_ScriptService { String content = this.getScriptService() .getScript(getUploadScriptId(getUserForTest())) .getScriptContent(); - RunScenarioModel afterUpdate = (RunScenarioModel) MarshalHelper + RunScenarioModel afterUpdate = MarshalHelper .unmarshal(RunScenarioModel.class, content); assertEquals(1, afterUpdate.getPages().size()); } diff --git a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Bench4qTestScriptAdapter.java b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Bench4qTestScriptAdapter.java index 2777e55e..e9e4664d 100644 --- a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Bench4qTestScriptAdapter.java +++ b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Bench4qTestScriptAdapter.java @@ -20,11 +20,10 @@ import org.bench4q.share.models.agent.scriptrecord.PageModel; import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; public class Bench4qTestScriptAdapter implements IScriptAdapter { - private int idGenerator =1; + private int idGenerator = 1; private int pageCount; private RunScenarioModel runScenarioModel; private List childrenUrls = new ArrayList(); - private BehaviorModel preTimerBehavior = null; private static Logger logger = Logger .getLogger(Bench4qTestScriptAdapter.class); @@ -72,7 +71,7 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter { this.getRunScenarioModel().getPages().add(new PageModel(idGenerator++)); assert (pageCountEqualWithPageSizeInScenario()); } - + public void insertUserBehaviorsToScenario(BehaviorModel model) { List batches = this.getCurrentPage().getBatches(); model.setId(idGenerator++); @@ -86,29 +85,31 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter { return; } guardChildBatchExist(batches, parentBatchId); - getBatchById(batches, getBatchById(batches, parentBatchId).getChildId()).getBehaviors() - .add(model); + getBatchById(batches, getBatchById(batches, parentBatchId).getChildId()) + .getBehaviors().add(model); } - private BatchModel getBatchById(List batches, int batchId){ - for(BatchModel batchModel : batches){ - if(batchModel.getId() == batchId){ + + private BatchModel getBatchById(List batches, int batchId) { + for (BatchModel batchModel : batches) { + if (batchModel.getId() == batchId) { return batchModel; } } return null; } + private boolean guardChildBatchExist(List batches, int parentBatchId) { if (isChildBatchAbsent(batches, parentBatchId)) { BatchModel batchBehavior = createBatchBehaviorWithProperBatchId(); batchBehavior.setParentId(parentBatchId); batches.add(batchBehavior); - BatchModel parentBatch = getBatchById(batches,parentBatchId); - if(parentBatch != null){ + BatchModel parentBatch = getBatchById(batches, parentBatchId); + if (parentBatch != null) { parentBatch.setChildId(batchBehavior.getId()); } return false; - }else{ + } else { return true; } } @@ -132,22 +133,22 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter { private BatchModel createBatchBehaviorWithProperBatchId() { BatchModel batchBehavior = new BatchModel(idGenerator++); -// batchBehavior.setId(RunScenarioModelHelper.getBatches( -// this.runScenarioModel).size()); + // batchBehavior.setId(RunScenarioModelHelper.getBatches( + // this.runScenarioModel).size()); batchBehavior.setParentId(-1); batchBehavior.setChildId(-1); -// List behaviors = new ArrayList(); -// batchBehavior.setBehaviors(behaviors); + // List behaviors = new ArrayList(); + // batchBehavior.setBehaviors(behaviors); return batchBehavior; } private boolean isChildBatchAbsent(List batches, int parentBatchId) { -// if (parentBatchId >= batches.size()) { -// return false; -// } + // if (parentBatchId >= batches.size()) { + // return false; + // } BatchModel batchModel = getBatchById(batches, parentBatchId); - if(batchModel != null){ + if (batchModel != null) { return batchModel.getChildId() < 0; } return false; @@ -189,17 +190,18 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter { public int getParentBatchIdWithParentUrl(String url) { List batchesInScenario = RunScenarioModelHelper .getBatches(this.getRunScenarioModel()); -// for (int batchId = 0; batchId < batchesInScenario.size(); batchId++) { -// BatchModel batch = batchesInScenario.get(batchId); -// for (BehaviorModel behavior : batch.getBehaviors()) { -// for (ParameterModel parameter : behavior.getParameters()) { -// if (parameter.getKey().equals("url") -// && parameter.getValue().equals(url)) { -// return batchId; -// } -// } -// } -// } + // for (int batchId = 0; batchId < batchesInScenario.size(); batchId++) + // { + // BatchModel batch = batchesInScenario.get(batchId); + // for (BehaviorModel behavior : batch.getBehaviors()) { + // for (ParameterModel parameter : behavior.getParameters()) { + // if (parameter.getKey().equals("url") + // && parameter.getValue().equals(url)) { + // return batchId; + // } + // } + // } + // } for (int i = 0; i < batchesInScenario.size(); i++) { BatchModel batch = batchesInScenario.get(i); for (BehaviorModel behavior : batch.getBehaviors()) { @@ -238,8 +240,8 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter { return; } try { - this.setRunScenarioModel((RunScenarioModel) MarshalHelper - .unmarshal(RunScenarioModel.class, text)); + this.setRunScenarioModel(MarshalHelper.unmarshal( + RunScenarioModel.class, text)); } catch (JAXBException e) { logger.error(e, e); this.setRunScenarioModel(new RunScenarioModel()); diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/helper/MarshalHelper.java b/Bench4Q-Share/src/main/java/org/bench4q/share/helper/MarshalHelper.java index f1d6ebb6..0f97c85d 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/helper/MarshalHelper.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/helper/MarshalHelper.java @@ -28,14 +28,15 @@ public class MarshalHelper { } } - public static Object unmarshal(Class classToUnmarshal, String input) + @SuppressWarnings("unchecked") + public static T unmarshal(Class classToUnmarshal, String input) throws JAXBException { try { Unmarshaller unmarshaller; unmarshaller = JAXBContext.newInstance(classToUnmarshal) .createUnmarshaller(); - return unmarshaller.unmarshal(new ByteArrayInputStream(input + return (T) unmarshaller.unmarshal(new ByteArrayInputStream(input .getBytes("utf-8"))); } catch (Exception e) { e.printStackTrace(); @@ -53,9 +54,9 @@ public class MarshalHelper { * @param input * @return null if there is an exception happened. */ - public static Object tryUnmarshal(Class classToUnmarshal, String input) { + public static T tryUnmarshal(Class classToUnmarshal, String input) { try { - return unmarshal(classToUnmarshal, input); + return (T) unmarshal(classToUnmarshal, input); } catch (Exception e) { e.printStackTrace(); return null; diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java index 1999625c..219161d7 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java @@ -105,7 +105,7 @@ public class ScriptController extends BaseController { if (operateScriptServerResponseModel.isSuccess()) { ScriptModel scriptModel = operateScriptServerResponseModel .getScriptModels().get(0); - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper + RunScenarioModel runScenarioModel = MarshalHelper .tryUnmarshal(RunScenarioModel.class, scriptModel.getScriptContent()); if (runScenarioModel == null) { @@ -135,7 +135,7 @@ public class ScriptController extends BaseController { if (operateScriptServerResponseModel.isSuccess()) { ScriptModel scriptModel = operateScriptServerResponseModel .getScriptModels().get(0); - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper + RunScenarioModel runScenarioModel = MarshalHelper .tryUnmarshal(RunScenarioModel.class, scriptModel.getScriptContent()); if (runScenarioModel == null) { @@ -362,7 +362,7 @@ public class ScriptController extends BaseController { return fail(map, ""); } - RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper + RunScenarioModel runScenarioModel = MarshalHelper .tryUnmarshal( RunScenarioModel.class, operateScriptServerResponseModel.getScriptModels() diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/AgentManagerMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/AgentManagerMessager.java index b371ac1e..7a75de12 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/AgentManagerMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/AgentManagerMessager.java @@ -30,7 +30,7 @@ public class AgentManagerMessager extends MasterMessager { createFaliAgentResponseModel(); } - return (AgentResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( AgentResponseModel.class, httpResponse.getContent()); } catch (Exception e) { this.handleException(httpResponse, e); @@ -71,7 +71,7 @@ public class AgentManagerMessager extends MasterMessager { return createFaliAgentResponseModel(); } - return (AgentResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( AgentResponseModel.class, httpResponse.getContent()); } catch (Exception e) { this.handleException(httpResponse, e); diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java index 3e6c6ffc..9b0da12c 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/MonitorMessager.java @@ -35,7 +35,7 @@ public class MonitorMessager extends MasterMessager { return null; } - MonitorMemoryResponseModel memoryResponseModel = (MonitorMemoryResponseModel) MarshalHelper + MonitorMemoryResponseModel memoryResponseModel = MarshalHelper .unmarshal(MonitorMemoryResponseModel.class, httpResponse.getContent()); return memoryResponseModel; @@ -61,7 +61,7 @@ public class MonitorMessager extends MasterMessager { return null; } - MonitorProcessorResponseModel monitorProcessorResponseModel = (MonitorProcessorResponseModel) MarshalHelper + MonitorProcessorResponseModel monitorProcessorResponseModel = MarshalHelper .unmarshal(MonitorProcessorResponseModel.class, httpResponse.getContent()); return monitorProcessorResponseModel; @@ -85,7 +85,7 @@ public class MonitorMessager extends MasterMessager { handleInvalidatedResponse(url); return null; } - MonitorNetworkReponseModel networkInterfaceModel = (MonitorNetworkReponseModel) MarshalHelper + MonitorNetworkReponseModel networkInterfaceModel = MarshalHelper .unmarshal(MonitorNetworkReponseModel.class, httpResponse.getContent()); return networkInterfaceModel; @@ -110,7 +110,7 @@ public class MonitorMessager extends MasterMessager { this.handleInvalidatedResponse(url); return null; } - MonitorPhysicalDiskResponseModel monitorPhysicalDiskResponseModel = (MonitorPhysicalDiskResponseModel) MarshalHelper + MonitorPhysicalDiskResponseModel monitorPhysicalDiskResponseModel = MarshalHelper .unmarshal(MonitorPhysicalDiskResponseModel.class, httpResponse.getContent()); return monitorPhysicalDiskResponseModel; diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java index 29e5644b..bf01b448 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/PluginMessager.java @@ -112,7 +112,7 @@ public class PluginMessager extends MasterMessager { private PluginResponseModel extractPluginResponseModel( HttpResponse httpResponse) throws JAXBException { - PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper + PluginResponseModel pluginResponseModel = MarshalHelper .unmarshal(PluginResponseModel.class, httpResponse.getContent()); if (!pluginResponseModel.isSuccess()) { logger.info(pluginResponseModel.getFailMessage()); diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/RecordPortMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/RecordPortMessager.java index a7ee4521..e7520b40 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/RecordPortMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/RecordPortMessager.java @@ -68,7 +68,7 @@ public class RecordPortMessager extends MasterMessager { private OrganizeRecordPortResponseModel extractOrganizeRecordPortResponseModel( HttpResponse httpResponse) throws JAXBException { - OrganizeRecordPortResponseModel organizeRecordPortResponseModel = (OrganizeRecordPortResponseModel) MarshalHelper + OrganizeRecordPortResponseModel organizeRecordPortResponseModel = MarshalHelper .unmarshal(OrganizeRecordPortResponseModel.class, httpResponse.getContent()); if (organizeRecordPortResponseModel.getPortModels() == null) { diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java index e3980569..361a26ca 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/ScriptMessager.java @@ -84,7 +84,7 @@ public class ScriptMessager extends MasterMessager { System.out.println(httpResponse.getContent()); if (!validateHttpResponse(httpResponse)) return null; - return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( OperateScriptServerResponseModel.class, httpResponse.getContent()); @@ -108,7 +108,7 @@ public class ScriptMessager extends MasterMessager { paramFiles, stringParts); if (!validateHttpResponse(httpResponse)) return null; - return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( OperateScriptServerResponseModel.class, httpResponse.getContent()); @@ -154,7 +154,7 @@ public class ScriptMessager extends MasterMessager { // paramFiles, "paramContents[]", stringPart); // if (!validateHttpResponse(httpResponse)) // return null; - // return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( + // return MarshalHelper.unmarshal( // OperateScriptServerResponseModel.class, // httpResponse.getContent()); // @@ -224,7 +224,7 @@ public class ScriptMessager extends MasterMessager { private OperateScriptServerResponseModel extractOperateScriptServerResponseModel( HttpResponse httpResponse) throws JAXBException { - return (OperateScriptServerResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( OperateScriptServerResponseModel.class, httpResponse.getContent()); } @@ -239,7 +239,7 @@ public class ScriptMessager extends MasterMessager { handleInvalidatedResponse(url); return null; } - return (ScriptFilterModel) MarshalHelper.tryUnmarshal( + return MarshalHelper.tryUnmarshal( ScriptFilterModel.class, httpResponse.getContent()); } catch (Exception e) { this.handleException(httpResponse, e); diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/TestPlanMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/TestPlanMessager.java index d765f428..04b8a24d 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/TestPlanMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/TestPlanMessager.java @@ -92,7 +92,7 @@ public class TestPlanMessager extends MasterMessager { return null; } - return (TestPlanScriptBriefResultModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( TestPlanScriptBriefResultModel.class, httpResponse.getContent()); } catch (Exception e) { @@ -111,7 +111,7 @@ public class TestPlanMessager extends MasterMessager { makeAccessTockenMap(accessToken)); if (!validateHttpResponse(httpResponse)) return null; - return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( ScriptBehaviorsBriefModel.class, httpResponse.getContent()); } catch (Exception e) { this.handleException(httpResponse, e); @@ -131,7 +131,7 @@ public class TestPlanMessager extends MasterMessager { handleInvalidatedResponse(url); return null; } - return (TestPlanDBModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( TestPlanDBModel.class, httpResponse.getContent()); } catch (Exception e) { handleException(httpResponse, e); @@ -205,14 +205,14 @@ public class TestPlanMessager extends MasterMessager { private TestPlanResponseModel extractTestPlanResponseModel( HttpResponse httpResponse) throws JAXBException, UnsupportedEncodingException { - return (TestPlanResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( TestPlanResponseModel.class, httpResponse.getContent()); } private TestPlanResultModel extractTestPlanResultModel( HttpResponse httpResponse) throws JAXBException, UnsupportedEncodingException { - return (TestPlanResultModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( TestPlanResultModel.class, httpResponse.getContent()); } @@ -231,7 +231,7 @@ public class TestPlanMessager extends MasterMessager { } System.out.println("getLatestScriptBriefResult:\r\n" + httpResponse.getContent()); - return (ScriptBriefResultModel) MarshalHelper.tryUnmarshal( + return MarshalHelper.tryUnmarshal( ScriptBriefResultModel.class, httpResponse.getContent()); } catch (Exception e) { @@ -252,7 +252,7 @@ public class TestPlanMessager extends MasterMessager { handleInvalidatedResponse(url); return null; } - return (ScriptPagesBriefModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( ScriptPagesBriefModel.class, httpResponse.getContent()); } catch (Exception e) { diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/UserMessager.java b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/UserMessager.java index 2e22effb..29cfdd03 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/UserMessager.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/masterMessager/UserMessager.java @@ -28,7 +28,7 @@ public class UserMessager extends MasterMessager { if (!validateHttpResponse(httpResponse)) { return null; } - return (RegisterResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( RegisterResponseModel.class, httpResponse.getContent()); } catch (Exception e) { @@ -69,7 +69,7 @@ public class UserMessager extends MasterMessager { httpResponse = this.getHttpRequester().sendGet(url, params, null); if (!validateHttpResponse(httpResponse)) return null; - return (AuthorizeResponseModel) MarshalHelper.unmarshal( + return MarshalHelper.unmarshal( AuthorizeResponseModel.class, httpResponse.getContent()); } catch (Exception e) {