Title: [1640] trunk/core/distribution/src/site/content: JBEHAVE-287: Added dryRun flag to StepsConfiguration to allow the verification of the steps matching without executing them.
Revision
1640
Author
mauro
Date
2010-05-13 16:57:37 -0500 (Thu, 13 May 2010)

Log Message

JBEHAVE-287:  Added dryRun flag to StepsConfiguration to allow the verification of the steps matching without executing them.

Modified Paths

Diff

Modified: trunk/core/distribution/src/site/content/pending-steps.html (1639 => 1640)

--- trunk/core/distribution/src/site/content/pending-steps.html	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/distribution/src/site/content/pending-steps.html	2010-05-13 21:57:37 UTC (rev 1640)
@@ -31,6 +31,23 @@
 } 
 </pre>
 
+<h2>Dry Run Mode</h2>
+
+<p>It may be sometimes useful to run in dry-run mode, checking if any steps are pending but without actually
+executed any of the steps, as this may take a considerable time.  The dry-run mode may be enabled via
+the StepsConfiguration:</p>
+
+<pre class="brush: java">
+StepsConfiguration stepsConfiguration = new StepsConfiguration();
+stepsConfiguration.useMonitor(new PrintStreamStepMonitor()); // default is SilentStepMonitor()
+stepsConfiguration.doDryRun(true); // default is "false"
+Steps steps = new StepsFactory(stepsConfiguration, new MySteps());
+</pre>
+
+<p>We've here configured the steps to use a verbose monitoring, so that the use can see that in dry-run mode 
+the step that is about to be performed will be followed by a "(DRY RUN)" additional tag.   When dry-run mode
+is activated, it will also be shown in the reporters' output.
+</p>
 <div class="clear">
 <hr />
 </div>

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java (1639 => 1640)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -60,7 +60,7 @@
         		monitor, new TraderConverter(mockTradePersister())));  // define converter for custom type Trader
         configuration.usePatternBuilder(new PrefixCapturingPatternBuilder("%")); // use '%' instead of '$' to identify parameters
         configuration.useMonitor(monitor);
-        
+        configuration.doDryRun(false);
         addSteps(createSteps(configuration));
     }
 

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties (1639 => 1640)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties	2010-05-13 21:57:37 UTC (rev 1640)
@@ -14,3 +14,4 @@
 Pending=PENDENTE
 NotPerformed=NON ESEGUITO
 Failed=FALLITO
+DryRun=ESECUZIONE SIMULATA

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/ScenarioRunnerBehaviour.java (1639 => 1640)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/ScenarioRunnerBehaviour.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/ScenarioRunnerBehaviour.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -6,8 +6,8 @@
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verify;
 
 import java.util.HashMap;
 import java.util.List;
@@ -28,6 +28,7 @@
 import org.jbehave.scenario.steps.StepCreator;
 import org.jbehave.scenario.steps.StepResult;
 import org.jbehave.scenario.steps.Steps;
+import org.jbehave.scenario.steps.StepsConfiguration;
 import org.jbehave.scenario.steps.StepCreator.Stage;
 import org.junit.Test;
 import org.mockito.InOrder;
@@ -55,6 +56,7 @@
         ScenarioReporter reporter = mock(ScenarioReporter.class);
         StepCreator creator = mock(StepCreator.class);
         CandidateSteps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         when(mySteps.getSteps()).thenReturn(someCandidateSteps);
         IllegalArgumentException anException = new IllegalArgumentException();
         Step pendingStep = mock(Step.class);
@@ -114,6 +116,7 @@
         ScenarioReporter reporter = mock(ScenarioReporter.class);
         StepCreator creator = mock(StepCreator.class);
         CandidateSteps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         when(mySteps.getSteps()).thenReturn(someCandidateSteps);
         Step successfulStep = mock(Step.class);
         when(successfulStep.perform()).thenReturn(StepResult.success("successfulStep"));
@@ -154,6 +157,7 @@
         Step fourthStepAlsoPending = mock(Step.class);
         StepCreator creator = mock(StepCreator.class);
         Steps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         when(creator.createStepsFrom((ScenarioDefinition) anyObject(), eq(tableRow), eq(mySteps))).thenReturn(
                 new Step[] { firstStepNormal, secondStepPending, thirdStepNormal, fourthStepAlsoPending });
         when(firstStepNormal.perform()).thenReturn(StepResult.success("Given I succeed"));
