Skip to content

Commit

Permalink
JBEHAVE-1039: Do not perform scenarios that are not allowed by filter…
Browse files Browse the repository at this point in the history
…. Add scenario and filter to monitoring.
  • Loading branch information
maurotalevi committed Aug 16, 2014
1 parent 77c5c62 commit 7783ff8
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 41 deletions.
31 changes: 20 additions & 11 deletions ides/eclipse/lifecycle-mapping-metadata.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<!-- Why this is needed for Eclipe: http://wiki.eclipse.org/M2E_plugin_execution_not_covered -->
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
Expand All @@ -12,7 +11,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
Expand Down Expand Up @@ -47,11 +46,9 @@
<artifactId>maven-hpi-plugin</artifactId>
<versionRange>[3.0,)</versionRange>
<goals>
<goal>insert-test</goal>
<goal>resolve-test-dependencies</goal>
<goal>test-hpl</goal>
<goal>
resolve-test-dependencies
</goal>
<goal>insert-test</goal>
</goals>
</pluginExecutionFilter>
<action>
Expand All @@ -64,13 +61,13 @@
<artifactId>maven-scala-plugin</artifactId>
<versionRange>[2.9.1,)</versionRange>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
<goal>testCompile</goal>
<goal>compile</goal>
<goal>add-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
Expand All @@ -83,9 +80,21 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<versionRange>3.2</versionRange>
<goals>
<goal>descriptor</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>

Expand Up @@ -25,6 +25,7 @@
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.AnnotatedEmbedderRunner;
import org.jbehave.core.model.Meta;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Story;
import org.jbehave.core.model.StoryDuration;
import org.jbehave.core.model.StoryMaps;
Expand Down Expand Up @@ -341,6 +342,12 @@ public void storiesNotAllowed(List<Story> stories, MetaFilter filter, boolean ve
}
log(sb.toString(), MSG_INFO);
}

public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) {
StringBuffer sb = new StringBuffer();
sb.append("Scenario "+scenario.getTitle()+" excluded by filter: " + filter.asString() + "\n");
log(sb.toString(), MSG_INFO);
}

