Skip to content
Permalink
Browse files

Added source files

Added .java source files both for the core, and the shopping sample
application for JavaFX.
  • Loading branch information...
bertilmuth committed Sep 27, 2016
1 parent d2b7d94 commit 494c8991f5675e5ca03edac05b0659a7811ed6d3
Showing with 2,868 additions and 47 deletions.
  1. +6 −47 .gitignore
  2. +19 −0 requirementsascodecore/build.gradle
  3. +41 −0 requirementsascodecore/src/main/java/org/requirementsascode/Actor.java
  4. +105 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCase.java
  5. +114 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCaseFlow.java
  6. +117 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCaseModel.java
  7. +39 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCaseModelElement.java
  8. +200 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCaseModelRun.java
  9. +193 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCaseStep.java
  10. +26 −0 requirementsascodecore/src/main/java/org/requirementsascode/UseCaseStepCondition.java
  11. +4 −0 requirementsascodecore/src/main/java/org/requirementsascode/event/AutonomousSystemReactionEvent.java
  12. +9 −0 ...mentsascodecore/src/main/java/org/requirementsascode/exception/ElementAlreadyExistsException.java
  13. +9 −0 ...ntsascodecore/src/main/java/org/requirementsascode/exception/MissingUseCaseStepPartException.java
  14. +15 −0 ...ascodecore/src/main/java/org/requirementsascode/exception/MoreThanOneStepCouldReactException.java
  15. +9 −0 ...ementsascodecore/src/main/java/org/requirementsascode/exception/NoSuchElementExistsException.java
  16. +115 −0 requirementsascodecore/src/test/java/org/requirementsascode/AbstractTestCase.java
  17. +12 −0 requirementsascodecore/src/test/java/org/requirementsascode/AllTests.java
  18. +294 −0 requirementsascodecore/src/test/java/org/requirementsascode/CreateModelTest.java
  19. +90 −0 requirementsascodecore/src/test/java/org/requirementsascode/ExceptionHandlingTest.java
  20. +159 −0 requirementsascodecore/src/test/java/org/requirementsascode/ExceptionsThrownTest.java
  21. +486 −0 requirementsascodecore/src/test/java/org/requirementsascode/SystemReactionTest.java
  22. +6 −0 requirementsascodecore/src/test/java/org/requirementsascode/event/EnteredNumber.java
  23. +24 −0 requirementsascodecore/src/test/java/org/requirementsascode/event/EnteredText.java
  24. +26 −0 requirementsascodesamples/shoppingappjavafx/build.gradle
  25. +32 −0 requirementsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/domain/Product.java
  26. +40 −0 ...mentsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/domain/ProductContainer.java
  27. +17 −0 ...irementsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/domain/PurchaseOrder.java
  28. +82 −0 ...tsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/domain/ShippingInformation.java
  29. +16 −0 requirementsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/domain/Stock.java
  30. +67 −0 ...mentsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/gui/ShoppingApplication.java
  31. +67 −0 ...codesamples/shoppingappjavafx/src/main/java/shoppingfxexample/gui/ShoppingApplicationDisplay.java
  32. +61 −0 ...pjavafx/src/main/java/shoppingfxexample/gui/controller/DisplayPurchaseOrderSummaryController.java
  33. +89 −0 ...ingappjavafx/src/main/java/shoppingfxexample/gui/controller/DisplayStockedProductsController.java
  34. +43 −0 ...gappjavafx/src/main/java/shoppingfxexample/gui/controller/EnterShippingInformationController.java
  35. +27 −0 ...mples/shoppingappjavafx/src/main/java/shoppingfxexample/gui/fxml/DisplayPurchaseOrderSummary.fxml
  36. +35 −0 ...odesamples/shoppingappjavafx/src/main/java/shoppingfxexample/gui/fxml/DisplayStockedProducts.fxml
  37. +21 −0 ...esamples/shoppingappjavafx/src/main/java/shoppingfxexample/gui/fxml/EnterShippingInformation.fxml
  38. +79 −0 ...amples/shoppingappjavafx/src/main/java/shoppingfxexample/usecase/ShoppingExampleUseCaseModel.java
  39. +15 −0 ...entsascodesamples/shoppingappjavafx/src/main/java/shoppingfxexample/usecase/event/BuyProduct.java
  40. +17 −0 ...codesamples/shoppingappjavafx/src/main/java/shoppingfxexample/usecase/event/CheckoutPurchase.java
  41. +24 −0 ...pjavafx/src/main/java/shoppingfxexample/usecase/event/DisplayStockedProductsAndPurchaseOrder.java
  42. +16 −0 ...les/shoppingappjavafx/src/main/java/shoppingfxexample/usecase/event/EnterShippingInformation.java
  43. +2 −0 settings.gradle
