Search in sources :

Example 1 with StoryMaps

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

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

the class EmbedderBehaviour method shouldMapStoriesAsPaths.

@SuppressWarnings("unchecked")
@Test
public void shouldMapStoriesAsPaths() throws Throwable {
    // Given
    StoryMapper mapper = mock(StoryMapper.class);
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    Embedder embedder = embedderWith(mapper, performableTree, embedderControls, monitor);
    Configuration configuration = embedder.configuration();
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    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 = new Story(storyPath);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
    }
    // When
    List<StoryMap> maps = asList(new StoryMap("filter", new HashSet<>(stories.values())));
    StoryMaps storyMaps = new StoryMaps(maps);
    when(mapper.getStoryMaps()).thenReturn(storyMaps);
    embedder.mapStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(mapper).map(Matchers.eq(stories.get(storyPath)), Matchers.any(MetaFilter.class));
        assertThat(out.toString(), containsString("Mapping story " + storyPath));
    }
    assertThatMapsViewGenerated(out);
}
Also used : PrintStream(java.io.PrintStream) 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) JUnitStoryMaps(org.jbehave.core.junit.JUnitStoryMaps) StoryMaps(org.jbehave.core.model.StoryMaps) StoryMap(org.jbehave.core.model.StoryMap) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with StoryMaps

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

the class StoryMapperBehaviour method shouldMapStoriesAllowedByFilter.

@Test
public void shouldMapStoriesAllowedByFilter() throws Throwable {
    // Given
    Meta meta1 = mock(Meta.class, "meta1");
    Story story1 = new Story("/path/to/story1", Description.EMPTY, meta1, Narrative.EMPTY, asList(new Scenario("scenario1", meta1)));
    Meta meta2 = mock(Meta.class, "meta2");
    Story story2 = new Story("/path/to/story2", Description.EMPTY, meta2, Narrative.EMPTY, asList(new Scenario("scenario2", meta2)));
    MetaFilter filter = mock(MetaFilter.class);
    String filterAsString = "-some property";
    // When
    StoryMapper mapper = new StoryMapper();
    when(meta1.inheritFrom(meta1)).thenReturn(meta1);
    when(meta2.inheritFrom(meta2)).thenReturn(meta2);
    when(filter.allow(meta1)).thenReturn(false);
    when(filter.allow(meta2)).thenReturn(true);
    when(filter.asString()).thenReturn(filterAsString);
    mapper.map(story1, filter);
    mapper.map(story2, filter);
    // Then
    StoryMaps storyMaps = mapper.getStoryMaps();
    assertThat(storyMaps.getMaps().size(), equalTo(1));
    StoryMap storyMap = storyMaps.getMap(filterAsString);
    assertThat(storyMap.getMetaFilter(), equalTo(filterAsString));
    assertThat(storyMap.getStories().get(0).getPath(), equalTo(story2.getPath()));
    assertThat(storyMap.getStoryPaths(), equalTo(asList(story2.getPath())));
}
Also used : Meta(org.jbehave.core.model.Meta) StoryMap(org.jbehave.core.model.StoryMap) Story(org.jbehave.core.model.Story) StoryMaps(org.jbehave.core.model.StoryMaps) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Aggregations

Story (org.jbehave.core.model.Story)3 StoryMaps (org.jbehave.core.model.StoryMaps)3 Test (org.junit.Test)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Meta (org.jbehave.core.model.Meta)2 StoryMap (org.jbehave.core.model.StoryMap)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)1 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)1 Configuration (org.jbehave.core.configuration.Configuration)1 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)1 BatchFailures (org.jbehave.core.failures.BatchFailures)1 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)1