public ContinuesAt(String stepName, UseCase useCase) { super(stepName, ((FlowStep)useCase.findStep(stepName)).getPreviousStepInFlow().orElse(null)); } }
void setReactWhile(Condition reactWhileCondition) { this.reactWhile = reactWhileCondition; createLoop(); } private void createLoop() {
/** * Convenience method that returns the condition of the flow. * * <p> * Internally this calls the method of the same name of the first step in the * flow. * * @return the condition */ public Optional<Condition> getCondition() { Optional<Condition> condition = getFirstStep().flatMap(step -> step.getCondition()); return condition; } }
public ContinuesWithoutAlternativeAt(String continueAtStepName, FlowStep currentStep) { super(continueAtStepName); FlowStep continueAtStep = ((FlowStep) currentStep.getUseCase().findStep(continueAtStepName)); continueAtStep.orAfter(currentStep); }
/** * Returns the flow the latest step that has been run is contained in. * * @return the latest flow run */ public Optional<Flow> getLatestFlow() { return getLatestStep().filter(step -> step instanceof FlowStep).map(step -> ((FlowStep)step).getFlow()); }
@Test public void createsTwoStepsInBasicFlowAndCheckIfTheyExistByIndex() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); List<FlowStep> steps = useCasePart.getUseCase().getBasicFlow().getSteps(); assertEquals(2, steps.size()); assertEquals(SYSTEM_DISPLAYS_TEXT, steps.get(0).getName()); assertEquals(SYSTEM_DISPLAYS_TEXT_AGAIN, steps.get(1).getName()); }
private void createLoop() { getFlowPosition().orAfter(this); }
private void enableStartOfFirstStepOfIncludedFlowAfterIncludeStep(FlowStep firstStepOfIncludedFlow) { firstStepOfIncludedFlow.orAfter(includeStep); } }
@SuppressWarnings("rawtypes") @Override public Object exec(List arguments) throws TemplateModelException { if (arguments.size() != 1) { throw new TemplateModelException("Wrong number of arguments. Must be 1."); } Step step = getStep(arguments.get(0)); String reactWhile = ""; if (step instanceof FlowStep) { Condition reactWhileCondition = ((FlowStep) step).getReactWhile(); if (reactWhileCondition != null) { reactWhile = REACT_WHILE_PREFIX + getLowerCaseWordsOfClassName(reactWhileCondition.getClass()) + REACT_WHILE_POSTFIX; } } return new SimpleScalar(reactWhile); }
/** * Includes the use case with the specified name. * * The runner starts the included use case right after the current step. The * runner returns to the current flow when it reaches the end of an included * flow. The runner then continues after the current step of the current flow. * * @param useCaseName * the name of the use case to include * @return the step system part, to ease creation of further steps and flows * @throws NoSuchElementInModel * if the included use case has not been specified before */ public StepSystemPart<ModelRunner> includesUseCase(String useCaseName) { FlowStep flowStep = (FlowStep) step; UseCase includedUseCase = flowStep.getModel().findUseCase(useCaseName); StepSystemPart<ModelRunner> stepSystemPart = as(systemActor) .system(new IncludesUseCase(includedUseCase, flowStep)); return stepSystemPart; }
/** * Returns the steps contained in this flow. Do not modify the returned * collection directly. * * @return a collection of the steps */ public List<FlowStep> getSteps() { List<FlowStep> steps = getUseCase().getModifiableSteps().stream() .filter(step -> step instanceof FlowStep) .map(step -> (FlowStep)step) .filter(step -> this.equals(step.getFlow())) .collect(Collectors.toList()); return Collections.unmodifiableList(steps); }
@Test public void createsOneStepInAlternativeFlowAndCheckIfItExistsByIndex() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()).flow(ALTERNATIVE_FLOW) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); List<FlowStep> steps = useCasePart.getUseCase().findFlow(ALTERNATIVE_FLOW).getSteps(); assertEquals(1, steps.size()); assertEquals(SYSTEM_DISPLAYS_TEXT_AGAIN, steps.get(0).getName()); }
/** * Convenience method that returns the position of the flow (as defined e.g. by * "InsteadOf"). * * <p> * Internally this calls the method of the same name of the first step in the * flow. * * @return the flow position, or null if the flow is empty. */ public FlowPosition getFlowPosition() { FlowPosition flowPosition = getFirstStep().map(step -> step.getFlowPosition()).orElse(null); return flowPosition; }
@Override public boolean isRunnerAtRightPositionFor(FlowStep step, ModelRunner modelRunner) { FlowStep previousStep = step.getPreviousStepInFlow().orElse(null); After after = new After(previousStep); return after.test(modelRunner); } }
private boolean isAtEndOfIncludedFlow() { Optional<FlowStep> lastStepOfRunningFlow = getLatestStep().map(ls -> getLastStepOf(((FlowStep)ls).getFlow())); boolean result = getLatestStep() .map(ls -> ls.getUseCase().equals(includedUseCase) && ls.equals(lastStepOfRunningFlow.get())) .orElse(false); return result; }
@Test public void createsSingleStepWithNoPreviousStep() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()); Collection<Step> steps = useCasePart.getUseCase().getSteps(); assertEquals(1, steps.size()); Optional<FlowStep> previousStep = ((FlowStep) steps.iterator().next()).getPreviousStepInFlow(); assertFalse(previousStep.isPresent()); }
@Test public void createsTwoStepsInDifferentFlowsThatBothHaveNoPreviousSteps() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart .basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .flow(ALTERNATIVE_FLOW) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); FlowStep firstUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT); FlowStep secondUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT_AGAIN); assertFalse(firstUseCaseStep.getPreviousStepInFlow().isPresent()); assertFalse(secondUseCaseStep.getPreviousStepInFlow().isPresent()); }
@Test public void createsTwoStepsAndPreviousStepOfSecondOneIsFirstOne() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); FlowStep firstUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT); FlowStep secondUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT_AGAIN); assertEquals(firstUseCaseStep, secondUseCaseStep.getPreviousStepInFlow().get()); }
@Test public void createsTwoStepsIncrementally() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); modelBuilder.useCase(USE_CASE).basicFlow().step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()); useCasePart = modelBuilder.useCase(USE_CASE); modelBuilder.useCase(USE_CASE).basicFlow() .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); FlowStep firstUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT); FlowStep secondUseCaseStep = (FlowStep)useCasePart.getUseCase().findStep(SYSTEM_DISPLAYS_TEXT_AGAIN); assertEquals(firstUseCaseStep, secondUseCaseStep.getPreviousStepInFlow().get()); }