Search in sources :

Example 1 with Meta

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

the class EmbedderBehaviour method shouldRunStoriesApplyingFilter.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesApplyingFilter() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    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);
    final StoryReporter storyReporter = mock(StoryReporter.class);
    Configuration configuration = new MostUsefulConfiguration() {

        @Override
        public StoryReporter storyReporter(String storyPath) {
            return storyReporter;
        }
    };
    embedder.useConfiguration(configuration);
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    Meta meta = mock(Meta.class);
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        when(story.getMeta()).thenReturn(meta);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
        assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
    }
    // When
    MetaFilter filter = mock(MetaFilter.class);
    when(filter.allow(meta)).thenReturn(false);
    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);
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(performableTree, never()).perform(runContext, stories.get(storyPath));
    }
    assertThatReportsViewGenerated(out);
    assertThat(embedder.hasExecutorService(), is(false));
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) Meta(org.jbehave.core.model.Meta) 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) Matchers.containsString(org.hamcrest.Matchers.containsString) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) Test(org.junit.Test)

Example 2 with Meta

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

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

the class RegexStoryParserBehaviour method shouldIgnoreCommentsInMetaProperties.

@Test
public void shouldIgnoreCommentsInMetaProperties() {
    String wholeStory = "Meta: !-- this is the theme @theme parsing !-- skip me @skip" + NL + "Scenario: " + NL + "Meta: !-- these are the authors @authors Mauro Paul" + NL + "Given a scenario " + NL + "When I parse it" + NL + "Then I should get steps";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    Meta storyMeta = story.getMeta();
    assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
    assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
    assertThat(story.getScenarios().get(0).getMeta().getProperty("authors"), equalTo("Mauro Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 4 with Meta

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndNarrative.

@Test
public void shouldParseStoryWithMetaAndNarrative() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "Narrative: This bit of text is ignored" + NL + "In order to renovate my house" + NL + "As a customer" + NL + "I want to get a loan" + NL + "Scenario: A scenario" + NL + "Meta: @author Mauro" + NL + "Given a step " + NL + "Scenario: Another scenario" + NL + "Meta: @author Paul" + NL + "Given another step ";
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.getPath(), equalTo(storyPath));
    Meta storyMeta = story.getMeta();
    assertThat(storyMeta.getProperty("theme"), equalTo("parsing"));
    assertThat(storyMeta.getProperty("skip"), equalTo(EMPTY));
    assertThat(storyMeta.getProperty("unknown"), equalTo(EMPTY));
    Narrative narrative = story.getNarrative();
    assertThat(narrative.isEmpty(), not(true));
    List<Scenario> scenarios = story.getScenarios();
    assertThat(scenarios.get(0).getTitle(), equalTo("A scenario"));
    assertThat(scenarios.get(0).getMeta().getProperty("author"), equalTo("Mauro"));
    assertThat(scenarios.get(1).getTitle(), equalTo("Another scenario"));
    assertThat(scenarios.get(1).getMeta().getProperty("author"), equalTo("Paul"));
}
Also used : Meta(org.jbehave.core.model.Meta) Narrative(org.jbehave.core.model.Narrative) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 5 with Meta

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

the class RegexStoryParserBehaviour method shouldParseStoryWithAllElements.

@Test
public void shouldParseStoryWithAllElements() {
    String wholeStory = "This is just a story description" + NL + NL + "Narrative: " + NL + "In order to see what we're not delivering" + NL + NL + "As a developer" + NL + "I want to see the narrative for my story when a scenario in that story breaks" + NL + "GivenStories: path1,path2" + NL + NL + "Lifecycle: " + NL + "Before: " + NL + NL + "Given a setup step" + NL + "After: " + NL + NL + "Then a teardown step" + NL + "Scenario: A pending scenario" + NL + NL + "Given a step that's pending" + NL + "When I run the scenario" + NL + "!-- A comment between steps" + NL + "Then I should see this in the output" + NL + "Scenario: A passing scenario" + NL + "Given I'm not reporting passing stories" + NL + "When I run the scenario" + NL + "Then this should not be in the output" + NL + "Scenario: A failing scenario" + NL + "Given a step that fails" + NL + "When I run the scenario" + NL + "Then I should see this in the output" + NL + "And I should see this in the output" + NL;
    Story story = parser.parseStory(wholeStory, storyPath);
    assertThat(story.toString(), containsString("This is just a story description"));
    assertThat(story.getDescription().asString(), equalTo("This is just a story description"));
    assertThat(story.toString(), containsString("Narrative"));
    assertThat(story.getNarrative().inOrderTo(), equalTo("see what we're not delivering"));
    assertThat(story.getNarrative().asA(), equalTo("developer"));
    assertThat(story.getNarrative().iWantTo(), equalTo("see the narrative for my story when a scenario in that story breaks"));
    assertThat(story.getGivenStories().getPaths(), hasItem("path1"));
    assertThat(story.getGivenStories().getPaths(), hasItem("path2"));
    assertThat(story.toString(), containsString("Lifecycle"));
    assertThat(story.getLifecycle().getBeforeSteps().size(), equalTo(1));
    assertThat(story.getLifecycle().getBeforeSteps(), hasItem("Given a setup step"));
    assertThat(story.getLifecycle().getAfterSteps().size(), equalTo(1));
    assertThat(story.getLifecycle().getAfterSteps(), hasItem("Then a teardown step"));
    Meta storyAsMeta = story.asMeta("story_");
    assertThat(storyAsMeta.getProperty("story_path"), equalTo(story.getPath()));
    assertThat(storyAsMeta.getProperty("story_description"), equalTo(story.getDescription().asString()));
    assertThat(storyAsMeta.getProperty("story_narrative"), equalTo(story.getNarrative().toString()));
    assertThat(story.toString(), containsString("A pending scenario"));
    Scenario firstScenario = story.getScenarios().get(0);
    assertThat(firstScenario.getTitle(), equalTo("A pending scenario"));
    assertThat(firstScenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(firstScenario.getSteps(), equalTo(asList("Given a step that's pending", "When I run the scenario", "!-- A comment between steps", "Then I should see this in the output")));
    Meta scenarioAsMeta = firstScenario.asMeta("scenario_");
    assertThat(scenarioAsMeta.getProperty("scenario_title"), equalTo(firstScenario.getTitle()));
    assertThat(scenarioAsMeta.getProperty("scenario_givenStories"), equalTo(firstScenario.getGivenStories().asString()));
    assertThat(scenarioAsMeta.getProperty("scenario_examplesTable"), equalTo(firstScenario.getExamplesTable().asString()));
    assertThat(story.toString(), containsString("A passing scenario"));
    Scenario secondScenario = story.getScenarios().get(1);
    assertThat(secondScenario.getTitle(), equalTo("A passing scenario"));
    assertThat(secondScenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(secondScenario.getSteps(), equalTo(asList("Given I'm not reporting passing stories", "When I run the scenario", "Then this should not be in the output")));
    assertThat(story.toString(), containsString("A failing scenario"));
    Scenario thirdScenario = story.getScenarios().get(2);
    assertThat(thirdScenario.getTitle(), equalTo("A failing scenario"));
    assertThat(thirdScenario.getGivenStories().getPaths().size(), equalTo(0));
    assertThat(thirdScenario.getSteps(), equalTo(asList("Given a step that fails", "When I run the scenario", "Then I should see this in the output", "And I should see this in the output")));
}
Also used : Meta(org.jbehave.core.model.Meta) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Aggregations

Meta (org.jbehave.core.model.Meta)32 Test (org.junit.Test)23 Story (org.jbehave.core.model.Story)11 Scenario (org.jbehave.core.model.Scenario)9 Matchers.containsString (org.hamcrest.Matchers.containsString)8 HashMap (java.util.HashMap)6 Properties (java.util.Properties)6 GivenStory (org.jbehave.core.model.GivenStory)6 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)6 StepMatcher (org.jbehave.core.parsers.StepMatcher)6 Silent (org.jbehave.core.steps.AbstractStepResult.Silent)6 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)6 Map (java.util.Map)4 PendingStep (org.jbehave.core.steps.StepCreator.PendingStep)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ScenarioType (org.jbehave.core.annotations.ScenarioType)3 ExamplesTable (org.jbehave.core.model.ExamplesTable)3 Lifecycle (org.jbehave.core.model.Lifecycle)3 BytecodeReadingParanamer (com.thoughtworks.paranamer.BytecodeReadingParanamer)2 CachingParanamer (com.thoughtworks.paranamer.CachingParanamer)2