Skip to content

Commit d3c30dc

Browse files
committed
Keep all integration test files together in the target folder
* replace all writes to stdout suppressed by JUnit5 * cleaning up unit tests to run locally * move system-test domains folder under target folder * removed second after-test callback for timing and logging and consolidated * keep all integration test files in the build target for debugging purposes
1 parent c6d9d11 commit d3c30dc

File tree

8 files changed

+530
-499
lines changed

8 files changed

+530
-499
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<unit-test-wlst-dir>${env.WLST_DIR}</unit-test-wlst-dir>
5555
<skipITs>true</skipITs>
5656
<alias-test-skipITs>true</alias-test-skipITs>
57+
<test.groups>gate</test.groups>
5758
</properties>
5859

5960
<dependencyManagement>
@@ -118,6 +119,9 @@
118119
<groupId>org.apache.maven.plugins</groupId>
119120
<artifactId>maven-failsafe-plugin</artifactId>
120121
<version>3.0.0-M5</version>
122+
<configuration>
123+
<groups>${test.groups}</groups>
124+
</configuration>
121125
</plugin>
122126
<plugin>
123127
<groupId>org.apache.maven.plugins</groupId>

system-test/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<argLine>
7979
-Xmx1024m
8080
</argLine>
81+
<groups>gate</groups>
8182
<systemProperties>
8283
<property>
8384
<name>wdtversion</name>
@@ -103,7 +104,7 @@
103104
<phase>integration-test</phase>
104105
<configuration>
105106
<systemPropertyVariables>
106-
<java.util.logging.SimpleFormatter.format>&lt;%1$tm-%1$td-%1$tY %1$tH:%1$tM:%1$tS&gt; &lt;%4$s&gt; &lt;%2$s&gt; &lt;%5$s%6$s&gt;%n</java.util.logging.SimpleFormatter.format>
107+
<java.util.logging.SimpleFormatter.format>&lt;%1$tm-%1$td-%1$tY %1$tH:%1$tM:%1$tS&gt; &lt;%4$s&gt; %5$s%6$s%n</java.util.logging.SimpleFormatter.format>
107108
</systemPropertyVariables>
108109
<trimStackTrace>false</trimStackTrace>
109110
</configuration>

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

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,33 @@
66
import java.io.BufferedReader;
77
import java.io.File;
88
import java.io.FileReader;
9+
import java.io.IOException;
910
import java.nio.file.Files;
1011
import java.nio.file.Path;
1112
import java.nio.file.Paths;
1213
import java.util.ArrayList;
1314
import java.util.List;
1415

15-
import oracle.weblogic.deploy.integration.annotations.Logger;
16+
import oracle.weblogic.deploy.integration.annotations.TestingLogger;
1617
import oracle.weblogic.deploy.integration.utils.CommandResult;
1718
import oracle.weblogic.deploy.integration.utils.Runner;
1819
import oracle.weblogic.deploy.logging.PlatformLogger;
1920
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
20-
import oracle.weblogic.deploy.util.FileUtils;
21+
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2124

