From 7783ff813e9b47309f0e1f17c96f8dbc73abc3fe Mon Sep 17 00:00:00 2001 From: Mauro Talevi Date: Sat, 16 Aug 2014 15:40:03 +0200 Subject: [PATCH] JBEHAVE-1039: Do not perform scenarios that are not allowed by filter. Add scenario and filter to monitoring. --- ides/eclipse/lifecycle-mapping-metadata.xml | 31 ++++++++----- .../org/jbehave/ant/AbstractEmbedderTask.java | 7 +++ .../core/embedder/EmbedderMonitor.java | 3 ++ .../embedder/EmbedderMonitorDecorator.java | 5 +++ .../core/embedder/NullEmbedderMonitor.java | 5 +++ .../core/embedder/PerformableTree.java | 20 ++++++--- .../embedder/PrintStreamEmbedderMonitor.java | 9 +++- .../jbehave/core/embedder/StoryManager.java | 2 +- .../core/embedder/EmbedderBehaviour.java | 43 ++++++++++--------- .../jbehave/mojo/AbstractEmbedderMojo.java | 11 ++++- 10 files changed, 95 insertions(+), 41 deletions(-) diff --git a/ides/eclipse/lifecycle-mapping-metadata.xml b/ides/eclipse/lifecycle-mapping-metadata.xml index 9cb75be60d..9a4d18b901 100644 --- a/ides/eclipse/lifecycle-mapping-metadata.xml +++ b/ides/eclipse/lifecycle-mapping-metadata.xml @@ -1,6 +1,5 @@ - @@ -12,7 +11,7 @@ - + @@ -47,11 +46,9 @@ maven-hpi-plugin [3.0,) - insert-test + resolve-test-dependencies test-hpl - - resolve-test-dependencies - + insert-test @@ -64,13 +61,13 @@ maven-scala-plugin [2.9.1,) - add-source - compile testCompile + compile + add-source - + @@ -83,9 +80,21 @@ - + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + + descriptor + + + + - diff --git a/jbehave-ant/src/main/java/org/jbehave/ant/AbstractEmbedderTask.java b/jbehave-ant/src/main/java/org/jbehave/ant/AbstractEmbedderTask.java index fa5a7449dd..1456c9d2d0 100755 --- a/jbehave-ant/src/main/java/org/jbehave/ant/AbstractEmbedderTask.java +++ b/jbehave-ant/src/main/java/org/jbehave/ant/AbstractEmbedderTask.java @@ -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; @@ -341,6 +342,12 @@ public void storiesNotAllowed(List 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); diff --git a/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitor.java b/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitor.java index c7d7e75ec4..f052cb7c70 100755 --- a/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitor.java +++ b/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitor.java @@ -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; @@ -35,6 +36,8 @@ public interface EmbedderMonitor { void storiesNotAllowed(List notAllowed, MetaFilter filter, boolean verbose); + void scenarioNotAllowed(Scenario scenario, MetaFilter filter); + void batchFailed(BatchFailures failures); void beforeOrAfterStoriesFailed(); diff --git a/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitorDecorator.java b/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitorDecorator.java index f75da6891a..694ea02406 100755 --- a/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitorDecorator.java +++ b/jbehave-core/src/main/java/org/jbehave/core/embedder/EmbedderMonitorDecorator.java @@ -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; @@ -64,6 +65,10 @@ public void storiesNotAllowed(List 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); } diff --git a/jbehave-core/src/main/java/org/jbehave/core/embedder/NullEmbedderMonitor.java b/jbehave-core/src/main/java/org/jbehave/core/embedder/NullEmbedderMonitor.java index 91498e3733..d8c49224d4 100644 --- a/jbehave-core/src/main/java/org/jbehave/core/embedder/NullEmbedderMonitor.java +++ b/jbehave-core/src/main/java/org/jbehave/core/embedder/NullEmbedderMonitor.java @@ -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; @@ -50,6 +51,9 @@ public void storiesNotAllowed(List notAllowed, MetaFilter filter) { public void storiesNotAllowed(List notAllowed, MetaFilter filter, boolean verbose) { } + public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) { + } + public void batchFailed(BatchFailures failures) { } @@ -115,4 +119,5 @@ public void usingExecutorService(ExecutorService executorService) { public void usingControls(EmbedderControls embedderControls) { } + } diff --git a/jbehave-core/src/main/java/org/jbehave/core/embedder/PerformableTree.java b/jbehave-core/src/main/java/org/jbehave/core/embedder/PerformableTree.java index 3247b10759..a8c87f1c53 100644 --- a/jbehave-core/src/main/java/org/jbehave/core/embedder/PerformableTree.java +++ b/jbehave-core/src/main/java/org/jbehave/core/embedder/PerformableTree.java @@ -411,6 +411,7 @@ public static class RunContext { private final Configuration configuration; private final InjectableStepsFactory stepsFactory; private final List candidateSteps; + private final EmbedderMonitor embedderMonitor; private final MetaFilter filter; private final BatchFailures failures; private Map cancelledStories = new HashMap(); @@ -420,10 +421,11 @@ public static class RunContext { private StoryReporter reporter; private Map> pendingStories = new HashMap>(); - 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; @@ -496,7 +498,7 @@ public PerformableSteps scenarioSteps(Scenario scenario, Map 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; @@ -597,6 +599,10 @@ public MetaFilter getFilter() { public BatchFailures getFailures() { return failures; } + + public EmbedderMonitor embedderMonitor(){ + return embedderMonitor; + } } public static interface Performable { @@ -795,6 +801,10 @@ public List 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()) { @@ -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); } } diff --git a/jbehave-core/src/main/java/org/jbehave/core/embedder/PrintStreamEmbedderMonitor.java b/jbehave-core/src/main/java/org/jbehave/core/embedder/PrintStreamEmbedderMonitor.java index 453fed45c9..cde714e3b2 100755 --- a/jbehave-core/src/main/java/org/jbehave/core/embedder/PrintStreamEmbedderMonitor.java +++ b/jbehave-core/src/main/java/org/jbehave/core/embedder/PrintStreamEmbedderMonitor.java @@ -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; @@ -85,7 +86,13 @@ public void storiesNotAllowed(List 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 + "'"); } diff --git a/jbehave-core/src/main/java/org/jbehave/core/embedder/StoryManager.java b/jbehave-core/src/main/java/org/jbehave/core/embedder/StoryManager.java index ca9375c66c..dfebad0709 100644 --- a/jbehave-core/src/main/java/org/jbehave/core/embedder/StoryManager.java +++ b/jbehave-core/src/main/java/org/jbehave/core/embedder/StoryManager.java @@ -84,7 +84,7 @@ private List storiesOf(List storyPaths) { public void runStories(List 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); diff --git a/jbehave-core/src/test/java/org/jbehave/core/embedder/EmbedderBehaviour.java b/jbehave-core/src/test/java/org/jbehave/core/embedder/EmbedderBehaviour.java index f2db7e05fc..e6c6a1ff5d 100755 --- a/jbehave-core/src/test/java/org/jbehave/core/embedder/EmbedderBehaviour.java +++ b/jbehave-core/src/test/java/org/jbehave/core/embedder/EmbedderBehaviour.java @@ -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> embeddables = asList(MyStory.class, MyOtherEmbeddable.class); @@ -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 @@ -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); @@ -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); @@ -640,10 +641,10 @@ private void testStoryIfTimeoutIsSet(Answer 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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/AbstractEmbedderMojo.java b/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/AbstractEmbedderMojo.java index f12a6d4bd8..b076add77d 100755 --- a/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/AbstractEmbedderMojo.java +++ b/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/AbstractEmbedderMojo.java @@ -1,5 +1,7 @@ package org.jbehave.mojo; +import static org.apache.commons.lang.ArrayUtils.isNotEmpty; + import java.io.File; import java.net.MalformedURLException; import java.net.URL; @@ -23,13 +25,12 @@ 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; import org.jbehave.core.reporters.ReportsCount; -import static org.apache.commons.lang.ArrayUtils.isNotEmpty; - /** * Abstract mojo that holds all the configuration parameters to specify and load * stories. @@ -428,6 +429,12 @@ public void storiesNotAllowed(List stories, MetaFilter filter, boolean ve getLog().info(sb.toString()); } + public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) { + StringBuffer sb = new StringBuffer(); + sb.append("Scenario '"+scenario.getTitle()+"' excluded by filter: " + filter.asString() + "\n"); + getLog().info(sb.toString()); + } + public void runningWithAnnotatedEmbedderRunner(String className) { getLog().info("Running with AnnotatedEmbedderRunner '" + className + "'"); }