@@ -1,47 +1,6 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.gradle
.project
.settings
.classpath
build
bin
@@ -0,0 +1,19 @@
version = '0.1'

apply plugin: 'java'
apply plugin: 'jacoco'

repositories {
mavenCentral()
}

jar {
manifest {
attributes 'Implementation-Title': 'Requirements as Code - Core',
'Implementation-Version': version
}
}

dependencies {
testCompile 'junit:junit:4.12'
}
@@ -0,0 +1,41 @@
package org.requirementsascode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class Actor extends UseCaseModelElement{
private Map<UseCase, List<UseCaseStep>> useCaseToStepMap;

Actor(String name, UseCaseModel useCaseModel) {
super(name, useCaseModel);
this.useCaseToStepMap = new HashMap<>();
}

public Set<UseCase> getUseCases() {
Set<UseCase> useCases = useCaseToStepMap.keySet();
return Collections.unmodifiableSet(useCases);
}

public List<UseCaseStep> getUseCaseSteps(UseCase useCase) {
List<UseCaseStep> steps = getModifiableUseCaseStepsList(useCase);
return Collections.unmodifiableList(steps);
}

void newStep(UseCase namedUseCase, UseCaseStep namedUseCaseStep) {
Objects.requireNonNull(namedUseCase);
Objects.requireNonNull(namedUseCaseStep);

List<UseCaseStep> steps = getModifiableUseCaseStepsList(namedUseCase);
steps.add(namedUseCaseStep);
}

private List<UseCaseStep> getModifiableUseCaseStepsList(UseCase useCase) {
useCaseToStepMap.putIfAbsent(useCase, new ArrayList<>());
return useCaseToStepMap.get(useCase);
}
}
@@ -0,0 +1,105 @@
package org.requirementsascode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;

import org.requirementsascode.UseCaseFlow.ConditionalPart;
import org.requirementsascode.exception.ElementAlreadyExistsException;
import org.requirementsascode.exception.NoSuchElementExistsException;

public class UseCase extends UseCaseModelElement{
private List<UseCaseFlow> flows;
private LinkedList<UseCaseStep> steps;
private ConditionalPart basicFlow;

UseCase(String name, UseCaseModel useCaseModel) {
super(name, useCaseModel);
this.flows = new ArrayList<>();
this.steps = new LinkedList<>();
this.basicFlow = newFlow("Basic Flow");
}

public ConditionalPart basicFlow() {
return basicFlow;
}

public ConditionalPart newFlow(String flowName) {
Objects.requireNonNull(flowName);

if(hasFlow(flowName)){
throw new ElementAlreadyExistsException(flowName);
}
UseCaseFlow flow = new UseCaseFlow(flowName, this);
return flow.newConditionalPart();
}

void addFlow(UseCaseFlow flow){
Objects.requireNonNull(flow);

flows.add(flow);
}

public UseCaseFlow getFlow(String flowName) {
Objects.requireNonNull(flowName);

Optional<UseCaseFlow> optionalFlow = flows.stream().filter(flow -> flowName.equals(flow.getName())).findAny();
if(!optionalFlow.isPresent()){
throw new NoSuchElementExistsException(flowName);
}
return optionalFlow.get();
}

public List<UseCaseFlow> getFlows() {
return Collections.unmodifiableList(flows);
}

public UseCaseStep getStep(String stepName) {
Objects.requireNonNull(stepName);

Optional<UseCaseStep> optionalStep = steps.stream().filter(step -> stepName.equals(step.getName())).findAny();
if(!optionalStep.isPresent()){
throw new NoSuchElementExistsException(stepName);
}
return optionalStep.get();
}

UseCaseStep newStep(String stepName, UseCaseFlow flow, UseCaseStep previousStep, Predicate<UseCaseModelRun> predicate) {
Objects.requireNonNull(stepName);
Objects.requireNonNull(flow);

if(hasStep(stepName)){
throw new ElementAlreadyExistsException(stepName);
}
UseCaseStep newStep = new UseCaseStep(stepName, flow, previousStep, predicate);
return newStep;
}

void addStep(UseCaseStep step){
Objects.requireNonNull(step);

steps.add(step);
}

public boolean hasStep(String stepName) {
Objects.requireNonNull(stepName);

boolean hasStep = steps.stream().anyMatch(step -> stepName.equals(step.getName()));
return hasStep;
}

public boolean hasFlow(String flowName) {
Objects.requireNonNull(flowName);

boolean hasStep = flows.stream().anyMatch(flow -> flowName.equals(flow.getName()));
return hasStep;
}

public List<UseCaseStep> getUseCaseSteps() {
return Collections.unmodifiableList(steps);
}
}
@@ -0,0 +1,114 @@
package org.requirementsascode;