2225
public class BaseTest {
23-
@Logger
26+
@TestingLogger
2427
private static final PlatformLogger logger = WLSDeployLogFactory.getLogger("integration.tests");
2528
protected static final String FS = File.separator;
2629
private static final String SAMPLE_ARCHIVE_FILE = "archive.zip";
2730
private static final String WDT_ZIPFILE = "weblogic-deploy.zip";
2831
private static final String WDT_HOME_DIR = "weblogic-deploy";
2932
protected static final String SAMPLE_MODEL_FILE_PREFIX = "simple-topology";
3033
protected static final String SAMPLE_VARIABLE_FILE = "domain.properties";
31-
private static int maxIterations = 50;
32-
private static int waitTime = 5;
33-
private static String projectRoot = "";
34+
private static final int maxIterations = 50;
35+
private static final int waitTime = 5;
3436
protected static String mwhome_12213 = "";
3537
protected static String createDomainScript = "";
3638
protected static String compareModelScript = "";
@@ -39,17 +41,14 @@ public class BaseTest {
3941
protected static String deployAppScript = "";
4042
protected static String encryptModelScript = "";
4143
protected static String validateModelScript = "";
42-
protected static String domainParent12213 = "";
44+
protected static String domainParentDir = "";
4345
protected static final String ORACLE_DB_IMG = "phx.ocir.io/weblogick8s/database/enterprise";
4446
protected static final String ORACLE_DB_IMG_TAG = "12.2.0.1-slim";
4547
private static final String DB_CONTAINER_NAME = "InfraDB";
4648

4749
protected static void initialize() {
4850

4951
logger.info("Initializing the tests ...");
50-
projectRoot = System.getProperty("user.dir");
51-
logger.info("DEBUG: projectRoot=" + projectRoot);
52-
5352
mwhome_12213 = System.getProperty("MW_HOME");
5453

5554
createDomainScript = getWDTScriptsHome() + FS + "createDomain.sh";
@@ -60,7 +59,7 @@ protected static void initialize() {
6059
validateModelScript = getWDTScriptsHome() + FS + "validateModel.sh";
6160
compareModelScript = getWDTScriptsHome() + FS + "compareModel.sh";
6261

63-
domainParent12213 = "." + FS + "domains";
62+
domainParentDir = "." + FS + "target" + FS + "domains";
6463
}
6564

6665
protected static void setup() throws Exception {
@@ -74,40 +73,21 @@ protected static void setup() throws Exception {
7473
executeAndVerify(cmd);
7574

7675
// create domain_parent directory if not existing
77-
File domainParentDir = new File(domainParent12213);
76+
File domainParentDir = new File(BaseTest.domainParentDir);
7877
if(!domainParentDir.exists()) {
79-
domainParentDir.mkdir();
78+
assertTrue(domainParentDir.mkdir(), "Setup failed to create Domain parent directory");
8079
}
81-
82-
chmodScriptFiles(createDomainScript, discoverDomainScript, updateDomainScript, deployAppScript,
83-
encryptModelScript, validateModelScript);
84-
8580
}
8681

8782
protected static void cleanup() throws Exception {
8883
logger.info("cleaning up the test environment ...");
8984

90-
// remove WDT script home directory
91-
String cmd = "rm -rf " + getTargetDir() + FS + WDT_HOME_DIR;
92-
Runner.run(cmd);
93-
9485
String command = "docker rm -f " + DB_CONTAINER_NAME;
9586
Runner.run(command);
96-
97-
// delete the domain directory created by the tests
98-
File domainParentDir = new File(domainParent12213);
99-
100-
if(domainParentDir.exists()) {
101-
FileUtils.deleteDirectory(domainParentDir);
102-
}
103-
}
104-
105-
protected static String getProjectRoot() {
106-
return projectRoot;
10787
}
10888

109-
protected static String getTargetDir() {
110-
return getProjectRoot() + FS + "target";
89+
protected static Path getTargetDir() {
90+
return Paths.get("target");
11191
}
11292

11393
protected static void chmodScriptFiles(String... filenames) throws Exception {
@@ -127,9 +107,8 @@ protected static void pullOracleDBDockerImage() throws Exception {
127107
private static void pullDockerImage(String imagename, String imagetag) throws Exception {
128108

129109
String cmd = "docker pull " + imagename + ":" + imagetag;
130-
logger.info("executing command: " + cmd);
131110
CommandResult result = Runner.run(cmd);
132-
logger.info("DEBUG: result.stdout=" + result.stdout() );
111+
assertEquals(0, result.exitValue(), "Docker pull failed for " + imagename);
133112

134113
// verify the docker image is pulled
135114
result = Runner.run("docker images | grep " + imagename + " | grep " +
@@ -169,7 +148,6 @@ protected void verifyErrorMsg(CommandResult result, String errorMsg) throws Exce
169148

170149
protected void verifyModelFile(String modelFile) throws Exception {
171150
String cmd = "ls " + modelFile + " | wc -l";
172-
logger.info("executing command: " + cmd);
173151
CommandResult result = Runner.run(cmd);
174152
if(Integer.parseInt(result.stdout().trim()) != 1) {
175153
throw new Exception("no model file is created as expected");
@@ -188,8 +166,8 @@ protected void verifyFileDoesNotExists(String filePath) throws Exception {
188166
}
189167
}
190168

191-
protected static String getResourcePath() {
192-
return getProjectRoot() + FS + "src" + FS + "test" + FS + "resources";
169+
protected static Path getResourcePath() {
170+
return Paths.get("src", "test", "resources");
193171
}
194172

195173
protected static String getGeneratedResourcePath() {
@@ -210,8 +188,8 @@ protected static String getSampleModelFile(String suffix) {
210188
return getResourcePath() + FS + SAMPLE_MODEL_FILE_PREFIX + suffix + ".yaml";
211189
}
212190

213-
protected static String getInstallerTargetDir() {
214-
return getProjectRoot() + FS + ".." + FS + "installer" + FS + "target";
191+
protected static Path getInstallerTargetDir() {
192+
return Paths.get("..", "installer", "target");
215193
}
216194

217195
protected static String getSampleVariableFile() {
@@ -224,30 +202,28 @@ protected static void createDBContainer() throws Exception {
224202
Runner.run(command);
225203

226204
String exposePort = "";
227-
System.out.println("***********\n\n\n**********\n\n\n********\n "
228-
+ System.getProperty("db.use.container.network")
229-
+ "\n**************\n\n********");
230205
if (System.getProperty("db.use.container.network").equals("false")) {
231-
exposePort = " -p1521:1521 ";
206+
exposePort = " -p1521:1521 -p5500:5500 ";
232207
}
233208

234209
command = "docker run -d --name " + DB_CONTAINER_NAME + " --env=\"DB_PDB=InfraPDB1\"" +
235210
" --env=\"DB_DOMAIN=us.oracle.com\" --env=\"DB_BUNDLE=basic\" " + exposePort
236211
+ ORACLE_DB_IMG + ":" + ORACLE_DB_IMG_TAG;
237212
Runner.run(command);
213+
}
238214

239-
// wait for the db is ready
240-
command = "docker ps | grep " + DB_CONTAINER_NAME;
241-
checkCmdInLoop(command, "healthy");
215+
static void waitForDatabase() throws IOException, InterruptedException {
216+
// Wait for the database container to be healthy before continuing
217+
String command = "docker inspect --format='{{json .State.Health}}' " + DB_CONTAINER_NAME;
218+
checkCmdInLoop(command, "\"Status\":\"healthy");
242219
}
243220

244-
protected static void replaceStringInFile(String filename, String originalString, String newString)
221+
protected static void replaceStringInFile(Path original, Path output, String originalString, String newString)
245222
throws Exception {
246-
Path path = Paths.get(filename);
247223

248-
String content = new String(Files.readAllBytes(path));
224+
String content = new String(Files.readAllBytes(original));
249225
content = content.replaceAll(originalString, newString);
250-
Files.write(path, content.getBytes());
226+
Files.write(output, content.getBytes());
251227
}
252228

253229
protected String getDBContainerIP() throws Exception {
@@ -289,22 +265,21 @@ protected BufferedReader inputYaml(String yamlFileName) throws Exception {
289265
}
290266

291267
private static CommandResult executeAndVerify(String command) throws Exception {
292-
logger.info("Executing command: " + command);
293268
CommandResult result = Runner.run(command);
294269
verifyExitValue(result, command);
295270
return result;
296271
}
297272

298-
private static void checkCmdInLoop(String cmd, String matchStr)
299-
throws Exception {
273+
private static void checkCmdInLoop(String cmd, String matchStr) throws IOException, InterruptedException {
300274
int i = 0;
301275
while (i < maxIterations) {
302276
CommandResult result = Runner.run(cmd);
303277

304278
// pod might not have been created or if created loop till condition
305279
if (result.exitValue() != 0
306-
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
307-
logger.info("Output for " + cmd + "\n" + result.stdout() + "\n " + result.stdout());
280+
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
281+
282+
logger.info("Output for '" + cmd + "'\n" + result.stdout() + "\n " + result.stdout());
308283
// check for last iteration
309284
if (i == (maxIterations - 1)) {
310285
throw new RuntimeException(
@@ -323,7 +298,7 @@ private static void checkCmdInLoop(String cmd, String matchStr)
323298
Thread.sleep(waitTime * 1000);
324299
i++;
325300
} else {
326-
logger.info("get the expected String " + matchStr);
301+
logger.info("Found expected result: " + matchStr);
327302
break;
328303
}
329304
}

0 commit comments

Comments
 (0)