Search in sources :

Example 1 with StoryMap

use of org.jbehave.core.model.StoryMap 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 2 with StoryMap

use of org.jbehave.core.model.StoryMap 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)2 StoryMap (org.jbehave.core.model.StoryMap)2 StoryMaps (org.jbehave.core.model.StoryMaps)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 Matchers.containsString (org.hamcrest.Matchers.containsString)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 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)1 JUnitStory (org.jbehave.core.junit.JUnitStory)1 JUnitStoryMaps (org.jbehave.core.junit.JUnitStoryMaps)1 Meta (org.jbehave.core.model.Meta)1 Scenario (org.jbehave.core.model.Scenario)1