public ContinuesAfter(String stepName, UseCase useCase) { super(stepName, (FlowStep)useCase.findStep(stepName)); } }
/** * Start the "happy day scenario" where all is fine and dandy. * * @return the flow part to create the steps of the basic flow. */ public FlowPart basicFlow() { Flow useCaseFlow = getUseCase().getBasicFlow(); return new FlowPart(useCaseFlow, this); }
public void enableStartOfIncludedUseCase() { for (Flow includedFlow : includedUseCase.getFlows()) { enableStartOfIncludedFlow(includedFlow); } }
@Test public void flowsAreUniquelyIdentifiedByName() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); UseCase useCase = useCasePart.getUseCase(); useCase.newFlow(ALTERNATIVE_FLOW); Flow existingFlow = useCase.findFlow(ALTERNATIVE_FLOW); assertEquals(2, useCase.getFlows().size()); // This is 2 because the basic flow always exists Iterator<Flow> flowIt = useCase.getFlows().iterator(); assertEquals(useCase.getBasicFlow(), flowIt.next()); assertEquals(existingFlow, flowIt.next()); }
@Test public void createsTwoStepsWithoutFlow() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart .on(EntersText.class).system(displaysEnteredText()) .on(EntersNumber.class).system(displaysEnteredNumber()) .build(); Collection<Step> steps = useCasePart.getUseCase().getSteps(); assertEquals(2, steps.size()); Iterator<Step> stepIt = steps.iterator(); Step step = stepIt.next(); assertEquals("S1", step.getName()); assertEquals(USE_CASE, step.getUseCase().getName()); step = stepIt.next(); assertEquals("S2", step.getName()); assertEquals(USE_CASE, step.getUseCase().getName()); }
@Test public void createsSingleStepThatHandlesUserCommandWithFlow() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); Model model = useCasePart.basicFlow() .step(CUSTOMER_ENTERS_TEXT).user(EntersText.class).system(displaysEnteredText()) .build(); UseCase useCase = useCasePart.getUseCase(); assertFalse(useCase.getBasicFlow().getCondition().isPresent()); Collection<Step> steps = useCase.getSteps(); assertEquals(1, steps.size()); Step step = steps.iterator().next(); assertEquals(CUSTOMER_ENTERS_TEXT, step.getName()); assertEquals(USE_CASE, step.getUseCase().getName()); assertEquals(model.getUserActor(), step.getActors()[0]); }
private String getStepNameOrIncludedUseCase(Step step) { String stepNameOrIncludedUseCase = ""; if (hasSystemReaction(step)) { Consumer<?> systemReaction = step.getSystemReaction(); if (systemReaction instanceof AbstractContinues) { stepNameOrIncludedUseCase = " " + ((AbstractContinues) systemReaction).getStepName(); } else if (systemReaction instanceof IncludesUseCase) { stepNameOrIncludedUseCase = " " + ((IncludesUseCase) systemReaction).getIncludedUseCase().getName(); } } return stepNameOrIncludedUseCase; } }
@Test public void implicitlyCreatesEmptyBasicFlow() { modelBuilder.useCase(USE_CASE); Model model = modelBuilder.build(); UseCase useCase = model.findUseCase(USE_CASE); Collection<Flow> flows = useCase.getFlows(); assertEquals(1, flows.size()); assertEquals(useCase.getBasicFlow(), flows.iterator().next()); assertFalse(useCase.getBasicFlow().getFirstStep().isPresent()); }
/** * Creates a use case with the specified name that belongs to the specified model. * * @param useCaseName * the name of the use case to be created * @param model * the model that will contain the new use case */ UseCase(String useCaseName, Model model) { super(useCaseName, model); this.nameToFlowMap = new LinkedHashMap<>(); this.nameToStepMap = new LinkedHashMap<>(); this.basicFlow = newFlow(BASIC_FLOW); }
@Test public void createsTwoStepsAndCheckIfTheyExistInUseCaseByName() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()); Collection<Step> steps = useCasePart.getUseCase().getSteps(); assertEquals(2, steps.size()); boolean firstUseCaseStepExists = useCasePart.getUseCase().hasStep(SYSTEM_DISPLAYS_TEXT); boolean secondUseCaseStepExists = useCasePart.getUseCase().hasStep(SYSTEM_DISPLAYS_TEXT_AGAIN); assertTrue(firstUseCaseStepExists); assertTrue(secondUseCaseStepExists); }
/** * Returns the steps contained in this use case. * * @return a collection of the steps */ public Collection<Step> getSteps() { Collection<Step> modifiableSteps = getModifiableSteps(); return Collections.unmodifiableCollection(modifiableSteps); }
@Test public void createsNoSteps() { modelBuilder.useCase(USE_CASE); Model model = modelBuilder.build(); UseCase useCase = model.findUseCase(USE_CASE); Collection<Step> steps = useCase.getSteps(); assertEquals(0, steps.size()); }
/** * Creates a step with the specified name that belongs to the specified * use case. * * @param useCase the use case this step belongs to * @param stepName * the name of the step to be created */ Step(String stepName, UseCase useCase) { super(stepName, useCase.getModel()); this.useCase = useCase; }
UseCase newUseCase(String useCaseName) { UseCase useCase = new UseCase(useCaseName, this); saveModelElement(useCase, nameToUseCaseMap); return useCase; }
@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()); }
@Test public void createsSingleStepThatHandlesUserCommandWithUseCaseButWithoutFlow() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); Model model = useCasePart .on(EntersText.class).system(displaysEnteredText()) .build(); UseCase useCase = useCasePart.getUseCase(); Collection<Step> steps = useCase.getSteps(); assertEquals(1, steps.size()); Step step = steps.iterator().next(); assertEquals("S1", step.getName()); assertEquals(USE_CASE, step.getUseCase().getName()); assertEquals(model.getSystemActor(), step.getActors()[0]); }
@Test public void createsSingleUseCase() { modelBuilder.useCase(USE_CASE); Model model = modelBuilder.build(); assertTrue(model.hasUseCase(USE_CASE)); Collection<UseCase> useCases = model.getUseCases(); assertEquals(1, useCases.size()); assertEquals(USE_CASE, useCases.iterator().next().getName()); }
/** * Start a flow with the specified name. * * @param flowName * the name of the flow. * * @return the flow part to create the steps of the flow. */ public FlowPart flow(String flowName) { Flow useCaseFlow = getUseCase().newFlow(flowName); return new FlowPart(useCaseFlow, this); }
Collection<Step> getModifiableSteps() { return getModifiableUseCases().stream().map(useCase -> useCase.getModifiableSteps()) .flatMap(steps -> steps.stream()).collect(Collectors.toList()); }
@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()); }