Acumos Adapter updates to support v3 schema
[dcaegen2/platform.git] / adapter / acumos / tests / test_spec.py
1 # ============LICENSE_START====================================================
2 # org.onap.dcae
3 # =============================================================================
4 # Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
5 # Copyright (c) 2021 highstreet technologies GmbH. All rights reserved.
6 # =============================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END======================================================
19
20 from testing_helpers import get_json_fixture, get_fixture_path
21 from aoconversion import dataformat_gen, spec_gen, utils
22
23 TEST_META = get_json_fixture("models/example-model/metadata.json")
24
25
26 def test_generate_spec(mock_schemas):
27     """
28     Test generating data formats from the protobuf
29     """
30     test_proto_path = get_fixture_path("models/example-model/model.proto")
31     data_formats = dataformat_gen._generate_dcae_data_formats(test_proto_path, TEST_META, utils.dataformat_schema.get(),
32                                                               utils.schema_schema.get())
33     assert spec_gen._generate_spec(
34         "example-model", TEST_META, utils.component_schema.get(), data_formats,
35         "latest"
36     ) == {
37                "self": {
38                    "version": "1.0.0",
39                    "name": "example-model",
40                    "description": "Automatically generated from Acumos model",
41                    "component_type": "docker",
42                },
43                "services": {"calls": [], "provides": []},
44                "streams": {
45                    "subscribes": [
46                        {"config_key": "add_subscriber", "format": "NumbersIn", "version": "1.0.0",
47                         "type": "message_router"}
48                    ],
49                    "publishes": [
50                        {"config_key": "add_publisher", "format": "NumberOut", "version": "1.0.0",
51                         "type": "message_router"}
52                    ],
53                },
54                "parameters": [
55                    {
56                        "name": "streams_subscribes",
57                        "value": "{\"add_subscriber\":{\"dmaap_info\":{\"topic_url\":\"http://message-router:3904/events/unauthenticated.example-model_In\"},\"type\":\"message_router\"}}",
58                        "description": "standard http port collector will open for listening;",
59                        "sourced_at_deployment": False,
60                        "policy_editable": False,
61                        "designer_editable": False
62                    },
63                    {
64                        "name": "streams_publishes",
65                        "value": "{\"add_publisher\":{\"dmaap_info\":{\"topic_url\":\"http://message-router:3904/events/unauthenticated.example-model_Out\"},\"type\":\"message_router\"}}",
66                        "description": "standard http port collector will open for listening;",
67                        "sourced_at_deployment": False,
68                        "policy_editable": False,
69                        "designer_editable": False
70                    }
71                ],
72                "auxilary": {
73                    "helm": {
74                        "service": {
75                            "type": "ClusterIP",
76                            "name": "example-model",
77                            "has_internal_only_ports": "true",
78                            "ports": [{
79                                "name": "http",
80                                "port": 8443,
81                                "plain_port": 8080,
82                                "port_protocol": "http"
83                            }
84                            ]
85                        }
86                    },
87                    "healthcheck": {"type": "HTTP", "interval": "15s", "timeout": "1s", "port": 8080,
88                                    "endpoint": "/healthcheck"}},
89                "artifacts": [{"type": "docker image", "uri": "example-model:latest"}],
90            }