Skip to content

Commit c30224f

Browse files
authored
Add unit test and integration test for compareModel (#833)
* Add unit test and integration test for compareModel * update comments * Fix compile error * change script variable name * copyright updates
1 parent df51ec5 commit c30224f

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

core/src/test/python/compare_model_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,47 @@ def testCompareModel4(self):
523523

524524
self.assertEqual(return_code, 0)
525525

526+
# This test is to ensure any behavior change does not impact WKO
527+
def testCompareModel5(self):
528+
_method_name = 'testCompareModel5'
529+
530+
_models_dir = self._resources_dir + '/compare'
531+
_new_model_file = _models_dir + '/model-4-new.yaml'
532+
_old_model_file = _models_dir + '/model-4-new.yaml'
533+
534+
_output_dir = os.path.join(self._results_dir, 'model-5')
535+
if not os.path.isdir(_output_dir):
536+
os.mkdir(_output_dir)
537+
538+
args_map = {
539+
'-oracle_home': '/oracle',
540+
'-output_dir': _output_dir,
541+
'-trailing_arguments': [_new_model_file, _old_model_file]
542+
}
543+
544+
try:
545+
model_context = ModelContext('CompareModelTestCase', args_map)
546+
differ = ModelFileDiffer(_new_model_file, _old_model_file, model_context, _output_dir)
547+
return_code = differ.compare()
548+
self.assertEqual(return_code, 0)
549+
550+
yaml_result = _output_dir + os.sep + 'diffed_model.yaml'
551+
self.assertEqual(os.path.exists(yaml_result), False, "YAML result should not exist: " + yaml_result)
552+
553+
json_result = _output_dir + os.sep + 'diffed_model.json'
554+
self.assertEqual(os.path.exists(json_result), False, "JSON result should not exist: " + json_result)
555+
556+
json_result = _output_dir + os.sep + 'compare_model_stdout'
557+
self.assertEqual(os.path.exists(json_result), False, "compare_model.stdout result should not exist: " +
558+
json_result)
559+
560+
except (CompareException, PyWLSTException), te:
561+
return_code = 2
562+
self._logger.severe('WLSDPLY-05709', te.getLocalizedMessage(), error=te,
563+
class_name=self._program_name, method_name=_method_name)
564+
565+
self.assertEqual(return_code, 0)
566+
526567

527568
if __name__ == '__main__':
528569
unittest.main()

system-test/src/test/java/oracle/weblogic/deploy/integration/BaseTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019, 2020, Oracle Corporation and/or its affiliates.
1+
// Copyright 2019, 2021, Oracle Corporation and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.deploy.integration;
@@ -30,6 +30,7 @@ public class BaseTest {
3030
private static String projectRoot = "";
3131
protected static String mwhome_12213 = "";
3232
protected static String createDomainScript = "";
33+
protected static String compareModelScript = "";
3334
protected static String discoverDomainScript = "";
3435
protected static String updateDomainScript = "";
3536
protected static String deployAppScript = "";
@@ -54,6 +55,8 @@ protected static void initialize() {
5455
deployAppScript = getWDTScriptsHome() + FS + "deployApps.sh";
5556
encryptModelScript = getWDTScriptsHome() + FS + "encryptModel.sh";
5657
validateModelScript = getWDTScriptsHome() + FS + "validateModel.sh";
58+
compareModelScript = getWDTScriptsHome() + FS + "compareModel.sh";
59+
5760
domainParent12213 = "." + FS + "domains";
5861
}
5962

@@ -183,6 +186,18 @@ protected void verifyModelFile(String modelFile) throws Exception {
183186
}
184187
}
185188

189+
protected void verifyFileExists(String filePath) throws Exception {
190+
if (!Files.exists(Paths.get(filePath))) {
191+
throw new Exception("File does not exists but should " + filePath);
192+
}
193+
}
194+
195+
protected void verifyFileDoesNotExists(String filePath) throws Exception {
196+
if (Files.exists(Paths.get(filePath))) {
197+
throw new Exception("File exists but should not " + filePath);
198+
}
199+
}
200+
186201
protected void logTestBegin(String testMethodName) throws Exception {
187202
logger.info("=======================================");
188203
logger.info("BEGIN test " + testMethodName + " ...");

system-test/src/test/java/oracle/weblogic/deploy/integration/ITWdt.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019, 2020, Oracle Corporation and/or its affiliates.
1+
// Copyright 2019, 2021, Oracle Corporation and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -773,6 +773,31 @@ public void testNValidateModelWithoutVariableFile() throws Exception {
773773
logTestEnd(testMethodName);
774774
}
775775

776+
/**
777+
* test compareModel.sh with only attribute difference. The files existences test whether it impacts WKO operation
778+
* @throws Exception - if any error occurs
779+
*/
780+
@Test
781+
public void testCompareModelRemoveAttribute() throws Exception {
782+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
783+
logTestBegin(testMethodName);
784+
Path tempPath = Files.createTempDirectory("wdt_temp_output");
785+
String tmpdir = tempPath.toFile().getAbsolutePath();
786+
tempPath.toFile().deleteOnExit();
787+
String cmd = compareModelScript + " -oracle_home " + mwhome_12213 + " -output_dir " + tmpdir
788+
+ " " + getSampleModelFile("1-lessattribute") + " " + getSampleModelFile("1");
789+
logger.info("Executing command: " + cmd);
790+
ExecResult result = ExecCommand.exec(cmd);
791+
verifyResult(result, "compareModel.sh completed successfully");
792+
793+
String diffedModelYaml = tmpdir + File.separator + "diffed_model.yaml";
794+
String compareModelStdout = tmpdir + File.separator + "compare_model_stdout";
795+
verifyFileExists(compareModelStdout);
796+
verifyFileDoesNotExists(diffedModelYaml);
797+
798+
logTestEnd(testMethodName);
799+
}
800+
776801
/**
777802
* test validateModel.sh with invalid model file
778803
* @throws Exception - if any error occurs
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
domainInfo:
2+
AdminUserName: weblogic
3+
AdminPassword: welcome1
4+
ServerStartMode: '@@PROP:SERVER_START_MODE@@'
5+
topology:
6+
Name: '@@PROP:DOMAIN_NAME@@'
7+
AdminServerName: '@@PROP:ADMIN_NAME@@'
8+
ProductionModeEnabled: '@@PROP:PRODUCTION_MODE_ENABLED@@'
9+
Cluster:
10+
'@@PROP:CLUSTER_NAME@@':
11+
ClientCertProxyEnabled: true
12+
#FrontendHost: localhost
13+
DynamicServers:
14+
ServerTemplate: template1
15+
CalculatedListenPorts: true
16+
ServerNamePrefix: '@@PROP:MANAGED_SERVER_NAME_BASE@@'
17+
DynamicClusterSize: '@@PROP:CONFIGURED_MANAGED_SERVER_COUNT@@'
18+
MaxDynamicClusterSize: '@@PROP:CONFIGURED_MANAGED_SERVER_COUNT@@'
19+
Server:
20+
'@@PROP:ADMIN_NAME@@':
21+
ListenPort: '@@PROP:ADMIN_PORT@@'
22+
NetworkAccessPoint:
23+
T3Channel:
24+
ListenAddress: None
25+
ListenPort: '@@PROP:T3_CHANNEL_PORT@@'
26+
PublicAddress: '@@PROP:T3_PUBLIC_ADDRESS@@'
27+
PublicPort: '@@PROP:T3_CHANNEL_PORT@@'
28+
ServerTemplate:
29+
template1:
30+
ListenPort: '@@PROP:MANAGED_SERVER_PORT@@'
31+
appDeployments:
32+
Application:
33+
# Quote needed because of hyphen in string
34+
'simple-app':
35+
SourcePath: 'wlsdeploy/applications/simple-app.war'
36+
Target: '@@PROP:CLUSTER_NAME@@'
37+
ModuleType: war
38+
StagingMode: nostage
39+
PlanStagingMode: nostage

0 commit comments

Comments
 (0)