コード例 #1
0
  @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());
      }
    }
  }
コード例 #2
0
ファイル: RuntimeGlue.java プロジェクト: lxw03/cucumber-jvm
 @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);
 }
コード例 #3
0
ファイル: RuntimeGlue.java プロジェクト: lxw03/cucumber-jvm
 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;
 }
コード例 #4
0
 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()));
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 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;
 }
コード例 #7
0
ファイル: Runtime.java プロジェクト: bap2000/cucumber-jvm
 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;
 }
コード例 #8
0
  /**
   * @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()]);
  }
コード例 #9
0
 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;
 }
コード例 #10
0
 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());
   }
 }
コード例 #11
0
 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;
 }
コード例 #12
0
  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;
  }
コード例 #13
0
 public String getPattern() {
   return stepDefinition.getPattern();
 }