Title: [1390] trunk/core/jbehave-core/src/java/org/jbehave/scenario: JBEHAVE-161: Report different stories to different HTML files.

Diff

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

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/TraderScenario.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -24,7 +24,7 @@
 
 			@Override
 			public ScenarioReporter forReportingScenarios() {
-				return new CollectingScenarioReporter(new PrintStreamScenarioReporter(), new HtmlPrintStreamScenarioReporter(new FilePrintStreamFactory().createPrintStream("index")));
+				return new CollectingScenarioReporter(new PrintStreamScenarioReporter(), new HtmlPrintStreamScenarioReporter(new FilePrintStreamFactory()));
 			}
             
         }, new TraderSteps()); 

Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java (1389 => 1390)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -1,33 +1,27 @@
 package org.jbehave.scenario;
 
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.stub;
 import static org.mockito.Mockito.verify;
 
-import org.jbehave.scenario.definition.StoryDefinition;
-import org.jbehave.scenario.parser.ScenarioDefiner;
 import org.jbehave.scenario.steps.CandidateSteps;
 import org.junit.Test;
 
 public class ScenarioBehaviour {
 
     @Test
-    public void shouldLoadStoryDefinitionAndRunUsingTheScenarioRunner() throws Throwable {
+    public void shouldRunUsingTheScenarioRunner() throws Throwable {
         // Given
         ScenarioRunner runner = mock(ScenarioRunner.class);
-        ScenarioDefiner scenarioDefiner = mock(ScenarioDefiner.class);
         Configuration configuration = mock(Configuration.class);
         CandidateSteps steps = mock(CandidateSteps.class);
-        StoryDefinition storyDefinition = new StoryDefinition();
-        stub(configuration.forDefiningScenarios()).toReturn(scenarioDefiner);
-        stub(scenarioDefiner.loadScenarioDefinitionsFor(MyScenario.class)).toReturn(storyDefinition);
+        Class<MyScenario> scenarioClass = MyScenario.class;
 
         // When
         RunnableScenario scenario = new MyScenario(runner, configuration, steps);
         scenario.runScenario();
 
         // Then
-        verify(runner).run(storyDefinition, configuration, false, steps);
+        verify(runner).run(scenarioClass, configuration, steps);
     }
 
     private class MyScenario extends JUnitScenario {

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -6,7 +6,6 @@
 import java.util.List;
 
 import org.jbehave.scenario.definition.KeyWords;
-import org.jbehave.scenario.definition.StoryDefinition;
 import org.jbehave.scenario.parser.ScenarioNameResolver;
 import org.jbehave.scenario.steps.CandidateSteps;
 import org.jbehave.scenario.steps.Stepdoc;
@@ -67,9 +66,8 @@
     }
 
     public void runScenario() throws Throwable {
-        StoryDefinition story = configuration.forDefiningScenarios().loadScenarioDefinitionsFor(scenarioClass);
         CandidateSteps[] steps = candidateSteps.toArray(new CandidateSteps[candidateSteps.size()]);
-        scenarioRunner.run(story, configuration, false, steps);
+        scenarioRunner.run(scenarioClass, configuration, steps);
     }
 
     public void addSteps(CandidateSteps... steps) {

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -1,12 +1,13 @@
 package org.jbehave.scenario;
 
+import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.jbehave.scenario.definition.ExamplesTable;
 import org.jbehave.scenario.definition.ScenarioDefinition;
 import org.jbehave.scenario.definition.StoryDefinition;
-import org.jbehave.scenario.definition.ExamplesTable;
 import org.jbehave.scenario.errors.ErrorStrategy;
 import org.jbehave.scenario.errors.PendingError;
 import org.jbehave.scenario.errors.PendingErrorStrategy;
@@ -33,11 +34,13 @@
 
     public void run(Class<? extends RunnableScenario> scenarioClass, Configuration configuration, CandidateSteps... candidateSteps) throws Throwable {
 		StoryDefinition story = configuration.forDefiningScenarios().loadScenarioDefinitionsFor(scenarioClass);
+		story.namedAs(scenarioClass.getSimpleName());
 		run(story, configuration, candidateSteps);
     }
 
     public void run(String scenarioPath, Configuration configuration, boolean embeddedStory, CandidateSteps... candidateSteps) throws Throwable {
 		StoryDefinition story = configuration.forDefiningScenarios().loadScenarioDefinitionsFor(scenarioPath);
+        story.namedAs(new File(scenarioPath).getName());
 		run(story, configuration, embeddedStory, candidateSteps);
     }    
 

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -9,6 +9,7 @@
 
     private final Blurb blurb;
     private final List<ScenarioDefinition> scenarioDefinitions;
+    private String name = "Story";
 
     public StoryDefinition(ScenarioDefinition... scenarioDefinitions) {
         this(asList(scenarioDefinitions));
@@ -34,4 +35,12 @@
     public List<ScenarioDefinition> getScenarios() {
         return unmodifiableList(scenarioDefinitions);
     }
+    
+    public String getName(){
+        return name;
+    }
+    
+    public void namedAs(String name){
+        this.name = name;
+    }
 }

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/CollectingScenarioReporter.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/CollectingScenarioReporter.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/CollectingScenarioReporter.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -58,7 +58,9 @@
     }
 
     public void beforeStory(StoryDefinition story) {
-        beforeStory(story.getBlurb());
+        for (ScenarioReporter reporter : reporters) {
+            reporter.beforeStory(story);
+        }
     }
     
     public void beforeStory(Blurb blurb) {

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/FilePrintStreamFactory.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/FilePrintStreamFactory.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/FilePrintStreamFactory.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -4,43 +4,37 @@
 import java.io.FileNotFoundException;
 import java.io.PrintStream;
 
-import org.jbehave.scenario.RunnableScenario;
-
 /**
- * Creates {...@link PrintStream} instance that write to a file. It also provides useful
- * defaults for reporting scenarios.
+ * Creates {...@link PrintStream} instances that write to a file. It also provides useful
+ * defaults for the file directory and the extension.
  */
-public class FilePrintStreamFactory {
+public class FilePrintStreamFactory implements PrintStreamFactory {
 
-    private static final File DIR = new File("target", "scenario-reports");
+    private static final File DEFAULT_DIRECTORY = new File("target", "scenario-reports");
     private static final String HTML = "html";
-    private final File dir;
+    private final File directory;
     private final String extension;
 
     public FilePrintStreamFactory() {
-        this(DIR, HTML);
+        this(DEFAULT_DIRECTORY, HTML);
     }
 
-    public FilePrintStreamFactory(File dir, String extension) {
-        this.dir = dir;
+    public FilePrintStreamFactory(File directory, String extension) {
+        this.directory = directory;
         this.extension = extension;
     }
 
-    public PrintStream createPrintStream(Class<? extends RunnableScenario> scenarioClass) {
-       return createPrintStream(scenarioClass.getSimpleName());
-    }
-
-    public PrintStream createPrintStream(String scenarioName) {
+    public PrintStream createPrintStream(String storyName) {
         try {
-            return new PrintStream(streamFile(dir, scenarioName, extension));
+            return new PrintStream(fileFor(directory, storyName, extension));
         } catch (FileNotFoundException e) {
             throw new RuntimeException(e);
         }
     }
 
-    private static File streamFile(File dir, String fileName, String extension) {
+    private File fileFor(File dir, String name, String ext) {
         dir.mkdirs();
-        return new File(dir, fileName + "." + extension);
+        return new File(dir, name + "." + ext);
     }
 
 }

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/HtmlPrintStreamScenarioReporter.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/HtmlPrintStreamScenarioReporter.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/HtmlPrintStreamScenarioReporter.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -2,15 +2,12 @@
 
 import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
 
-import java.io.PrintStream;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
 
 import org.jbehave.scenario.definition.Blurb;
 import org.jbehave.scenario.definition.ExamplesTable;
-import org.jbehave.scenario.definition.KeyWords;
 import org.jbehave.scenario.definition.StoryDefinition;
 
 /**
@@ -26,27 +23,12 @@
  */
 public class HtmlPrintStreamScenarioReporter extends PrintStreamScenarioReporter {
 
-    public HtmlPrintStreamScenarioReporter() {
-        super();
-    }
+    private final PrintStreamFactory printStreamFactory;
 
-    public HtmlPrintStreamScenarioReporter(KeyWords keywords) {
-        super(keywords);
+    public HtmlPrintStreamScenarioReporter(PrintStreamFactory printStreamFactory) {
+        this.printStreamFactory = printStreamFactory;
     }
 
-    public HtmlPrintStreamScenarioReporter(PrintStream output) {
-        super(output);
-    }
-
-    public HtmlPrintStreamScenarioReporter(Properties outputPatterns) {
-        super(outputPatterns);
-    }
-
-    public HtmlPrintStreamScenarioReporter(PrintStream output, Properties outputPatterns, KeyWords keywords,
-            boolean reportErrors) {
-        super(output, outputPatterns, keywords, reportErrors);
-    }
-
     public void successful(String step) {
         String defaultPattern = "<div class=\"step.successful\">{0}</div>\n";
         output.print(format("successful.html", defaultPattern, escapeHtml(step)));
@@ -69,6 +51,7 @@
     }
 
     public void beforeStory(StoryDefinition story) {
+        usePrintStream(printStreamFactory.createPrintStream(story.getName()));
         beforeStory(story.getBlurb());
     }
 

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PassSilentlyDecorator.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PassSilentlyDecorator.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PassSilentlyDecorator.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -28,8 +28,13 @@
         afterStoryState.report();
     }
 
-    public void beforeStory(StoryDefinition story) {
-        beforeStory(story.getBlurb());
+    public void beforeStory(final StoryDefinition story) {
+        beforeStoryState = new State() {
+            public void report() {
+                delegate.beforeStory(story);
+                beforeStoryState = State.SILENT;
+            }
+        };
     }
     
     public void beforeStory(final Blurb blurb) {

Added: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamFactory.java (0 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamFactory.java	                        (rev 0)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamFactory.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -0,0 +1,12 @@
+package org.jbehave.scenario.reporters;
+
+import java.io.PrintStream;
+
+/**
+ * Creates {...@link PrintStream} instances for named stories
+ */
+public interface PrintStreamFactory {
+
+    PrintStream createPrintStream(String storyName);
+
+}

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java (1389 => 1390)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2009-11-25 13:55:54 UTC (rev 1389)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2009-11-25 18:13:09 UTC (rev 1390)
@@ -54,7 +54,7 @@
  */
 public class PrintStreamScenarioReporter implements ScenarioReporter {
 
-    protected final PrintStream output;
+    protected PrintStream output;
     protected final Properties outputPatterns;
     protected final KeyWords keywords;
     protected final boolean reportErrors;
@@ -169,5 +169,14 @@
         }
         return defaultPattern;
     }
+    
+    /**
+     * Changes print stream used for output
+     * 
+     * @param output the new PrintStream to use
+     */
+    protected void usePrintStream(PrintStream output){
+        this.output = output;
+    }
 
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to