11"""
2- Copyright (c) 2017, 2018 , Oracle and/or its affiliates. All rights reserved.
2+ Copyright (c) 2017, 2019 , Oracle and/or its affiliates. All rights reserved.
33The Universal Permissive License (UPL), Version 1.0
44"""
5+ import copy
6+ import os
57import pprint
68import unittest
79
2022from wlsdeploy .aliases .alias_constants import DEFAULT
2123from wlsdeploy .aliases .alias_constants import DEFAULT_NAME_VALUE
2224from wlsdeploy .aliases .alias_constants import FLATTENED_FOLDER_DATA
25+ from wlsdeploy .aliases .alias_constants import FOLDER_PARAMS
2326from wlsdeploy .aliases .alias_constants import FOLDERS
2427from wlsdeploy .aliases .alias_constants import GET
2528from wlsdeploy .aliases .alias_constants import GET_MBEAN_TYPE
4851
4952
5053class ListTestCase (unittest .TestCase ):
54+ _resources_dir = '../../test-classes/'
55+ _test_json_files = [
56+ 'Test'
57+ ]
58+ _test_category_file_map = dict ()
5159
5260 _required_category_folder_keys = [
5361 'copyright' ,
@@ -67,6 +75,7 @@ class ListTestCase(unittest.TestCase):
6775 CONTAINS ,
6876 DEFAULT_NAME_VALUE ,
6977 FLATTENED_FOLDER_DATA ,
78+ FOLDER_PARAMS ,
7079 VERSION ,
7180 WLST_CREATE_PATH ,
7281 WLST_LIST_PATH ,
@@ -121,6 +130,9 @@ def setUp(self):
121130 self .alias_entries = AliasEntries (wls_version = '12.2.1.3' )
122131 self .online_alias_entries = AliasEntries (wls_version = '12.2.1.3' , wlst_mode = WlstModes .ONLINE )
123132 self .category_file_map = self .alias_entries ._unit_test_only_get_category_map_files ()
133+ for testfile in self ._test_json_files :
134+ category_file_path = os .path .join (self ._resources_dir , '%s.json' % testfile )
135+ self ._test_category_file_map [testfile ] = category_file_path
124136
125137 def testForJsonFileTypos (self ):
126138 category_results = dict ()
@@ -132,10 +144,25 @@ def testForJsonFileTypos(self):
132144 message = pprint .pformat (category_results )
133145 self .assertEqual (len (category_results ), 0 , message )
134146
147+ def testTestFilesForJsonFileTypos (self ):
148+ category_results = dict ()
149+ for category_name , category_file_path in self ._test_category_file_map .iteritems ():
150+ category_dict = self ._load_test_category_file (category_file_path )
151+ results = self ._scan_category_dict_for_unknown_fields (category_name , category_dict )
152+ if len (results ) > 0 :
153+ category_results [category_name ] = results
154+ message = pprint .pformat (category_results )
155+ self .assertEqual (len (category_results ), 0 , message )
156+
135157 def _load_category_file (self , category_file_path ):
136158 category_input_stream = FileUtils .getResourceAsStream (category_file_path )
137159 self .assertNotEquals (category_input_stream , None )
160+ json_translator = JsonStreamTranslator (category_file_path , category_input_stream )
161+ return json_translator .parse ()
138162
163+ def _load_test_category_file (self , category_file_path ):
164+ category_input_stream = FileUtils .getFileAsStream (category_file_path )
165+ self .assertNotEquals (category_input_stream , None )
139166 json_translator = JsonStreamTranslator (category_file_path , category_input_stream )
140167 return json_translator .parse ()
141168
@@ -277,7 +304,6 @@ def _verify_folder_wlst_paths_attribute_type(self, folder_name, attribute_value)
277304 result .append (self ._get_invalid_dictionary_type_message (folder_name , WLST_PATHS , attribute_value ))
278305 return result
279306
280-
281307 def _verify_folder_wlst_type_attribute_type (self , folder_name , attribute_value ):
282308 result = []
283309 if type (attribute_value ) is not str :
@@ -337,6 +363,31 @@ def _verify_folder_flattened_folder_data_attribute_value(self, folder_name, attr
337363 attribute_value [NAME_VALUE ]))
338364 return result
339365
366+ def _verify_folder_folder_params_attribute_value (self , folder_name , attribute_value ):
367+ result = []
368+ if type (attribute_value ) is not list or (len (attribute_value ) > 0 and
369+ type (attribute_value [0 ]) is not dict ):
370+ result .append (self ._get_invalid_list_of_dict_type_message (folder_name , FOLDER_PARAMS ,
371+ attribute_value ))
372+ else :
373+ folder_params = copy .deepcopy (attribute_value )
374+ for folder_param in folder_params :
375+ if VERSION not in folder_param :
376+ result .append (self ._get_missing_required_attribute_key_message (folder_name ,
377+ VERSION , FOLDER_PARAMS ))
378+ for folder in folder_param :
379+ if folder in self ._required_folder_keys :
380+ verify_function_name = '_verify_folder_%s_attribute_type' % folder
381+ verify_function = getattr (self , verify_function_name )
382+ result .extend (verify_function (folder_name , folder_param [folder ]))
383+ elif folder in self ._optional_folder_keys :
384+ verify_function_name = '_verify_folder_%s_attribute_value' % folder
385+ verify_function = getattr (self , verify_function_name )
386+ result .extend (verify_function (folder_name , folder_param [folder ]))
387+ else :
388+ result .append (self ._get_unknown_folder_key_message (folder_name , folder ))
389+ return result
390+
340391 def _verify_folder_version_attribute_value (self , folder_name , attribute_value ):
341392 result = []
342393 if type (attribute_value ) is not str :
@@ -629,6 +680,10 @@ def _get_invalid_list_type_message(self, folder_name, attribute_name, attribute_
629680 return 'Folder at path %s has %s attribute that is expected to be a list but is a %s instead' % \
630681 (folder_name , attribute_name , str (type (attribute_value )))
631682
683+ def _get_invalid_list_of_dict_type_message (self , folder_name , attribute_name , attribute_value ):
684+ return 'Folder at path %s has %s attribute that is expected to be a list of dict but is a %s instead' % \
685+ (folder_name , attribute_name , str (type (attribute_value )))
686+
632687 def _get_invalid_string_type_message (self , folder_name , attribute_name , attribute_value ):
633688 return 'Folder at path %s has %s attribute that is expected to be a string but is a %s instead' % \
634689 (folder_name , attribute_name , str (type (attribute_value )))
0 commit comments