Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 3.0
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Right now the converters are called before running the scenario, which prevents using stateful converters.

      The parametrised step with the parameter conversion should be created lazily upon invocation of the Step#perform() method.

        Activity

        Mauro Talevi made changes -
        Field Original Value New Value
        Summary Allow lazy parameter convertion : fix CandidateStep Allow lazy parameter convertion
        Fix Version/s 3.0 [ 16302 ]
        Description Right now the converters are called before running the scenario, which prevents using stateful converters.

        Here is an easy fix : change CandidateStep#createStep to the following

        {code}
        protected Step createStep(final String stepAsString, final Map<String, String> tableRow, final Matcher matcher,
                                      final Method method, final StepMonitor stepMonitor, String[] groupNames) {
                final Type[] types = method.getGenericParameterTypes();
                final String[] annotationNames = annotatedParameterNames();
                final String[] parameterNames = paranamer.lookupParameterNames(method, false);
                final String translatedStep = translatedStep(stepAsString, tableRow, types, annotationNames, parameterNames);
                
                return new Step() {
                    public StepResult perform() {
                        try {
                            stepMonitor.performing(stepAsString);
                            method.invoke(steps, argsForStep(tableRow, matcher, types, annotationNames, parameterNames));
                            return StepResult.success(stepAsString).withTranslatedText(translatedStep);
                        } catch (Throwable t) {
                            return failureWithOriginalException(stepAsString, t);
                        }
                    }

                    private StepResult failureWithOriginalException(final String stepAsString, Throwable t) {
                        if (t instanceof InvocationTargetException && t.getCause() != null) {
                            if (t.getCause() instanceof PendingError) {
                                return StepResult.pending(stepAsString, (PendingError) t.getCause());
                            } else {
                                return StepResult.failure(stepAsString, t.getCause());
                            }
                        }
                        return StepResult.failure(stepAsString, t);
                    }

                    public StepResult doNotPerform() {
                        return StepResult.notPerformed(stepAsString);
                    }

                };
            }
        {code}
        Right now the converters are called before running the scenario, which prevents using stateful converters.

        Here is an easy fix : change StepCreator#createParametrisedStep to the following

        {code}
        protected Step createParametrisedStep(final String stepAsString, final Map<String, String> tableRow, final Matcher matcher, final Method method, final StepMonitor stepMonitor, String[] groupNames) {
                final Type[] types = method.getGenericParameterTypes();
                final String[] annotationNames = annotatedParameterNames();
                final String[] parameterNames = paranamer.lookupParameterNames(method, false);
                final String translatedStep = translatedStep(stepAsString, tableRow, types, annotationNames, parameterNames);
                
                return new Step() {
                    public StepResult perform() {
                        try {
                            stepMonitor.performing(stepAsString);
                            method.invoke(steps, argsForStep(tableRow, matcher, types, annotationNames, parameterNames));
                            return StepResult.success(stepAsString).withTranslatedText(translatedStep);
                        } catch (Throwable t) {
                            return failureWithOriginalException(stepAsString, t);
                        }
                    }

                    private StepResult failureWithOriginalException(final String stepAsString, Throwable t) {
                        if (t instanceof InvocationTargetException && t.getCause() != null) {
                            if (t.getCause() instanceof PendingError) {
                                return StepResult.pending(stepAsString, (PendingError) t.getCause());
                            } else {
                                return StepResult.failure(stepAsString, t.getCause());
                            }
                        }
                        return StepResult.failure(stepAsString, t);
                    }

                    public StepResult doNotPerform() {
                        return StepResult.notPerformed(stepAsString);
                    }

                };
            }
        {code}
        Component/s Core [ 11086 ]
        Mauro Talevi made changes -
        Description Right now the converters are called before running the scenario, which prevents using stateful converters.

        Here is an easy fix : change StepCreator#createParametrisedStep to the following

        {code}
        protected Step createParametrisedStep(final String stepAsString, final Map<String, String> tableRow, final Matcher matcher, final Method method, final StepMonitor stepMonitor, String[] groupNames) {
                final Type[] types = method.getGenericParameterTypes();
                final String[] annotationNames = annotatedParameterNames();
                final String[] parameterNames = paranamer.lookupParameterNames(method, false);
                final String translatedStep = translatedStep(stepAsString, tableRow, types, annotationNames, parameterNames);
                
                return new Step() {
                    public StepResult perform() {
                        try {
                            stepMonitor.performing(stepAsString);
                            method.invoke(steps, argsForStep(tableRow, matcher, types, annotationNames, parameterNames));
                            return StepResult.success(stepAsString).withTranslatedText(translatedStep);
                        } catch (Throwable t) {
                            return failureWithOriginalException(stepAsString, t);
                        }
                    }

                    private StepResult failureWithOriginalException(final String stepAsString, Throwable t) {
                        if (t instanceof InvocationTargetException && t.getCause() != null) {
                            if (t.getCause() instanceof PendingError) {
                                return StepResult.pending(stepAsString, (PendingError) t.getCause());
                            } else {
                                return StepResult.failure(stepAsString, t.getCause());
                            }
                        }
                        return StepResult.failure(stepAsString, t);
                    }

                    public StepResult doNotPerform() {
                        return StepResult.notPerformed(stepAsString);
                    }

                };
            }
        {code}
        Right now the converters are called before running the scenario, which prevents using stateful converters.

        The parametrised step with the parameter conversion should be created lazily upon invocation of the Step#perform() method.
        Mauro Talevi made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Bruno Bieth
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: