|
| 1 | +""" |
| 2 | +Copyright (c) 2024, Oracle and/or its affiliates. |
| 3 | +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +""" |
| 5 | + |
| 6 | +from base_test import BaseTestCase |
| 7 | +from wlsdeploy.aliases.aliases import Aliases |
| 8 | +from wlsdeploy.aliases.wlst_modes import WlstModes |
| 9 | +from wlsdeploy.logging.platform_logger import PlatformLogger |
| 10 | +from wlsdeploy.tool.deploy import deployer_utils |
| 11 | +from wlsdeploy.util.model import Model |
| 12 | +from wlsdeploy.util.model_context import ModelContext |
| 13 | + |
| 14 | + |
| 15 | +class ApplicationsDeployerTest(BaseTestCase): |
| 16 | + __class_name = 'ApplicationsDeployerTest' |
| 17 | + __logger = PlatformLogger('wlsdeploy.deploy') |
| 18 | + |
| 19 | + wls_version = '12.2.1.3' |
| 20 | + |
| 21 | + def __init__(self, *args): |
| 22 | + BaseTestCase.__init__(self, *args) |
| 23 | + |
| 24 | + def setUp(self): |
| 25 | + BaseTestCase.setUp(self) |
| 26 | + |
| 27 | + def tearDown(self): |
| 28 | + BaseTestCase.tearDown(self) |
| 29 | + |
| 30 | + def test_is_structured_app(self): |
| 31 | + """ |
| 32 | + Test that _is_structured_app() returns correct values for different deployments. |
| 33 | + """ |
| 34 | + # structured app in the archive |
| 35 | + self.check_is_structured_app('wlsdeploy/structuredApplications/myApp/app/my.war', |
| 36 | + 'wlsdeploy/structuredApplications/myApp/plan/Plan.xml', |
| 37 | + True) |
| 38 | + |
| 39 | + # not structured: need a parent dir under structuredApplications/myApp |
| 40 | + self.check_is_structured_app('wlsdeploy/structuredApplications/my.war', |
| 41 | + 'wlsdeploy/structuredApplications/Plan.xml', |
| 42 | + False) |
| 43 | + |
| 44 | + # not structured: archive location for non-structured apps |
| 45 | + self.check_is_structured_app('wlsdeploy/applications/myApp/app/my.war', |
| 46 | + 'wlsdeploy/applications/myApp/plan/Plan.xml', |
| 47 | + False) |
| 48 | + |
| 49 | + # structured app using plan dir |
| 50 | + self.check_is_structured_app('wlsdeploy/structuredApplications/myApp/app/my.war', |
| 51 | + 'plan/Plan.xml', |
| 52 | + True, |
| 53 | + plan_dir='wlsdeploy/structuredApplications/myApp') |
| 54 | + |
| 55 | + # not structured: app in archive, plan dir outside archive |
| 56 | + self.check_is_structured_app('wlsdeploy/structuredApplications/myApp/app/my.war', |
| 57 | + 'plan/Plan.xml', |
| 58 | + False, |
| 59 | + plan_dir='/myApp') |
| 60 | + |
| 61 | + # structured app outside archive |
| 62 | + self.check_is_structured_app('/home/myApp/app/my.war', |
| 63 | + '/home/myApp/plan/Plan.xml', |
| 64 | + True) |
| 65 | + |
| 66 | + # not structured: app outside archive no match |
| 67 | + self.check_is_structured_app('/home/myApp/app/my.war', |
| 68 | + '/home/myOtherApp/plan/Plan.xml', |
| 69 | + False) |
| 70 | + |
| 71 | + # structured app outside archive using plan dir |
| 72 | + self.check_is_structured_app('/home/myApp/app/my.war', |
| 73 | + 'plan/Plan.xml', |
| 74 | + True, |
| 75 | + plan_dir='/home/myApp') |
| 76 | + |
| 77 | + # not structured: app outside archive, plan dir doesn't match |
| 78 | + self.check_is_structured_app('/home/myApp/app/my.war', |
| 79 | + 'plan/Plan.xml', |
| 80 | + False, |
| 81 | + plan_dir='/home/myOtherApp') |
| 82 | + |
| 83 | + # not structured: app outside archive no plan path or dir |
| 84 | + self.check_is_structured_app('/home/myApp/app/my.war', |
| 85 | + None, |
| 86 | + False) |
| 87 | + |
| 88 | + def check_is_structured_app(self, source_path, plan_path, expected_result, plan_dir=None): |
| 89 | + """ |
| 90 | + Check if the source path and plan path identify a structured application. |
| 91 | + :param source_path: the source path to check |
| 92 | + :param plan_path: the plan path to check |
| 93 | + :param expected_result: the expected result, True or False |
| 94 | + :param plan_dir: plan directory to check (optional) |
| 95 | + """ |
| 96 | + app_dict = { |
| 97 | + 'SourcePath': source_path, |
| 98 | + 'PlanPath': plan_path, |
| 99 | + 'PlanDir': plan_dir |
| 100 | + } |
| 101 | + |
| 102 | + model_dict = { |
| 103 | + 'appDeployments': { |
| 104 | + 'Application': { |
| 105 | + 'myApp': app_dict |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + model = Model(model_dict) |
| 111 | + model_context = ModelContext(self.__class_name, {'-archive_file': 'fake.zip'}) |
| 112 | + aliases = Aliases(model_context=model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self.wls_version) |
| 113 | + applications_deployer = deployer_utils.get_applications_deployer(model, model_context, aliases) |
| 114 | + |
| 115 | + result, structured_app_dir = applications_deployer._is_structured_app(app_dict) |
| 116 | + self.assertEqual(expected_result, result, '_is_structured_app() should return ' + str(expected_result) |
| 117 | + + ' for source path ' + str(source_path) + ', plan path ' + str(plan_path) |
| 118 | + + ', and plan dir ' + str(plan_dir)) |
0 commit comments