1
1
"""
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.
3
3
The Universal Permissive License (UPL), Version 1.0
4
4
"""
5
+ import copy
6
+ import os
5
7
import pprint
6
8
import unittest
7
9
20
22
from wlsdeploy .aliases .alias_constants import DEFAULT
21
23
from wlsdeploy .aliases .alias_constants import DEFAULT_NAME_VALUE
22
24
from wlsdeploy .aliases .alias_constants import FLATTENED_FOLDER_DATA
25
+ from wlsdeploy .aliases .alias_constants import FOLDER_PARAMS
23
26
from wlsdeploy .aliases .alias_constants import FOLDERS
24
27
from wlsdeploy .aliases .alias_constants import GET
25
28
from wlsdeploy .aliases .alias_constants import GET_MBEAN_TYPE
48
51
49
52
50
53
class ListTestCase (unittest .TestCase ):
54
+ _resources_dir = '../../test-classes/'
55
+ _test_json_files = [
56
+ 'Test'
57
+ ]
58
+ _test_category_file_map = dict ()
51
59
52
60
_required_category_folder_keys = [
53
61
'copyright' ,
@@ -67,6 +75,7 @@ class ListTestCase(unittest.TestCase):
67
75
CONTAINS ,
68
76
DEFAULT_NAME_VALUE ,
69
77
FLATTENED_FOLDER_DATA ,
78
+ FOLDER_PARAMS ,
70
79
VERSION ,
71
80
WLST_CREATE_PATH ,
72
81
WLST_LIST_PATH ,
@@ -121,6 +130,9 @@ def setUp(self):
121
130
self .alias_entries = AliasEntries (wls_version = '12.2.1.3' )
122
131
self .online_alias_entries = AliasEntries (wls_version = '12.2.1.3' , wlst_mode = WlstModes .ONLINE )
123
132
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
124
136
125
137
def testForJsonFileTypos (self ):
126
138
category_results = dict ()
@@ -132,10 +144,25 @@ def testForJsonFileTypos(self):
132
144
message = pprint .pformat (category_results )
133
145
self .assertEqual (len (category_results ), 0 , message )
134
146
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
+
135
157
def _load_category_file (self , category_file_path ):
136
158
category_input_stream = FileUtils .getResourceAsStream (category_file_path )
137
159
self .assertNotEquals (category_input_stream , None )
160
+ json_translator = JsonStreamTranslator (category_file_path , category_input_stream )
161
+ return json_translator .parse ()
138
162
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 )
139
166
json_translator = JsonStreamTranslator (category_file_path , category_input_stream )
140
167
return json_translator .parse ()
141
168
@@ -277,7 +304,6 @@ def _verify_folder_wlst_paths_attribute_type(self, folder_name, attribute_value)
277
304
result .append (self ._get_invalid_dictionary_type_message (folder_name , WLST_PATHS , attribute_value ))
278
305
return result
279
306
280
-
281
307
def _verify_folder_wlst_type_attribute_type (self , folder_name , attribute_value ):
282
308
result = []
283
309
if type (attribute_value ) is not str :
@@ -337,6 +363,31 @@ def _verify_folder_flattened_folder_data_attribute_value(self, folder_name, attr
337
363
attribute_value [NAME_VALUE ]))
338
364
return result
339
365
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
+
340
391
def _verify_folder_version_attribute_value (self , folder_name , attribute_value ):
341
392
result = []
342
393
if type (attribute_value ) is not str :
@@ -629,6 +680,10 @@ def _get_invalid_list_type_message(self, folder_name, attribute_name, attribute_
629
680
return 'Folder at path %s has %s attribute that is expected to be a list but is a %s instead' % \
630
681
(folder_name , attribute_name , str (type (attribute_value )))
631
682
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
+
632
687
def _get_invalid_string_type_message (self , folder_name , attribute_name , attribute_value ):
633
688
return 'Folder at path %s has %s attribute that is expected to be a string but is a %s instead' % \
634
689
(folder_name , attribute_name , str (type (attribute_value )))
0 commit comments