@@ -195,6 +199,7 @@
         ErrorStrategy errorStrategy = mock(ErrorStrategy.class);
         StepCreator creator = mock(StepCreator.class);
         Steps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         when(creator.createStepsFrom((ScenarioDefinition) anyObject(), eq(tableRow), eq(mySteps))).thenReturn(
                 new Step[] { firstStepExceptional, secondStepNotPerformed });
         StoryDefinition storyDefinition = new StoryDefinition(new ScenarioDefinition(""));
@@ -229,6 +234,7 @@
         when(secondStep.perform()).thenReturn(StepResult.success("secondStep"));
         StepCreator creator = mock(StepCreator.class);
         CandidateSteps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         ScenarioDefinition scenario1 = mock(ScenarioDefinition.class);
         ScenarioDefinition scenario2 = mock(ScenarioDefinition.class);
         when(creator.createStepsFrom(scenario1, tableRow, mySteps)).thenReturn(new Step[] { pendingStep });
@@ -258,6 +264,7 @@
         when(afterStep.perform()).thenReturn(StepResult.success("secondStep"));
         StepCreator creator = mock(StepCreator.class);
         CandidateSteps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         StoryDefinition storyDefinition = new StoryDefinition();
         boolean embeddedStory = false;
         when(creator.createStepsFrom(storyDefinition, Stage.BEFORE, embeddedStory, mySteps)).thenReturn(new Step[] { beforeStep });
@@ -283,6 +290,7 @@
         PendingErrorStrategy strategy = mock(PendingErrorStrategy.class);
         StepCreator creator = mock(StepCreator.class);
         Steps mySteps = mock(Steps.class);
+        when(mySteps.getConfiguration()).thenReturn(new StepsConfiguration());
         when(creator.createStepsFrom((ScenarioDefinition) anyObject(), eq(tableRow), eq(mySteps))).thenReturn(
                 new Step[] { pendingStep });
         StoryDefinition storyDefinition = new StoryDefinition(new ScenarioDefinition(""));

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/keywords_it.properties (1639 => 1640)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/keywords_it.properties	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/i18n/keywords_it.properties	2010-05-13 21:57:37 UTC (rev 1640)
@@ -14,3 +14,4 @@
 Pending=PENDENTE
 NotPerformed=NON ESEGUITO
 Failed=FALLITO
+DryRun=Esecuzione Simulata: i passi non sono stati eseguiti

Modified: trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/steps/CandidateStepBehaviour.java (1639 => 1640)

--- trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/behaviour/java/org/jbehave/scenario/steps/CandidateStepBehaviour.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -289,6 +289,23 @@
         ensureThat(steps.whenTimes, equalTo(2));
     }
 
