Search in sources :

Example 6 with BatchFailures

use of org.jbehave.core.failures.BatchFailures 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 BatchFailures

use of org.jbehave.core.failures.BatchFailures in project serenity-jbehave by serenity-bdd.

the class SerenityReportingRunner method createPerformableTree.

private PerformableTree createPerformableTree(List<String> storyPaths) {
    ExtendedEmbedder configuredEmbedder = this.getConfiguredEmbedder();
    configuredEmbedder.useMetaFilters(getMetaFilters());
    BatchFailures failures = new BatchFailures(configuredEmbedder.embedderControls().verboseFailures());
    PerformableTree performableTree = new PerformableTree();
    RunContext context = performableTree.newRunContext(getConfiguration(), configuredEmbedder.stepsFactory(), configuredEmbedder.embedderMonitor(), configuredEmbedder.metaFilter(), failures);
    performableTree.addStories(context, storiesOf(performableTree, storyPaths));
    return performableTree;
}
Also used : BatchFailures(org.jbehave.core.failures.BatchFailures) PerformableTree(org.jbehave.core.embedder.PerformableTree) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) ExtendedEmbedder(net.serenitybdd.jbehave.embedders.ExtendedEmbedder)

Example 8 with BatchFailures

use of org.jbehave.core.failures.BatchFailures in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPathsInBatchIfBatchFlagIsSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doBatch(true);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    Configuration configuration = embedder.configuration();
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    MetaFilter filter = embedder.metaFilter();
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
    }
    RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    for (String storyPath : storyPaths) {
        doNothing().when(performableTree).perform(runContext, stories.get(storyPath));
    }
    // When
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        assertThat(out.toString(), containsString("Running story " + storyPath));
    }
}
Also used : PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 9 with BatchFailures

use of org.jbehave.core.failures.BatchFailures in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldRunStoriesAsPaths.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPaths() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    MetaFilter filter = embedder.metaFilter();
    final StoryReporter storyReporter = mock(StoryReporter.class);
    MostUsefulConfiguration configuration = new MostUsefulConfiguration() {

        @Override
        public StoryReporter storyReporter(String storyPath) {
            return storyReporter;
        }
    };
    embedder.useConfiguration(configuration);
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
        assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
    }
    RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    // When
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(stories.get(storyPath)));
        assertThat(out.toString(), containsString("Running story " + storyPath));
    }
    assertThatReportsViewGenerated(out);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 10 with BatchFailures

use of org.jbehave.core.failures.BatchFailures in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldNotRunStoriesIfSkipFlagIsSet.

@SuppressWarnings("unchecked")
@Test
public void shouldNotRunStoriesIfSkipFlagIsSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doSkip(true);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    Configuration configuration = embedder.configuration();
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    MetaFilter filter = embedder.metaFilter();
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
    }
    RunContext runContext = new RunContext(configuration, stepsFactory, monitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    // When
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(performableTree, never()).perform(runContext, stories.get(storyPath));
        assertThat(out.toString(), not(containsString("Running story " + storyPath)));
    }
    assertThat(out.toString(), containsString("Skipped stories " + storyPaths));
}
Also used : PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Aggregations

BatchFailures (org.jbehave.core.failures.BatchFailures)14 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 RunContext (org.jbehave.core.embedder.PerformableTree.RunContext)8 Story (org.jbehave.core.model.Story)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)7 Configuration (org.jbehave.core.configuration.Configuration)7 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)7 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)7 JUnitStory (org.jbehave.core.junit.JUnitStory)7 InjectableStepsFactory (org.jbehave.core.steps.InjectableStepsFactory)7 File (java.io.File)4 Properties (java.util.Properties)4 ReportsCount (org.jbehave.core.reporters.ReportsCount)4