|
| 1 | +""" |
| 2 | +Copyright (c) 2021, Oracle and/or its affiliates. |
| 3 | +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +""" |
| 5 | +import os |
| 6 | + |
| 7 | +from base_test import BaseTestCase |
| 8 | +from wlsdeploy.aliases.model_constants import APPLICATION |
| 9 | +from wlsdeploy.aliases.model_constants import APP_DEPLOYMENTS |
| 10 | +from wlsdeploy.aliases.model_constants import AUTHENTICATION_PROVIDER |
| 11 | +from wlsdeploy.aliases.model_constants import CALCULATED_LISTEN_PORTS |
| 12 | +from wlsdeploy.aliases.model_constants import CLUSTER |
| 13 | +from wlsdeploy.aliases.model_constants import DEFAULT_AUTHENTICATOR |
| 14 | +from wlsdeploy.aliases.model_constants import DYNAMIC_SERVERS |
| 15 | +from wlsdeploy.aliases.model_constants import REALM |
| 16 | +from wlsdeploy.aliases.model_constants import SECURITY_CONFIGURATION |
| 17 | +from wlsdeploy.aliases.model_constants import TOPOLOGY |
| 18 | +from wlsdeploy.tool.util.filters import wko_filter |
| 19 | +from wlsdeploy.util.model_context import ModelContext |
| 20 | +from wlsdeploy.util.model_translator import FileToPython |
| 21 | + |
| 22 | + |
| 23 | +class WkoFilterTestCase(BaseTestCase): |
| 24 | + _program_name = 'wko_filter_test' |
| 25 | + _jta_cluster = 'JTACluster' |
| 26 | + _jta_cluster_info_list = 'DeterminerCandidateResourceInfoList' |
| 27 | + _provider_class_name = 'ProviderClassName' |
| 28 | + _multi_version_app = 'MultiVersionApp' |
| 29 | + |
| 30 | + def __init__(self, *args): |
| 31 | + BaseTestCase.__init__(self, *args) |
| 32 | + self.MODELS_DIR = os.path.join(self.TEST_CLASSES_DIR, 'prepare') |
| 33 | + self.PREPARE_OUTPUT_DIR = os.path.join(self.TEST_OUTPUT_DIR, 'prepare') |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + BaseTestCase.setUp(self) |
| 37 | + self._establish_directory(self.PREPARE_OUTPUT_DIR) |
| 38 | + |
| 39 | + def testFilter(self): |
| 40 | + """ |
| 41 | + Filter the model and verify the results |
| 42 | + """ |
| 43 | + model_file = os.path.join(self.MODELS_DIR, 'wko-filter.yaml') |
| 44 | + translator = FileToPython(model_file, use_ordering=True) |
| 45 | + model = translator.parse() |
| 46 | + |
| 47 | + # online attributes are in the model before filtering |
| 48 | + |
| 49 | + jta_cluster = self._traverse(model, TOPOLOGY, CLUSTER, 'staticCluster', self._jta_cluster) |
| 50 | + self.assertEqual(True, self._jta_cluster_info_list in jta_cluster, |
| 51 | + self._jta_cluster_info_list + " should be in " + self._jta_cluster + " before filtering") |
| 52 | + |
| 53 | + authenticator = self._traverse(model, TOPOLOGY, SECURITY_CONFIGURATION, REALM, 'yourRealm', |
| 54 | + AUTHENTICATION_PROVIDER, DEFAULT_AUTHENTICATOR, DEFAULT_AUTHENTICATOR) |
| 55 | + self.assertEqual(True, self._provider_class_name in authenticator, |
| 56 | + self._provider_class_name + " should be in " + DEFAULT_AUTHENTICATOR + " before filtering") |
| 57 | + |
| 58 | + my_app = self._traverse(model, APP_DEPLOYMENTS, APPLICATION, 'myApp') |
| 59 | + self.assertEqual(True, self._multi_version_app in my_app, |
| 60 | + self._multi_version_app + " should be in \"myApp\" before filtering") |
| 61 | + |
| 62 | + # Apply the filter |
| 63 | + |
| 64 | + self._suspend_logs('wlsdeploy.tool.util') |
| 65 | + model_context = ModelContext(self._program_name, {}) |
| 66 | + wko_filter.filter_model(model, model_context) |
| 67 | + self._restore_logs() |
| 68 | + |
| 69 | + # Dynamic clusters should have "CalculatedListenPorts" set to false |
| 70 | + |
| 71 | + self._match(0, model, TOPOLOGY, CLUSTER, 'dynamicCluster', DYNAMIC_SERVERS, CALCULATED_LISTEN_PORTS) |
| 72 | + self._match(0, model, TOPOLOGY, CLUSTER, 'dynamicCluster2', DYNAMIC_SERVERS, CALCULATED_LISTEN_PORTS) |
| 73 | + |
| 74 | + # Online-only attributes should be removed from the model |
| 75 | + |
| 76 | + jta_cluster = self._traverse(model, TOPOLOGY, CLUSTER, 'staticCluster', self._jta_cluster) |
| 77 | + self._no_dictionary_key(jta_cluster, self._jta_cluster_info_list) |
| 78 | + |
| 79 | + authenticator = self._traverse(model, TOPOLOGY, SECURITY_CONFIGURATION, REALM, 'yourRealm', |
| 80 | + AUTHENTICATION_PROVIDER, DEFAULT_AUTHENTICATOR, DEFAULT_AUTHENTICATOR) |
| 81 | + self._no_dictionary_key(authenticator, self._provider_class_name) |
| 82 | + |
| 83 | + my_app = self._traverse(model, APP_DEPLOYMENTS, APPLICATION, 'myApp') |
| 84 | + self._no_dictionary_key(my_app, self._multi_version_app) |
0 commit comments