Search in sources :

Example 1 with ViewGenerator

use of org.jbehave.core.reporters.ViewGenerator in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldFailWhenGeneratingReportsViewWithPendingSteps.

@Test(expected = RunningStoriesFailed.class)
public void shouldFailWhenGeneratingReportsViewWithPendingSteps() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doGenerateViewAfterStories(false);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    ViewGenerator viewGenerator = mock(ViewGenerator.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.configuration().useViewGenerator(viewGenerator).usePendingStepStrategy(new FailingUponPendingStep());
    File outputDirectory = new File("target/output");
    List<String> formats = asList("html");
    Properties viewResources = new Properties();
    when(viewGenerator.getReportsCount()).thenReturn(new ReportsCount(2, 0, 1, 2, 0, 0, 1, 0));
    embedder.generateReportsView(outputDirectory, formats, viewResources);
    // Then
    verify(viewGenerator).generateReportsView(outputDirectory, formats, viewResources);
    assertThatReportsViewGenerated(out);
}
Also used : PrintStream(java.io.PrintStream) ViewGenerator(org.jbehave.core.reporters.ViewGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) ReportsCount(org.jbehave.core.reporters.ReportsCount) FailingUponPendingStep(org.jbehave.core.failures.FailingUponPendingStep) File(java.io.File) Test(org.junit.Test)

Example 2 with ViewGenerator

use of org.jbehave.core.reporters.ViewGenerator in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldHandleFailuresAccordingToStrategy.

@Test
public void shouldHandleFailuresAccordingToStrategy() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    ViewGenerator viewGenerator = mock(ViewGenerator.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    EmbedderFailureStrategy failureStategy = mock(EmbedderFailureStrategy.class);
    embedder.useEmbedderFailureStrategy(failureStategy);
    embedder.configuration().useViewGenerator(viewGenerator);
    File outputDirectory = new File("target/output");
    List<String> formats = asList("html");
    Properties viewResources = new Properties();
    // When
    ReportsCount count = new ReportsCount(1, 0, 1, 2, 1, 1, 1, 1);
    when(viewGenerator.getReportsCount()).thenReturn(count);
    embedder.generateReportsView(outputDirectory, formats, viewResources);
    // Then
    verify(failureStategy).handleFailures(count);
}
Also used : PrintStream(java.io.PrintStream) ViewGenerator(org.jbehave.core.reporters.ViewGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) EmbedderFailureStrategy(org.jbehave.core.embedder.Embedder.EmbedderFailureStrategy) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Test(org.junit.Test)

Example 3 with ViewGenerator

use of org.jbehave.core.reporters.ViewGenerator in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldGenerateReportsViewFromExistingReports.

@Test
public void shouldGenerateReportsViewFromExistingReports() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doGenerateViewAfterStories(false);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    ViewGenerator viewGenerator = mock(ViewGenerator.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.configuration().useViewGenerator(viewGenerator);
    File outputDirectory = new File("target/output");
    List<String> formats = asList("html");
    Properties viewResources = new Properties();
    when(viewGenerator.getReportsCount()).thenReturn(new ReportsCount(2, 0, 1, 2, 0, 0, 1, 0));
    embedder.generateReportsView(outputDirectory, formats, viewResources);
    // Then
    verify(viewGenerator).generateReportsView(outputDirectory, formats, viewResources);
    assertThatReportsViewGenerated(out);
}
Also used : PrintStream(java.io.PrintStream) ViewGenerator(org.jbehave.core.reporters.ViewGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Test(org.junit.Test)

Example 4 with ViewGenerator

use of org.jbehave.core.reporters.ViewGenerator in project jbehave-core by jbehave.

the class Embedder method generateMapsView.

private void generateMapsView(StoryMaps storyMaps) {
    Configuration configuration = configuration();
    StoryReporterBuilder builder = configuration.storyReporterBuilder();
    File outputDirectory = builder.outputDirectory();
    Properties viewResources = builder.viewResources();
    ViewGenerator viewGenerator = configuration.viewGenerator();
    try {
        embedderMonitor.generatingMapsView(outputDirectory, storyMaps, viewResources);
        viewGenerator.generateMapsView(outputDirectory, storyMaps, viewResources);
    } catch (RuntimeException e) {
        embedderMonitor.mapsViewGenerationFailed(outputDirectory, storyMaps, viewResources, e);
        throw new ViewGenerationFailed(outputDirectory, storyMaps, viewResources, e);
    }
}
Also used : StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ViewGenerator(org.jbehave.core.reporters.ViewGenerator) Properties(java.util.Properties) File(java.io.File)

Example 5 with ViewGenerator

use of org.jbehave.core.reporters.ViewGenerator in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldThrowExceptionIfViewGenerationFails.

@Test(expected = ViewGenerationFailed.class)
public void shouldThrowExceptionIfViewGenerationFails() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    ViewGenerator viewGenerator = mock(ViewGenerator.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.configuration().useViewGenerator(viewGenerator);
    File outputDirectory = new File("target/output");
    List<String> formats = asList("html");
    Properties viewResources = new Properties();
    doThrow(new RuntimeException()).when(viewGenerator).generateReportsView(outputDirectory, formats, viewResources);
    embedder.generateReportsView(outputDirectory, formats, viewResources);
// Then fail as expected
}
Also used : PrintStream(java.io.PrintStream) ViewGenerator(org.jbehave.core.reporters.ViewGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Aggregations

ViewGenerator (org.jbehave.core.reporters.ViewGenerator)11 File (java.io.File)10 Properties (java.util.Properties)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 OutputStream (java.io.OutputStream)9 PrintStream (java.io.PrintStream)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)9 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)9 Test (org.junit.Test)9 ReportsCount (org.jbehave.core.reporters.ReportsCount)8 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)2 Configuration (org.jbehave.core.configuration.Configuration)1 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)1 EmbedderFailureStrategy (org.jbehave.core.embedder.Embedder.EmbedderFailureStrategy)1 FailingUponPendingStep (org.jbehave.core.failures.FailingUponPendingStep)1