Search in sources :

Example 1 with ReportsCount

use of org.jbehave.core.reporters.ReportsCount 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 ReportsCount

use of org.jbehave.core.reporters.ReportsCount 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 ReportsCount

use of org.jbehave.core.reporters.ReportsCount 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 ReportsCount

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

the class EmbedderMonitorBehaviour method shouldOnlyPrintFailuresWithReportingFailuresMonitor.

@Test
public void shouldOnlyPrintFailuresWithReportingFailuresMonitor() throws Throwable {
    OutputStream out = new ByteArrayOutputStream();
    ReportingFailuresEmbedderMonitor monitor = new ReportingFailuresEmbedderMonitor(new PrintStream(out));
    monitor.runningEmbeddable("embeddable");
    monitor.runningStory("/path");
    monitor.generatingReportsView(new File("target"), Arrays.asList(Format.HTML.name()), new Properties());
    monitor.reportsViewGenerated(new ReportsCount(1, 0, 1, 2, 1, 0, 1, 1));
    assertThat(out.toString(), is(""));
    monitor.batchFailed(new BatchFailures());
    monitor.storyFailed("/path", new RuntimeException());
    assertThat(out.toString(), is(not("")));
}
Also used : PrintStream(java.io.PrintStream) BatchFailures(org.jbehave.core.failures.BatchFailures) OutputStream(java.io.OutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ReportsCount(org.jbehave.core.reporters.ReportsCount) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 5 with ReportsCount

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

the class EmbedderMonitorBehaviour method shouldAllowDecorationOfDelegate.

@Test
public void shouldAllowDecorationOfDelegate() throws Throwable {
    // Given
    EmbedderMonitor delegate = mock(EmbedderMonitor.class);
    EmbedderMonitor monitor = new EmbedderMonitorDecorator(delegate);
    // When
    Object annotatedInstance = new Object();
    monitor.annotatedInstanceNotOfType(annotatedInstance, annotatedInstance.getClass());
    BatchFailures failures = new BatchFailures();
    monitor.batchFailed(failures);
    monitor.beforeOrAfterStoriesFailed();
    String name = "name";
    Throwable cause = new Throwable();
    monitor.embeddableFailed(name, cause);
    monitor.embeddableNotConfigurable(name);
    List<String> names = asList("name1");
    monitor.embeddablesSkipped(names);
    File outputDirectory = new File("target");
    StoryMaps storyMaps = mock(StoryMaps.class);
    Properties viewProperties = mock(Properties.class);
    monitor.generatingMapsView(outputDirectory, storyMaps, viewProperties);
    Properties viewResources = mock(Properties.class);
    monitor.generatingNavigatorView(outputDirectory, viewResources);
    List<String> formats = asList("TXT");
    monitor.generatingReportsView(outputDirectory, formats, viewProperties);
    String storyPath = "path";
    List<String> metaFilters = asList("- skip");
    monitor.mappingStory(storyPath, metaFilters);
    monitor.mapsViewGenerationFailed(outputDirectory, storyMaps, viewProperties, cause);
    Meta meta = mock(Meta.class);
    MetaFilter filter = mock(MetaFilter.class);
    monitor.metaNotAllowed(meta, filter);
    monitor.navigatorViewGenerationFailed(outputDirectory, viewResources, cause);
    monitor.navigatorViewNotGenerated();
    Properties properties = mock(Properties.class);
    monitor.processingSystemProperties(properties);
    ReportsCount count = mock(ReportsCount.class);
    monitor.reportsViewGenerated(count);
    monitor.reportsViewGenerationFailed(outputDirectory, formats, viewProperties, cause);
    monitor.reportsViewNotGenerated();
    monitor.runningEmbeddable(name);
    monitor.runningStory(storyPath);
    monitor.runningWithAnnotatedEmbedderRunner(name);
    List<String> storyPaths = asList("path1");
    monitor.storiesSkipped(storyPaths);
    monitor.storyFailed(storyPath, cause);
    Story story = mock(Story.class);
    long durationInSecs = 1L;
    long timeoutInSecs = 2L;
    StoryDuration storyDuration = new StoryDuration(timeoutInSecs);
    monitor.storyTimeout(story, storyDuration);
    String value = "value";
    monitor.systemPropertySet(name, value);
    int threads = 2;
    monitor.usingThreads(threads);
    // Then
    verify(delegate).annotatedInstanceNotOfType(annotatedInstance, annotatedInstance.getClass());
    verify(delegate).batchFailed(failures);
    verify(delegate).beforeOrAfterStoriesFailed();
    verify(delegate).embeddableFailed(name, cause);
    verify(delegate).embeddableNotConfigurable(name);
    verify(delegate).embeddablesSkipped(names);
    verify(delegate).generatingMapsView(outputDirectory, storyMaps, viewProperties);
    verify(delegate).generatingNavigatorView(outputDirectory, viewResources);
    verify(delegate).generatingReportsView(outputDirectory, formats, viewProperties);
    verify(delegate).mappingStory(storyPath, metaFilters);
    verify(delegate).mapsViewGenerationFailed(outputDirectory, storyMaps, viewProperties, cause);
    verify(delegate).metaNotAllowed(meta, filter);
    verify(delegate).navigatorViewGenerationFailed(outputDirectory, viewResources, cause);
    verify(delegate).navigatorViewNotGenerated();
    verify(delegate).processingSystemProperties(properties);
    verify(delegate).reportsViewGenerated(count);
    verify(delegate).reportsViewGenerationFailed(outputDirectory, formats, viewProperties, cause);
    verify(delegate).reportsViewNotGenerated();
    verify(delegate).storiesSkipped(storyPaths);
    verify(delegate).storyFailed(storyPath, cause);
    verify(delegate).storyTimeout(story, storyDuration);
    verify(delegate).systemPropertySet(name, value);
    verify(delegate).usingThreads(threads);
}
Also used : Meta(org.jbehave.core.model.Meta) StoryDuration(org.jbehave.core.model.StoryDuration) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) StoryMaps(org.jbehave.core.model.StoryMaps) BatchFailures(org.jbehave.core.failures.BatchFailures) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

ReportsCount (org.jbehave.core.reporters.ReportsCount)12 File (java.io.File)11 Properties (java.util.Properties)11 Test (org.junit.Test)11 Matchers.containsString (org.hamcrest.Matchers.containsString)10 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)9 OutputStream (java.io.OutputStream)8 PrintStream (java.io.PrintStream)8 ViewGenerator (org.jbehave.core.reporters.ViewGenerator)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)7 BatchFailures (org.jbehave.core.failures.BatchFailures)4 Embedder (org.jbehave.core.embedder.Embedder)2 EmbedderMonitor (org.jbehave.core.embedder.EmbedderMonitor)2 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Log (org.apache.maven.plugin.logging.Log)1 Project (org.apache.tools.ant.Project)1 EmbedderFailureStrategy (org.jbehave.core.embedder.Embedder.EmbedderFailureStrategy)1 FailingUponPendingStep (org.jbehave.core.failures.FailingUponPendingStep)1 Meta (org.jbehave.core.model.Meta)1