public void runningStory(String path) {
log("Running story " + path, MSG_INFO);
Expand Down
Expand Up @@ -7,6 +7,7 @@

import org.jbehave.core.failures.BatchFailures;
import org.jbehave.core.model.Meta;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Story;
import org.jbehave.core.model.StoryDuration;
import org.jbehave.core.model.StoryMaps;
Expand Down Expand Up @@ -35,6 +36,8 @@ public interface EmbedderMonitor {

void storiesNotAllowed(List<Story> notAllowed, MetaFilter filter, boolean verbose);

void scenarioNotAllowed(Scenario scenario, MetaFilter filter);

void batchFailed(BatchFailures failures);

void beforeOrAfterStoriesFailed();
Expand Down
Expand Up @@ -7,6 +7,7 @@

import org.jbehave.core.failures.BatchFailures;
import org.jbehave.core.model.Meta;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Story;
import org.jbehave.core.model.StoryDuration;
import org.jbehave.core.model.StoryMaps;
Expand Down Expand Up @@ -64,6 +65,10 @@ public void storiesNotAllowed(List<Story> stories, MetaFilter filter, boolean ve
delegate.storiesNotAllowed(stories, filter, verbose);
}

public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) {
delegate.scenarioNotAllowed(scenario, filter);
}

public void batchFailed(BatchFailures failures) {
delegate.batchFailed(failures);
}
Expand Down
Expand Up @@ -7,6 +7,7 @@

import org.jbehave.core.failures.BatchFailures;
import org.jbehave.core.model.Meta;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Story;
import org.jbehave.core.model.StoryDuration;
import org.jbehave.core.model.StoryMaps;
Expand Down Expand Up @@ -50,6 +51,9 @@ public void storiesNotAllowed(List<Story> notAllowed, MetaFilter filter) {
public void storiesNotAllowed(List<Story> notAllowed, MetaFilter filter, boolean verbose) {
}

public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) {
}

public void batchFailed(BatchFailures failures) {
}

Expand Down Expand Up @@ -115,4 +119,5 @@ public void usingExecutorService(ExecutorService executorService) {
public void usingControls(EmbedderControls embedderControls) {
}


}
Expand Up @@ -411,6 +411,7 @@ public static class RunContext {
private final Configuration configuration;
private final InjectableStepsFactory stepsFactory;
private final List<CandidateSteps> candidateSteps;
private final EmbedderMonitor embedderMonitor;
private final MetaFilter filter;
private final BatchFailures failures;
private Map<Story, StoryDuration> cancelledStories = new HashMap<Story, StoryDuration>();
Expand All @@ -420,10 +421,11 @@ public static class RunContext {
private StoryReporter reporter;
private Map<String, List<PendingStep>> pendingStories = new HashMap<String, List<PendingStep>>();

public RunContext(Configuration configuration, InjectableStepsFactory stepsFactory, MetaFilter filter,
BatchFailures failures) {
public RunContext(Configuration configuration, InjectableStepsFactory stepsFactory, EmbedderMonitor embedderMonitor,
MetaFilter filter, BatchFailures failures) {
this.configuration = configuration;
this.stepsFactory = stepsFactory;
this.embedderMonitor = embedderMonitor;
this.candidateSteps = stepsFactory.createCandidateSteps();
this.filter = filter;
this.failures = failures;
Expand Down Expand Up @@ -496,7 +498,7 @@ public PerformableSteps scenarioSteps(Scenario scenario, Map<String, String> par
}

public RunContext childContextFor(GivenStory givenStory) {
RunContext child = new RunContext(configuration, stepsFactory, filter, failures);
RunContext child = new RunContext(configuration, stepsFactory, embedderMonitor, filter, failures);
child.path = configuration.pathCalculator().calculate(path, givenStory.getPath());
child.givenStory = true;
return child;
Expand Down Expand Up @@ -597,6 +599,10 @@ public MetaFilter getFilter() {
public BatchFailures getFailures() {
return failures;
}

public EmbedderMonitor embedderMonitor(){
return embedderMonitor;
}
}

public static interface Performable {
Expand Down Expand Up @@ -795,6 +801,10 @@ public List<ExamplePerformableScenario> getExamples() {
}

public void perform(RunContext context) throws InterruptedException {
if ( !isAllowed() ) {
context.embedderMonitor().scenarioNotAllowed(scenario, context.filter());
return;
}
context.reporter().beforeScenario(scenario.getTitle());
State state = context.state();
if (!examplePerformableScenarios.isEmpty()) {
Expand Down Expand Up @@ -1005,8 +1015,8 @@ public void setDurationInMillis(long durationInMillis) {
}

public RunContext newRunContext(Configuration configuration, InjectableStepsFactory stepsFactory,
MetaFilter filter, BatchFailures failures) {
return new RunContext(configuration, stepsFactory, filter, failures);
EmbedderMonitor embedderMonitor, MetaFilter filter, BatchFailures failures) {
return new RunContext(configuration, stepsFactory, embedderMonitor, filter, failures);
}

}
Expand Up @@ -11,6 +11,7 @@
import org.jbehave.core.ConfigurableEmbedder;
import org.jbehave.core.failures.BatchFailures;
import org.jbehave.core.model.Meta;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Story;
import org.jbehave.core.model.StoryDuration;
import org.jbehave.core.model.StoryMaps;
Expand Down Expand Up @@ -85,7 +86,13 @@ public void storiesNotAllowed(List<Story> stories, MetaFilter filter, boolean ve
print(sb.toString());
}

public void runningWithAnnotatedEmbedderRunner(String className) {
public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) {
StringBuffer sb = new StringBuffer();
sb.append("Scenario '"+scenario.getTitle()+"' excluded by filter: " + filter.asString() + "\n");
print(sb.toString());
}

public void runningWithAnnotatedEmbedderRunner(String className) {
print("Running with AnnotatedEmbedderRunner '" + className + "'");
}

Expand Down
Expand Up @@ -84,7 +84,7 @@ private List<Story> storiesOf(List<String> storyPaths) {

public void runStories(List<Story> stories, MetaFilter filter, BatchFailures failures) {
// create new run context
context = performableTree.newRunContext(configuration, stepsFactory, filter, failures);
context = performableTree.newRunContext(configuration, stepsFactory, embedderMonitor, filter, failures);

// add stories
performableTree.addStories(context, stories);
Expand Down
Expand Up @@ -418,6 +418,7 @@ public void shouldRunStoriesAsPaths() throws Throwable {
// Given
PerformableTree performableTree = mock(PerformableTree.class);
EmbedderControls embedderControls = new EmbedderControls();
EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
OutputStream out = new ByteArrayOutputStream();
EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
Expand Down Expand Up @@ -446,9 +447,9 @@ public StoryReporter storyReporter(String storyPath) {
when(story.getPath()).thenReturn(storyPath);
assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);

// When
Expand Down Expand Up @@ -501,9 +502,9 @@ public StoryReporter storyReporter(String storyPath) {
// When
MetaFilter filter = mock(MetaFilter.class);
when(filter.allow(meta)).thenReturn(false);
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);
embedder.runStoriesAsPaths(storyPaths);
Expand Down Expand Up @@ -573,9 +574,9 @@ public void shouldNotRunStoriesIfSkipFlagIsSet() throws Throwable {
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down Expand Up @@ -640,10 +641,10 @@ private void testStoryIfTimeoutIsSet(Answer<PerformableTree> answer) throws Thro
when(story.getPath()).thenReturn(storyPath);

Mockito.doAnswer(answer).when(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(story));
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(MetaFilter.class),
isA(BatchFailures.class))).thenReturn(runContext);
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);

// When
boolean exceptionWasThrown = false;
Expand Down Expand Up @@ -684,9 +685,9 @@ public void shouldThrowExceptionUponFailingStoriesAsPathsIfIgnoreFailureInStorie
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down Expand Up @@ -725,9 +726,9 @@ public void shouldNotThrowExceptionUponFailingStoriesAsPathsIfIgnoreFailureInSto
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down Expand Up @@ -771,9 +772,9 @@ public void shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throwable {
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down Expand Up @@ -816,9 +817,9 @@ public void shouldThrowExceptionUponFailingStoriesAsPathsInBatchIfIgnoreFailureI
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down Expand Up @@ -858,9 +859,9 @@ public void shouldRunFailingStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throw
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down Expand Up @@ -908,9 +909,9 @@ public void shouldNotGenerateViewWhenRunningStoriesAsPathsIfGenerateViewAfterSto
when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
when(story.getPath()).thenReturn(storyPath);
}
RunContext runContext = new RunContext(configuration, stepsFactory, filter, new BatchFailures());
RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
when(
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class),
performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class),
isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(
runContext);

Expand Down

0 comments on commit 7783ff8

Please sign in to comment.