Michael Hoennig
2022-10-21 8eab3b7cd55ba45cd589f7f5e5aef95be190270c
commit | author | age
b433f9 1 # hsadminNg Development
e0b3d2 2
5b8688 3 This documents gives an overview of the development environment and tools.
H 4 For architecture consider the files in the `doc` and `adr` folder.
5
512651 6 <!-- generated TOC begin: -->
MH 7 - [Setting up the Development Environment](#setting-up-the-development-environment)
4721d1 8   - [SDKMAN](#sdkman)
MH 9   - [PostgreSQL Server](#postgresql-server)
10   - [Markdown](#markdown)
11     - [Render Markdown embedded PlantUML](#render-markdown-embedded-plantuml)
c31956 12     - [Render Markdown Embedded Mermaid Diagrams](#render-markdown-embedded-mermaid-diagrams)
7d4815 13   - [IDE Specific Settings](#ide-specific-settings)
MH 14     - [IntelliJ IDEA](#intellij-idea)
4721d1 15   - [Other Tools](#other-tools)
512651 16 - [Running the SQL files](#running-the-sql-files)
4721d1 17   - [For RBAC](#for-rbac)
MH 18   - [For Historization](#for-historization)
7d4815 19 - [Coding Guidelines](#coding-guidelines)
MH 20   - [Directory and Package Structure](#directory-and-package-structure)
21     - [General Directory Structure](#general-directory-structure)
22     - [Source Code Package Structure](#source-code-package-structure)
23   - [Spotless Code Formatting](#spotless-code-formatting)
24   - [JaCoCo Test Code Coverage Check](#jacoco-test-code-coverage-check)
25   - [PiTest Mutation Testing](#pitest-mutation-testing)
cacfba 26     - [Remark](#remark)
7d4815 27   - [OWASP Security Vulnerability Check](#owasp-security-vulnerability-check)
MH 28   - [Dependency-License-Compatibility](#dependency-license-compatibility)
29   - [Dependency Version Upgrade](#dependency-version-upgrade)
30 - [How To ...](#how-to-...)
c31956 31   - [How to Configure .pgpass for the Default PostgreSQL Database?](#how-to-configure-.pgpass-for-the-default-postgresql-database?)
e51485 32   - [How to Run the Tests Against a Local User-Space Podman Daemon?](#how-to-run-the-tests-against-a-local-user-space-podman-daemon?)
cacfba 33     - [Install and Run Podman](#install-and-run-podman)
MH 34     - [Use the Command Line to Run the Tests Against the Podman Daemon ](#use-the-command-line-to-run-the-tests-against-the-podman-daemon-)
35     - [Use IntelliJ IDEA Run the Tests Against the Podman Daemon](#use-intellij-idea-run-the-tests-against-the-podman-daemon)
36     - [~/.testcontainers.properties](#~/.testcontainers.properties)
e51485 37   - [How to Run the Tests Against a Remote Podman or Docker Daemon?](#how-to-run-the-tests-against-a-remote-podman-or-docker-daemon?)
cacfba 38   - [How to Run the Application on a Different Port?](#how-to-run-the-application-on-a-different-port?)
7d4815 39   - [How to Use a Persistent Database for Integration Tests?](#how-to-use-a-persistent-database-for-integration-tests?)
c31956 40   - [How to Amend Liquibase SQL Changesets?](#how-to-amend-liquibase-sql-changesets?)
MH 41   - [How to Re-Generate Spring-Controller-Interfaces from OpenAPI specs?](#how-to-re-generate-spring-controller-interfaces-from-openapi-specs?)
7d4815 42 - [Further Documentation](#further-documentation)
512651 43 <!-- generated TOC end. -->
MH 44
b433f9 45 ## Setting up the Development Environment
e0b3d2 46
5b8688 47 All instructions assume that you're using a current _Linux_ or _MacOS_ operating system.
H 48 Everything is tested on _Ubuntu Linux 22.04_ and _MacOS Monterey (12.4)_.
9beaf5 49
MH 50 To be able to build and run the Java Spring Boot application, you need the following tools:
51
5b8688 52 - Docker 20.x (on MacOS you also need *Docker Desktop* or similar)
433d0e 53 - PostgreSQL Server 13.7-bullseye 
MH 54   (see instructions below to install and run in Docker)
55 - Java JDK at least recent enough to run Gradle
56   (JDK 17.x will be automatically installed by Gradle toolchain support)
9beaf5 57 - Gradle in some not too outdated version (7.4 will be installed via wrapper)
MH 58
59 You also might need an IDE (e.g. *IntelliJ IDEA* or *Eclipse* or *VS Code* with *[STS](https://spring.io/tools)* and a GUI Frontend for *PostgreSQL* like *Postbird*.
60
61 If you have at least Docker, the Java JDK and Gradle installed in appropriate versions and in your `PATH`, then you can start like this:
62
63     cd your-hsadmin-ng-directory
64     
e2bdb9 65     gradle wrapper  # downloads the configured Gradle version into the project
5b8688 66     source .aliases # creates some comforable bash aliases, e.g. 'gw'='./gradlew'
9beaf5 67
MH 68     gw test         # compiles and runs unit- and integration-tests
69     
70     pg-sql-run      # downloads + runs PostgreSQL in a Docker container on localhost:5432
71     gw bootRun      # compiles and runs the application on localhost:8080
72
512651 73     # the following command should reply with "pong":
MH 74     curl http://localhost:8080/api/ping
75
4721d1 76     # the following command should return a JSON array with just all customers:
512651 77     curl \
3fa02d 78         -H 'current-user: superuser-alex@hostsharing.net' \
3541b0 79         http://localhost:8080/api/test/customers
9beaf5 80
9a7b68 81     # the following command should return a JSON array with just all packages visible for the admin of the customer yyy:
4721d1 82     curl \
3fa02d 83         -H 'current-user: superuser-alex@hostsharing.net' -H 'assumed-roles: test_customer#yyy.admin' \
3541b0 84         http://localhost:8080/api/test/packages
4721d1 85
2ac476 86     # add a new customer
MH 87     curl \
3fa02d 88         -H 'current-user: superuser-alex@hostsharing.net' -H "Content-Type: application/json" \
9a7b68 89         -d '{ "prefix":"ttt", "reference":80001, "adminUserName":"admin@ttt.example.com" }' \
3541b0 90         -X POST http://localhost:8080/api/test/customers
512651 91
3fa02d 92 If you wonder who 'superuser-alex@hostsharing.net' and 'superuser-fran@hostsharing.net' are and where the data comes from:
a33cb4 93 Mike and Sven are just example global admin accounts as part of the example data which is automatically inserted in Testcontainers and Development environments.
9a7b68 94 Also try for example 'admin@xxx.example.com' or 'unknown@example.org'.
2ac476 95
5b8688 96 If you want a formatted JSON output, you can pipe the result to `jq` or similar.
9beaf5 97
5f08b4 98 And to see the full, currently implemented, API, open http://localhost:8080/swagger-ui/index.html.
MH 99
9beaf5 100 If you still need to install some of these tools, find some hints in the next chapters. 
MH 101
102
103 ### SDKMAN
104
105 *SdkMan* is not necessary, but helpful to install and switch between different versions of SDKs (Software-Development-Kits) and development tools in general, e.g. *JDK* and *Gradle*.
5b8688 106 It is available for _Linux_ and _MacOS_, _WSL_, _Cygwin_, _Solaris_ and _FreeBSD_.
9beaf5 107
MH 108 You can get it from: https://sdkman.io/.
109
110 <big>**&#9888;**</big>
111 Yeah, the `curl ... | bash` install method looks quite scary;
112 but in a development environment you're downloading executables all the time,
113 e.g. through `npm`, `Maven` or `Gradle` when downloading dependencies.
114 Thus, maybe you should at least use a separate Linux account for development.
115
116 Once it's installed, you can install *JDK* and *Gradle*:
117
118     sdk install java 17.0.3-tem
119     sdk install gradle
120
121     sdk use java 17.0.3-tem # use this to switch between installed JDK versions
122
123
f2d0fb 124 ### PostgreSQL Server
e0b3d2 125
9beaf5 126 You could use any PostgreSQL Server (from version 13 on) installed on your machine.
MH 127 You might amend the port and user settings in `src/main/resources/application.yml`, though.
306f8d 128
9beaf5 129 But the easiest way to run PostgreSQL is via Docker.
e0b3d2 130
f2d0fb 131 Initially, pull an image compatible to current PostgreSQL version of Hostsharing:
d18263 132
9beaf5 133     docker pull postgres:13.7-bullseye 
2fa728 134
306f8d 135 <big>**&#9888;**</big>
MH 136 If we switch the version, please also amend the documentation as well as the aliases file. Thanks! 
137
f2d0fb 138 Create and run a container with the given PostgreSQL version:
e0b3d2 139
f2d0fb 140     docker run --name hsadmin-ng-postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:13.7-bullseye
e0b3d2 141
306f8d 142     # or via alias: 
MH 143     pg-sql-run
144
f2d0fb 145 To check if the PostgreSQL container is running, the following command should list a container with the name "hsadmin-ng-postgres": 
e0b3d2 146
306f8d 147     docker container ls 
e0b3d2 148
f2d0fb 149 Stop the PostgreSQL container:
MH 150     
151     docker stop hsadmin-ng-postgres
306f8d 152     # or via alias: pg-sql-stop
e0b3d2 153
f2d0fb 154 Start the PostgreSQL container again:
e0b3d2 155
f2d0fb 156     docker container start hsadmin-ng-postgres
306f8d 157     # or via alias: pg-sql-start
6efa16 158
f2d0fb 159 Remove the PostgreSQL container:
6efa16 160
f2d0fb 161     docker rm hsadmin-ng-postgres
306f8d 162     
MH 163     # or via alias:
164     pg-sql-remove
165
166 To reset to a clean database, use:
167
168     pg-sql-stop; pg-sql-remove; pg-sql-run
169
170     # or via alias:
171     pg-sql-reset
6efa16 172
f2d0fb 173 After the PostgreSQL container is removed, you need to create it again as shown in "Create and run ..." above.
6efa16 174
e97022 175 Given the container is running, to create a backup in ~/backup, run:
MH 176
306f8d 177     docker exec -i hsadmin-ng-postgres /usr/bin/pg_dump --clean --create -U postgres postgres | gzip -9 > ~/backup/hsadmin-ng-postgres.sql.gz
MH 178
179     # or via alias:
180     pg-sql-backup >~/backup/hsadmin-ng-postgres.sql.gz
e97022 181
MH 182
183 Again, given the container is running, to restore the backup from ~/backup, run:
184
185     gunzip --stdout --keep ~/backup/hsadmin-ng-postgres.sql.gz | docker exec -i hsadmin-ng-postgres psql -U postgres -d postgres
306f8d 186
MH 187     # or via alias:
188     pg-sql-restore <~/backup/hsadmin-ng-postgres.sql.gz
e97022 189
MH 190
512651 191 ### Markdown
6efa16 192
512651 193 To generate the TOC (Table of Contents), a little bash script from a
MH 194 [Blog Article](https://medium.com/@acrodriguez/one-liner-to-generate-a-markdown-toc-f5292112fd14) was used.
195
c31956 196 Given this is in PATH as `md-toc`, use:
MH 197
198 ```shell
199 md-toc <README.md 2 4 | sed -e 's/^    //g'
200 ```
201
512651 202 To render the Markdown files, especially to watch embedded PlantUML diagrams, you can use one of the following methods:
MH 203
204 #### Render Markdown embedded PlantUML
205
206 Can you see the following diagram right in your IDE?
5b8688 207 I mean a real graphic diagram, not just some markup code.
6efa16 208
f2d0fb 209 ```plantuml
MH 210 @startuml
211 me -> you: Can you see this diagram?
212 you -> me: Sorry, I don't :-(
213 me -> you: Install some tooling!
214 @enduml
215 ```
6efa16 216
f2d0fb 217 If not, you need to install some tooling.
6efa16 218
512651 219 ##### for IntelliJ IDEA (or derived products)
6efa16 220
18f323 221 You just need the bundled Markdown plugin enabled and install and activate the PlantUML plugin in its [settings](jetbrains://idea/settings?name=Languages+%26+Frameworks--Markdown). 
6efa16 222
f2d0fb 223 You might also need to install Graphviz on your operating system.
MH 224 For Debian-based Linux systems this might work:
7ba20b 225
f2d0fb 226 ```sh
MH 227 sudo apt install graphviz
228 ```
1284c2 229
MH 230
512651 231 ##### Ubuntu Linux command line
7ba20b 232
f2d0fb 233 ```sh
MH 234 sudo apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-extra-utils texlive-latex-extra pandoc-plantuml-filter
235 ```
7ba20b 236
f2d0fb 237 ```sh
MH 238 pandoc --filter pandoc-plantuml rbac.md -o rbac.pdf
239 ```
7ba20b 240
512651 241 ##### for other IDEs / operating systems
c31956 242
MH 243 If you have figured out how it works, please add instructions above this section.
244
245 #### Render Markdown Embedded Mermaid Diagrams
246
247 The source of RBAC role diagrams are much easier to read with Mermaid than with PlantUML or GraphViz, that's the main reason Mermaid ist used too.
248
249 Can you see the following diagram right in your IDE?
250 I mean a real graphic diagram, not just some markup code.
251 @startuml
252 me -> you: Can you see this diagram?
253 you -> me: Sorry, I don't :-(
254 me -> you: Install some tooling!
255 @enduml
256
257 ```mermaid
258 graph TD;
259     A[Can you see this diagram?];
260     A --> yes;
261     A --> no;
262     no --> F[Follow the instructions below!]
263     F --> yes
264     yes --> E[Then everything is fine.]
265 ```
266
267 If not, you need to install some tooling.
268
269 ##### for IntelliJ IDEA (or derived products)
270
271 You just need the bundled Markdown plugin enabled and install and activate the Mermaid plugin in its [settings](jetbrains://idea/settings?name=Languages+%26+Frameworks--Markdown).
272
273
274 ##### for other IDEs / command-line / operating systems
9a19a6 275
f2d0fb 276 If you have figured out how it works, please add instructions above this section.
306f8d 277
433d0e 278 ### IDE Specific Settings
MH 279
280 #### IntelliJ IDEA
281
282 Go to [Gradle Settings}(jetbrains://idea/settings?name=Build%2C+Execution%2C+Deployment--Build+Tools--Gradle) and select "Build and run using" and "Run tests using" both to "gradle".
283 Otherwise, settings from `build.gradle`, like compiler arguments, are not applied when compiling through *IntelliJ IDEA*.
284
285 Go to [Annotations Processors](jetbrains://idea/settings?name=Build%2C+Execution%2C+Deployment--Compiler--Annotation+Processors) and activate annotation processing.
286 Otherwise, *IntelliJ IDEA* can't see *Lombok* generated classes 
287 and will show false errors (missing identifiers).
288
512651 289 ### Other Tools
MH 290
5b8688 291 **jq**: a JSON formatter. 
H 292 On _Debian_'oid systems you can install it with `sudo apt-get install jq`.
293 On _MacOS_ you can install it with `brew install jq`, given you have _brew_ installed.
306f8d 294
MH 295 ## Running the SQL files
296
297 ### For RBAC
298
9beaf5 299 The Schema is automatically created via *Liquibase*, a database migration library.
MH 300 Currently, also some test data is automatically created.
306f8d 301
9beaf5 302 To increase the amount of test data, increase the number of generated customers in `2022-07-28-051-hs-customer.sql` and run that
306f8d 303
MH 304 If you already have data, e.g. for customers 0..999 (thus with reference numbers 10000..10999) and want to add another 1000 customers, amend the for loop to 1000...1999 and also uncomment and amend the `CONTINUE WHEN` or `WHERE` conditions in the other test data generators, using the first new customer reference number (in the example that's 11000).
305
306 ### For Historization
307
9beaf5 308 The historization is not yet integrated into the *Liquibase*-scripts.
MH 309 You can explore the prototype as follows:
306f8d 310
MH 311 - start with an empty database
312   (the example tables are currently not compatible with RBAC),
9beaf5 313 - then run `historization.sql` in the database,
MH 314 - finally run `examples.sql` in the database.
03ee2c 315
a2f2fd 316 ## Coding Guidelines
MH 317
318 ### Directory and Package Structure
319
433d0e 320 #### General Directory Structure
MH 321
0486dc 322 `.aliases`
MH 323     Shell-aliases for common tasks.
433d0e 324
0486dc 325 `build/`
MH 326     Output directory for gradle build results. Ignored by git.
433d0e 327
0486dc 328 `build.gradle`
MH 329     Gradle build-file. Contains dependencies and build configurations.
433d0e 330
0486dc 331 `doc/`
MH 332     Contains project documentation.
433d0e 333
0486dc 334 `.editorconfig`
MH 335     Rules for indentation etc. considered by many code editors.
433d0e 336
0486dc 337 `etc/`
MH 338     Miscellaneous configurations, as long as these don't need to be in the rood directory. 
433d0e 339
0486dc 340 `.git/`
MH 341     Git repository. Do not temper with this!
433d0e 342
0486dc 343 `.gitattributes`
MH 344     Git configurations regarding text file format conversion between operating systems. 
433d0e 345
0486dc 346 `.gitignore`
MH 347     Git configuration regarding which files and directories should be ignored (not checked in).
433d0e 348
0486dc 349 `.gradle/`
MH 350     Config files created by `gradle wrapper`. Ignored by git.
351
352 `gradle/`
353     The gradle distribution downloaded by `gradle wrapper`. Ignored by git.
354
355 `gradlew` and `gradlew.bat` use these batches to run gradle for builds etc. 
356
357 `.idea/` (optional)
358     Config and cache files created by *IntelliJ IDEA*. Ignore by git.
359
360 `LICENSE.md`
361     Contains the license used for this software.
362
363 `out/` (optional)
364     Build output created by *IntelliJ IDEA". Ignored by git. 
365
366 `README.md`
367     Contains an overview about how to build the project and the used tools. 
368
369 `.run/` (optional)
370     Created by *IntelliJ IDEA* to contain run and debug configurations.
371
372 `settings.gradle`
373     Configuration file for gradle.
374
375 `sql/`
376     Contains SQL scripts for experiments and useful tasks.
377     Most of this will sooner or later be moved to Liquibase-scripts.
378
379 `src/`
380     The actual source-code, see [Source Code Package Structure](#source-code-package-structure) for details.
381
382 `TODO.md`
383     Requirements of initial project. Do not touch!
384
385 `TODO-progress.png`
386     Generated diagram image of the project progress.
387
388 `tools/`
389     Some shell-scripts to useful tasks.
433d0e 390
MH 391
392 #### Source Code Package Structure
393
394 For the source code itself, the general standard Java directory structure is used, where productive and test code are separated like this:
a2f2fd 395
MH 396 ```
397 src
398     main/
399         java/
400             net.hostsharing.hasadminng/
401         resources/
402         
403     test/
404         java/
405             net.hostsharing.hasadminng/
406         resources/
407 ```
408
409 The Java package structure below contains:
410
411 - config and global (utility) packages,
412   these should not access any other packages within the project
413 - rbac, containing all packages related to the RBAC subsystem
414 - hs, containing Hostsharing business object related packages
415
416 Underneath of rbac and hs, the structure is business oriented, NOT technical / layer -oriented.
417
418 Some of these rules are checked with *ArchUnit* unit tests.
419
80b1e0 420
a2f2fd 421 ### Spotless Code Formatting
MH 422
423 Code formatting for Java is checked via *spotless*.
424 The formatting style can be checked with this command:
425
426 ```shell
427 gw spotlessCheck
428 ```
429
80b1e0 430 This task is also included in `gw build` and `gw check`.
a2f2fd 431
MH 432 To apply formatting rules, use:
433
434 ```shell
435 gw spotlessApply
436 ```
437
a66ed8 438 ### JaCoCo Test Code Coverage Check
MH 439
440 This project uses the JaCoCo test code coverage report with limit checks.
441 It can be executed with:
442
443 ```shell
444 gw jacocoTestReport
445 ```
446
447 This task is also automatically run after `gw test`.
448 It is configured in [build.gradle](build.gradle).
449
450 A report is generated under [build/reports/jacoco/tests/test/index.html](./build/reports/jacoco/test/html/index.html).
451
452 Additionally, quality limits are checked via:
453
454 ```shell
455 gw jacocoTestCoverageVerification
456 ```
457
458 This task is also executed as part of `gw check`.
459
460
7d4815 461 ### PiTest Mutation Testing
MH 462
463 PiTest mutation testing is configured for unit tests.
464 It can be executed with:
465
466 ```shell
467 gw pitest
468 ```
469
470 Classes to be scanned, tests to be executed and thresholds are configured in [build.gradle](build.gradle).
471
472 A report is generated under [build/reports/pitest/index.html](./build/reports/pitest/index.html).
473 A link to the report is also printed after the `pitest` run.
474
475 This task is also executed as part of `gw check`.
476
477 #### Remark
478
479 In this project, there is little business logic in *Java* code;
480 most business code is in *plsql* 
481 and *Java* ist mostly used for mapping REST calls to database queries.
482 This mapping ist mostly done through *Spring* annotations and other implicit code.
483
484 Therefore, there are only few unit tests and thus mutation testing has limited value.
485 We'll see if this changes when the project progresses and more validations are added.
486
487
80b1e0 488 ### OWASP Security Vulnerability Check
MH 489
490 An OWASP security vulnerability is configured and can be utilized by running:
491
492 ```shell
493 gw dependencyCheckAnalyze
494 ```
495
496 This task is also included in `gw build` and `gw check`.
497 It is configured in [build.gradle](build.gradle).
498
499 Often vulnerability reports don't apply to our use cases.
500 Therefore, reports can be [suppressed](./etc/owasp-dependency-check-suppression.xml).
501 In case of suppression, a note must be added to explain why it does not apply to us.
502
503 See also: https://jeremylong.github.io/DependencyCheck/dependency-check-gradle/index.html.
504
c4531c 505 ### Dependency-License-Compatibility
a2f2fd 506
c4531c 507 The `gw check` phase depends on a dependency-license-compatibility check.
MH 508 If any dependency violates the configured [list of allowed licenses](etc/allowed-licenses.json), the build will fail.
509 New licenses can be added to that list after a legal investigation.
510
511 <big>**&#9888;**</big>
512 *GPL* (*GNU General Public License*) is only allowed with classpath exception.
513 Do <u>not</u> use any dependencies under *GPL* without this exception,
80f342 514 except if these offer an alternative license which is allowed.
MH 515 *LGPL* (*GNU <u>Library</u> General Public License*) is also allowed.
c4531c 516
MH 517 To run just the dependency-license-compatibility check, use:
518
519 ```shell
520 gw checkLicense
521 ```
522
523 If the check fails, a report can be found here: The generated license can be found under [dependencies-without-allowed-license.json](/build/reports/dependency-license/dependencies-without-allowed-license.json).
524
525 And to generate a report, use:
526
527 ```shell
528 gw generateLicenseReport
529 ```
530
531 The generated license can be found here: [index.html](build/reports/dependency-license/index.html).
532
533 More information can be found on the [project's website](https://github.com/jk1/Gradle-License-Report).
534
8b4e78 535 ### Dependency Version Upgrade
MH 536
537 Dependency versions can be automatically upgraded to the latest available version:
538
539 ```shell
540 gw useLatestVersions
541 ```
542
543 Afterwards, `gw check` is automatically started.
544 Please only commit+push to master if the check run shows no errors.
545
e51485 546 More infos, e.g. on blacklists see on the [project's website](https://github.com/patrikerdes/gradle-use-latest-versions-plugin).
8b4e78 547
MH 548
c4531c 549 ## How To ...
MH 550
082bdd 551 ### How to Configure .pgpass for the Default PostgreSQL Database?
MH 552
553 To access the default database schema as used during development, add this line to your `.pgpass` file in your users home directory:
554
555 ```
556 localhost:5432:postgres:postgres:password
557 ```
558
559 Amend host and port if necessary.
560
cacfba 561
e51485 562 ### How to Run the Tests Against a Local User-Space Podman Daemon?
cacfba 563
e51485 564 Using a normal Docker daemon running as root has some security issues.
cacfba 565 As an alternative, this chapter shows how you can run a Podman daemon in user-space.
MH 566
567 #### Install and Run Podman
568
569 You can find directions in [this project on Github](https://stackoverflow.com/questions/71549856/testcontainers-with-podman-in-java-tests) 
570
571 Summary for Debian-based Linux systems:
572
573 1. Install Podman, e.g. like this:
574
575  ```shell
e51485 576 sudo apt-get -y install podman
cacfba 577 ```
MH 578
430f75 579 2Then start it like this:
MH 580
581 ```shell
cacfba 582 systemctl --user enable --now podman.socket
MH 583 systemctl --user status podman.socket
584 ls -la /run/user/$UID/podman/podman.sock
430f75 585 ```
MH 586
587 These commands are also available in `.aliases` as `podman-start`.
cacfba 588
MH 589
590 #### Use the Command Line to Run the Tests Against the Podman Daemon 
591
592 1. In a local shell. in which you want to run the tests, set some environment variables:
593
594 ```shell
595 export DOCKER_HOST="unix:///run/user/$UID/podman/podman.sock"
596 export TESTCONTAINERS_RYUK_DISABLED=true
597 ```
598
430f75 599 These commands are also available in `.aliases` as `podman-use`. 
MH 600
cacfba 601 Disabling RYUK is necessary, because it's not supported by Podman.
MH 602 Supposedly this means that containers are not properly cleaned up after test runs,
603 but I could not see any remaining containers after test runs.
604 If we are running into problems with stale containers,
605 we need to register a shutdown-hook in the test source code.
606
607 2. Now You Can Run the Tests
608
609 ```shell
610 gw clean test # gw is from the .aliases file
611 ```
612
613 #### Use IntelliJ IDEA Run the Tests Against the Podman Daemon
614
e51485 615 To run the tests against a Podman Daemon in IntelliJ IDEA too, you also need to set the environment variables `DOCKER_HOST` and `TESTCONTAINERS_RYUK_DISABLED` as show above.
cacfba 616 This can either be done in the environment from which IDEA is started.
7d8d6b 617 Or you can use the run config template for gradle to set these variables:
MH 618
619 ![IntelliJ IDEA Gradle Run Template](./doc/.images/intellij-idea-gradle-run-template.png)
620
621 If you already have Gradle run configs, you need to delete them, so they get re-created from the template.
622 Alternatively you need to add the environment varibles here too:
623
624 ![IntelliJ IDEA Gradle Run Config Example](./doc/.images/intellij-idea-gradle-run-config.png)
625
cacfba 626 Find more information [here](https://www.jetbrains.com/help/idea/run-debug-configuration.html).
MH 627
7d8d6b 628
cacfba 629 #### ~/.testcontainers.properties
MH 630
631 It should be possible to set these environment variables in `~/.testcontainers.properties`,
632 but it did not work so far.
633 Maybe a problem with quoting.
634
635 If you manage to make it work, please amend this documentation, thanks.
636
637
e51485 638 ### How to Run the Tests Against a Remote Podman or Docker Daemon?
cacfba 639
e51485 640 1. On the remote host, you need to have a Podman or Docker daemon running on a port accessible from the Internet. 
cacfba 641 Probably, you want to protect it with a VPN, but that's not part of this documentation.
MH 642
643 e.g. to make Podman listen to a port, run this:
644
645 ```shell
646 podman system service -t 0 tcp:HOST:PORT # please replace HOST+PORT
647 ```
648
649 2. In a local shell. in which you want to run the tests, set some environment variables:
650
651 ```shell
652 export DOCKER_HOST=tcp://HOST:PORT # please replace HOST+PORT again
653 export TESTCONTAINERS_RYUK_DISABLED=true  # only for Podman
654 ```
655
656 Regarding RYUK, see also in the directions for a locally running Podman, above.
657
658 3. Now you can run the tests:
659
660 ```shell
661 gw clean test # gw is from the .aliases file
662 ```
663
e51485 664 For information about how to run the tests in IntelliJ IDEA against a remote Podman daemon, see also in the chapter above just with the HOST:PORT-based DOCKER_HOST.
cacfba 665
MH 666 ### How to Run the Application on a Different Port?
e2bdb9 667
MH 668 By default, `gw bootRun` starts the application on port 8080.
669
670 This port can be changed in
671 [src/main/resources/application.yml](src/main/resources/application.yml) through the property `server.port`.
03ee2c 672
MH 673 ### How to Use a Persistent Database for Integration Tests?
674
675 Usually, the `DataJpaTest` integration tests run against a database in a temporary docker container.
676 As soon as the test ends, the database is gone; this might make debugging difficult.
677
e2bdb9 678 Alternatively, a persistent database could be used by amending the
MH 679 [resources/application.yml](src/main/resources/application.yml) through the property `spring.datasource.url` in [src/test/resources/application.yml](src/test/resources/application.yml) , e.g. to the JDBC-URL from [src/main/resources/application.yml](src/main/resources/application.yml).
03ee2c 680
MH 681 If the persistent database and the temporary database show different results, one of these reasons could be the cause:
682
683 1. You might have some changesets only running in either context,
684    check the `context: ...` in the changeset control lines.
685 2. You might have changes in the database which interfere with the tests,
686    e.g. from a previous run of tests or manually applied.
687    It's best to run `pg-sql-reset && gw bootRun` before each test run, to have a clean database.
c31956 688   
MH 689 ### How to Amend Liquibase SQL Changesets?
2ac476 690
MH 691 Liquibase changesets are meant to be immutable and based on each other.
692 That means, once a changeset is written, it never changes, not even a whitespace or comment.
693 Liquibase is a *database migration tool*, not a *database initialization tool*.
694
695 This, if you need to add change a table, stored procedure or whatever, 
696 create a new changeset and apply `ALTER`, `DROP`, `CREATE OR REPLACE` or whatever SQL commands to perform your changes.
697 These changes will be automatically applied once the application starts up again.
698 This way, any staging or production database will always match the application code. 
699
700 But, during initial development that can be a big hassle because the database structure changes a lot in that stage.
701 Also, the actual structure of the database won't be easily recognized anymore through lots of migration changesets.
702
703 Therefore, during initial development, it's good approach just to amend the existing changesets and delete the database:
704
705 ```shell
706 pg-sql-reset
707 gw bootRun
708 ```
709
710 <big>**&#9888;**</big>
711 Just don't forget switching to the migration mode, once there is a production database!
2eb8b7 712
c31956 713 ### How to Re-Generate Spring-Controller-Interfaces from OpenAPI specs?
MH 714
715 The API is described as OpenAPI specifications in `src/main/resources/api-definition/`.
716
717 Once generated, the interfaces for the Spring-Controllers can be found in `build/generated/sources/openapi`.
718
719 These interfaces have to be implemented by subclasses named `*Controller`.
720
721 All gradle tasks which need the generated interfaces depend on the Gradle task  `processSpring` which controls the code generation.
722 It can also be executed directly:
723
724 ```shell
725 gw processSpring
726 ```
727
766382 728 ### How to Generate Database Table Diagrams?
MH 729
730 Some overview documentation about the database can be generated via [postgresql_autodoc](https://github.com/cbbrowne/autodoc").
731 To make it easier, the command line is included in the `.aliases`, just call:
732
733 ```shell
734 postgres-autodoc
735 ```
736
737 The output will list the generated files.
738
c31956 739
2eb8b7 740 ## Further Documentation
MH 741
742 - the `doc` directory contains architecture concepts and a glossary
743 - TODO.md tracks requirements and progress for the contract of the initial project,
744   please do not amend anything in this document