add three tests and pass them, now i can add the children behaviors to
right batches now. But can only deal with one parent behavior per batch
This commit is contained in:
parent
cb40ffe4d6
commit
959ecb2109
|
@ -47,7 +47,7 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
|
|||
|
||||
public void insertUserBehaviorsToScenario(BehaviorBaseModel model) {
|
||||
List<BatchBehavior> batches = this.getRunScenarioModel().getBatches();
|
||||
int batchId = -1;
|
||||
int parentBatchId = -1;
|
||||
if (batches == null) {
|
||||
this.getRunScenarioModel().setBatches(
|
||||
new ArrayList<BatchBehavior>());
|
||||
|
@ -57,37 +57,40 @@ public class Bench4qTestScriptAdapter implements IScriptAdapter {
|
|||
if (!parameter.getKey().equals("url")) {
|
||||
continue;
|
||||
}
|
||||
batchId = contains(parameter.getValue());
|
||||
parentBatchId = getParentBatchId(parameter.getValue());
|
||||
}
|
||||
|
||||
if (batchId < 0) {
|
||||
batches.add(createBatchBehavior(model, batches));
|
||||
if (parentBatchId < 0) {
|
||||
batches.add(createBatchBehavior(model, batches.size()));
|
||||
return;
|
||||
}
|
||||
while (batches.size() <= batchId) {
|
||||
batches.add(new BatchBehavior());
|
||||
if (batches.get(parentBatchId).getChildId() < 0) {
|
||||
BatchBehavior batchBehavior = createBatchBehavior(model,
|
||||
batches.size());
|
||||
batchBehavior.setParentId(parentBatchId);
|
||||
batches.add(batchBehavior);
|
||||
batches.get(parentBatchId).setChildId(batches.size() - 1);
|
||||
return;
|
||||
}
|
||||
BatchBehavior batchBehavior = batches.get(batchId);
|
||||
batchBehavior.setId(batchId);
|
||||
batchBehavior.getBehaviors().add(model);
|
||||
batches.get(batches.get(parentBatchId).getChildId()).getBehaviors()
|
||||
.add(model);
|
||||
}
|
||||
|
||||
private BatchBehavior createBatchBehavior(BehaviorBaseModel model,
|
||||
List<BatchBehavior> batches) {
|
||||
int batchId) {
|
||||
BatchBehavior batchBehavior = new BatchBehavior();
|
||||
batchBehavior.setId(batches.size());
|
||||
batchBehavior.setParent_id(-1);
|
||||
batchBehavior.setChild_id(-1);
|
||||
batchBehavior.setId(batchId);
|
||||
batchBehavior.setParentId(-1);
|
||||
batchBehavior.setChildId(-1);
|
||||
List<BehaviorBaseModel> behaviors = new ArrayList<BehaviorBaseModel>();
|
||||
behaviors.add(model);
|
||||
batchBehavior.setBehaviors(behaviors);
|
||||
return batchBehavior;
|
||||
}
|
||||
|
||||
private int contains(String url) {
|
||||
private int getParentBatchId(String url) {
|
||||
for (ChildrenUrl childrenUrl : this.getChildrenUrls()) {
|
||||
if (childrenUrl.getUrl().equals(url)) {
|
||||
return childrenUrl.getStoreBatchId();
|
||||
return childrenUrl.getParentBatchId();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
|
|
@ -16,6 +16,11 @@ import org.junit.Test;
|
|||
|
||||
public class TestParentRequest {
|
||||
private IScriptAdapter adapater;
|
||||
private static String parentUrl = "www.apache.com";
|
||||
private static String childUrl = "www.yahoo.com";
|
||||
private static String independentUrl = "www.baidu.com";
|
||||
private static String independentUrl2 = "www.eclipse.org";
|
||||
private static String childUrl2 = "www.tomcat.com";
|
||||
|
||||
private IScriptAdapter getAdapater() {
|
||||
return adapater;
|
||||
|
@ -30,16 +35,40 @@ public class TestParentRequest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAddOneBehaviorToBatchWihoutChildrenUrl() {
|
||||
this.getAdapater()
|
||||
.insertUserBehaviorsToScenario(
|
||||
createUserBehavior("http://wiki.apache.org/tomcat/TomcatVersions"));
|
||||
public void testAddOneBehaviorWihoutChildrenUrl() {
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(parentUrl));
|
||||
assertNotNull(this.getAdapater().getRunScenarioModel());
|
||||
assertNotNull(this.getAdapater().getRunScenarioModel().getBatches());
|
||||
assertNotNull(this.getAdapater().getRunScenarioModel().getBatches()
|
||||
.get(0));
|
||||
assertTrue(this.getAdapater().getRunScenarioModel().getBatches().get(0)
|
||||
.getId() == 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTwoBehaviorWithOutChildrenUrl() {
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(parentUrl));
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl, 0));
|
||||
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(independentUrl));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(independentUrl2));
|
||||
RunScenarioModel runScenarioModel = this.getAdapater()
|
||||
.getRunScenarioModel();
|
||||
assertNotNull(runScenarioModel);
|
||||
assertNotNull(runScenarioModel.getBatches());
|
||||
assertTrue(runScenarioModel.getBatches().size() == 3);
|
||||
assertTrue(runScenarioModel.getBatches().get(1).getBehaviors().size() == 1);
|
||||
assertTrue(runScenarioModel.getBatches().get(2).getBehaviors().size() == 1);
|
||||
assertTrue(runScenarioModel.getBatches().get(1).getBehaviors().get(0)
|
||||
.getParameters().get(0).getValue().equals(independentUrl));
|
||||
assertTrue(runScenarioModel.getBatches().get(2).getBehaviors().get(0)
|
||||
.getParameters().get(0).getValue().equals(independentUrl2));
|
||||
}
|
||||
|
||||
private UserBehaviorModel createUserBehavior(String url) {
|
||||
|
@ -58,25 +87,92 @@ public class TestParentRequest {
|
|||
|
||||
@Test
|
||||
public void testAddBehaviorWithInChildrenUrl() {
|
||||
String url = "http://wiki.apache.org/wiki/modernized/css/common.css";
|
||||
this.getAdapater().getChildrenUrls().add(createChildrenUrl(url));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(url));
|
||||
assertNotNull(this.getAdapater().getRunScenarioModel());
|
||||
assertNotNull(this.getAdapater().getRunScenarioModel().getBatches());
|
||||
assertNotNull(this.getAdapater().getRunScenarioModel().getBatches()
|
||||
.get(0));
|
||||
List<BatchBehavior> batches = this.getAdapater().getRunScenarioModel()
|
||||
.getBatches();
|
||||
System.out.println(batches.get(1).getId());
|
||||
createUserBehavior(parentUrl));
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl, 0));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(childUrl));
|
||||
RunScenarioModel runScenarioModel = this.getAdapater()
|
||||
.getRunScenarioModel();
|
||||
assertNotNull(runScenarioModel);
|
||||
assertNotNull(runScenarioModel.getBatches());
|
||||
assertNotNull(runScenarioModel.getBatches().get(0));
|
||||
assertNotNull(runScenarioModel.getBatches().get(1));
|
||||
List<BatchBehavior> batches = runScenarioModel.getBatches();
|
||||
assertTrue(batches.get(1).getId() == 1);
|
||||
}
|
||||
|
||||
private ChildrenUrl createChildrenUrl(String url) {
|
||||
private ChildrenUrl createChildrenUrl(String url, int parentBatchId) {
|
||||
ChildrenUrl childrenUrl = new ChildrenUrl();
|
||||
childrenUrl.setParentBatchId(-1);
|
||||
childrenUrl.setParentBatchId(parentBatchId);
|
||||
childrenUrl.setStoreBatchId(1);
|
||||
childrenUrl.setUrl(url);
|
||||
return childrenUrl;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddBehaviorsIncludeInAndOut() {
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(parentUrl));
|
||||
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl, 0));
|
||||
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(childUrl));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(independentUrl));
|
||||
List<BatchBehavior> batches = this.getAdapater().getRunScenarioModel()
|
||||
.getBatches();
|
||||
assertTrue(batches.get(1).getBehaviors().size() == 1);
|
||||
assertTrue(batches.get(2).getBehaviors().size() == 1);
|
||||
assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0)
|
||||
.getValue().equals(childUrl));
|
||||
assertTrue(batches.get(2).getBehaviors().get(0).getParameters().get(0)
|
||||
.getValue().equals(independentUrl));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoBehaviorsInChildrenUrl() {
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(parentUrl));
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl, 0));
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl2, 0));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(childUrl));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(childUrl2));
|
||||
List<BatchBehavior> batches = this.getAdapater().getRunScenarioModel()
|
||||
.getBatches();
|
||||
System.out.println(batches.size());
|
||||
assertTrue(batches.size() == 2);
|
||||
assertTrue(batches.get(0).getBehaviors().get(0).getParameters().get(0)
|
||||
.getValue().equals(parentUrl));
|
||||
assertTrue(batches.get(1).getBehaviors().get(0).getParameters().get(0)
|
||||
.getValue().equals(childUrl));
|
||||
assertTrue(batches.get(1).getBehaviors().get(1).getParameters().get(0)
|
||||
.getValue().equals(childUrl2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTwoInTwoOut() {
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(parentUrl));
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl, 0));
|
||||
this.getAdapater().getChildrenUrls()
|
||||
.add(createChildrenUrl(childUrl2, 0));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(childUrl));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(childUrl2));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(independentUrl));
|
||||
this.getAdapater().insertUserBehaviorsToScenario(
|
||||
createUserBehavior(independentUrl2));
|
||||
assertTrue(this.getAdapater().getRunScenarioModel().getBatches().size() == 4);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue