Exemplo n.º 1
0
  @Test
  public void shouldRunScenarioAndLifecycleStepsInCorrectOrderWithExamplesTable() throws Throwable {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    Map<String, String> tableRow = examplesTable.getRow(0);
    Scenario scenario1 =
        new Scenario(
            "my title 1",
            Meta.EMPTY,
            GivenStories.EMPTY,
            examplesTable,
            asList("step <one>", "step <two>"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.storyControls().doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    Step firstStep = mockSuccessfulStep("step <one>");
    Step secondStep = mockSuccessfulStep("step <two>");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow))
        .thenReturn(asList(firstStep, secondStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);

    Step beforeExampleStep = mockSuccessfulStep("beforeExampleStep");
    Step afterExampleStep = mockSuccessfulStep("afterExampleStep");
    when(collector.collectBeforeOrAfterScenarioSteps(
            eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.BEFORE), eq(ScenarioType.EXAMPLE)))
        .thenReturn(asList(beforeExampleStep));
    when(collector.collectBeforeOrAfterScenarioSteps(
            eq(asList(mySteps)), Matchers.<Meta>any(), eq(Stage.AFTER), eq(ScenarioType.EXAMPLE)))
        .thenReturn(asList(afterExampleStep));

    Step beforeStep = mockSuccessfulStep("lifecycleBeforeStep");
    Step afterStep = mockSuccessfulStep("lifecycleAfterStep");
    when(collector.collectLifecycleSteps(
            eq(asList(mySteps)), eq(Lifecycle.EMPTY), any(Meta.class), eq(Stage.BEFORE)))
        .thenReturn(asList(beforeStep));
    when(collector.collectLifecycleSteps(
            eq(asList(mySteps)), eq(Lifecycle.EMPTY), any(Meta.class), eq(Stage.AFTER)))
        .thenReturn(asList(afterStep));

    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configuration, asList(mySteps), story);

    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).successful("beforeExampleStep");
    inOrder.verify(reporter).successful("lifecycleBeforeStep");
    inOrder.verify(reporter).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).successful("lifecycleAfterStep");
    inOrder.verify(reporter).successful("afterExampleStep");
  }
Exemplo n.º 2
0
 @Given("authentication policy for $orgName: $authPolicyTable")
 public void updateOrganizationWithDefaultAuthPolicy(String orgName, ExamplesTable table) {
   Organization org = organizationDao.findByName(orgName);
   Map<String, String> row = table.getRow(0);
   org.setAuthenticationPolicy(new AuthenticationPolicyBuilder(row).build());
   organizationDao.persist(org);
 }
 @Given("with living cells at following positions : $table")
 public void givenInitialPositionTable(ExamplesTable table) {
   List<Map<String, String>> rows = table.getRows();
   for (Map<String, String> row : rows) {
     int x = Integer.valueOf(row.get("x"));
     int y = Integer.valueOf(row.get("y"));
     initialStates.add(new Coordinate(x, y));
   }
 }
Exemplo n.º 4
0
  @Test
  public void shouldRunScenarioWithExamplesTable() throws Throwable {
    // Given
    ExamplesTable examplesTable = new ExamplesTable("|one|two|\n|1|2|\n");
    Map<String, String> tableRow = examplesTable.getRow(0);
    Scenario scenario1 =
        new Scenario(
            "my title 1",
            Meta.EMPTY,
            GivenStories.EMPTY,
            examplesTable,
            asList("step <one>", "step <two>"));
    Story story = new Story(new Description("my blurb"), Narrative.EMPTY, asList(scenario1));
    Step step = mock(Step.class);
    StepResult result = mock(StepResult.class);
    when(step.perform(null)).thenReturn(result);
    StoryReporter reporter = mock(ConcurrentStoryReporter.class);
    StepCollector collector = mock(StepCollector.class);
    FailureStrategy failureStrategy = mock(FailureStrategy.class);
    Configuration configuration = configurationWith(reporter, collector, failureStrategy);
    configuration.storyControls().doDryRun(true);
    CandidateSteps mySteps = new Steps(configuration);
    Step firstStep = mockSuccessfulStep("step <one>");
    Step secondStep = mockSuccessfulStep("step <two>");
    when(collector.collectScenarioSteps(asList(mySteps), scenario1, tableRow))
        .thenReturn(asList(firstStep, secondStep));
    boolean givenStory = false;
    givenStoryWithNoBeforeOrAfterSteps(story, givenStory, collector, mySteps);

    // When
    StoryRunner runner = new StoryRunner();
    runner.run(configuration, asList(mySteps), story);

    // Then
    InOrder inOrder = inOrder(reporter, failureStrategy);
    inOrder.verify(reporter).beforeStory(story, givenStory);
    inOrder.verify(reporter).beforeScenario("my title 1");
    inOrder.verify(reporter).successful("step <one>");
    inOrder.verify(reporter).successful("step <two>");
    inOrder.verify(reporter).afterScenario();
    inOrder.verify(reporter).afterStory(givenStory);
  }
Exemplo n.º 5
0
 private void runScenariosParametrisedByExamples(
     RunContext context, Scenario scenario, Lifecycle lifecycle, Meta storyAndScenarioMeta)
     throws Throwable {
   ExamplesTable table = scenario.getExamplesTable();
   reporter.get().beforeExamples(scenario.getSteps(), table);
   Keywords keywords = context.configuration().keywords();
   for (Map<String, String> scenarioParameters : table.getRows()) {
     Meta parameterMeta = parameterMeta(keywords, scenarioParameters);
     if (!parameterMeta.isEmpty() && !context.filter.allow(parameterMeta)) {
       continue;
     }
     reporter.get().example(scenarioParameters);
     if (context.configuration().storyControls().resetStateBeforeScenario()) {
       context.resetState();
     }
     runBeforeOrAfterScenarioSteps(
         context, scenario, storyAndScenarioMeta, Stage.BEFORE, ScenarioType.EXAMPLE);
     runStepWithLifecycle(context, lifecycle, scenarioParameters, scenario, storyAndScenarioMeta);
     runBeforeOrAfterScenarioSteps(
         context, scenario, storyAndScenarioMeta, Stage.AFTER, ScenarioType.EXAMPLE);
   }
   reporter.get().afterExamples();
 }
  @Given("the following trades: $tradesTable")
  public void theTrades(ExamplesTable tradesTable) {

    for (Map<String, String> row : tradesTable.getRows()) {
      String symbol = row.get("symbol");
      String minsAgo = row.get("mins-ago");
      String tradedPrice = row.get("traded-price");
      String quantity = row.get("quantity");

      Stock stock = new Stock.Builder().symbol(symbol).type(TYPE.COMMON).build();

      StockTrade trade =
          new StockTrade.Builder()
              .stock(stock)
              .timestamp(
                  new Date(System.currentTimeMillis() - Integer.valueOf(minsAgo) * 60 * 1000))
              .quantity(Integer.valueOf(quantity))
              .tradedPrice(Double.valueOf(tradedPrice))
              .build();

      tradeRepository.captureTrade(trade);
    }
  }
 private void assertThatExamplesTableIsConverted(final ParameterConverters parameterConverters) {
   final String tableAsString = "||one||two||\n" + "|1|2|";
   final ExamplesTable table = new ExamplesTable(tableAsString);
   assertThat(table.getHeaders(), hasItems("one", "two"));
 }