Search in sources :

Example 6 with ReportsCount

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

the class EmbedderTaskBehaviour method shouldCreateNewEmbedderWithAntMonitor.

@Test
public void shouldCreateNewEmbedderWithAntMonitor() {
    // Given
    Project project = mock(Project.class);
    AbstractEmbedderTask task = new AbstractEmbedderTask() {
    };
    task.setProject(project);
    // When
    Embedder embedder = task.newEmbedder();
    // Then
    EmbedderMonitor embedderMonitor = embedder.embedderMonitor();
    assertThat(embedderMonitor.toString(), equalTo("AntEmbedderMonitor"));
    // and verify monitor calls are propagated to Project log
    BatchFailures failures = new BatchFailures();
    embedderMonitor.batchFailed(failures);
    verify(project).log(task, "Failed to run batch " + failures, MSG_WARN);
    String name = "name";
    Throwable cause = new RuntimeException();
    embedderMonitor.embeddableFailed(name, cause);
    verify(project).log(task, "Failed to run embeddable " + name, cause, MSG_WARN);
    List<String> classNames = asList("name1", "name2");
    embedderMonitor.embeddablesSkipped(classNames);
    verify(project).log(task, "Skipped embeddables " + classNames, MSG_INFO);
    embedderMonitor.runningEmbeddable(name);
    verify(project).log(task, "Running embeddable " + name, MSG_INFO);
    List<String> storyPaths = asList("/path1", "/path2");
    embedderMonitor.storiesSkipped(storyPaths);
    verify(project).log(task, "Skipped stories " + storyPaths, MSG_INFO);
    String path = "/path";
    embedderMonitor.storyFailed(path, cause);
    verify(project).log(task, "Failed to run story " + path, cause, MSG_WARN);
    embedderMonitor.runningStory(path);
    verify(project).log(task, "Running story " + path, MSG_INFO);
    Object annotatedInstance = new Object();
    Class<?> type = Object.class;
    embedderMonitor.annotatedInstanceNotOfType(annotatedInstance, type);
    verify(project).log(task, "Annotated instance " + annotatedInstance + " not of type " + type, MSG_WARN);
    File outputDirectory = new File("/dir");
    List<String> formats = asList(Format.CONSOLE.name(), Format.HTML.name());
    Properties viewProperties = new Properties();
    embedderMonitor.generatingReportsView(outputDirectory, formats, viewProperties);
    verify(project).log(task, "Generating reports view to '" + outputDirectory + "' using formats '" + formats + "'" + " and view properties '" + viewProperties + "'", MSG_INFO);
    embedderMonitor.reportsViewGenerationFailed(outputDirectory, formats, viewProperties, cause);
    verify(project).log(task, "Failed to generate reports view to '" + outputDirectory + "' using formats '" + formats + "'" + " and view properties '" + viewProperties + "'", cause, MSG_WARN);
    int stories = 2;
    int storiesNotAllowed = 1;
    int storiesPending = 1;
    int scenarios = 4;
    int scenariosFailed = 1;
    int scenariosNotAllowed = 0;
    int scenariosPending = 1;
    int stepsFailed = 1;
    embedderMonitor.reportsViewGenerated(new ReportsCount(stories, storiesNotAllowed, storiesPending, scenarios, scenariosFailed, scenariosNotAllowed, scenariosPending, stepsFailed));
    verify(project).log(task, "Reports view generated with " + stories + " stories (of which " + storiesPending + " pending) containing " + scenarios + " scenarios (of which " + scenariosPending + " pending)", MSG_INFO);
    verify(project).log(task, "Meta filters excluded " + storiesNotAllowed + " stories and  " + scenariosNotAllowed + " scenarios", MSG_INFO);
    embedderMonitor.reportsViewNotGenerated();
    verify(project).log(task, "Reports view not generated", MSG_INFO);
}
Also used : EmbedderMonitor(org.jbehave.core.embedder.EmbedderMonitor) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) Project(org.apache.tools.ant.Project) BatchFailures(org.jbehave.core.failures.BatchFailures) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Test(org.junit.Test)

Example 7 with ReportsCount

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

the class EmbedderBehaviour method shouldThrowExceptionIfNoScenariosRunForStoriesAndIgnoreFlagIsNotSet.

@Test(expected = RunningStoriesFailed.class)
public void shouldThrowExceptionIfNoScenariosRunForStoriesAndIgnoreFlagIsNotSet() 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();
    when(viewGenerator.getReportsCount()).thenReturn(new ReportsCount(1, 0, 0, 0, 0, 0, 0, 1));
    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) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Test(org.junit.Test)

Example 8 with ReportsCount

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

the class EmbedderBehaviour method shouldThrowExceptionIfScenariosFailedAndIgnoreFlagIsNotSet.

@Test(expected = RunningStoriesFailed.class)
public void shouldThrowExceptionIfScenariosFailedAndIgnoreFlagIsNotSet() 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();
    when(viewGenerator.getReportsCount()).thenReturn(new ReportsCount(1, 0, 1, 2, 1, 1, 1, 1));
    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) ReportsCount(org.jbehave.core.reporters.ReportsCount) File(java.io.File) Test(org.junit.Test)

Example 9 with ReportsCount

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

the class EmbedderBehaviour method shouldNotThrowExceptionIfScenariosFailedAndIgnoreFlagIsSet.

@Test
public void shouldNotThrowExceptionIfScenariosFailedAndIgnoreFlagIsSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doIgnoreFailureInView(true);
    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(1, 0, 1, 2, 1, 0, 1, 1));
    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 10 with ReportsCount

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

the class EmbedderBehaviour method shouldFailWhenGeneratingReportsViewWithFailedSteps.

@Test(expected = RunningStoriesFailed.class)
public void shouldFailWhenGeneratingReportsViewWithFailedSteps() 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, 0, 2, 1, 0, 0, 1));
    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)

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