+    @Test
+    public void shouldPerformStepsInDryRunMode() {
+    	StepsConfiguration configuration = new StepsConfiguration();
+    	configuration.doDryRun(true);
+        NamedTypeSteps steps = new NamedTypeSteps(configuration);
+        CandidateStep[] candidateSteps = steps.getSteps();
+        ensureThat(candidateSteps.length, equalTo(2));
+        candidateSteps[0].createFrom(tableRow, "Given foo named xyz").perform();
+        candidateSteps[0].createFrom(tableRow, "And foo named xyz").perform();
+        candidateSteps[1].createFrom(tableRow, "When foo named Bar").perform();
+        candidateSteps[1].createFrom(tableRow, "And foo named Bar").perform();
+        ensureThat(steps.givenName, nullValue());
+        ensureThat(steps.givenTimes, equalTo(0));
+        ensureThat(steps.whenName, nullValue());
+        ensureThat(steps.whenTimes, equalTo(0));
+    }
+
 	@Test(expected=StartingWordNotFound.class)
     public void shouldNotCreateStepOfWrongType() {
         NamedTypeSteps steps = new NamedTypeSteps();
@@ -306,7 +323,15 @@
 		int givenTimes;
 		int whenTimes;
 
-        @Given("foo named $name")
+		public NamedTypeSteps(){
+			this(new StepsConfiguration());
+		}
+		
+        public NamedTypeSteps(StepsConfiguration configuration) {
+			super(configuration);
+		}
+
+		@Given("foo named $name")
         public void givenFoo(String name) {
         	givenName = name;
         	givenTimes++;

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/ScenarioRunner.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/ScenarioRunner.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/ScenarioRunner.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -55,6 +55,9 @@
         errorStrategy = configuration.forHandlingErrors();
         resetErrorState(embeddedStory);
         
+        if ( isDryRun(candidateSteps) ){ 
+        	reporter.dryRun();
+        }
         reporter.beforeStory(story, embeddedStory);          
         runStorySteps(story, embeddedStory, StepCreator.Stage.BEFORE, candidateSteps);
         for (ScenarioDefinition scenario : story.getScenarios()) {
@@ -72,6 +75,15 @@
         currentStrategy.handleError(throwable);
     }
 
+	private boolean isDryRun(CandidateSteps[] candidateSteps) {
+		for (CandidateSteps steps : candidateSteps) {
+			if ( steps.getConfiguration().dryRun() ){
+				return true;
+			}
+		}
+		return false;
+	}
+
 	private void resetErrorState(boolean embeddedStory) {
 		if ( embeddedStory ) {
 			// do not reset error state for embedded stories

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/definition/KeyWords.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -32,9 +32,11 @@
     public static final String NOT_PERFORMED = "NotPerformed";
     public static final String FAILED = "Failed";
     public static final String EXAMPLES_TABLE_ROW = "ExamplesTableRow";
+    public static final String DRY_RUN = "DryRun";
+    
     public static final List<String> KEYWORDS = asList(NARRATIVE, IN_ORDER_TO, AS_A, I_WANT_TO, SCENARIO,
             GIVEN_SCENARIOS, EXAMPLES_TABLE, GIVEN, WHEN, THEN, AND, IGNORABLE, PENDING, NOT_PERFORMED, FAILED,
-            EXAMPLES_TABLE_ROW);
+            EXAMPLES_TABLE_ROW, DRY_RUN);
 
     private final String narrative;
     private final String inOrderTo;
@@ -52,6 +54,7 @@
     private final String notPerformed;
     private final String failed;
     private final String examplesTableRow;
+	private final String dryRun;
     private final String[] others;
     private StringEncoder encoder;
 
@@ -73,6 +76,7 @@
         keywords.put(NOT_PERFORMED, "NOT PERFORMED");
         keywords.put(FAILED, "FAILED");
         keywords.put(EXAMPLES_TABLE_ROW, "Example:");
+        keywords.put(DRY_RUN, "Dry Run: steps are not executed");
         return keywords;
     }
 
@@ -115,6 +119,7 @@
         this.notPerformed = keyword(NOT_PERFORMED, keywords);
         this.failed = keyword(FAILED, keywords);
         this.examplesTableRow = keyword(EXAMPLES_TABLE_ROW, keywords);
+        this.dryRun = keyword(DRY_RUN, keywords);
         this.others = new String[] { and, ignorable };
         this.encoder = encoder;
     }
@@ -150,7 +155,7 @@
         this.given = given;
         this.when = when;
         this.then = then;
-        if (others.length < 7) {
+        if (others.length < 11) {
             throw new InsufficientKeywordsException(others);
         }
         this.and = others[0];
@@ -163,6 +168,7 @@
         this.inOrderTo = others[7];
         this.asA = others[8];
         this.iWantTo = others[9];
+        this.dryRun = others[10];
         this.others = others;
     }
 
@@ -230,6 +236,10 @@
         return examplesTableRow;
     }
 
+    public String dryRun(){
+    	return dryRun;
+    }
+    
     public String[] others() {
         return others;
     }
@@ -254,7 +264,7 @@
     public static final class InsufficientKeywordsException extends RuntimeException {
 
         public InsufficientKeywordsException(String... others) {
-            super("Insufficient keywords: " + asList(others) + ", but requires another " + (10 - others.length));
+            super("Insufficient keywords: " + asList(others) + ", but requires another " + (11 - others.length));
         }
 
     }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/keywords_en.properties (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/keywords_en.properties	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/i18n/keywords_en.properties	2010-05-13 21:57:37 UTC (rev 1640)
@@ -14,3 +14,5 @@
 Pending=PENDING
 NotPerformed=NOT PERFORMED
 Failed=FAILED
+DryRun=DRY RUN
+

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/DelegatingScenarioReporter.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/DelegatingScenarioReporter.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/DelegatingScenarioReporter.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -137,6 +137,12 @@
         }
     }
 
