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
5 Comments
Joachim Blixt (Samsung)
Hi,
I am trying to build,
mvn clean
test,
the example provided here but it fails and it looks like cba-parent:pom:1.0.0-SNAPSHOT is not found and it is referred from test-blueprint-kotlin-parent:1.0.0-SNAPSHOT.BR
Joachim
Joachim Blixt (Samsung)
Hi again,
Now I see that the attached example is wrong as the groupId of parent is wrong. It is correct in the pom.xml example on wiki. After building CDS I could build the project.
BR
Joachim
Jozsef Csongvai
Thanks Joachim Blixt (Samsung)
I have updated the example
Jozsef Csongvai
currently mvn test is broken with version 1.1.0-SNAPSHOT. A fix has been submitted
https://gerrit.onap.org/r/c/ccsdk/cds/+/118189
Joachim Blixt (Samsung)
Hi again,
As I am really new in this area I was trying to follow this example and struggled a lot to get the enrichment to pass. I used debugger and so on and
the main problem was that the node types was not found. I found via debugger that the only way they seems to be loaded was via some bootstrap call, that was not called at all. I then saw some example of curl call when I googled. Maybe this is documented in some other pages or part of other pages but for me it was hard to really know this extra manual step.
I used this (after CDS startup and before
mvn clean
install
-Pdeploy-cba)
:curl --location --request POST 'http://localhost:8081/api/v1/blueprint-model/bootstrap' --header 'Content-Type: application/json' --header 'Authorization: Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==' --data-raw '{
"loadModelType" : true,
"loadResourceDictionary" : true,
"loadCBA" : false
}'
And all woorked fine!
BR
Joachim