Three layers template hello world like Java application, back end and downstream microservices with a banal/trivial business logic.
- The frontend asks the user whom too greet, and the user answers e.g.
"world". - The frontend does a HTTP call to the backend microservice asking for an interjection and an adjective (initial part) to be used in the greeting, e.g.
"Hello strange". - The backend does a downstream HTTP call to the far backend microservice asking for an adjective (modifier) with which to color the greeting, e.g.
"strange". - The frontend presents to the user the resulting greeting , e.g.
"Hello, strange world".
| Term | Description | Example |
|---|---|---|
Greeting |
"Hello, strange world!" or "Goodnight, somewhat sleepy dog!" | |
Initial part |
"Hello, strange" or "Goodbye, very dark" | |
Interjection |
"Hello" or "Hi" | |
Modifier |
"strange" or "immensely weird" | |
Greetee |
"world" or "human being" | |
Frontend |
Prompts the user for the greetee, calls downstream to get the rest of the greeting and presents the result | |
Backend |
Calls downstream to the far backend to get the modifier and concatenates it with an interjection to produce the initial part of the greeting | |
Far backend |
Queries an RDBMS to get a random modifier |
- Windows 10
- Java 13
- Maven 3.6.2
- Simplicity
- Write highly testable classes
- High coverage
- Not using overkill technologies and frameworks
- Decoupling
- No superfluous, silly or evident commenting
- Self explanatory code, using descriptive and precise words for method names, variables etc..
- Kill checked exceptions as fast as they are caught, don't rethrow them.
- When relevant and possible, prefer return codes to exceptions to communicate exceptional flow between classes
- This is NOT a library
- This is NOT a framework
- This is NOT a utility repo
- This does not solve any business problems for you
- It is meant as an offer from which you can pick the most appropriate module(s) and code from a working full-fledged three layer microservice-based app with a business logic as simple as you can imagine
- It covers many of the technologies often called upon in such an environment, like e.g. REST, json, resilience, swagger, database, ...
- Maven/surefire/site reporting
- Three layers: Frontend, backend and downstream far backend
| Frontend | Backend | Far backend | Note | |
|---|---|---|---|---|
| ArchUnit | NOT YET | NOT YET | NOT YET | Architecture checker |
| AssertJ | X | X | X | Fluent test layer above Jupiter |
| Checkstyle | X | X | X | Code layout tool |
| Conf2 | X | X | X | Easy configuration, properties etc. |
| doInTransaction | N/A | N/A | X | Database transaction pattern |
| Docker | NOT YET | NOT YET | NOT YET | Self contained (os + app + ...) virtualized application container |
| Elm | ? | N/A | N/A | Functional programming GUI programming tool. Alternative to Web Components. Could probably also exist side-by-side with Web Components. |
| FlyWay | N/A | N/A | X | Database creation and migration |
| H2 | N/A | N/A | X | In-memory database |
| JaCoCo | X | X | X | Code coverage |
| Java 9+ modules | N/A? | NOT YET | NOT YET | |
| JDBC | N/A | N/A | No | In test |
| Jersey | N/A | X | X | |
| Jetty | N/A | X | X | Servlet container |
| Json deserialize | X | X | In test | Rest communication data format |
| Json serialize | N/A | N/A | X | Rest communication data format |
| Junit/Jupiter | X | X | X | Unit tests |
| Logback | X | X | X | |
| Lombok | X | X | X | Getters, setters and other boilerplate code |
| NCSS | Incompat. | Incompat. | Incompat. | Code complexity reporting |
| OWASP | X | X | X | Library security vulnerability reporting |
| PACT | NOT YET | NOT YET | NOT YET | REST server contract testing |
| PiTest | X | X | X | Mutation tests |
| Prometheus | N/A | X | X | Runtime metrics reporting |
| QueryDSL | N/A | N/A | X | Thin fluency layer above JDBC |
| Resilience4J | N/A | NOT YET | X | Resilience guard of downstream calls |
| RestAssured | N/A | NOT YET | X | For testing an application's REST endpoint(s) |
| Rest client | X | X | In test | |
| Rest server | N/A | X | X | Resource API, REST endpoint |
| Independent project | X | X | X | Split parent and children modules for independencies |
| Swagger | N/A | NOT YET | X | Rest API documentation |
| Vavr | N/A | NOT YET | X | Functional programming collection library etc. (e.g. tuples) |
| WireMock | X | X | N/A | Stubs an endpoint being called by some method |
| Web components | NOT YET | N/A | N/A | Frontend browser technology. Alternative to Elm. Could probably also exist side-by-side with Elm. |
- Tidy up the poms!
- Remove overlapping classes when building fat jars
- Liveness and readiness
- Compile all reports to the site directory
- Tidy up all that report/site mess
- Remember to add Prometheus to the data source as well
- Remember to add Prometheus to the logback configurations as well
- Skip plugin/dependency management in favour of letting mama become a properties bom (bill of materials). Only use management when required to solve transitive dependencies problems.
- Consistent naming
- Remove exception rethrows
- Move more common stuff to the common library
- Error page upon HTTP errors
- Docker
- Make DO-s immutable
- Make a Maven archetype of it
- Spring
- Hibernate and/or JPA or other ORM technologies of very high complexity
- AOP, not even for transaction boundaries
- Start the servlet container running the far backend application:
java -jar hellostrangeworld-farbackend\target\hellostrangeworld-farbackend.jar - In the browser, access:
http://localhost:8099/api/Modifier - Refresh the browser to get different database entries
- Run the far backend as described above
- Start the servlet container running the backend application:
java -jar hellostrangeworld-backend\target\hellostrangeworld-backend.jar - In the browser, access:
http://localhost:8089/api/InitialPart - Refresh the browser to get different database entries
- Run the far backend as described above
- Run the backend as described above
- Run the frontend:
java -jar hellostrangeworld-frontend\target\hellostrangeworld-frontend.jar
- Run a complete build
mvn clean install org.pitest:pitest-maven:mutationCoverage
- Run a complete build of the far backend when flyway clean has been run or it has never before been built
cd hellostrangeworld-farbackend&mvn clean flyway:migrate install&cd..
- Run the pi tests:
mvn org.pitest:pitest-maven:mutationCoverage
- Run pi tests on all the applications (Reports: **/target/pit-reports/YYYYMMDDHHmm/index.html)
CLS&mvn -P mutation-tests clean install
- Make a build site (run from the sub roots)
mvn site
- Build the application without tests
CLS&mvn clean install -v -DskipTests=true
- Run the far backend servlet container:
java -ea -cp hellostrangeworld-farbackend/target/* net.barakiroth.hellostrangeworld.farbackend.Main
- Access the metrics
http://localhost:8099/internal/metrics/
or
http://localhost:8089/internal/metrics/
- Find ports listened to in Windows
netstat -aon | find /i "listening" | find /i "8089"
-Kill a process (e.g. when locking a port):
taskkill /F /PID 8089
- Run owasp analysis
mvn -X org.owasp:dependency-check-maven:check -P owasp
- Run checkstyle (Report in ./hellostrangeworld/target/site/checkstyle-aggregate.html)
mvn clean install checkstyle:check site -P checkstyle -Dcheckstyle.config.location=google_checks.xml
- If hung-up on some FlyWay migration:
mvn -pl :hellostrangeworld-farbackend flyway:clean&mvn -pl :hellostrangeworld-farbackend flyway:migrate
- Check dependenies updatability
mvn versions:display-dependency-updates
- Dependency tree
mvn dependency:tree -Dverbose
Producing and consuming JSON or XML in Java REST Services with Jersey and Jackson
Mutation Testing with PITest
Real world mutation testing
My PITEST won't run. Coverage generation minion exited abnormally. I need help to configure my pom.xml properly
Most fundamental use of H2
Hikari leakage
Guide to Resilience4j
Fault tolerance library designed for functional programming
JUnit 5 Tutorial: Writing Assertions With Hamcrest
JUnit test for System.out.println()