+	public void dryRun() {
+        for (ScenarioReporter reporter : delegates) {
+            reporter.dryRun();
+        }
+	}
+	
     public Collection<ScenarioReporter> getDelegates() {
         return delegates;
     }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/HtmlPrintStreamScenarioReporter.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/HtmlPrintStreamScenarioReporter.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/HtmlPrintStreamScenarioReporter.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -69,6 +69,7 @@
         patterns.setProperty("example", "\n<h3 class=\"example\">{0} {1}</h3>\n");
         patterns.setProperty("parameterValueStart", "<span class=\"step parameter\">");
         patterns.setProperty("parameterValueEnd", "</span>");
+        patterns.setProperty("dryRun", "<div class=\"dryRun\">{0}</div>\n");
         return patterns;
     }
 

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PassSilentlyDecorator.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PassSilentlyDecorator.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PassSilentlyDecorator.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -165,6 +165,14 @@
         example(tableRow);        
     }
 
+	public void dryRun() {
+		currentScenario.add(new Todo() {
+			public void doNow() {
+				delegate.dryRun();
+			}
+		});
+	}
+
     private static interface Todo {
         void doNow();
     }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -220,7 +220,11 @@
     public void examplesTableRow(Map<String, String> tableRow) {
         example(tableRow);        
     }
-
+    
+    public void dryRun(){
+    	print(format("dryRun", "{0}\n", keywords.dryRun()));
+    }
+    
     /**
      * Formats event output by key, usually equal to the method name.
      * 

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ScenarioReporter.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ScenarioReporter.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/ScenarioReporter.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -61,4 +61,6 @@
 
     void failed(String step, Throwable e);
 
+	void dryRun();
+
 }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/StatisticsScenarioReporter.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/StatisticsScenarioReporter.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/StatisticsScenarioReporter.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -108,6 +108,9 @@
         example(tableRow);
     }
 
+	public void dryRun() {
+	}
+
     private void count(String event) {
         Integer count = data.get(event);
         if (count == null) {
@@ -136,4 +139,5 @@
         }
     }
 
+
 }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/StepFailureScenarioReporterDecorator.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/StepFailureScenarioReporterDecorator.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/StepFailureScenarioReporterDecorator.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -93,6 +93,10 @@
         delegate.afterExamples();        
     }
 
+	public void dryRun() {
+		delegate.dryRun();
+	}
+
     public void examplesTable(ExamplesTable table) {
         beforeExamples(new ArrayList<String>(), table);
     }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/XmlPrintStreamScenarioReporter.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/XmlPrintStreamScenarioReporter.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/XmlPrintStreamScenarioReporter.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -68,6 +68,7 @@
         patterns.setProperty("example", "\n<example keyword=\"{0}\">{1}</example>\n");
         patterns.setProperty("parameterValueStart", "<parameter>");
         patterns.setProperty("parameterValueEnd", "</parameter>");
+        patterns.setProperty("dryRun", "<dryRun>{0}</dryRun>\n");
         return patterns;
     }
 

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateStep.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -35,15 +35,16 @@
     private final Integer priority;
     private final StepType stepType;
     private final Method method;
-    protected final Object steps;
-    protected final ParameterConverters parameterConverters;
+    private final Object steps;
+    private final ParameterConverters parameterConverters;
     private final Map<StepType, String> startingWordsByType;
     private final Pattern pattern;
     private final String[] groupNames;
 
     private StepMonitor stepMonitor = new SilentStepMonitor();
     private Paranamer paranamer = new NullParanamer();
-
+    private boolean dryRun = false;
+    
     public CandidateStep(String patternAsString, int priority, StepType stepType, Method method,
             CandidateSteps steps, StepPatternBuilder patternBuilder,
             ParameterConverters parameterConverters, Map<StepType, String> startingWords) {
@@ -72,11 +73,19 @@
         this.paranamer = paranamer;
     }
 
-    protected Paranamer getParanamer() {
+    public Paranamer getParanamer() {
         return paranamer;
     }
 
-    public Integer getPriority() {
+    public boolean dryRun() {
+		return dryRun;
+	}
+
+	public void doDryRun(boolean dryRun) {
+		this.dryRun = dryRun;
+	}
+
+	public Integer getPriority() {
         return priority;
     }
 
@@ -306,8 +315,10 @@
         return new Step() {
             public StepResult perform() {
                 try {
-                    stepMonitor.performing(stepAsString);
-                    method.invoke(steps, args);
+                    stepMonitor.performing(stepAsString, dryRun);
+                    if ( !dryRun ){
+                        method.invoke(steps, args);                    	
+                    }
                     return StepResult.success(stepAsString).withTranslatedText(translatedStep);
                 } catch (Throwable t) {
                     return failureWithOriginalException(stepAsString, t);

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateSteps.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateSteps.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/CandidateSteps.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -50,6 +50,12 @@
      * @return The list of steps 
      */
     List<Step> runAfterScenario();
