Skip to content

Commit 58b3c38

Browse files
committed
Added get_model_attribute_name for alias validation testing
1 parent 235fe74 commit 58b3c38

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,37 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
841841
result={model_attribute_name: model_attribute_value})
842842
return model_attribute_name, model_attribute_value
843843

844+
def get_model_attribute_name(self, location, wlst_attribute_name):
845+
"""
846+
Returns the model attribute name for the specified WLST attribute name and value.
847+
848+
model_attribute_value will be set to None, if value assigned to wlst_attribute_value arg
849+
is the default value for model_attribute_name.
850+
:param location: the location
851+
:param wlst_attribute_name: the WLST attribute name
852+
:return: the name and value
853+
:raises: AliasException: if an error occurs
854+
"""
855+
_method_name = 'get_model_attribute_name'
856+
857+
self._logger.entering(str(location), wlst_attribute_name,
858+
class_name=self._class_name, method_name=_method_name)
859+
model_attribute_name = None
860+
861+
attribute_info = self._alias_entries.get_alias_attribute_entry_by_wlst_name(location, wlst_attribute_name)
862+
if attribute_info is not None:
863+
model_attribute_name = attribute_info[MODEL_NAME]
864+
865+
if wlst_attribute_name not in ('Id', 'Tag', 'Name') and model_attribute_name is None:
866+
ex = exception_helper.create_alias_exception('WLSDPLY-08406', wlst_attribute_name,
867+
location.get_folder_path())
868+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
869+
raise ex
870+
871+
self._logger.exiting(class_name=self._class_name, method_name=_method_name,
872+
result=model_attribute_name)
873+
return model_attribute_name
874+
844875
def get_model_attribute_names(self, location):
845876
"""
846877
Returns the model attribute names for the specified location.

core/src/test/python/aliases_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,5 +1096,26 @@ def testIssue38Fix(self):
10961096

10971097
return
10981098

1099+
def testGetModelAttributeName(self):
1100+
location=LocationContext().append_location(FOLDERS.JMS_SYSTEM_RESOURCE)
1101+
token = self.aliases.get_name_token(location)
1102+
location.add_name_token(token, 'TheModule')
1103+
location.append_location(FOLDERS.JMS_RESOURCE)
1104+
location.append_location(FOLDERS.DISTRIBUTED_TOPIC)
1105+
token = self.aliases.get_name_token(location)
1106+
location.add_name_token(token, 'TheTopic')
1107+
1108+
# model name should be the same, whether online or offline
1109+
expected_model_name = 'SafExportPolicy'
1110+
1111+
model_name = self.aliases.get_model_attribute_name(location, 'SafExportPolicy')
1112+
self.assertEqual(model_name, expected_model_name)
1113+
1114+
model_name = self.online_aliases.get_model_attribute_name(location, 'SAFExportPolicy')
1115+
self.assertEqual(model_name, expected_model_name)
1116+
1117+
return
1118+
1119+
10991120
if __name__ == '__main__':
11001121
unittest.main()

0 commit comments

Comments
 (0)