Add dcae-cli and component-json-schemas projects
[dcaegen2/platform/cli.git] / dcae-cli / dcae_cli / util / tests / test_cdap_util.py
1 # ============LICENSE_START=======================================================
2 # org.onap.dcae
3 # ================================================================================
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18 #
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
20
21 from dcae_cli.util.cdap_util import _merge_spec_config_into_broker_put,  normalize_cdap_params
22
23
24 def test_normalize_cdap_params():
25     spec = {"parameters" : {}}
26     normalized = normalize_cdap_params(spec)
27     assert normalized == {"app_preferences" : {},
28                          "app_config" : {},
29                          "program_preferences" : []}
30
31 def test_cdap_util():
32     """
33     Tests both _merge_spec_config_into_broker_put and normalize_cdap_params
34     """
35     jar = "bahphomet.com/nexus/doomsday.jar"
36     config = {
37         "artifact_name" : "testname",
38         "artifact_version" : "6.6.6",
39         "streamname" : "stream",
40         "programs" : [{"program_type" : "flows", "program_id" : "flow_id"}],
41         "namespace" : "underworld"
42     }
43     spec = {
44         "self": {
45             "version": "6.6.6",
46             "description": "description",
47             "component_type": "cdap",
48             "name": "name"
49         },
50         "parameters" : {
51             "app_preferences" : [{"name" : "he", "description" : "", "value" :  "shall rise"}],
52             "program_preferences" : [{"program_type" : "flows", "program_id" : "flow_id", "program_pref" : [{"name": "foo", "description" : "", "value" : "bar"}]}]
53         },
54
55         "streams": {
56                       "publishes": [],
57                       "subscribes" : []
58                    },
59         "services": {
60                       "calls" : [],
61                       'provides': [
62                            {"request":   {"format" : 'std.format_one', "version" : "1.0.0"},
63                             "response" : {"format" : "std.format_two", "version" : "1.5.0"},
64                             "service_name" : "baphomet",
65                             "service_endpoint" : "rises",
66                             "verb" : "GET"}
67                         ]
68                     },
69     }
70     parsed_parameters = normalize_cdap_params(spec) 
71     templated_conf = {"streams_publishes":{}, "streams_subscribes": {},
72         "services_calls": {}} #TODO: Incorporate a test templated_conf
73     broker_put = _merge_spec_config_into_broker_put(jar, config, spec, parsed_parameters, templated_conf)
74
75     expected = {
76         "app_config": {"services_calls" : {},
77                        "streams_publishes" : {},
78                        "streams_subscribes": {}
79                       },
80         "app_preferences": {"he" : "shall rise"},
81         "artifact_name" : "testname",
82         "artifact_version" : "6.6.6",
83         "jar_url": "bahphomet.com/nexus/doomsday.jar",
84         "namespace": "underworld",
85         "program_preferences" : [{"program_type" : "flows", "program_id" : "flow_id", "program_pref" : {"foo" : "bar"}}],
86         "programs" : [{"program_type" : "flows", "program_id" : "flow_id"}],
87         "service_component_type": "cdap",
88         "services": [{"service_name" : "baphomet", "service_endpoint" : "rises", "endpoint_method" : "GET"}],
89         "streamname": "stream",
90         "cdap_application_type" : "program-flowlet"
91         }
92
93     assert broker_put == expected