Fix Cert-service tests
[integration/csit.git] / tests / usecases-5G-bulkpm / 5G-bulkpm / resources / JsonValidatorLibrary.py
1 # -*- coding: utf-8 -*-
2
3 import logging
4
5 from jsonschema import validate, ValidationError, SchemaError
6 from simplejson import load
7
8
9 class JsonValidatorLibrary(object):
10
11     def __init__(self):
12         pass
13
14     @staticmethod
15     def validate(schema_path, json_path):
16         logging.info("Schema path: " + schema_path)
17         logging.info("JSON path: " + json_path)
18         schema = None
19         data = None
20         try:
21             schema = load(open(schema_path, 'r'))
22             data = load(open(json_path, 'r'))
23         except (IOError, ValueError, OSError) as e:
24             logging.error(e.message)
25             return 1
26
27         try:
28             validate(data, schema)
29         except (ValidationError, SchemaError) as e:
30             logging.error(e.message)
31             return 1
32
33         # logger.log("JSON validation successful")
34         print("JSON validation successful")
35         return 0
36
37
38 if __name__ == '__main__':
39     lib = JsonValidatorLibrary()
40 # sys.exit(JsonValidatorLibrary().validate(sys.argv[1], sys.argv[2]))