Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Drawio
borderfalse
diagramNameCPS DB Testing components diagram
simpleViewerfalse
linksauto
tbstyleinline
lboxfalse
diagramWidth791781
revision34

  • Docker provides a container with running database instance which is used during the test
  • Test container component communicates with Docker via CLI (or Engine API depending on Docker deployment),
    manages required container to be created/started before test and stopped/removed after the test is completed
  • Test container component is used by JUnit test as a Class Rule 
  • The connection to test database is served using standard Spring framework components 

...

Running instance of database for integration test is provided by Test TestContainers Java library component. 

...

Drawio
borderfalse
diagramNameCPS Test Containers life circle mgmt diagram
simpleViewerfalse
width
linksauto
tbstyleinline
lboxfalse
diagramDisplayName
diagramWidth761
revision2


NB. The default remaining test containers removal (on JVM termination) was served by dedicated RYUK container (part of TestContainers library).
However this container requires running as privileged one, so it was disabled in order make TestContainers available on Jenkins. It made it
necessary to explicitly invoke test container removal logic on JVM termination event.


@SpringBootTest

Using @SpringBootTest annotation for tests allows @Autowired Spring components (including JPA repository instances) initialization for testing
same way as it's done on regular Spring Boot application execution. However both CPS Spring Boot application class and associated configuration
are allocated in CPS-REST maven module which is cannot be accessed from CPS-RI module on build (when the tests classes are compiled and executed).

In order to fulfill the @SpringBootTest requirements and to properly initialize DataSource object substitutions for both Spring Boot application
class and configuration (DataSource properties) are set directly within CPS-RI module (test scope).


Drawio
borderfalse
diagramNameCPS Spring boot RI dependencies on build
simpleViewerfalse
width
linksauto
tbstyleinline
lboxfalse
diagramDisplayName
diagramWidth651
revision1


Database initialization notes

...

It should be taken into account the ports exposed for a test containers are defined dynamically to allow concurrent tests executions
and to avoid conflicts with containers already running within a Docker. It means the connection parameters for a newly created test container
require to be set before

Test template


Resources

Frameworks and libraries:

...