@Override public void setValues(StepDefinition otherDefinition) { if (!(otherDefinition instanceof ListConditionStepDefinition)) { throw new SimpleWorkflowException( "An instance of SerialStepsDefinition is required to set values"); } ListConditionStepDefinition<T> definition = (ListConditionStepDefinition<T>) otherDefinition; setId(definition.getId()); setName(definition.getName()); setParameters(new HashMap<String, Object>(otherDefinition.getParameters())); steps = new ArrayList<StepDefinition>(); if (definition.getSteps() != null && definition.getSteps().size() > 0) { for (StepDefinition stepDefinition : definition.getSteps()) { steps.add(stepDefinition.clone()); } } conditions = new ArrayList<ConditionDefinition>(); if (definition.getConditions() != null && definition.getConditions().size() > 0) { for (ConditionDefinition condition : definition.getConditions()) { conditions.add(condition.clone()); } } }
@Override public void addStepDefinition(StepDefinition stepDefinition) { StepDefinition previous = stepDefinitionsByPattern.get(stepDefinition.getPattern()); if (previous != null) { throw new DuplicateStepDefinitionException(previous, stepDefinition); } stepDefinitionsByPattern.put(stepDefinition.getPattern(), stepDefinition); }
private List<StepDefinitionMatch> stepDefinitionMatches(String uri, Step step) { List<StepDefinitionMatch> result = new ArrayList<StepDefinitionMatch>(); for (StepDefinition stepDefinition : stepDefinitionsByPattern.values()) { List<Argument> arguments = stepDefinition.matchedArguments(step); if (arguments != null) { result.add( new StepDefinitionMatch(arguments, stepDefinition, uri, step, localizedXStreams)); } } return result; }
private CucumberException arityMismatch(int parameterCount) { List<Argument> arguments = createArgumentsForErrorMessage(step); return new CucumberException( String.format( "Arity mismatch: Step Definition '%s' with pattern [%s] is declared with %s parameters. However, the gherkin step has %s arguments %s. \nStep: %s%s", stepDefinition.getLocation(true), stepDefinition.getPattern(), parameterCount, arguments.size(), arguments, step.getKeyword(), step.getName())); }
public final List<IRubyObject> step_match_list(String step_name, String formatted_step_name) throws Throwable { List<IRubyObject> matches = new ArrayList<IRubyObject>(); for (StepDefinition stepDefinition : stepDefinitions) { List<StepArgument> arguments = stepDefinition.arguments_from(step_name); if (arguments != null) { matches.add( languageMixin.create_step_match( stepDefinition, step_name, formatted_step_name, arguments)); } } return matches; }
private List<StepDefinitionMatch> stepDefinitionMatches(String uri, Step step) { List<StepDefinitionMatch> result = new ArrayList<StepDefinitionMatch>(); for (Backend backend : backends) { for (StepDefinition stepDefinition : backend.getStepDefinitions()) { List<Argument> arguments = stepDefinition.matchedArguments(step); if (arguments != null) { result.add( new StepDefinitionMatch(arguments, stepDefinition, uri, step, this.transformers)); } } } return result; }
private List<StepDefinitionMatch> stepDefinitionMatches(String uri, Step step) { List<StepDefinitionMatch> result = new ArrayList<StepDefinitionMatch>(); for (Backend backend : backends) { for (StepDefinition stepDefinition : backend.getStepDefinitions()) { List<Argument> arguments = stepDefinition.matchedArguments(step); if (arguments != null) { result.add( new StepDefinitionMatch( arguments, stepDefinition, uri, step, localizedXStreams, tableHeaderMapper)); } } } return result; }
/** * @param step the step to run * @param xStream used to convert a string to declared stepdef arguments * @return an Array matching the types or {@code parameterTypes}, or an array of String if {@code * parameterTypes} is null */ private Object[] transformedArgs(Step step, LocalizedXStreams.LocalizedXStream xStream) { int argumentCount = getArguments().size(); if (step.getRows() != null) { argumentCount++; } else if (step.getDocString() != null) { argumentCount++; } Integer parameterCount = stepDefinition.getParameterCount(); if (parameterCount != null && argumentCount != parameterCount) { throw arityMismatch(parameterCount); } List<Object> result = new ArrayList<Object>(); int n = 0; for (Argument a : getArguments()) { ParameterInfo parameterInfo = getParameterType(n, String.class); Object arg = parameterInfo.convert(a.getVal(), xStream); result.add(arg); n++; } if (step.getRows() != null) { result.add(tableArgument(step, n, xStream)); } else if (step.getDocString() != null) { result.add(step.getDocString().getValue()); } return result.toArray(new Object[result.size()]); }
private ParameterInfo getParameterType(int n, Type argumentType) { ParameterInfo parameterInfo = stepDefinition.getParameterType(n, argumentType); if (parameterInfo == null) { // Some backends return null because they don't know parameterInfo = new ParameterInfo(argumentType, null, null, false, null); } return parameterInfo; }
public void runStep(I18n i18n) throws Throwable { try { stepDefinition.execute(i18n, transformedArgs(step, localizedXStreams.get(i18n.getLocale()))); } catch (CucumberException e) { throw e; } catch (Throwable t) { throw removeFrameworkFramesAndAppendStepLocation(t, getStepLocation()); } }
public StepDefinitionMatch( List<Argument> arguments, StepDefinition stepDefinition, String featurePath, Step step, LocalizedXStreams localizedXStreams) { super(arguments, stepDefinition.getLocation(false)); this.stepDefinition = stepDefinition; this.featurePath = featurePath; this.step = step; this.localizedXStreams = localizedXStreams; }
private Throwable removeFrameworkFramesAndAppendStepLocation( Throwable error, StackTraceElement stepLocation) { StackTraceElement[] stackTraceElements = error.getStackTrace(); if (stackTraceElements.length == 0 || stepLocation == null) { return error; } int newStackTraceLength; for (newStackTraceLength = 1; newStackTraceLength < stackTraceElements.length; ++newStackTraceLength) { if (stepDefinition.isDefinedAt(stackTraceElements[newStackTraceLength - 1])) { break; } } StackTraceElement[] newStackTrace = new StackTraceElement[newStackTraceLength + 1]; System.arraycopy(stackTraceElements, 0, newStackTrace, 0, newStackTraceLength); newStackTrace[newStackTraceLength] = stepLocation; error.setStackTrace(newStackTrace); return error; }
public String getPattern() { return stepDefinition.getPattern(); }