66
77import wlsdeploy .util .variables as variables
88from oracle .weblogic .deploy .util import VariableException
9+ from wlsdeploy .util .model_context import ModelContext
910from wlsdeploy .util .model_translator import FileToPython
1011
1112
@@ -19,14 +20,17 @@ class VariablesTestCase(unittest.TestCase):
1920 def setUp (self ):
2021 self .name = 'VariablesTestCase'
2122
23+ # create a context with resource directory as Oracle home, to support @@ORACLE_HOME@@ resolution
24+ self .model_context = ModelContext ("test" , {'-oracle_home' : self ._resources_dir })
25+
2226 def testReadVariables (self ):
2327 variable_map = variables .load_variables (self ._variables_file )
2428 self .assertEqual (variable_map ['my-abc' ], 'xyz' )
2529
2630 def testSubstituteYaml (self ):
2731 model = FileToPython (self ._resources_dir + '/variables-test.yaml' , self ._use_ordering ).parse ()
2832 variable_map = variables .load_variables (self ._variables_file )
29- variables .substitute (model , variable_map )
33+ variables .substitute (model , variable_map , self . model_context )
3034 self .assertEqual (model ['topology' ]['Name' ], 'xyz123' )
3135 self .assertEqual (model ['topology' ]['Server' ]['s1' ]['ListenPort' ], '1009' )
3236 self .assertEqual (model ['topology' ]['Server' ]['s2' ]['Cluster' ], 'myCluster' )
@@ -36,7 +40,7 @@ def testSubstituteYaml(self):
3640 def testSubstituteJson (self ):
3741 model = FileToPython (self ._resources_dir + '/variables-test.json' , self ._use_ordering ).parse ()
3842 variable_map = variables .load_variables (self ._variables_file )
39- variables .substitute (model , variable_map )
43+ variables .substitute (model , variable_map , self . model_context )
4044 self .assertEqual (model ['topology' ]['Name' ], 'xyz123' )
4145 self .assertEqual (model ['topology' ]['Server' ]['s1' ]['ListenPort' ], '1009' )
4246 self .assertEqual (model ['topology' ]['Server' ]['s2' ]['Cluster' ], 'myCluster' )
@@ -51,7 +55,7 @@ def testVariableNotFound(self):
5155 model = FileToPython (self ._resources_dir + '/variables-test.json' , self ._use_ordering ).parse ()
5256 model ['topology' ]['Name' ] = '${bad.variable}'
5357 variable_map = variables .load_variables (self ._variables_file )
54- variables .substitute (model , variable_map )
58+ variables .substitute (model , variable_map , self . model_context )
5559 self .assertEqual (model ['topology' ]['Name' ], '${bad.variable}' )
5660
5761 def testPropertyNotFound (self ):
@@ -62,7 +66,7 @@ def testPropertyNotFound(self):
6266 model = FileToPython (self ._resources_dir + '/variables-test.json' , self ._use_ordering ).parse ()
6367 model ['topology' ]['Name' ] = '@@PROP:bad.variable@@'
6468 variable_map = variables .load_variables (self ._variables_file )
65- variables .substitute (model , variable_map )
69+ variables .substitute (model , variable_map , self . model_context )
6670 except VariableException :
6771 pass
6872 else :
@@ -71,19 +75,24 @@ def testPropertyNotFound(self):
7175 def testFileVariable (self ):
7276 path = self ._resources_dir + '/' + self ._file_variable_name
7377 model = {'domainInfo' : {'AdminUserName' : '@@FILE:' + path + '@@' }}
74- variables .substitute (model , {})
78+ variables .substitute (model , {}, self . model_context )
7579 self .assertEqual (model ['domainInfo' ]['AdminUserName' ], 'file-variable-value' )
7680
7781 def testFileVariableWithVariable (self ):
7882 model = {'domainInfo' : {'AdminUserName' : '@@FILE:${variable_dir}/' + self ._file_variable_name + '@@' }}
79- variables .substitute (model , {'variable_dir' : self ._resources_dir })
83+ variables .substitute (model , {'variable_dir' : self ._resources_dir }, self .model_context )
84+ self .assertEqual (model ['domainInfo' ]['AdminUserName' ], 'file-variable-value' )
85+
86+ def testFileVariableWithConstant (self ):
87+ model = {'domainInfo' : {'AdminUserName' : '@@FILE:@@ORACLE_HOME@@/' + self ._file_variable_name + '@@' }}
88+ variables .substitute (model , {'variable_dir' : self ._resources_dir }, self .model_context )
8089 self .assertEqual (model ['domainInfo' ]['AdminUserName' ], 'file-variable-value' )
8190
8291 def testFileVariableNotFound (self ):
8392 try :
8493 path = self ._resources_dir + '/no-file.txt'
8594 model = {'domainInfo' : {'AdminUserName' : '@@FILE:' + path + '@@' }}
86- variables .substitute (model , {})
95+ variables .substitute (model , {}, self . model_context )
8796 self .assertEqual (model ['domainInfo' ]['AdminUserName' ], 'file-variable-value' )
8897 except VariableException :
8998 pass
0 commit comments