Search in sources :

Example 26 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class RegexStoryParserBehaviour method shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale.

@Test
public void shouldParseStoryWithLifecycleAfterUponOutcomeInNonEnglishLocale() {
    String wholeStory = "Lebenszyklus: " + NL + "Nach:" + NL + NL + "Ergebnis: JEDES " + NL + "Gegeben im Lager sind 200 T-Shirts" + NL + "Ergebnis: ERFOLG " + NL + "Gegeben im Lager sind 300 T-Shirts" + NL + "Ergebnis: FEHLER " + NL + "Gegeben im Lager sind 400 T-Shirts" + NL + "Szenario:" + NL + "Wenn ein Kunde 20 T-Shirts bestellt";
    parser = new RegexStoryParser(new LocalizedKeywords(Locale.GERMAN), new LoadFromClasspath(), new TableTransformers());
    Story story = parser.parseStory(wholeStory, storyPath);
    List<String> beforeSteps = story.getLifecycle().getBeforeSteps();
    assertThat(beforeSteps.isEmpty(), equalTo(true));
    Lifecycle lifecycle = story.getLifecycle();
    List<String> afterSteps = lifecycle.getAfterSteps();
    assertThat(afterSteps.get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
    assertThat(afterSteps.get(1), equalTo("Gegeben im Lager sind 300 T-Shirts"));
    assertThat(afterSteps.get(2), equalTo("Gegeben im Lager sind 400 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.ANY).get(0), equalTo("Gegeben im Lager sind 200 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.SUCCESS).get(0), equalTo("Gegeben im Lager sind 300 T-Shirts"));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).size(), equalTo(1));
    assertThat(lifecycle.getAfterSteps(Outcome.FAILURE).get(0), equalTo("Gegeben im Lager sind 400 T-Shirts"));
    Scenario scenario = story.getScenarios().get(0);
    List<String> steps = scenario.getSteps();
    assertThat(steps.get(0), equalTo("Wenn ein Kunde 20 T-Shirts bestellt"));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Lifecycle(org.jbehave.core.model.Lifecycle) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Matchers.containsString(org.hamcrest.Matchers.containsString) GivenStory(org.jbehave.core.model.GivenStory) Story(org.jbehave.core.model.Story) TableTransformers(org.jbehave.core.model.TableTransformers) Scenario(org.jbehave.core.model.Scenario) Test(org.junit.Test)

Example 27 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class StepsBehaviour method shouldNotCreateStepIfStartingWordNotFound.

@Test(expected = StartingWordNotFound.class)
public void shouldNotCreateStepIfStartingWordNotFound() {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
    LocalizedSteps steps = new LocalizedSteps(configuration);
    List<StepCandidate> candidates = steps.listCandidates();
    assertThat(candidates.size(), equalTo(3));
    // misspelled starting word
    candidates.get(0).createMatchedStep("Dado che un dato che", tableRow);
}
Also used : Locale(java.util.Locale) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Test(org.junit.Test)

Example 28 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class PrintStreamOutputBehaviour method shouldNotSuppressStackTraceForNotKnownFailure.

@Test
public void shouldNotSuppressStackTraceForNotKnownFailure() {
    // Given
    final OutputStream out = new ByteArrayOutputStream();
    PrintStreamFactory factory = new PrintStreamFactory() {

        public PrintStream createPrintStream() {
            return new PrintStream(out);
        }
    };
    TxtOutput reporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
    reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new NullPointerException()));
    reporter.afterScenario();
    assertThat(dos2unix(out.toString()), startsWith("Then I should have a balance of $30 (FAILED)\n" + "(java.lang.NullPointerException)\n" + "\n" + "java.lang.NullPointerException\n" + "\tat "));
}
Also used : LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 29 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class StoryNarrator method narrateAnInterestingStory.

