Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

import org.graphwalker.core.generator.RandomPath;
import org.graphwalker.core.generator.SingletonRandomGenerator;
import org.graphwalker.core.machine.Context;
import org.graphwalker.core.machine.Machine;
import org.graphwalker.core.machine.SimpleMachine;
Expand All @@ -36,6 +37,9 @@

import java.util.concurrent.TimeUnit;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
* @author Nils Olsson
*/
Expand Down Expand Up @@ -64,6 +68,7 @@ public class ComplexConditionsTest {

@Test
public void combinedCondition_2_vertices() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();
CombinedCondition condition = new CombinedCondition();
condition.addStopCondition(new ReachedVertex("v_Browse"));
Expand All @@ -75,10 +80,12 @@ public void combinedCondition_2_vertices() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("v_LoginPrompted"));
}

@Test
public void combinedCondition_2_edges() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();
CombinedCondition condition = new CombinedCondition();
condition.addStopCondition(new ReachedEdge("e_ToggleRememberMe"));
Expand All @@ -90,10 +97,12 @@ public void combinedCondition_2_edges() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("e_InvalidCredentials"));
}

@Test
public void combinedCondition_vertex_edge() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();
CombinedCondition condition = new CombinedCondition();
condition.addStopCondition(new ReachedVertex("v_Browse"));
Expand All @@ -105,10 +114,12 @@ public void combinedCondition_vertex_edge() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("e_InvalidCredentials"));
}

@Test
public void alternativeCondition_2_vertices() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();
AlternativeCondition condition = new AlternativeCondition();
condition.addStopCondition(new ReachedVertex("v_Browse"));
Expand All @@ -120,10 +131,12 @@ public void alternativeCondition_2_vertices() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("v_LoginPrompted"));
}

@Test
public void alternativeCondition_2_edges() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();
AlternativeCondition condition = new AlternativeCondition();
condition.addStopCondition(new ReachedEdge("e_ToggleRememberMe"));
Expand All @@ -135,10 +148,12 @@ public void alternativeCondition_2_edges() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("e_InvalidCredentials"));
}

@Test
public void alternativeCondition_vertex_edge() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();
AlternativeCondition condition = new AlternativeCondition();
condition.addStopCondition(new ReachedVertex("v_Browse"));
Expand All @@ -150,19 +165,45 @@ public void alternativeCondition_vertex_edge() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("e_InvalidCredentials"));
}

// random((reached_vertex(v_Browse) AND edge_coverage(100)) OR time(1000))
@Test
public void and_plus_or_a() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();

CombinedCondition c1 = new CombinedCondition();
c1.addStopCondition(new ReachedVertex("v_Browse"));
c1.addStopCondition(new EdgeCoverage(100));

AlternativeCondition c2 = new AlternativeCondition();
c2.addStopCondition(new TimeDuration(1000, TimeUnit.SECONDS));
c2.addStopCondition(c1);

context.setModel(model.build()).setPathGenerator(new RandomPath(c2));
context.setNextElement(context.getModel().findElements("e_Init").get(0));

Machine machine = new SimpleMachine(context);
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("v_Browse"));
}

// random((reached_vertex(v_Browse) AND edge_coverage(100)) OR time(10))
// random((reached_vertex(v_Browse) AND edge_coverage(100)) OR reached_vertex(v_LoginPrompted))
@Test
public void and_plus_or() throws Exception {
public void and_plus_or_b() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();

CombinedCondition c1 = new CombinedCondition();
c1.addStopCondition(new ReachedVertex("v_Browse"));
c1.addStopCondition(new EdgeCoverage(100));

AlternativeCondition c2 = new AlternativeCondition();
c2.addStopCondition(new TimeDuration(10, TimeUnit.SECONDS));
c2.addStopCondition(new ReachedVertex("v_LoginPrompted"));
c2.addStopCondition(c1);

context.setModel(model.build()).setPathGenerator(new RandomPath(c2));
Expand All @@ -172,5 +213,35 @@ public void and_plus_or() throws Exception {
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("v_LoginPrompted"));
}

// random((reached_vertex(v_Browse) AND edge_coverage(100)) OR (reached_vertex(v_ClientNotRunning) AND edge_coverage(100)))
@Test
public void and_plus_or_c() throws Exception {
SingletonRandomGenerator.setSeed(1111);
Context context = new TestExecutionContext();

CombinedCondition c1 = new CombinedCondition();
c1.addStopCondition(new ReachedVertex("v_Browse"));
c1.addStopCondition(new EdgeCoverage(100));

CombinedCondition c2 = new CombinedCondition();
c2.addStopCondition(new ReachedVertex("v_ClientNotRunning"));
c2.addStopCondition(new EdgeCoverage(100));

AlternativeCondition c3 = new AlternativeCondition();
c3.addStopCondition(c1);
c3.addStopCondition(c2);


context.setModel(model.build()).setPathGenerator(new RandomPath(c3));
context.setNextElement(context.getModel().findElements("e_Init").get(0));

Machine machine = new SimpleMachine(context);
while (machine.hasNextStep()) {
machine.getNextStep();
}
assertThat(machine.getCurrentContext().getCurrentElement().getName(), is("v_Browse"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,28 @@ public void issue_341_b() {
assertThat(c2.getStopConditions().get(1), instanceOf(ReachedVertex.class));
}

@Test
public void issue_341_c() {
PathGenerator generator = GeneratorFactory.parse("random((reached_vertex(v_Browse) AND edge_coverage(100)) OR (reached_vertex(v_ClientNotRunning) AND edge_coverage(100)))");
assertThat(generator, instanceOf(RandomPath.class));
assertThat(generator.getStopCondition(), instanceOf(AlternativeCondition.class));

AlternativeCondition c1 = (AlternativeCondition) generator.getStopCondition();
assertThat(c1.getStopConditions().size(), is(2));
assertThat(c1.getStopConditions().get(0), instanceOf(CombinedCondition.class));
assertThat(c1.getStopConditions().get(1), instanceOf(CombinedCondition.class));

CombinedCondition c2 = (CombinedCondition)c1.getStopConditions().get(0);
assertThat(c2.getStopConditions().size(), is(2));
assertThat(c2.getStopConditions().get(0), instanceOf(ReachedVertex.class));
assertThat(c2.getStopConditions().get(1), instanceOf(EdgeCoverage.class));

CombinedCondition c3 = (CombinedCondition)c1.getStopConditions().get(1);
assertThat(c3.getStopConditions().size(), is(2));
assertThat(c3.getStopConditions().get(0), instanceOf(ReachedVertex.class));
assertThat(c3.getStopConditions().get(1), instanceOf(EdgeCoverage.class));
}

@Test
public void predefinedPath_predefinedPathStopCondition() {
PathGenerator generator = GeneratorFactory.parse("predefined_path(predefined_path)");
Expand Down