+    
+    /**
+     * Returns the steps configuration
+     * 
+     * @return The StepsConfiguration
+     */
+    StepsConfiguration getConfiguration();
 
-
 }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/PrintStreamStepMonitor.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/PrintStreamStepMonitor.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/PrintStreamStepMonitor.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -14,6 +14,8 @@
 	private static final String CONVERTED_VALUE_OF_TYPE = "Converted value ''{0}'' of type ''{1}'' to ''{2}'' with converter ''{3}''";
 	private static final String STEP_MATCHES_TYPE = "Step ''{0}'' (with previous step ''{1}'') ''{2}'' type ''{3}''";
 	private static final String STEP_MATCHES_PATTERN = "Step ''{0}'' {1} pattern ''{2}''";
+	private static final String PERFORMING = "Performing step ''{0}'' {1}";
+	private static final String DRY_RUN = "(DRY RUN)";
 	private static final String MATCHES = "matches";
 	private static final String DOES_NOT_MATCH = "does not match";
 	private static final String USING_NAME_FOR_ARG = "Using {0} name ''{1}'' for position {2}";
@@ -54,8 +56,9 @@
 		print(output, message);
 	}
 
-	public void performing(String step) {
-		print(output, step);
+	public void performing(String step, boolean dryRun) {
+		String message = format(PERFORMING, step, (dryRun? DRY_RUN : "" ));
+		print(output, message);
 	}
 
 	public void usingAnnotatedNameForArg(String name, int position) {

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/StepMonitor.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/StepMonitor.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/StepMonitor.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -16,7 +16,7 @@
 
     void convertedValueOfType(String value, Type type, Object converted, Class<?> converterClass);
 
-    void performing(String step);
+    void performing(String step, boolean dryRun);
 
 	void usingAnnotatedNameForArg(String name, int position);
 

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/Steps.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/Steps.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/Steps.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -156,21 +156,21 @@
                 Given annotation = method.getAnnotation(Given.class);
                 String value = encode(annotation.value());
                 int priority = annotation.priority();
-                createCandidateStep(steps, method, GIVEN, value, priority);
+                addCandidateStep(steps, method, GIVEN, value, priority);
                 createCandidateStepsFromAliases(steps, method, GIVEN, priority);
             }
             if (method.isAnnotationPresent(When.class)) {
                 When annotation = method.getAnnotation(When.class);
                 String value = encode(annotation.value());
                 int priority = annotation.priority();
-                createCandidateStep(steps, method, WHEN, value, priority);
+                addCandidateStep(steps, method, WHEN, value, priority);
                 createCandidateStepsFromAliases(steps, method, WHEN, priority);
             }
             if (method.isAnnotationPresent(Then.class)) {
                 Then annotation = method.getAnnotation(Then.class);
                 String value = encode(annotation.value());
                 int priority = annotation.priority();
-                createCandidateStep(steps, method, THEN, value, priority);
+                addCandidateStep(steps, method, THEN, value, priority);
                 createCandidateStepsFromAliases(steps, method, THEN, priority);
             }
         }
@@ -181,19 +181,20 @@
         return configuration.getKeywords().encode(value);
     }
 