static void narrateAnInterestingStory(StoryReporter reporter, boolean withFailure) {
    Properties meta = new Properties();
    meta.setProperty("theme", "testing");
    meta.setProperty("author", "Mauro");
    Lifecycle.Steps beforeScenarioSteps = new Lifecycle.Steps(Scope.SCENARIO, asList("Given a scenario step"));
    Lifecycle.Steps beforeStorySteps = new Lifecycle.Steps(Scope.STORY, asList("Given a story step"));
    Lifecycle.Steps afterScenarioSteps = new Lifecycle.Steps(Scope.SCENARIO, asList("Given a scenario step"));
    Lifecycle.Steps afterStorySteps = new Lifecycle.Steps(Scope.STORY, asList("Given a story step"));
    Lifecycle lifecycle = new Lifecycle(asList(beforeScenarioSteps, beforeStorySteps), asList(afterScenarioSteps, afterStorySteps));
    Story story = new Story("/path/to/story", new Description("An interesting story & special chars"), new Meta(meta), new Narrative("renovate my house", "customer", "get a loan"), GivenStories.EMPTY, lifecycle, new ArrayList<Scenario>());
    boolean givenStory = false;
    reporter.beforeStory(story, givenStory);
    reporter.dryRun();
    reporter.narrative(story.getNarrative());
    reporter.lifecyle(lifecycle);
    reporter.beforeScenario(new Scenario("I ask for a loan", Meta.EMPTY));
    reporter.beforeGivenStories();
    reporter.givenStories(asList("/given/story1", "/given/story2"));
    reporter.afterGivenStories();
    reporter.successful("Given I have a balance of $50");
    reporter.ignorable("!-- Then ignore me");
    reporter.comment("!-- A comment");
    reporter.successful("When I request $20");
    reporter.successful("When I ask Liz for a loan of $100");
    reporter.successful("When I ask Liz for a loan of $" + StepCreator.PARAMETER_VALUE_START + "99" + StepCreator.PARAMETER_VALUE_END);
    reporter.successful("When I write special chars <>&\"");
    reporter.successful("When I write special chars in parameter " + StepCreator.PARAMETER_VALUE_START + "<>&\"" + StepCreator.PARAMETER_VALUE_END);
    reporter.successful("When I write two parameters " + StepCreator.PARAMETER_VALUE_START + ",,," + StepCreator.PARAMETER_VALUE_END + " and " + StepCreator.PARAMETER_VALUE_START + "&&&" + StepCreator.PARAMETER_VALUE_END);
    reporter.restarted("Then I should... - try again", new RestartingScenarioFailure("hi"));
    reporter.restartedStory(story, new RestartingStoryFailure("Restarted Story"));
    reporter.storyCancelled(story, new StoryDuration(1).setDurationInSecs(2));
    if (withFailure) {
        reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new Exception("Expected <30> got <25>")));
    } else {
        reporter.pending("Then I should have a balance of $30");
    }
    reporter.notPerformed("Then I should have $20");
    OutcomesTable outcomesTable = new OutcomesTable(new LocalizedKeywords(), "dd/MM/yyyy");
    outcomesTable.addOutcome("I don't return all", 100.0, equalTo(50.));
    Date actualDate = dateFor("01/01/2011");
    Date expectedDate = dateFor("02/01/2011");
    outcomesTable.addOutcome("A wrong date", actualDate, new IsDateEqual(expectedDate, outcomesTable.getDateFormat()));
    try {
        outcomesTable.verify();
    } catch (UUIDExceptionWrapper e) {
        reporter.failedOutcomes("Then I don't return loan", ((OutcomesFailed) e.getCause()).outcomesTable());
    }
    reporter.afterScenario();
    reporter.beforeScenario(new Scenario("Parametrised Scenario", Meta.EMPTY));
    ExamplesTable table = new ExamplesTable("|money|to|\n|$30|Mauro|\n|$50|Paul|\n");
    reporter.beforeExamples(asList("Given money <money>", "Then I give it to <to>"), table);
    reporter.example(table.getRow(0));
    reporter.successful("Given money $30");
    reporter.successful("Then I give it to Mauro");
    reporter.example(table.getRow(1));
    reporter.successful("Given money $50");
    reporter.successful("Then I give it to Paul");
    if (withFailure) {
        reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new Exception("Expected <30> got <25>")));
    } else {
        reporter.pending("Then I should have a balance of $30");
    }
    reporter.afterExamples();
    reporter.afterScenario();
    String method1 = "@When(\"something \\\"$param\\\"\")\n" + "@Pending\n" + "public void whenSomething() {\n" + "  // PENDING\n" + "}\n";
    String method2 = "@Then(\"something is <param1>\")\n" + "@Pending\n" + "public void thenSomethingIsParam1() {\n" + "  // PENDING\n" + "}\n";
    reporter.pendingMethods(asList(method1, method2));
    reporter.afterStory(givenStory);
}
Also used : RestartingStoryFailure(org.jbehave.core.failures.RestartingStoryFailure) OutcomesFailed(org.jbehave.core.model.OutcomesTable.OutcomesFailed) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Properties(java.util.Properties) ParseException(java.text.ParseException) Date(java.util.Date) RestartingScenarioFailure(org.jbehave.core.failures.RestartingScenarioFailure) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper)

Example 30 with LocalizedKeywords

use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.

the class StoryReporterBuilderBehaviour method shouldBuildWithCustomKeywords.

@Test
public void shouldBuildWithCustomKeywords() throws IOException {
    // Given
    String storyPath = storyPath(MyStory.class);
    Keywords keywords = new LocalizedKeywords(new Locale("it"));
    final OutputStream out = new ByteArrayOutputStream();
    StoryReporterBuilder builder = new StoryReporterBuilder() {

        @Override
        protected FilePrintStreamFactory filePrintStreamFactory(String storyPath) {
            return new FilePrintStreamFactory(new StoryLocation(codeLocation(), storyPath)) {

                @Override
                public PrintStream createPrintStream() {
                    return new PrintStream(out);
                }
            };
        }
    };
    // When
    StoryReporter reporter = builder.withDefaultFormats().withFormats(TXT).withKeywords(keywords).build(storyPath);
    reporter.failed("Dato un passo che fallisce", new UUIDExceptionWrapper(new RuntimeException("ouch")));
    ((ConcurrentStoryReporter) reporter).invokeDelayed();
    // Then
    assertThat(builder.keywords(), equalTo(keywords));
    assertThat(out.toString(), equalTo("Dato un passo che fallisce (FALLITO)\n(java.lang.RuntimeException: ouch)\n"));
}
Also used : Locale(java.util.Locale) PrintStream(java.io.PrintStream) Keywords(org.jbehave.core.configuration.Keywords) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoryLocation(org.jbehave.core.io.StoryLocation) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Aggregations

LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)35 Test (org.junit.Test)23 Properties (java.util.Properties)14 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)10 Locale (java.util.Locale)8 Keywords (org.jbehave.core.configuration.Keywords)8 SimpleDateFormat (java.text.SimpleDateFormat)7 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)7 TableTransformers (org.jbehave.core.model.TableTransformers)7 Configuration (org.jbehave.core.configuration.Configuration)6 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)6 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)6 SilentlyAbsorbingFailure (org.jbehave.core.failures.SilentlyAbsorbingFailure)5 LoadFromURL (org.jbehave.core.io.LoadFromURL)5 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)5 ParameterConverters (org.jbehave.core.steps.ParameterConverters)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)4 ArrayList (java.util.ArrayList)3 StoryLocation (org.jbehave.core.io.StoryLocation)3 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)3