Search in sources :

Example 6 with Meta

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

the class RegexStoryParserBehaviour method shouldParseStoryWithMetaAndGivenStories.

@Test
public void shouldParseStoryWithMetaAndGivenStories() {
    String wholeStory = "Meta: @skip @theme parsing" + NL + "GivenStories: path1,path2 " + 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));
    assertThat(story.getGivenStories().getPaths(), equalTo(asList("path1", "path2")));
    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) 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 7 with Meta

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

the class StepCreatorBehaviour method shouldInvokeAfterStepUponAnyOutcomeMethodWithExpectedParametersFromMeta.

@Test
public void shouldInvokeAfterStepUponAnyOutcomeMethodWithExpectedParametersFromMeta() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
    Properties properties = new Properties();
    properties.put("theme", "shopping cart");
    properties.put("variant", "book");
    // When
    Step stepWithMeta = stepCreator.createAfterStepUponOutcome(SomeSteps.methodFor("aMethodWithANamedParameter"), AfterScenario.Outcome.ANY, new Meta(properties));
    StepResult stepResult = stepWithMeta.perform(null);
    // Then
    assertThat(stepResult, instanceOf(Silent.class));
    assertThat(stepsInstance.args, instanceOf(Map.class));
    @SuppressWarnings("unchecked") Map<String, String> methodArgs = (Map<String, String>) stepsInstance.args;
    assertThat(methodArgs.get("variant"), is("book"));
    assertThat(methodArgs.get("theme"), is("shopping cart"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 8 with Meta

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

the class StepCreatorBehaviour method shouldInvokeAfterStepUponSuccessOutcomeMethodIfNoFailureOccurred.

@Test
public void shouldInvokeAfterStepUponSuccessOutcomeMethodIfNoFailureOccurred() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
    Properties properties = new Properties();
    properties.put("theme", "shopping cart");
    properties.put("variant", "book");
    // When
    Step stepWithMeta = stepCreator.createAfterStepUponOutcome(SomeSteps.methodFor("aMethodWithANamedParameter"), AfterScenario.Outcome.SUCCESS, new Meta(properties));
    StepResult stepResult = stepWithMeta.perform(null);
    // Then
    assertThat(stepResult, instanceOf(Silent.class));
    assertThat(stepsInstance.args, instanceOf(Map.class));
    @SuppressWarnings("unchecked") Map<String, String> methodArgs = (Map<String, String>) stepsInstance.args;
    assertThat(methodArgs.get("variant"), is("book"));
    assertThat(methodArgs.get("theme"), is("shopping cart"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with Meta

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

the class StepsBehaviour method shouldProvideStepsToBeNotPerformedAfterScenarioUponOutcome.

@Test
public void shouldProvideStepsToBeNotPerformedAfterScenarioUponOutcome() {
    MultipleAliasesSteps steps = new MultipleAliasesSteps();
    ScenarioType scenarioType = ScenarioType.NORMAL;
    List<BeforeOrAfterStep> beforeAfterScenario = steps.listBeforeOrAfterScenario(scenarioType);
    assertThat(beforeAfterScenario.size(), equalTo(4));
    beforeAfterScenario.get(0).createStep().doNotPerform(null);
    assertThat(steps.beforeNormalScenario, is(true));
    Meta storyAndScenarioMeta = null;
    UUIDExceptionWrapper failure = new UUIDExceptionWrapper();
    // uponOutcome=ANY
    beforeAfterScenario.get(1).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(failure);
    assertThat(steps.afterNormalScenario, is(true));
    // uponOutcome=SUCCESS
    beforeAfterScenario.get(2).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(failure);
    assertThat(steps.afterSuccessfulScenario, is(false));
    // uponOutcome=FAILURE
    beforeAfterScenario.get(3).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(failure);
    assertThat(steps.afterFailedScenario, is(true));
}
Also used : Meta(org.jbehave.core.model.Meta) ScenarioType(org.jbehave.core.annotations.ScenarioType) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 10 with Meta

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

the class StepsBehaviour method shouldProvideStepsToBePerformedBeforeAndAfterScenariosWithFailureOccuring.

@Test
public void shouldProvideStepsToBePerformedBeforeAndAfterScenariosWithFailureOccuring() {
    MultipleAliasesSteps steps = new MultipleAliasesSteps();
    ScenarioType scenarioType = ScenarioType.NORMAL;
    List<BeforeOrAfterStep> beforeAfterScenario = steps.listBeforeOrAfterScenario(scenarioType);
    assertThat(beforeAfterScenario.size(), equalTo(4));
    beforeAfterScenario.get(0).createStep().perform(null);
    assertThat(steps.beforeNormalScenario, is(true));
    Meta storyAndScenarioMeta = null;
    // uponOutcome=ANY
    beforeAfterScenario.get(1).createStepUponOutcome(storyAndScenarioMeta).perform(null);
    assertThat(steps.afterNormalScenario, is(true));
    // uponOutcome=SUCCESS
    beforeAfterScenario.get(2).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(null);
    assertThat(steps.afterSuccessfulScenario, is(false));
    // uponOutcome=FAILURE
    beforeAfterScenario.get(3).createStepUponOutcome(storyAndScenarioMeta).doNotPerform(null);
    assertThat(steps.afterFailedScenario, is(true));
}
Also used : Meta(org.jbehave.core.model.Meta) ScenarioType(org.jbehave.core.annotations.ScenarioType) 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