|
| 1 | +""" |
| 2 | +Copyright (c) 2024, Oracle and/or its affiliates. |
| 3 | +The Universal Permissive License (UPL), Version 1.0 |
| 4 | +""" |
| 5 | +import os |
| 6 | +import unittest |
| 7 | + |
| 8 | +from base_test import BaseTestCase |
| 9 | +from wlsdeploy.aliases.aliases import Aliases |
| 10 | +from wlsdeploy.aliases.location_context import LocationContext |
| 11 | +from wlsdeploy.aliases.validation_codes import ValidationCodes |
| 12 | +from wlsdeploy.util.model_context import ModelContext |
| 13 | +from wlsdeploy.util.model_translator import FileToPython |
| 14 | + |
| 15 | + |
| 16 | +class VariableInjectorFilesTest(BaseTestCase): |
| 17 | + """ |
| 18 | + Test the variable injector file contents. |
| 19 | + """ |
| 20 | + def __init__(self, *args): |
| 21 | + BaseTestCase.__init__(self, *args) |
| 22 | + self.INJECTORS_DIR = os.path.join(self.TEST_CONFIG_DIR, 'injectors') |
| 23 | + self.VALID_CODES = [ValidationCodes.VALID, ValidationCodes.CONTEXT_INVALID] |
| 24 | + |
| 25 | + def setUp(self): |
| 26 | + model_context = ModelContext("test", {}) |
| 27 | + self.aliases = Aliases(model_context, wls_version=self.ALIAS_WLS_VERSION) |
| 28 | + |
| 29 | + def test_injector_files(self): |
| 30 | + """ |
| 31 | + Verify that paths in the injector files are valid. |
| 32 | + """ |
| 33 | + for file_name in os.listdir(self.INJECTORS_DIR): |
| 34 | + if file_name.endswith(".json"): |
| 35 | + file_path = os.path.join(self.INJECTORS_DIR, file_name) |
| 36 | + translator = FileToPython(file_path, use_ordering=True) |
| 37 | + injector_dict = translator.parse() |
| 38 | + for injector_path in injector_dict: |
| 39 | + elements = injector_path.split('.') |
| 40 | + location = LocationContext() |
| 41 | + for element in elements[:-1]: |
| 42 | + location.append_location(element) |
| 43 | + name_token = self.aliases.get_name_token(location) |
| 44 | + if name_token is not None: |
| 45 | + location.add_name_token(name_token, 'TOKEN') |
| 46 | + |
| 47 | + code, _message = self.aliases.is_version_valid_location(location) |
| 48 | + is_valid = code in self.VALID_CODES |
| 49 | + self.assertEqual(is_valid, True, "Folder " + str(element) + " in path " + str(injector_path) |
| 50 | + + " in injector file " + str(file_name) + " is not valid") |
| 51 | + |
| 52 | + attribute_name = elements[-1] |
| 53 | + code, _message = self.aliases.is_valid_model_attribute_name(location, attribute_name) |
| 54 | + is_valid = code in self.VALID_CODES |
| 55 | + self.assertEqual(is_valid, True, "Attribute " + str(attribute_name) + " in path " + |
| 56 | + str(injector_path) + " in injector file " + str(file_name) + " is not valid") |
| 57 | + |
| 58 | + |
| 59 | +if __name__ == '__main__': |
| 60 | + unittest.main() |
0 commit comments