GraphWalker / graphwalker-project

This is the repo for the Model-based testing tool GraphWalker.

Home Page:http://graphwalker.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Action in vertex not taken into account

epoiseau opened this issue · comments

I have a model created using the studio. Actions specified in edges are taken into account. Actions specified in Vertex are not taken into account. I have used the same command for the action both in vertex and edges. The action is similar to this one (setting a variable to a value)

test=true;

So the question is : Are actions in vertex taken into account ?
See attached example.

test.json.txt

I believe GraphWalker is evaluating the expression test=true; after the evaluation of which out edges are available.
So in other words, actions are executed as the last thing done in an element.

It seems that actions in vertices are lost, after model.build()
In JsonContextFactory.java line 155, maybe it's a bug.

  public List<Context> create(String jsonStr) {
    List<Context> contexts = new ArrayList<>();
    JsonMultimodel jsonMultimodel = new Gson().fromJson(jsonStr, JsonMultimodel.class);

    if (isNull(jsonMultimodel) || isNull(jsonMultimodel.getModels())) {
      throw new ContextFactoryException("The json file is not a valid GraphWalker model(s) file");
    }

    // Seed the [global] singleton random generator, if any seed was set in the json file
    if (jsonMultimodel.getSeed() != null) {
      SingletonRandomGenerator.setSeed(jsonMultimodel.getSeed());
    }

    for (JsonModel jsonModel : jsonMultimodel.getModels()) {
      JsonContext context = new JsonContext();
      Model model = jsonModel.getModel();

      context.setModel(model.build()); // after this line, actions in vertices are lost.
      if (jsonModel.getGenerator() != null) {
        context.setPathGenerator(GeneratorFactory.parse(jsonModel.getGenerator()));
      }
      for (Element element : context.getModel().getElements()) {
        if (element.getId().equals(jsonModel.getStartElementId())) {
          context.setNextElement(element);
          break;
        }
      }
      contexts.add(context);
    }

    return contexts;
  }

Indeed, It's a bug. Good catch @xiechunhong , thanks!

Setting actions are missing in:

public void setVertex(Vertex.RuntimeVertex vertex) {
id = vertex.getId();
name = vertex.getName();
sharedState = vertex.getSharedState();
if (vertex.hasRequirements()) {
requirements = new ArrayList<>();
for (Requirement requirement : vertex.getRequirements()) {
requirements.add(requirement.getKey());
}
}
if (vertex.hasProperties()) {
properties = new HashMap<>();
properties.putAll(vertex.getProperties());
}
}

I'll fix it during the day.

I created a PR #233 .

Super fast response! @KristianKarl
Another thing:
In graphwalker-core SimpleMachine.java,the execute method for vertex, there is no actions execution call (just like the first line in edge execute method), could it be another bug, or it is just as designed?
private void execute(RuntimeVertex vertex) (line 303)

  private void execute(RuntimeEdge edge) {
    execute(edge.getActions()); // this line will execute the actions defined in edge
    if (edge.hasName()) {
      getCurrentContext().execute(edge.getName());
    }
  }

  private void execute(List<Action> actions) {
    for (Action action : actions) {
      getCurrentContext().execute(action);
    }
  }

  private void execute(RuntimeVertex vertex) {
    // maybe vertex also need to execute the actions here
    if (vertex.hasName()) {
      getCurrentContext().execute(vertex.getName());
    }
  }

OK, I see your changes of the code, the issue (vertex doesn't execute the actions in SimpleMachine.java) I mentioned at the above comment is fixed! Great work! @KristianKarl

The fix is available now in the latest 4.3.0-SNAPSHOT version, which is available here: https://github.com/GraphWalker/graphwalker-project/releases/tag/LATEST-BUILDS