Skip to content

Commit fef2088

Browse files
committed
Added a unit test for wko_filter
1 parent 165e97b commit fef2088

File tree

4 files changed

+145
-2
lines changed

4 files changed

+145
-2
lines changed

core/src/main/python/wlsdeploy/tool/util/filters/wko_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from wlsdeploy.util import dictionary_utils
2323

2424
_class_name = 'wko_filter'
25-
_logger = PlatformLogger('wlsdeploy.aliases')
25+
_logger = PlatformLogger('wlsdeploy.tool.util')
2626

2727

2828
def filter_model(model, model_context):

core/src/test/python/base_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _restore_logs(self):
6666

6767
def _match(self, value, dictionary, *args):
6868
dictionary_value = self._traverse(dictionary, *args)
69-
if dictionary_value != str(value):
69+
if str(dictionary_value) != str(value):
7070
key = '/'.join(list(args))
7171
self.fail(key + ' equals ' + str(dictionary_value) + ', should equal ' + str(value))
7272

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""
2+
Copyright (c) 2021, 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+
import os
6+
7+
from base_test import BaseTestCase
8+
from wlsdeploy.aliases.model_constants import APPLICATION
9+
from wlsdeploy.aliases.model_constants import APP_DEPLOYMENTS
10+
from wlsdeploy.aliases.model_constants import AUTHENTICATION_PROVIDER
11+
from wlsdeploy.aliases.model_constants import CALCULATED_LISTEN_PORTS
12+
from wlsdeploy.aliases.model_constants import CLUSTER
13+
from wlsdeploy.aliases.model_constants import DEFAULT_AUTHENTICATOR
14+
from wlsdeploy.aliases.model_constants import DYNAMIC_SERVERS
15+
from wlsdeploy.aliases.model_constants import REALM
16+
from wlsdeploy.aliases.model_constants import SECURITY_CONFIGURATION
17+
from wlsdeploy.aliases.model_constants import TOPOLOGY
18+
from wlsdeploy.tool.util.filters import wko_filter
19+
from wlsdeploy.util.model_context import ModelContext
20+
from wlsdeploy.util.model_translator import FileToPython
21+
22+
23+
class WkoFilterTestCase(BaseTestCase):
24+
_program_name = 'wko_filter_test'
25+
_jta_cluster = 'JTACluster'
26+
_jta_cluster_info_list = 'DeterminerCandidateResourceInfoList'
27+
_provider_class_name = 'ProviderClassName'
28+
_multi_version_app = 'MultiVersionApp'
29+
30+
def __init__(self, *args):
31+
BaseTestCase.__init__(self, *args)
32+
self.MODELS_DIR = os.path.join(self.TEST_CLASSES_DIR, 'prepare')
33+
self.PREPARE_OUTPUT_DIR = os.path.join(self.TEST_OUTPUT_DIR, 'prepare')
34+
35+
def setUp(self):
36+
BaseTestCase.setUp(self)
37+
self._establish_directory(self.PREPARE_OUTPUT_DIR)
38+
39+
def testFilter(self):
40+
"""
41+
Filter the model and verify the results
42+
"""
43+
model_file = os.path.join(self.MODELS_DIR, 'wko-filter.yaml')
44+
translator = FileToPython(model_file, use_ordering=True)
45+
model = translator.parse()
46+
47+
# online attributes are in the model before filtering
48+
49+
jta_cluster = self._traverse(model, TOPOLOGY, CLUSTER, 'staticCluster', self._jta_cluster)
50+
self.assertEqual(True, self._jta_cluster_info_list in jta_cluster,
51+
self._jta_cluster_info_list + " should be in " + self._jta_cluster + " before filtering")
52+
53+
authenticator = self._traverse(model, TOPOLOGY, SECURITY_CONFIGURATION, REALM, 'yourRealm',
54+
AUTHENTICATION_PROVIDER, DEFAULT_AUTHENTICATOR, DEFAULT_AUTHENTICATOR)
55+
self.assertEqual(True, self._provider_class_name in authenticator,
56+
self._provider_class_name + " should be in " + DEFAULT_AUTHENTICATOR + " before filtering")
57+
58+
my_app = self._traverse(model, APP_DEPLOYMENTS, APPLICATION, 'myApp')
59+
self.assertEqual(True, self._multi_version_app in my_app,
60+
self._multi_version_app + " should be in \"myApp\" before filtering")
61+
62+
# Apply the filter
63+
64+
self._suspend_logs('wlsdeploy.tool.util')
65+
model_context = ModelContext(self._program_name, {})
66+
wko_filter.filter_model(model, model_context)
67+
self._restore_logs()
68+
69+
# Dynamic clusters should have "CalculatedListenPorts" set to false
70+
71+
self._match(0, model, TOPOLOGY, CLUSTER, 'dynamicCluster', DYNAMIC_SERVERS, CALCULATED_LISTEN_PORTS)
72+
self._match(0, model, TOPOLOGY, CLUSTER, 'dynamicCluster2', DYNAMIC_SERVERS, CALCULATED_LISTEN_PORTS)
73+
74+
# Online-only attributes should be removed from the model
75+
76+
jta_cluster = self._traverse(model, TOPOLOGY, CLUSTER, 'staticCluster', self._jta_cluster)
77+
self._no_dictionary_key(jta_cluster, self._jta_cluster_info_list)
78+
79+
authenticator = self._traverse(model, TOPOLOGY, SECURITY_CONFIGURATION, REALM, 'yourRealm',
80+
AUTHENTICATION_PROVIDER, DEFAULT_AUTHENTICATOR, DEFAULT_AUTHENTICATOR)
81+
self._no_dictionary_key(authenticator, self._provider_class_name)
82+
83+
my_app = self._traverse(model, APP_DEPLOYMENTS, APPLICATION, 'myApp')
84+
self._no_dictionary_key(my_app, self._multi_version_app)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
domainInfo:
2+
AdminUserName: weblogic
3+
AdminPassword: 'welcome1'
4+
topology:
5+
Name: DemoDomain
6+
Cluster:
7+
staticCluster:
8+
CoherenceClusterSystemResource: DataGridConfig
9+
JTACluster:
10+
# remove, attribute is online only
11+
DeterminerCandidateResourceInfoList: []
12+
Notes: not here
13+
dynamicCluster:
14+
DynamicServers:
15+
# add CalculatedListenPorts set to false
16+
MaxDynamicClusterSize: 4
17+
DynamicClusterSize: 3
18+
dynamicCluster2:
19+
DynamicServers:
20+
MaxDynamicClusterSize: 4
21+
# change CalculatedListenPorts to false
22+
CalculatedListenPorts: true
23+
DynamicClusterSize: 3
24+
Server:
25+
m1:
26+
Cluster: staticCluster
27+
ListenPort: 5001
28+
m2:
29+
Cluster: staticCluster
30+
# string value should match numeric value
31+
ListenPort: "5001"
32+
m3:
33+
Cluster: staticCluster
34+
# this should cause a warning message
35+
ListenPort: 5002
36+
37+
# confirm that model traversal deals with artificial type folders correctly
38+
SecurityConfiguration:
39+
Realm:
40+
yourRealm:
41+
AuthenticationProvider:
42+
DefaultAuthenticator:
43+
DefaultAuthenticator:
44+
ControlFlag: OPTIONAL
45+
# remove, attribute is online only
46+
ProviderClassName: 'com.defaultClass'
47+
'My custom IdentityAsserter':
48+
# confirm that model traversal allows unrecognized provider type,
49+
# such as this custom provider
50+
'com.custom.CustomIdentityAsserter':
51+
ControlFlag: SUFFICIENT
52+
UseDefaultUserNameMapper: true
53+
54+
appDeployments:
55+
Application:
56+
myApp:
57+
SourcePath: 'wlsdeploy/applications/sample-app.war'
58+
# remove, attribute is online only
59+
MultiVersionApp: false

0 commit comments

Comments
 (0)