Skip to content

Commit

Permalink
les-test reference implementation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Reppel committed Apr 21, 2018
1 parent 9cb3bb8 commit 1035fe1
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "exec",
"cwd": "${workspaceFolder}/samples/tests",
"program": "${workspaceFolder}/cmd/esp/esp",
"env": {},
"args": ["validate"],
"showLog": true
}
"mode": "debug",
"program": "${file}"
},
]
}
67 changes: 67 additions & 0 deletions cmd/eml-compliance-test/.generated.eventsourcing.eml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
EmlVersion: 0.1-alpha
Solution: TODO List
Contexts:
- Name: TODO List
Streams:
- Stream: User
Commands:
- Command:
Name: Register
Parameters:
- Name: userId
Type: string
Rules:
- IsRequired
- Name: notificationEmail
Type: string
Rules: []
Preconditions: []
Postconditions:
- UserRegistered
Events:
- Event:
Name: UserRegistered
Properties:
- Name: userId
Type: string
- Name: notificationEmail
Type: string
- Stream: TodoItem
Commands:
- Command:
Name: AddItem
Parameters:
- Name: userId
Type: string
Rules:
- MustExistIn UserLookup
- Name: description
Type: string
Rules: []
- Name: todoitemId
Type: string
Rules:
- IsRequired
Preconditions: []
Postconditions:
- TodoItemAdded
Events:
- Event:
Name: TodoItemAdded
Properties:
- Name: description
Type: string
- Name: todoitemId
Type: string
Readmodels:
- Readmodel:
Name: UserLookup
Key: userId
SubscribesTo:
- UserRegistered
- Readmodel:
Name: TODOList
Key: todoitemId
SubscribesTo:
- TodoItemAdded
Errors: []
2 changes: 2 additions & 0 deletions cmd/eml-compliance-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api

67 changes: 67 additions & 0 deletions cmd/eml-compliance-test/Eventsourcing.eml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
EmlVersion: 0.1-alpha
Solution: TODO List
Contexts:
- Name: TODO List
Streams:
- Stream: User
Commands:
- Command:
Name: Register
Parameters:
- Name: userId
Type: string
Rules:
- IsRequired
- Name: notificationEmail
Type: string
Rules: []
Preconditions: []
Postconditions:
- UserRegistered
Events:
- Event:
Name: UserRegistered
Properties:
- Name: userId
Type: string
- Name: notificationEmail
Type: string
- Stream: TodoItem
Commands:
- Command:
Name: AddItem
Parameters:
- Name: userId
Type: string
Rules:
- MustExistIn UserLookup
- Name: description
Type: string
Rules: []
- Name: todoitemId
Type: string
Rules:
- IsRequired
Preconditions: []
Postconditions:
- TodoItemAdded
Events:
- Event:
Name: TodoItemAdded
Properties:
- Name: description
Type: string
- Name: todoitemId
Type: string
Readmodels:
- Readmodel:
Name: UserLookup
Key: userId
SubscribesTo:
- UserRegistered
- Readmodel:
Name: TODOList
Key: todoitemId
SubscribesTo:
- TodoItemAdded
Errors: []
11 changes: 11 additions & 0 deletions cmd/eml-compliance-test/Eventstorming.emd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TODO List
# A reference system which exercises all available features in EMD 0.10.1-alpha.

Register-> // userId, notificationEmail
User Registered // userId, notificationEmail
UserLookup* // userId, notificationEmail

Add Item-> // userId, description
TodoItem Added // description
TODO List* // todoitemId, description

33 changes: 33 additions & 0 deletions cmd/eml-compliance-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
SHELL := /bin/bash

.PHONY: test
test:
go run main.go

.PHONY: setup
setup: build-les build-les-node build-api

.PHONY: teardown
teardown:
pushd api \
&& docker-compose down \
&& popd \
&& rm -fr api

.PHONY: build-les
build-les:
cd ../les \
&& go build

.PHONY: build-les-node
build-les-node:
cd ../les-node \
&& go build