-    private void createCandidateStep(List<CandidateStep> steps, Method method, StepType stepType,
+    private void addCandidateStep(List<CandidateStep> steps, Method method, StepType stepType,
             String stepPatternAsString, int priority) {
         checkForDuplicateCandidateSteps(steps, stepType, stepPatternAsString);
-        CandidateStep step = createCandidateStep(method, stepType, stepPatternAsString, priority, configuration);
-        step.useStepMonitor(configuration.getMonitor());
-        step.useParanamer(configuration.getParanamer());
-        steps.add(step);
+        steps.add(createCandidateStep(method, stepType, stepPatternAsString, priority, configuration));
     }
 
     protected CandidateStep createCandidateStep(Method method, StepType stepType, String stepPatternAsString, int priority,
             StepsConfiguration configuration) {
-        return new CandidateStep(stepPatternAsString, priority, stepType, method, instance,
+        CandidateStep step = new CandidateStep(stepPatternAsString, priority, stepType, method, instance,
                 configuration.getPatternBuilder(), configuration.getParameterConverters(), configuration.getStartingWordsByType());
+        step.useStepMonitor(configuration.getMonitor());        
+        step.useParanamer(configuration.getParanamer());
+        step.doDryRun(configuration.dryRun());
+        return step;
     }
 
     private void checkForDuplicateCandidateSteps(List<CandidateStep> steps, StepType stepType, String patternAsString) {
@@ -208,12 +209,12 @@
         if (method.isAnnotationPresent(Aliases.class)) {
             String[] aliases = method.getAnnotation(Aliases.class).values();
             for (String alias : aliases) {
-                createCandidateStep(steps, method, stepType, alias, priority);
+                addCandidateStep(steps, method, stepType, alias, priority);
             }
         }
         if (method.isAnnotationPresent(Alias.class)) {
             String alias = method.getAnnotation(Alias.class).value();
-            createCandidateStep(steps, method, stepType, alias, priority);
+            addCandidateStep(steps, method, stepType, alias, priority);
         }
     }
 
@@ -271,6 +272,10 @@
         return steps;
     }
 
+	public StepsConfiguration getConfiguration() {
+		return configuration;
+	}
+    
     List<Step> scenarioStepsHaving(final Class<? extends Annotation> annotationClass, final StepPart forSuccess) {
         List<Step> steps = new ArrayList<Step>();
         for (final Method method : methodsOf(instance)) {
@@ -374,5 +379,5 @@
     public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
-    
+
 }

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/StepsConfiguration.java (1639 => 1640)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/StepsConfiguration.java	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/steps/StepsConfiguration.java	2010-05-13 21:57:37 UTC (rev 1640)
@@ -40,6 +40,7 @@
 	private KeyWords keywords;
 	private String[] startingWords;
 	private Map<StepType,String> startingWordsByType;
+	private boolean dryRun;
 
 	public StepsConfiguration() {
 		this(new I18nKeyWords());
@@ -47,22 +48,23 @@
 
 	public StepsConfiguration(KeyWords keywords) {
 		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
-				new NullParanamer(), new ParameterConverters(), keywords);
+				new NullParanamer(), new ParameterConverters(), keywords, false);
 	}
 
 	public StepsConfiguration(ParameterConverters converters) {
 		this(new PrefixCapturingPatternBuilder(), new SilentStepMonitor(),
-				new NullParanamer(), converters, new I18nKeyWords());
+				new NullParanamer(), converters, new I18nKeyWords(), false);
 	}
 
 	public StepsConfiguration(StepPatternBuilder patternBuilder,
 			StepMonitor monitor, Paranamer paranamer,
-			ParameterConverters parameterConverters, KeyWords keywords) {
+			ParameterConverters parameterConverters, KeyWords keywords, boolean dryRun) {
 		this.patternBuilder = patternBuilder;
 		this.monitor = monitor;
 		this.paranamer = paranamer;
 		this.parameterConverters = parameterConverters;
 		this.keywords = keywords;
+		this.dryRun = dryRun;
 		startingWordsFromKeywords();
 	}
 
@@ -181,4 +183,12 @@
 		startingWordsFromKeywords();
 	}
 
+	public boolean dryRun() {
+		return dryRun;
+	}
+	
+	public void doDryRun(boolean dryRun){
+		this.dryRun = dryRun;
+	}
+
 }

Modified: trunk/core/jbehave-core/src/main/resources/style/jbehave-reports.css (1639 => 1640)

--- trunk/core/jbehave-core/src/main/resources/style/jbehave-reports.css	2010-05-08 11:50:40 UTC (rev 1639)
+++ trunk/core/jbehave-core/src/main/resources/style/jbehave-reports.css	2010-05-13 21:57:37 UTC (rev 1640)
@@ -172,6 +172,14 @@
   color: red;
 }
 
+.dryRun {
+  border: solid;
+  color: red;
+  margin-left: 12px;
+  padding: 10px;
+  text-weight: bold;
+}
+
 .parameter {
   color: purple;
   padding-left: 0px;


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to