This is the third article of a series showing how to implement an application according to Hexagonal Architecture, also known as Ports and Adapters pattern, whose author is Dr. Alistair Cockburn.
So far we have seen the application design (Chapter 1) and structure (Chapter 2). As a result of the design, we got two things:
Figure 1: The big picture
The API definition, i.e. the interfaces (driver ports) with methods (use cases) that the application offers to users (driver actors).
getAllRatesByName
and issuePermit
methods).illegallyParkedCar
method).From these two things, we will begin to implement the different modules of the architecture, following a development sequence.
According to Alistair Cockburn (see for example his talk about Hexagonal Architecture at Agiles2020 conference), this development sequence would have some stages:
STAGE | DRIVER SIDE | HEXAGON (APPLICATION) |
DRIVEN SIDE |
---|---|---|---|
(S1) | Test cases | Hardcoded | - |
(S2) | Test cases | Real | Test doubles |
(S3) | Real | Real | Test doubles |
(S4) | Test cases | Real | Real |
(S5) | Real | Real | Real |
We can see that we start with test harness at both sides: first on the left side (S1) and then on the right side (S2).
From that moment on, we add real adapters at both sides: first we change left side technology (S3) and then we change right side technology (S4).
So that finally we get the application running in a production environment with real adapters at both sides (S5).
Some important things to remark:
In this section we will see the first stage in the development sequence: “Test Cases + Hardcoded Hexagon”.
Source code for this stage is available at stage1 tag in BlueZone GitHub Repository.
Figure 2: First development stage: Test Cases + Hardcoded Hexagon
We have these modules:
ForParkingCars
interface methods. Cucumber is a test automation tool built to support BDD (Behavior-Driven Development). If you are interested in BDD and Cucumber, see the Links section at the end of this article.ForCheckingCars
interface methods. To show different testing tools, this time we use TestNG framework, instead of Cucumber.ForParkingCars
and ForCheckingCars
interfaces), and the classes implementing them using hardcoded values (HardCodedCarParker and HardCodedCarChecker). In this first development stage, driven ports aren’t used yet.README.md file at BlueZone GitHub repository explains how to run the application.
Here you can see screen-shots of HTML reports, generated after running test cases:
Figure 3: "for parking cars" test HTML report, generated by Cucumber
Figure 4: "for checking cars" test HTML report, generated by TestNG
In the next stage we implement test doubles as adapters on the right side.
Let’s see.
TODO ASAP
TODO
https://jmgarridopaz.github.io/content/resources.html
https://en.wikipedia.org/wiki/Behavior-driven_development
https://beyondxscratch.com/2019/05/21/behavior-driven-development-from-scratch/