import java.util.Objects;
import java.util.UUID;
import java.util.function.Predicate;
import static org.requirementsascode.UseCaseStepCondition.*;

public class UseCaseFlow extends UseCaseModelElement{
private UseCase useCase;
private ConditionalPart conditionalPart;

public UseCaseFlow(String name, UseCase useCase) {
super(name, useCase.getUseCaseModel());

Objects.requireNonNull(useCase);
this.useCase = useCase;
this.useCase.addFlow(this);
}

public UseCase getUseCase() {
return useCase;
}

ConditionalPart newConditionalPart() {
conditionalPart = new ConditionalPart();
return conditionalPart;
}

void continueAfter(String continueAfterStepName, UseCaseStep stepBeforeJumpHappens) {
Objects.requireNonNull(continueAfterStepName);
Objects.requireNonNull(stepBeforeJumpHappens);

continueAfter(continueAfterStepName, stepBeforeJumpHappens, null);
}

private void continueAfter(String continueAfterStepName, UseCaseStep stepBeforeJumpHappens, Predicate<UseCaseModelRun> predicate) {
UseCaseStep continueAfterStep = getUseCase().getStep(continueAfterStepName);
String stepWhereJumpHappensName = uniqueStepWhereJumpHappensName(continueAfterStepName);

newStep(stepWhereJumpHappensName, stepBeforeJumpHappens, predicate)
.system(jumpTo(continueAfterStep));
}

private UseCaseStep newStep(String stepName, UseCaseStep previousStep, Predicate<UseCaseModelRun> predicate) {
UseCaseStep stepToLeave = getUseCase().newStep(
stepName,
this,
previousStep,
predicate);
return stepToLeave;
}

Runnable jumpTo(UseCaseStep stepToContinueAfter) {
return () -> getUseCaseModel().run().setLatestStep(stepToContinueAfter);
}

private String uniqueStepWhereJumpHappensName(String stepName) {
return UUID.randomUUID() + ": Continue with " + stepName;
}

public class ConditionalPart {
private Predicate<UseCaseModelRun> stepPredicate;
private Predicate<UseCaseModelRun> completePredicate;


private ConditionalPart() {
stepPredicate = inDifferentFlow();
}

private Predicate<UseCaseModelRun> inDifferentFlow() {
Predicate<UseCaseModelRun> alternativeFlowPredicate =
isSystemInDifferentFlowThan(UseCaseFlow.this);
return alternativeFlowPredicate;
}

public UseCaseStep newStep(String stepName) {
Objects.requireNonNull(stepName);

UseCaseStep newStep = UseCaseFlow.this.newStep(stepName, null, completePredicate);

return newStep;
}

public ConditionalPart atFirst() {
stepPredicate = inDifferentFlow().and(atFirstStep());
completePredicate = stepPredicate;
return this;
}

public ConditionalPart after(String stepName) {
Objects.requireNonNull(stepName);

UseCaseStep useCaseStep = useCase.getStep(stepName);
stepPredicate = inDifferentFlow().and(afterStep(useCaseStep));
completePredicate = stepPredicate;

return this;
}

public ConditionalPart when(Predicate<UseCaseModelRun> whenPredicate) {
completePredicate = stepPredicate.and(whenPredicate);
return this;
}


public UseCase continueAfter(String stepName) {
Objects.requireNonNull(stepName);

UseCaseFlow.this.continueAfter(stepName, null, completePredicate);

return getUseCase();
}
}
}

0 comments on commit 494c899

Please sign in to comment.
You can’t perform that action at this time.