Skip to content

Commit 8f6e5bc

Browse files
committed
Merge branch 'is-structured-unit-tests' into 'develop-4.0'
Added unit test for application deployer _is_structured_app(), with fixes See merge request weblogic-cloud/weblogic-deploy-tooling!1646
2 parents 4957ade + bf0ec01 commit 8f6e5bc

File tree

2 files changed

+122
-3
lines changed

2 files changed

+122
-3
lines changed

core/src/main/python/wlsdeploy/tool/deploy/applications_deployer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,12 @@ def __is_external_structured_app(self, model_source_path, combined_plan_path):
522522

523523
result = False
524524
structured_app_dir = None
525-
if not string_utils.is_empty(model_source_path) and not string_utils.is_empty(combined_plan_path):
525+
if not string_utils.is_empty(model_source_path) and not string_utils.is_empty(combined_plan_path) \
526+
and not WLSDeployArchive.isPathIntoArchive(model_source_path):
527+
526528
source_path_to_compare = model_source_path.replace('\\', '/')
527529
plan_path_to_compare = combined_plan_path.replace('\\', '/')
528530

529-
530531
# Try to determine the structured application_directory as best we can.
531532
source_path_elements = source_path_to_compare.split('/')
532533
app_dir_index = -1
@@ -537,7 +538,7 @@ def __is_external_structured_app(self, model_source_path, combined_plan_path):
537538
app_dir_index = idx
538539

539540
if app_dir_index > 0:
540-
fake_str_app_dir = '/'.join(source_path_elements[0:app_dir_index - 1])
541+
fake_str_app_dir = '/'.join(source_path_elements[0:app_dir_index])
541542
if plan_path_to_compare.startswith(fake_str_app_dir + '/'):
542543
result = True
543544
structured_app_dir = model_source_path[0:len(fake_str_app_dir)]
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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

Comments
 (0)