@Test //test that a steps from a step macro themselves matched to the list of step macros recursively, creating //a tree structure of steps //any capture groups in the step macro steps should be expanded before this matching occurs public void testRecursiveMatching() { StepMacro stepMacro = new StepMacro("I have a parent (.*) macro"); stepMacro.addStep(StepToken.createStep("", "With a step which matches a child <$1> macro")); StepMacro childStepMacro = new StepMacro("With a step which matches a child step macro"); childStepMacro.addStep(StepToken.createStep("", "Child Step")); StepToken scenarioStepToken = StepToken.createStep("Given", "I have a parent step macro"); stepMacro.processStep(scenarioStepToken, Arrays.asList(stepMacro, childStepMacro), false); assertEquals(scenarioStepToken.getChildSteps().size(), 1); assertEquals("With a step which matches a child step macro", scenarioStepToken.getChildSteps().get(0).getAction()); assertEquals(scenarioStepToken.getChildSteps().get(0).getChildSteps().size(), 1); assertEquals("Child Step", scenarioStepToken.getChildSteps().get(0).getChildSteps().get(0).getAction()); }
@Test public void testStepMacroPatternMatch() { StepMacro stepMacro = new StepMacro("I reference a step macro with (\\d+) steps and (\\d+) capture groups"); stepMacro.addStep(StepToken.createStep("Given", "my number of steps is <$1> steps")); stepMacro.addStep(StepToken.createStep("Then", "my number of groups is <$2> groups")); StepToken scenarioStepToken = StepToken.createStep("Given", "I reference a step macro with 2 steps and 2 capture groups"); stepMacro.processStep(scenarioStepToken, Collections.singletonList(stepMacro), false); assertEquals(scenarioStepToken.getChildSteps().size(), 2); assertEquals("my number of steps is 2 steps", scenarioStepToken.getChildSteps().get(0).getAction()); assertEquals("my number of groups is 2 groups", scenarioStepToken.getChildSteps().get(1).getAction()); }
/** * @param stepInvokerProvider container for StepInvoker to run the steps * @param step details of the step to be executed * @param stepCatalogue *@param skip is true the step will be skipped if found @return the exit state of the executed step */ private StepEndState processStep(ExecutionToken executionToken, StepInvokerProvider stepInvokerProvider, StepToken step, StepCatalogue stepCatalogue, boolean skip) { log.trace("Starting to process step " + (step.isStepMacro() ? "macro " : "") + step); executionListenerSupport.notifyStepStarted(executionToken, step); StepEndState endState; if ( step.isStepMacro() ) { endState = runSteps(executionToken, stepInvokerProvider, step.getChildSteps(), stepCatalogue, skip); } else { endState = processHandlerStep(executionToken, stepInvokerProvider, step, stepCatalogue, skip); } step.setEndState(endState); executionListenerSupport.notifyStepCompleted(executionToken, step); return endState; }
@Override public StepTokenBean marshal(StepToken v) throws Exception { StepTokenBean toRet = new StepTokenBean(); toRet.setTokenId(v.getTokenId()); toRet.setType(v.getType()); toRet.setAction(v.getAction()); toRet.setEndState(v.getEndState()); toRet.setMessage(v.getMessage()); //we don't want to add an error details attribute unless there's a real value if ( ! "".equals(v.getErrorDetails().trim())) { toRet.setErrorDetails(v.getErrorDetails()); } if (v.getException()!=null){ toRet.setException(v.getException()); toRet.setStackTrace(v.getStackTrace()); } toRet.setTimeTaken(v.getTimeTaken()); toRet.setTimeTakenSeconds(FormattingUtils.getTimeTakenAsSecondsString(v.getTimeTaken())); toRet.setChildSteps(v.getChildSteps()); return toRet; }