This guide will show how to add unit tests and debug CBA Kotlin scripts.
Add pom.xml to your CBA
.
├── Definitions │ └── definition.json ├── Scripts │ └── kotlin │ └── Script.kt ├── TOSCA-Metadata │ └── TOSCA.meta ├── pom.xml
Add the above pom.xml to your CBA and change artifactId to your-cba-name.
The pom references a parent which defines all test dependencies. The parent also includes a profile (-Pdeploy-cba) which will enrich and publish the CBA to a running CDS instance.
The deploy-cba profile can be configured by setting properties described in the example pom.
mvn clean test
# This will build /target/your-cba-name-1.0.0-SNAPSHOT-cba.zip mvn clean install
# This will build /target/your-cba-name-1.0.0-SNAPSHOT-cba.zip # Enrich CBA and add /target/your-cba-name-1.0.0-SNAPSHOT-enriched-cba.zip # Publish CBA to CDS mvn clean install -Pdeploy-cba
Add Unit tests
. ├── Definitions │ └── definition.json ├── Scripts │ └── kotlin │ └── Script.kt ├── TOSCA-Metadata │ └── TOSCA.meta ├── Tests │ └── kotlin │ └── ScriptTest.kt ├── pom.xml
Kotlin unit tests should be added under /Tests/kotlin as show above. Test files must contain "Test" in the filename, for example ScriptTest.kt or TestScript.kt
Example project:
Libraries:
Debugging
After the pom is added, the CBA can be used in IntelliJ as a maven project.
Create a new empty project
Give it a name
Click the + symbol and select import module
Select the pom.xml in your CBA directory
You should now be able to write, run and debug unit tests
CDS Runtime debuging
Open File → Project Structure
Click the + symbol and select Import Module
Select pom.xml in the CDS root directory
You should now have both your CBA and CDS as modules in the project
Make sure your cds run configuration is setup properly and then start CDS in debug mode
Right-click your cba package and select Open In Terminal
Make sure your cds properties are correct in your CBA pom.xml, then run the below command in the terminal
mvn clean install -Pdeploy-cba
Maven will enrich and deploy your CBA to CDS
You should now be able to place breakpoints in your script
Send your request to CDS and start debugging