Skip to content

Commit b34d11a

Browse files
CarolynRountreeddsharpe
authored andcommitted
Wdt system test save logs during cleanup (#465)
* Create after method to save logs even if exception
1 parent 4d4bf02 commit b34d11a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ protected static void cleanup() throws Exception {
9090
}
9191
}
9292

93+
protected static void saveLogFiles(String testMethodName) throws Exception {
94+
logger.info("saving log files ...");
95+
96+
// save the logs for this test instance in the workspace target directory
97+
String cmd = "tar -cvf" + getTargetDir() +FS + testMethodName + ".tar " + getTargetDir() + FS + WDT_HOME_DIR +
98+
FS + "logs";
99+
executeNoVerify(cmd);
100+
}
101+
93102
protected static String getProjectRoot() {
94103
return projectRoot;
95104
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import org.junit.runners.MethodSorters;
1111
import org.junit.BeforeClass;
1212
import org.junit.AfterClass;
13+
import org.junit.Rule;
1314
import org.junit.Test;
15+
import org.junit.rules.TestRule;
16+
import org.junit.rules.TestWatcher;
17+
import org.junit.runner.Description;
1418
import java.nio.file.Files;
1519
import java.nio.file.Path;
1620
import java.nio.file.Paths;
@@ -43,6 +47,22 @@ public static void staticUnprepare() throws Exception {
4347
cleanup();
4448
}
4549

50+
51+
@Rule
52+
public TestWatcher watcher = new TestWatcher() {
53+
@Override
54+
protected void failed(Throwable e, Description description) {
55+
if (e != null) {
56+
logger.info("Method " + description.getMethodName() + " Exception: " + e.getLocalizedMessage());
57+
}
58+
try {
59+
saveLogFiles(description.getMethodName());
60+
} catch (Exception le) {
61+
logger.info("Unable to save log files : " + le.getLocalizedMessage());
62+
}
63+
}
64+
};
65+
4666
/**
4767
* test createDomain.sh with only -oracle_home argument
4868
* @throws Exception - if any error occurs
@@ -362,6 +382,7 @@ public void testFDiscoverDomainWithRequiredArgument() throws Exception {
362382

363383
logger.info("executing command: " + cmd);
364384
ExecResult result = ExecCommand.exec(cmd);
385+
365386
verifyResult(result, "discoverDomain.sh completed successfully");
366387

367388
// unzip discoveredArchive.zip
@@ -393,6 +414,7 @@ public void testGDiscoverDomainWithModelFile() throws Exception {
393414

394415
logger.info("executing command: " + cmd);
395416
ExecResult result = ExecCommand.exec(cmd);
417+
396418
verifyResult(result, "discoverDomain.sh completed successfully");
397419

398420
// verify model file
@@ -418,6 +440,7 @@ public void testHDiscoverDomainJRFDomainType() throws Exception {
418440

419441
logger.info("executing command: " + cmd);
420442
ExecResult result = ExecCommand.exec(cmd);
443+
421444
verifyResult(result, "discoverDomain.sh completed successfully");
422445

423446
// verify model file

0 commit comments

Comments
 (0)