Search in sources :

Example 1 with StoryDuration

use of org.jbehave.core.model.StoryDuration 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)

Example 2 with StoryDuration

use of org.jbehave.core.model.StoryDuration in project jbehave-core by jbehave.

the class StoryManager method waitUntilAllDoneOrFailed.

public void waitUntilAllDoneOrFailed(RunContext context) {
    if (runningStories.values().isEmpty()) {
        return;
    }
    boolean allDone = false;
    boolean started = false;
    while (!allDone || !started) {
        allDone = true;
        for (RunningStory runningStory : runningStories.values()) {
            if (runningStory.isStarted()) {
                started = true;
                Story story = runningStory.getStory();
                Future<ThrowableStory> future = runningStory.getFuture();
                if (!future.isDone()) {
                    allDone = false;
                    StoryDuration duration = runningStory.getDuration();
                    runningStory.updateDuration();
                    if (duration.timedOut()) {
                        embedderMonitor.storyTimeout(story, duration);
                        context.cancelStory(story, duration);
                        future.cancel(true);
                        if (embedderControls.failOnStoryTimeout()) {
                            throw new StoryExecutionFailed(story.getPath(), new StoryTimedOut(duration));
                        }
                        continue;
                    }
                } else {
                    try {
                        ThrowableStory throwableStory = future.get();
                        Throwable throwable = throwableStory.getThrowable();
                        if (throwable != null) {
                            context.addFailure(story.getPath(), throwable);
                            if (!embedderControls.ignoreFailureInStories()) {
                                continue;
                            }
                        }
                    } catch (Throwable e) {
                        context.addFailure(story.getPath(), e);
                        if (!embedderControls.ignoreFailureInStories()) {
                            continue;
                        }
                    }
                }
            } else {
                started = false;
                allDone = false;
            }
        }
        tickTock();
    }
    writeStoryDurations(runningStories.values());
}
Also used : StoryDuration(org.jbehave.core.model.StoryDuration) Story(org.jbehave.core.model.Story)

Aggregations

Story (org.jbehave.core.model.Story)2 StoryDuration (org.jbehave.core.model.StoryDuration)2 File (java.io.File)1 Properties (java.util.Properties)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 BatchFailures (org.jbehave.core.failures.BatchFailures)1 Meta (org.jbehave.core.model.Meta)1 StoryMaps (org.jbehave.core.model.StoryMaps)1 ReportsCount (org.jbehave.core.reporters.ReportsCount)1 Test (org.junit.Test)1