.PHONY: build-api
build-api:
../les/les convert \
&& ../les-node/les-node -b \
&& cd api && npm install && docker-compose up -d \
&& docker-compose restart api # workaround for race condition (eventstore not yet available when API starts)

12 changes: 12 additions & 0 deletions cmd/eml-compliance-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Event Markup Language Compliance Test

Tests whether an API created from EML by a builder such as les-node complies with the EML specification.

* Are all the command processor end points working?
* Are the read models working?
* Are all the business rules implemented?
* Are the required validation errors returned when executing invalid commands?

## Howto

```make setup && sleep 1 && make test```
113 changes: 113 additions & 0 deletions cmd/eml-compliance-test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Event Markup Language Compliance Test
Tests whether an API created from EML by a builder such as les-node complies with the EML specification.
* Are all the command processor end points working?
* Are the read models working?
* Are all the business rules implemented?
* Are the required validation errors returned when executing invalid commands?
*/
package main

import (
"github.com/verdverm/frisby"
)

const apiURI = "http://localhost:3001/api/v1"
const testUserID = "4481c18058aa494fb033b65665c38de2"

func main() {
addingTodoListItemForUnknownUserFails()
// When
registeringUser()
// Then
userLookupReadmodelContainsUser()

// When
addingTodoListItem()
// Then
todoListContainsNewItem()
// omittingMandatoryCommandParameterFails()

frisby.Global.PrintReport()
}

func addingTodoListItemForUnknownUserFails() {
frisby.Create("Executing valid Command succeeds.").
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json, text/plain, */*").
Post(apiURI+"/TodoItem/AddItem").
SetJson(todoItem{
UserID: testUserID,
Description: "Carpe Diem",
TodoitemID: "10000"}).
Send().
ExpectStatus(400).
ExpectJson("message.0.field", "userId").
ExpectJson("message.0.msg", "userId does not exist.").
ExpectJsonLength("message", 1)
}

func registeringUser() {
frisby.Create("Executing valid registeringUser Command succeeds.").
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json, text/plain, */*").
Post(apiURI + "/User/Register").
SetJson(user{UserID: testUserID, NotificationEmail: "[email protected]"}).
Send().
ExpectStatus(202)
}

func addingTodoListItem() {
frisby.Create("Executing valid Command succeeds.").
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json, text/plain, */*").
Post(apiURI + "/TodoItem/AddItem").
SetJson(todoItem{UserID: testUserID, Description: "Carpe Diem", TodoitemID: "10000"}).
Send().
ExpectStatus(202)
}

func userLookupReadmodelContainsUser() {
frisby.Create("GET UserLookup Read Model succeeds.").
Get(apiURI+"/r/UserLookup").
Send().
ExpectStatus(200).
ExpectJson("0.userId", testUserID).
ExpectJson("0.notificationEmail", "[email protected]")
}

func todoListContainsNewItem() {
frisby.Create("GET Read Model succeeds.").
Get(apiURI+"/r/TODOList").
Send().
ExpectStatus(200).
ExpectJson("0.todoitemId", "10000").
ExpectJson("0.description", "Carpe Diem")
}

func omittingMandatoryCommandParameterFails() {
frisby.Create("Omitting mandatory field fails.").
SetHeader("Content-Type", "application/json").
SetHeader("Accept", "application/json, text/plain, */*").
Post(apiURI+"/TodoItem/AddItem").
SetJson(todoItem{Description: "Carpe Diem", TodoitemID: ""}).
Send().
ExpectStatus(400).
ExpectJson("message.0.field", "todoitemId").
ExpectJson("message.0.msg", "todoitemId is a required field.").
ExpectJsonLength("message", 1)
}

type user struct {
UserID string `json:"userId"`
NotificationEmail string `json:"notificationEmail"`
}

type todoItem struct {
UserID string `json:"userId"`
TodoitemID string `json:"todoitemId"`
Description string `json:"description"`
}

0 comments on commit 1035fe1

Please sign in to comment.