/** * Creates a new use case in the current model, and returns a part for building * its details. If a use case with the specified name already exists, returns a * part for the existing use case. * * @param useCaseName * the name of the existing use case / use case to be created. * @return the created / found use case's part. */ public UseCasePart useCase(String useCaseName) { UseCase useCase = model.hasUseCase(useCaseName) ? model.findUseCase(useCaseName) : model.newUseCase(useCaseName); return new UseCasePart(useCase, this); }
/** * 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; }
@Test public void thereIsOnlyOneBasicFlowPerUseCase() { modelBuilder.useCase(USE_CASE); Model model = modelBuilder.build(); UseCase uc = model.findUseCase(USE_CASE); assertEquals(1, uc.getFlows().size()); }
@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()); }
@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()); }
@Test public void useCasesAreUniquelyIdentifiedByName() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); Model model = useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).system(displaysConstantText()) .flow(ALTERNATIVE_FLOW) .step(SYSTEM_DISPLAYS_TEXT_AGAIN).system(displaysConstantText()).build(); assertEquals(1, model.getUseCases().size()); assertEquals(model.findUseCase(USE_CASE), model.getUseCases().iterator().next()); }
@Test public void createsSingleStepThatHandlesSystemEvent() { UseCasePart useCasePart = modelBuilder.useCase(USE_CASE); Model model = useCasePart.basicFlow() .step(SYSTEM_DISPLAYS_TEXT).on(EntersText.class).system(displaysEnteredText()) .build(); UseCase useCase = model.findUseCase(USE_CASE); Collection<Step> steps = useCase.getSteps(); assertEquals(1, steps.size()); Step step = steps.iterator().next(); assertEquals(SYSTEM_DISPLAYS_TEXT, step.getName()); assertEquals(USE_CASE, step.getUseCase().getName()); assertEquals(model.getSystemActor(), step.getActors()[0]); }