X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dcaegen2%2Fplatform.git;a=blobdiff_plain;f=adapter%2Facumos%2Ftests%2Ftest_df.py;fp=adapter%2Facumos%2Ftests%2Ftest_df.py;h=cdf41c41807a705f7c8bd1db867411797e8d838a;hp=0000000000000000000000000000000000000000;hb=849da15d5b7ddc68e4c2b90b603fc8948d4b5e6d;hpb=3f67c400813a60e4b8f9327e20eccc9033dc1b0b diff --git a/adapter/acumos/tests/test_df.py b/adapter/acumos/tests/test_df.py new file mode 100644 index 0000000..cdf41c4 --- /dev/null +++ b/adapter/acumos/tests/test_df.py @@ -0,0 +1,109 @@ +# ============LICENSE_START==================================================== +# org.onap.dcae +# ============================================================================= +# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. +# ============================================================================= +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END====================================================== + +from testing_helpers import get_json_fixture, get_fixture_path +from aoconversion import dataformat_gen + +TEST_META = get_json_fixture("models/example-model/metadata.json") +DRAFT_4_SCHEMA = get_json_fixture("jsdraft4schema.json") +DF_101 = get_json_fixture("dataformat_101.json") + + +def test_get_needed_formats(): + assert dataformat_gen._get_needed_formats(TEST_META) == ["NumbersIn", "NumberOut"] + + +def test_generate_dcae_data_formats(): + """ + Test generating data formats from the protobuf + """ + test_proto_path = get_fixture_path("models/example-model/model.proto") + assert dataformat_gen._generate_dcae_data_formats(test_proto_path, TEST_META, DF_101, DRAFT_4_SCHEMA) == [ + { + "self": {"name": "NumbersIn", "version": "1.0.0"}, + "dataformatversion": "1.0.1", + "jsonschema": { + "title": "NumbersIn", + "type": "object", + "properties": { + "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}, + "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}, + }, + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": {}, + }, + }, + { + "self": {"name": "NumberOut", "version": "1.0.0"}, + "dataformatversion": "1.0.1", + "jsonschema": { + "title": "NumberOut", + "type": "object", + "properties": {"result": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}}, + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": {}, + }, + }, + ] + + +def test_generate_dcae_data_formats_listofm(): + """ + Test generating data formats from the protobuf + This one tests the case where definitions needs to be populated in one of the data formats because it's referenced in a "top level" message + """ + test_meta = get_json_fixture("models/example-model-listofm/metadata.json") + test_proto_path = get_fixture_path("models/example-model-listofm/model.proto") + assert dataformat_gen._generate_dcae_data_formats(test_proto_path, test_meta, DF_101, DRAFT_4_SCHEMA) == [ + { + "self": {"name": "ArgsList", "version": "1.0.0"}, + "dataformatversion": "1.0.1", + "jsonschema": { + "title": "ArgsList", + "type": "object", + "properties": {"args": {"type": "array", "items": {"$ref": "#/definitions/Args"}}}, + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": { + "Args": { + "title": "Args", + "type": "object", + "properties": { + "x": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}, + "y": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}, + }, + } + }, + }, + }, + { + "self": {"name": "SumOut", "version": "1.0.0"}, + "dataformatversion": "1.0.1", + "jsonschema": { + "title": "SumOut", + "type": "object", + "properties": { + "value": { + "type": "array", + "items": {"type": "integer", "minimum": -9007199254740991, "maximum": 9007199254740991}, + } + }, + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": {}, + }, + }, + ]