diff options
author | Gary Wu <gary.i.wu@huawei.com> | 2019-02-14 15:30:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-14 15:30:11 +0000 |
commit | ec239a34059e888586c640ba0ba528e11e57ed1b (patch) | |
tree | d12f8c47e5285362b794a2c518c9a50ce9d632c7 /tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py | |
parent | de57b6bcc922d933af34f7b3088c9b7a02129a16 (diff) | |
parent | 4d438ce1f40fe4cf2632a7bdb5ee72910f5f8037 (diff) |
Merge "BulkPM Add Metadata Test Case"
Diffstat (limited to 'tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py')
-rw-r--r-- | tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py b/tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py new file mode 100644 index 00000000..12d5d856 --- /dev/null +++ b/tests/usecases/5G-bulkpm/resources/JsonValidatorLibrary.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +import sys +import logging +from simplejson import load +from jsonschema import validate, ValidationError, SchemaError + + +class JsonValidatorLibrary(object): + + def __init__(self): + pass + + def validate(self, schemaPath, jsonPath): + logging.info("Schema path: " + schemaPath) + logging.info("JSON path: " + jsonPath) + schema = None + data = None + try: + schema = load(open(schemaPath, 'r')) + data = load(open(jsonPath, 'r')) + except (IOError, ValueError, OSError) as e: + logging.error(e.message) + return 1 + + try: + validate(data, schema) + except (ValidationError, SchemaError) as e: + logging.error(e.message) + return 1 + + # logger.log("JSON validation successful") + print("JSON validation successful") + return 0 + +if __name__ == '__main__': + lib = JsonValidatorLibrary() + # sys.exit(JsonValidatorLibrary().validate(sys.argv[1], sys.argv[2])) |