Adding some minor features
[ccsdk/cds.git] / docs / modelingconcepts / test.rst
1 .. This work is a derivative of https://wiki.onap.org/display/DW/Modeling+Concepts#Concepts-2603186
2 .. This work is licensed under a Creative Commons Attribution 4.0
3 .. International License. http://creativecommons.org/licenses/by/4.0
4 .. Copyright (C) 2020 Deutsche Telekom AG.
5
6 .. _tests:
7
8 Tests
9 -----
10
11 The **tests** folder contains the **uat.yaml** file for execution the cba actions for sunny day and rainy day
12 scenario using mock data. The process to generate the uat file is documented TBD. The file can be dragged
13 and drop to the Tests folder after the test for all actions are executed.
14
15 NOTE: You need to activate the "uat" Spring Boot profile in order to enable the spy/verify endpoints.
16 They are disabled by default because the mocks created at runtime can potentially cause collateral problems in production.
17 You can either pass an option to JVM (``-Dspring.profiles.active=uat``) or set and export an
18 environment variable (``export spring_profiles_active=uat``).
19
20 A quick outline of the UAT generation process follows:
21
22 1. Create a minimum :file:`uat.yaml` containing only the NB requests to be sent to the BlueprintsProcessor (BPP) service;
23 2. Submit the blueprint CBA and this draft :file:`uat.yaml` to BPP in a single HTTP POST call:
24
25    ``curl -u ccsdkapps:ccsdkapps -F cba=@<path to your CBA file> -F uat=@<path to the
26    draft uat.yaml> http://localhost:8080/api/v1/uat/spy``
27 3. If your environment is properly setup, at the end this service will generate the complete :file:`uat.yaml`;
28 4. Revise the generate file, eventually removing superfluous message fields;
29 5. Include this file in your CBA under :file:`Tests/uat.yaml`;
30 6. Submit the candidate CBA + UAT to be validated by BPP, that now will create runtime mocks to simulate
31    all SB collaborators, by running:
32
33    ``$ curl -u ccsdkapps:ccsdkapps -F cba=@<path to your CBA file> http://localhost:8080/api/v1/uat/verify``
34 7. Once validated, your CBA enhanced with its corresponding UAT is eligible
35    to be integrated into the CDS project, under the folder :file:`components/model-catalog/blueprint-model/uat-blueprints`.
36
37 Reference link for sample generated uat.yaml file for pnf plug & play use case:
38 `uat.yaml file <https://gerrit.onap.org/r/gitweb?p=ccsdk/cds.git;a=tree;f=components/model-catalog/blueprint-model/uat-blueprints/pnf_config/Tests;h=230d506720c4a1066784c1fe9e0ba0206bbb13cf;hb=refs/heads/master>`_.
39
40 As UAT is part of unit testing, it runs in jenkins job
41 `ccsdk-cds-master-verify-java <https://jenkins.onap.org/job/ccsdk-cds-master-verify-java/>`_
42 whenever a new commit/patch pushed on gerrit in ccsdk/cds repo.
43
44 Executing UAT based test inside you own CBA as SpringBootTest based JUnit test
45 *******************************************************************************
46
47 Beside the above mentioned internal usage of UATs, it is also possible to execute the User Acceptance Tests (UATs)
48 locally inside your own CBA as a "simple JUnit" test.
49 Therefor there exists an abstract *SpringBootTest* class **BaseBlueprintsAcceptanceTest**
50 (see class in *archetype-blueprint*).
51 From this you need to implement an inherited class e.g. **BlueprintAcceptanceSunnyTest**
52 (see class in *archetype-blueprint*), which only needs to specify the **uat.yaml** file, that should be executed.
53 This means it is possible to simply integrate this kind of tests in your own regression test suite.
54
55 UATs aims to fully test your workflow of your CBA.
56
57 The BPP runs in an almost production-like configuration with some minor exceptions:
58
59 * It uses an embedded, in-memory, and initially empty H2 database, running in MySQL/MariaDB compatibility mode;
60 * All external services are mocked.
61
62 For further information about User Acceptance Tests (UATs) see the following README.md inside the CDS repository
63
64 `Link to uat-blueprints README.md in CDS Github repository
65 <https://github.com/onap/ccsdk-cds/blob/master/components/model-catalog/blueprint-model/uat-blueprints/README.md>`_
66
67 Additionally please mention, that you also need resources, which configures the SpringBootTest. These resources you can
68 also find in the *archetype-blueprint* (Tests/resources folder).
69
70 To have a good starting point with your cba development, please generate the cba *archetype-blueprint* project with
71 the following command.
72
73 .. code-block:: bash
74
75    mvn archetype:generate -DarchetypeGroupId=org.onap.ccsdk.cds.components.cba \
76                           -DarchetypeArtifactId=archetype-blueprint \
77                           -DarchetypeVersion=1.4.3-SNAPSHOT \
78                           -DgroupId=org.onap.ccsdk.cds.components.cba \
79                           -DartifactId=testUat \
80                           -Dversion=1.0-SNAPSHOT
81
82 There you will find the above mentioned base class, sample class and resources you could use as a starting point for
83 writing UAT tests inside your own CBA.