|
10 | 10 | from wlsdeploy.util.model_translator import FileToPython
|
11 | 11 | from wlsdeploy.util.model_context import ModelContext
|
12 | 12 |
|
| 13 | +import validate |
13 | 14 | from wlsdeploy.tool.validate.validator import Validator
|
14 | 15 | from wlsdeploy.tool.validate import validation_utils
|
15 | 16 | from wlsdeploy.aliases.wlst_modes import WlstModes
|
16 | 17 | from wlsdeploy.aliases import alias_constants
|
| 18 | +from wlsdeploy.util.cla_utils import CommandLineArgUtil |
17 | 19 |
|
18 | 20 | import oracle.weblogic.deploy.util.TranslateException as TranslateException
|
19 |
| - |
| 21 | +from oracle.weblogic.deploy.validate import ValidateException |
20 | 22 |
|
21 | 23 | class ValidationTestCase(unittest.TestCase):
|
22 | 24 | _program_name = 'validation_test'
|
@@ -65,6 +67,121 @@ def testModelValidation(self):
|
65 | 67 |
|
66 | 68 | self.assertNotEqual(return_code, Validator.ReturnCode.STOP)
|
67 | 69 |
|
| 70 | + def testPrintUsageFoldersOnly(self): |
| 71 | + _method_name = 'testPrintUsageFoldersOnly' |
| 72 | + |
| 73 | + _FOLDERS_ONLY = '-folders_only' |
| 74 | + |
| 75 | + args = { |
| 76 | + '-oracle_home': os.environ['MW_HOME'] |
| 77 | + } |
| 78 | + |
| 79 | + model_paths = [ |
| 80 | + 'topology:/Server' |
| 81 | + ] |
| 82 | + |
| 83 | + try: |
| 84 | + # Loop through valid list of model sections |
| 85 | + for model_path in model_paths: |
| 86 | + # Set print usage context |
| 87 | + args['-print_usage'] = '%s %s' % (model_path, _FOLDERS_ONLY) |
| 88 | + self._logger.info('args={0}', str(args), class_name=self._class_name, method_name=_method_name) |
| 89 | + model_context = ModelContext(self._program_name, args) |
| 90 | + model_validator = Validator(model_context, wlst_mode=WlstModes.ONLINE) |
| 91 | + model_validator.print_usage(model_path) |
| 92 | + self.assertEquals(True, True) |
| 93 | + except ValidateException, ve: |
| 94 | + self.fail(ve.getLocalizedMessage()) |
| 95 | + |
| 96 | + return |
| 97 | + |
| 98 | + def testPrintUsageAttributesOnly(self): |
| 99 | + _method_name = 'testPrintUsageAttributesOnly' |
| 100 | + |
| 101 | + _ATTRIBUTES_ONLY = '-attributes_only' |
| 102 | + |
| 103 | + args = { |
| 104 | + '-oracle_home': os.environ['MW_HOME'] |
| 105 | + } |
| 106 | + |
| 107 | + model_paths = [ |
| 108 | + 'domainInfo' |
| 109 | + ] |
| 110 | + |
| 111 | + try: |
| 112 | + # Loop through valid list of model sections |
| 113 | + for model_path in model_paths: |
| 114 | + # Set print usage context |
| 115 | + args['-print_usage'] = '%s %s' % (model_path, _ATTRIBUTES_ONLY) |
| 116 | + self._logger.info('args={0}', str(args), class_name=self._class_name, method_name=_method_name) |
| 117 | + model_context = ModelContext(self._program_name, args) |
| 118 | + model_validator = Validator(model_context, wlst_mode=WlstModes.ONLINE) |
| 119 | + model_validator.print_usage(model_path) |
| 120 | + self.assertEquals(True, True) |
| 121 | + except ValidateException, ve: |
| 122 | + self.fail(ve.getLocalizedMessage()) |
| 123 | + |
| 124 | + return |
| 125 | + |
| 126 | + def testPrintUsageRecursive(self): |
| 127 | + _method_name = 'testPrintUsageRecursive' |
| 128 | + |
| 129 | + _RECURSIVE = '-recursive' |
| 130 | + |
| 131 | + args = { |
| 132 | + '-oracle_home': os.environ['MW_HOME'] |
| 133 | + } |
| 134 | + |
| 135 | + model_paths = [ |
| 136 | + 'appDeployments:/Application' |
| 137 | + ] |
| 138 | + |
| 139 | + try: |
| 140 | + # Loop through valid list of model sections |
| 141 | + for model_path in model_paths: |
| 142 | + # Set print usage context |
| 143 | + args['-print_usage'] = '%s %s' % (model_path, _RECURSIVE) |
| 144 | + self._logger.info('args={0}', str(args), class_name=self._class_name, method_name=_method_name) |
| 145 | + model_context = ModelContext(self._program_name, args) |
| 146 | + model_validator = Validator(model_context, wlst_mode=WlstModes.ONLINE) |
| 147 | + model_validator.print_usage(model_path) |
| 148 | + self.assertEquals(True, True) |
| 149 | + except ValidateException, ve: |
| 150 | + self.fail(ve.getLocalizedMessage()) |
| 151 | + |
| 152 | + return |
| 153 | + |
| 154 | + def testPrintUsageCLAEnforcement(self): |
| 155 | + _method_name = 'testPrintUsageCLAEnforcement' |
| 156 | + |
| 157 | + _FOLDERS_ONLY = '-folders_only' |
| 158 | + _RECURSIVE = '-recursive' |
| 159 | + |
| 160 | + args = list() |
| 161 | + args.append(self._program_name) |
| 162 | + args.append('-oracle_home') |
| 163 | + args.append(os.environ['MW_HOME']) |
| 164 | + args.append('-print_usage') |
| 165 | + args.append('topology:/Server') |
| 166 | + args.append(_FOLDERS_ONLY) |
| 167 | + args.append('') |
| 168 | + args.append(_RECURSIVE) |
| 169 | + |
| 170 | + self._logger.info('args={0}', str(args), class_name=self._class_name, method_name=_method_name) |
| 171 | + |
| 172 | + try: |
| 173 | + # Should raise an exception because control options |
| 174 | + # are mutually exclusive, and we passed _FOLDERS_ONLY |
| 175 | + # and _RECURSIVE |
| 176 | + validate.main(args) |
| 177 | + except ValidateException, ve: |
| 178 | + self.fail(ve.getLocalizedMessage()) |
| 179 | + except SystemExit, se: |
| 180 | + exit_code = str(se) |
| 181 | + self.assertEqual(exit_code, str(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)) |
| 182 | + |
| 183 | + return |
| 184 | + |
68 | 185 | def testIsCompatibleDataType(self):
|
69 | 186 | _method_name = 'testIsCompatibleDataType'
|
70 | 187 |
|
|
0 commit comments