refactor
This commit is contained in:
coderfengyun 2014-09-19 14:06:25 +08:00
parent 6676927944
commit 73c26d9439
7 changed files with 32 additions and 53 deletions

View File

@ -14,7 +14,8 @@ import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
public class TimerBehavior extends PluginImplementBehavior {
public TimerBehavior(BehaviorModel timerBehaviorModel) {
if (timerBehaviorModel.getType() != Behavior.TIMER_BEHAVIOR) {
if (!timerBehaviorModel.getType().equalsIgnoreCase(
Behavior.TIMER_BEHAVIOR)) {
throw new Bench4QRunTimeException(
"The type is not expected. Expected is TIMER_BEHAVIOR, but it is "
+ timerBehaviorModel.getType());

View File

@ -14,7 +14,7 @@ import org.bench4q.share.models.agent.statistics.BehaviorBriefModel;
public class UserBehavior extends PluginImplementBehavior {
public UserBehavior(BehaviorModel behaviorModel) {
if (behaviorModel.getType() != Behavior.USER_BEHAVIOR) {
if (!behaviorModel.getType().equalsIgnoreCase(Behavior.USER_BEHAVIOR)) {
throw new Bench4QRunTimeException(
"Not the expected type, expected is USER_BEHAVIOR, but is "
+ behaviorModel.getType());

View File

@ -11,7 +11,6 @@ import javax.xml.bind.Marshaller;
import org.apache.log4j.Logger;
import org.bench4q.recorder.httpcapture.generator.ChildrenUrl;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.RunScenarioModelHelper;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
@ -188,7 +187,7 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
}
public int getParentBatchIdWithParentUrl(String url) {
List<BatchModel> batchesInScenario = RunScenarioModelHelper
List<BatchModel> batchesInScenario = RunScenarioModel
.getBatches(this.getRunScenarioModel());
// for (int batchId = 0; batchId < batchesInScenario.size(); batchId++)
// {

View File

@ -6,10 +6,11 @@ import java.util.ArrayList;
import java.util.List;
import org.bench4q.recorder.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.share.helper.RunScenarioModelHelper;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.junit.Test;
public class TestBench4qTestScriptAdapter {
@ -32,14 +33,14 @@ public class TestBench4qTestScriptAdapter {
@Test
public void testInsertUserBehaviorsToScenario() {
List<ParameterModel> params = new ArrayList<ParameterModel>();
params.add(RunScenarioModelHelper.createParameterModel("url",
"www.baidu.com"));
params.add(ParameterModel.createParameter("url", "www.baidu.com"));
this.getBench4qTestScriptAdapter().insertUserBehaviorsToScenario(
BehaviorModel.UserBehaviorBuilder(0, "http", "get", params));
assertEquals(
1,
RunScenarioModelHelper.getBatches(
this.getBench4qTestScriptAdapter()
.getRunScenarioModel()).size());
List<BatchModel> batches = new ArrayList<BatchModel>();
for (PageModel page : this.getBench4qTestScriptAdapter()
.getRunScenarioModel().getPages()) {
batches.addAll(page.getBatches());
}
assertEquals(1, batches.size());
}
}

View File

@ -7,7 +7,6 @@ import java.util.List;
import org.bench4q.recorder.httpcapture.Bench4qTestScriptAdapter;
import org.bench4q.recorder.httpcapture.IScriptAdapter;
import org.bench4q.recorder.httpcapture.generator.ChildrenUrl;
import org.bench4q.share.helper.RunScenarioModelHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.junit.Test;
@ -37,7 +36,7 @@ public class TestParentRequest extends TestRecordBase {
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(parentUrl));
assertNotNull(this.getAdapater().getRunScenarioModel());
List<BatchModel> batches = RunScenarioModelHelper.getBatches(this
List<BatchModel> batches = RunScenarioModel.getBatches(this
.getAdapater().getRunScenarioModel());
assertNotNull(batches);
assertNotNull(batches.get(0));
@ -59,7 +58,7 @@ public class TestParentRequest extends TestRecordBase {
RunScenarioModel runScenarioModel = this.getAdapater()
.getRunScenarioModel();
assertNotNull(runScenarioModel);
List<BatchModel> batches = RunScenarioModelHelper
List<BatchModel> batches = RunScenarioModel
.getBatches(runScenarioModel);
assertNotNull(batches);
assertTrue(batches.size() == 3);
@ -96,7 +95,7 @@ public class TestParentRequest extends TestRecordBase {
RunScenarioModel runScenarioModel = this.getAdapater()
.getRunScenarioModel();
assertNotNull(runScenarioModel);
List<BatchModel> batches = RunScenarioModelHelper
List<BatchModel> batches = RunScenarioModel
.getBatches(runScenarioModel);
assertNotNull(batches);
assertNotNull(batches.get(0));
@ -125,7 +124,7 @@ public class TestParentRequest extends TestRecordBase {
createUserBehaviorModel(childUrl));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(independentUrl));
List<BatchModel> batches = RunScenarioModelHelper.getBatches(this
List<BatchModel> batches = RunScenarioModel.getBatches(this
.getAdapater().getRunScenarioModel());
assertTrue(batches.get(1).getBehaviors().size() == 1);
assertTrue(batches.get(2).getBehaviors().size() == 1);
@ -150,7 +149,7 @@ public class TestParentRequest extends TestRecordBase {
createUserBehaviorModel(childUrl));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(childUrl2));
List<BatchModel> batches = RunScenarioModelHelper.getBatches(this
List<BatchModel> batches = RunScenarioModel.getBatches(this
.getAdapater().getRunScenarioModel());
System.out.println(batches.size());
assertTrue(batches.size() == 2);
@ -178,7 +177,7 @@ public class TestParentRequest extends TestRecordBase {
createUserBehaviorModel(independentUrl));
this.getAdapater().insertUserBehaviorsToScenario(
createUserBehaviorModel(independentUrl2));
assertTrue(RunScenarioModelHelper.getBatches(
assertTrue(RunScenarioModel.getBatches(
this.getAdapater().getRunScenarioModel()).size() == 4);
}

View File

@ -1,34 +0,0 @@
package org.bench4q.share.helper;
import java.util.ArrayList;
import java.util.List;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel;
public class RunScenarioModelHelper {
public static List<BatchModel> getBatches(
RunScenarioModel runScenarioModelNew) {
List<BatchModel> result = new ArrayList<BatchModel>();
for (PageModel page : runScenarioModelNew.getPages()) {
result.addAll(page.getBatches());
}
return result;
}
public static BehaviorModel createUserBehaviorModel(int id, String use,
String name, List<ParameterModel> parameterModels) {
return BehaviorModel
.UserBehaviorBuilder(id, name, use, parameterModels);
}
public static ParameterModel createParameterModel(String key, String value) {
ParameterModel parameterModel = new ParameterModel();
parameterModel.setKey(key);
parameterModel.setValue(value);
return parameterModel;
}
}

View File

@ -1,5 +1,6 @@
package org.bench4q.share.models.agent;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@ -7,6 +8,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
@ -17,6 +19,7 @@ public class RunScenarioModel {
private List<UsePluginModel> usePlugins;
private List<PageModel> pages;
private ScheduleModel scheduleModel;
@XmlElement
public int getPoolSize() {
return poolSize;
@ -55,8 +58,18 @@ public class RunScenarioModel {
this.scheduleModel = scheduleModel;
}
public static List<BatchModel> getBatches(
RunScenarioModel runScenarioModelNew) {
List<BatchModel> result = new ArrayList<BatchModel>();
for (PageModel page : runScenarioModelNew.getPages()) {
result.addAll(page.getBatches());
}
return result;
}
public RunScenarioModel() {
this.setUsePlugins(new LinkedList<UsePluginModel>());
this.setPages(new LinkedList<PageModel>());
}
}