-
Notifications
You must be signed in to change notification settings - Fork 52
First version #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sonfeldalmos
wants to merge
8
commits into
GraphWalker:master
Choose a base branch
from
sonfeldalmos:feature/Create_ModelBasedTestingFramework_Plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
First version #43
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db8441b
First version
3d63145
Injectable path first POC
2f55db5
Add example model
0772ca3
Final touches
d44f33f
Change stopping condition
22fb5f4
Refactor to achive SOLID
29a4acf
Add PredefinedPathSoppingCondition
c5844b5
Remove unused stuff
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,5 @@ obj/ | |
|
|
||
|
|
||
|
|
||
| graphwalker-cli-4.2.0 .jar | ||
| java-plugin-generator/pet.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "java.configuration.updateBuildConfiguration": "interactive" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
java-plugin-generator/src/main/java/com/mycompany/lib/Edge.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.mycompany.lib; | ||
|
|
||
| public class Edge { | ||
|
|
||
| private String name; | ||
| private String id; | ||
| private String sourceVertexId; | ||
| private String targetVertexId; | ||
|
|
||
| public String getSourceVertexId() { | ||
| return sourceVertexId; | ||
| } | ||
|
|
||
| public String getTargetVertexId() { | ||
| return targetVertexId; | ||
| } | ||
|
|
||
| public void setTargetVertexId(String targetVertexId) { | ||
| this.targetVertexId = targetVertexId; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
java-plugin-generator/src/main/java/com/mycompany/lib/Model.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.mycompany.lib; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Model { | ||
|
|
||
| public Model(){} | ||
| private String name; | ||
| private String id; | ||
| private String startElementId; | ||
| private String generator; | ||
| private List<String> predefinedPath = new ArrayList<>(); | ||
| private List<Vertex> vertices; | ||
| private List<Edge> edges; | ||
|
|
||
| public List<Edge> getEdges() { | ||
| return edges; | ||
| } | ||
|
|
||
| public void setEdges(List<Edge> edges) { | ||
| this.edges = edges; | ||
| } | ||
|
|
||
| public List<Vertex> getVertices() { | ||
| return vertices; | ||
| } | ||
|
|
||
| public void setVertices(List<Vertex> vertices) { | ||
| this.vertices = vertices; | ||
| } | ||
|
|
||
| public List<String> getPredefinedPath() { | ||
| return predefinedPath; | ||
| } | ||
|
|
||
| public void setPredefinedPath(List<String> predefinedPath) { | ||
| this.predefinedPath = predefinedPath; | ||
| } | ||
|
|
||
| public String getGenerator() { | ||
| return generator; | ||
| } | ||
|
|
||
| public void setGenerator(String generator) { | ||
| this.generator = generator; | ||
| } | ||
|
|
||
| public String getStartElementId() { | ||
| return startElementId; | ||
| } | ||
|
|
||
| public void setStartElementId(String startElementId) { | ||
| this.startElementId = startElementId; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
java-plugin-generator/src/main/java/com/mycompany/lib/Models.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.mycompany.lib; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Models { | ||
| private List<Model> models; | ||
|
|
||
| public List<Model> getModels() { | ||
| return models; | ||
| } | ||
|
|
||
| public void setModels(List<Model> models) { | ||
| this.models = models; | ||
| } | ||
| } |
45 changes: 0 additions & 45 deletions
45
java-plugin-generator/src/main/java/com/mycompany/lib/PluginGenerator.java
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
java-plugin-generator/src/main/java/com/mycompany/lib/PredefinedPathGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package com.mycompany.lib; | ||
|
|
||
| import org.graphwalker.core.model.Edge; | ||
| import org.graphwalker.core.model.Vertex; | ||
|
|
||
| import org.graphwalker.core.condition.StopCondition; | ||
| import org.graphwalker.core.generator.NoPathFoundException; | ||
| import org.graphwalker.core.generator.PathGeneratorBase; | ||
| import org.graphwalker.core.machine.Context; | ||
| import org.graphwalker.core.model.Element; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.google.gson.Gson; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.json.simple.JSONObject; | ||
| import org.json.simple.parser.JSONParser; | ||
| import java.io.FileReader; | ||
|
|
||
| public class PredefinedPathGenerator extends PathGeneratorBase<StopCondition> { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(PredefinedPathGenerator.class); | ||
| private List<String> predefinedPath; | ||
| private int currentPathIndex = 0; | ||
|
|
||
| private void Setfile(String path) { | ||
| JSONParser parser = new JSONParser(); | ||
| try { | ||
| Object obj = parser.parse(new FileReader(path)); | ||
| JSONObject fullFile = (JSONObject) obj; | ||
| Gson gson = new Gson(); | ||
| Models models = gson.fromJson(fullFile.toJSONString(), Models.class); | ||
| predefinedPath = models.getModels().get(0).getPredefinedPath(); | ||
|
|
||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
| public PredefinedPathGenerator(StopCondition stopCondition) { | ||
| setStopCondition(stopCondition); | ||
| Setfile("C:\\app\\inputs\\SimpleModel.json"); | ||
| } | ||
|
|
||
| @Override | ||
| public Context getNextStep() { | ||
| Context context = super.getNextStep(); | ||
| Element currentElement = context.getCurrentElement(); | ||
| List<Element> reachableElements = context.filter(context.getModel().getElements(currentElement)); | ||
|
|
||
| if (reachableElements.isEmpty()) { | ||
| LOG.error("currentElement: " + currentElement); | ||
| LOG.error("context.getModel().getElements(): " + context.getModel().getElements()); | ||
| throw new NoPathFoundException(context.getCurrentElement()); | ||
| } | ||
| Element nextElement; | ||
|
|
||
| if (currentElement instanceof Edge.RuntimeEdge) { | ||
| nextElement = getNextElementFromEdge(context, reachableElements, (Edge.RuntimeEdge) currentElement); | ||
| } else if (currentElement instanceof Vertex.RuntimeVertex) { | ||
| nextElement = getNextElementFromVertex(context, reachableElements, (Vertex.RuntimeVertex) currentElement); | ||
| } else { | ||
| LOG.error("Current element is neither an edge or a vertex"); | ||
| throw new NoPathFoundException(context.getCurrentElement()); | ||
| } | ||
| context.setCurrentElement(nextElement); | ||
| return context; | ||
| } | ||
|
|
||
| private Element getNextElementFromEdge(Context context, List<Element> reachableElements, | ||
| Edge.RuntimeEdge currentElement) { | ||
| if (reachableElements.size() != 1) { | ||
| LOG.error("Next vertex of predefined path is ambiguous (after step " + currentPathIndex | ||
| + ", from edge with id \"" + currentElement.getId() + "\")"); | ||
| throw new NoPathFoundException(currentElement); | ||
| } | ||
| currentPathIndex++; | ||
| return reachableElements.get(0); | ||
| } | ||
|
|
||
| private Element getNextElementFromVertex(Context context, List<Element> reachableElements, | ||
| Vertex.RuntimeVertex currentElement) { | ||
| for (Element elem : reachableElements) { | ||
| if (elem.getId().equals(predefinedPath.get(currentPathIndex))) { | ||
| return elem; | ||
| } | ||
| } | ||
| LOG.error("Next edge with id \"" + predefinedPath.get(currentPathIndex) | ||
| + "\" from predefined path is unreachable (either the guarding condition was not met or the edge has a different source vertex."); | ||
| throw new NoPathFoundException(currentElement); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasNextStep() { | ||
| return (currentPathIndex < predefinedPath.size()); | ||
| } | ||
|
|
||
| } | ||
35 changes: 35 additions & 0 deletions
35
java-plugin-generator/src/main/java/com/mycompany/lib/PredefinedPathStopCondition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
|
|
||
| // import org.graphwalker.core.condition.StopConditionBase; | ||
| // import org.graphwalker.core.model.Edge; | ||
| // import org.graphwalker.core.model.Vertex; | ||
|
|
||
| // public class PredefinedPathStopCondition extends StopConditionBase { | ||
|
|
||
| // public PredefinedPathStopCondition() { | ||
| // super("PredefinedPath"); | ||
| // } | ||
|
|
||
| // @Override | ||
| // public boolean isFulfilled() { | ||
| // return getCurrentStepCount() == getTotalStepCount(); | ||
| // } | ||
|
|
||
| // @Override | ||
| // public double getFulfilment() { | ||
| // return (double) getCurrentStepCount() / getTotalStepCount(); | ||
| // } | ||
|
|
||
| // private int getCurrentStepCount() { | ||
| // // *2 because each index increment corresponds to a vertex-edge step pair | ||
| // int currentStepCount = getContext().getPredefinedPathCurrentEdgeIndex() * 2; | ||
| // if (getContext().getCurrentElement() instanceof Vertex.RuntimeVertex) { | ||
| // return currentStepCount + 1; | ||
| // } | ||
| // return currentStepCount; | ||
| // } | ||
|
|
||
| // private int getTotalStepCount() { | ||
| // return (getContext().getModel().getPredefinedPath().size() * 2) + 1; | ||
| // } | ||
|
|
||
| // } |
20 changes: 20 additions & 0 deletions
20
java-plugin-generator/src/main/java/com/mycompany/lib/Vertex.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.mycompany.lib; | ||
|
|
||
| public class Vertex { | ||
| private String name; | ||
| private String id; | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| public void setName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method will be modified to utilize custom json handling