Skip to content

Commit 6907415

Browse files
committed
remove archive.zip and add more tests
1 parent 6e9d89d commit 6907415

File tree

8 files changed

+139
-43
lines changed

8 files changed

+139
-43
lines changed

imagetool/src/test/java/com/oracle/weblogic/imagetool/integration/BaseTest.java

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,43 @@ protected static void pullDockerImage() throws Exception {
105105
}
106106
}
107107

108-
protected static String getProjectRoot() {
108+
protected static void downloadInstallers(String... installers) throws Exception {
109+
// create the cache dir for downloading installers if not exists
110+
File cacheDir = new File(getInstallerCacheDir());
111+
if( !cacheDir.exists()) {
112+
cacheDir.mkdir();
113+
}
114+
115+
// check the required installer is downloaded
116+
for(String installer : installers) {
117+
File installFile = new File(getInstallerCacheDir() + FS + installer);
118+
if(!installFile.exists()) {
119+
throw new Exception("Please download " + installer + " from oracle support site and put it in " +
120+
getInstallerCacheDir());
121+
}
122+
}
123+
}
124+
125+
protected static String getProjectRoot() {
109126
return projectRoot;
110127
}
111128

112-
protected static String getTargetDir() {
129+
protected static String getTargetDir() {
113130
return getProjectRoot() + FS + "target";
114131
}
115132

116-
protected static String getImagetoolHome() {
133+
protected static String getImagetoolHome() {
117134
return getProjectRoot() + FS + "imagetool-" + VERSION + "-SNAPSHOT";
118135
}
119136

137+
protected static String getInstallerCacheDir() {
138+
return getProjectRoot() + FS + "caches";
139+
}
140+
141+
protected static String getWDTResourcePath() {
142+
return getProjectRoot() + FS + "src" + FS + "test" + FS + "resources" + FS + "wdt";
143+
}
144+
120145
protected void verifyResult(ExecResult result, String matchString) throws Exception {
121146
if(result.exitValue() != 0 || !result.stdout().contains(matchString)) {
122147
throw new Exception("verifying test result failed.");
@@ -151,46 +176,40 @@ protected void logTestEnd(String testMethodName) throws Exception {
151176

152177
protected ExecResult listItemsInCache() throws Exception {
153178
String command = imagetool + " cache listItems";
154-
logger.info("executing command: " + command);
155-
ExecResult result = ExecCommand.exec(command);
156-
verifyExitValue(result, command);
157-
logger.info(result.stdout());
158-
return result;
179+
return executeAndVerify(command, false);
159180
}
160181

161182
protected ExecResult addInstallerToCache(String type, String version, String path) throws Exception {
162183
String command = imagetool + " cache addInstaller --type " + type + " --version " + version +
163184
" --path " + path;
164-
logger.info("executing command: " + command);
165-
ExecResult result = ExecCommand.exec(command);
166-
verifyExitValue(result, command);
167-
logger.info(result.stdout());
168-
return result;
185+
return executeAndVerify(command, false);
169186
}
170187

171188
protected ExecResult addPatchToCache(String type, String patchId, String version, String path) throws Exception {
172189
String command = imagetool + " cache addPatch --type " + type + " --patchId " + patchId + "_" +
173190
version + " --path " + path;
174-
logger.info("Executing command: " + command);
175-
ExecResult result = ExecCommand.exec(command);
176-
verifyExitValue(result, command);
177-
logger.info(result.stdout());
178-
return result;
191+
return executeAndVerify(command, false);
179192
}
180193

181194
protected ExecResult addEntryToCache(String entryKey, String entryValue) throws Exception {
182195
String command = imagetool + " cache addEntry --key " + entryKey + " --value " + entryValue;
183-
logger.info("Executing command: " + command);
184-
ExecResult result = ExecCommand.exec(command);
185-
verifyExitValue(result, command);
186-
logger.info(result.stdout());
187-
return result;
196+
return executeAndVerify(command, false);
188197
}
189198

190199
protected ExecResult deleteEntryFromCache(String entryKey) throws Exception {
191200
String command = imagetool + " cache deleteEntry --key " + entryKey;
201+
return executeAndVerify(command, false);
202+
}
203+
204+
protected ExecResult buildWDTArchive() throws Exception {
205+
logger.info("Building WDT archive ...");
206+
String command = "sh " + getWDTResourcePath() + FS + "build-archive.sh";
207+
return executeAndVerify(command, true);
208+
}
209+
210+
private ExecResult executeAndVerify(String command, boolean isRedirectToOut) throws Exception {
192211
logger.info("Executing command: " + command);
193-
ExecResult result = ExecCommand.exec(command);
212+
ExecResult result = ExecCommand.exec(command, isRedirectToOut);
194213
verifyExitValue(result, command);
195214
logger.info(result.stdout());
196215
return result;

imagetool/src/test/java/com/oracle/weblogic/imagetool/integration/ITImagetool.java

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ITImagetool extends BaseTest {
2121
private static final String P27342434_INSTALLER = "p27342434_122130_Generic.zip";
2222
private static final String P28186730_INSTALLER = "p28186730_139400_Generic.zip";
2323
private static final String WDT_INSTALLER = "weblogic-deploy.zip";
24+
private static final String FMW_INSTALLER = "fmw_12.2.1.3.0_infrastructure_Disk1_1of1.zip";
2425
private static final String TEST_ENTRY_KEY = "mytestEntryKey";
2526
private static final String P27342434_ID = "27342434";
2627
private static final String P28186730_ID = "28186730";
@@ -43,6 +44,9 @@ public static void staticPrepare() throws Exception {
4344
setup();
4445
// pull base OS docker image used for test
4546
pullDockerImage();
47+
48+
// download the installers for the test
49+
downloadInstallers(JDK_INSTALLER, WLS_INSTALLER, WDT_INSTALLER, P27342434_INSTALLER, P28186730_INSTALLER);
4650
}
4751

4852
@AfterClass
@@ -70,7 +74,7 @@ public void test2CacheAddInstallerJDK() throws Exception {
7074
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
7175
logTestBegin(testMethodName);
7276

73-
String jdkPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + JDK_INSTALLER;
77+
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
7478
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
7579

7680
ExecResult result = listItemsInCache();
@@ -85,7 +89,7 @@ public void test3CacheAddInstallerWLS() throws Exception {
8589
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
8690
logTestBegin(testMethodName);
8791

88-
String wlsPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + WLS_INSTALLER;
92+
String wlsPath = getInstallerCacheDir() + FS + WLS_INSTALLER;
8993
addInstallerToCache("wls", WLS_VERSION, wlsPath);
9094

9195
ExecResult result = listItemsInCache();
@@ -115,7 +119,7 @@ public void test5CacheAddPatch() throws Exception {
115119
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
116120
logTestBegin(testMethodName);
117121

118-
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
122+
String patchPath = getInstallerCacheDir() + FS + P27342434_INSTALLER;
119123
deleteEntryFromCache(P27342434_ID + "_" + WLS_VERSION);
120124
addPatchToCache("wls", P27342434_ID, WLS_VERSION, patchPath);
121125

@@ -132,7 +136,7 @@ public void test6CacheAddEntry() throws Exception {
132136
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
133137
logTestBegin(testMethodName);
134138

135-
String mytestEntryValue = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
139+
String mytestEntryValue = getInstallerCacheDir() + FS + P27342434_INSTALLER;
136140
addEntryToCache(TEST_ENTRY_KEY, mytestEntryValue);
137141

138142
// verify the result
@@ -165,7 +169,7 @@ public void test8CreateWLSImgUseCache() throws Exception {
165169
logTestBegin(testMethodName);
166170

167171
// need to add the required patches 28186730 for Opatch before create wls images
168-
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P28186730_INSTALLER;
172+
String patchPath = getInstallerCacheDir() + FS + P28186730_INSTALLER;
169173
addPatchToCache("wls", P28186730_ID, OPATCH_VERSION, patchPath);
170174

171175
String command = imagetool + " create --jdkVersion " + JDK_VERSION + " --fromImage " +
@@ -203,32 +207,34 @@ public void testACreateWLSImgUsingWDT() throws Exception {
203207
logTestBegin(testMethodName);
204208

205209
// add WDT installer to the cache
206-
String wdtPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + WDT_INSTALLER;
210+
String wdtPath = getInstallerCacheDir() + FS + WDT_INSTALLER;
207211
addInstallerToCache("wdt", WDT_VERSION, wdtPath);
208212

209213
// add WLS installer to the cache
210-
String wlsPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + WLS_INSTALLER;
214+
String wlsPath = getInstallerCacheDir() + FS + WLS_INSTALLER;
211215
addInstallerToCache("wls", WLS_VERSION, wlsPath);
212216

213217
// add jdk installer to the cache
214-
String jdkPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + JDK_INSTALLER;
218+
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
215219
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
216220

217221
// need to add the required patches 28186730 for Opatch before create wls images
218222
// delete the cache entry first
219223
deleteEntryFromCache(P28186730_ID + "_opatch");
220-
String patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P28186730_INSTALLER;
224+
String patchPath = getInstallerCacheDir() + FS + P28186730_INSTALLER;
221225
addPatchToCache("wls", P28186730_ID, OPATCH_VERSION, patchPath);
222226

223227
// add the patch to the cache
224228
deleteEntryFromCache(P27342434_ID + "_" + WLS_VERSION);
225-
patchPath = getProjectRoot() + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER;
229+
patchPath = getInstallerCacheDir() + FS + P27342434_INSTALLER;
226230
addPatchToCache("wls", P27342434_ID, WLS_VERSION, patchPath);
227231

228-
String wdtResourcePath = getProjectRoot() + FS + "src" + FS + "test" + FS + "resources" + FS + "wdt" + FS;
229-
String wdtArchive = wdtResourcePath + WDT_ARCHIVE;
230-
String wdtModel = wdtResourcePath + WDT_MODEL;
231-
String wdtVariables = wdtResourcePath + WDT_VARIABLES;
232+
// build the wdt archive
233+
buildWDTArchive();
234+
235+
String wdtArchive = getWDTResourcePath() + FS + WDT_ARCHIVE;
236+
String wdtModel = getWDTResourcePath() + FS + WDT_MODEL;
237+
String wdtVariables = getWDTResourcePath() + FS + WDT_VARIABLES;
232238
String command = imagetool + " create --fromImage " +
233239
BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
234240
" --version " + WLS_VERSION + " --patches " + P27342434_ID + " --wdtVersion " + WDT_VERSION +
@@ -243,4 +249,41 @@ public void testACreateWLSImgUsingWDT() throws Exception {
243249

244250
logTestEnd(testMethodName);
245251
}
252+
253+
@Test
254+
public void testBCreateFMWImgFullInternetAccess() throws Exception {
255+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
256+
logTestBegin(testMethodName);
257+
258+
String user = System.getenv("ORACLE_SUPPORT_USERNAME");
259+
String password = System.getenv("ORACLE_SUPPORT_PASSWORD");
260+
if(user == null || password == null) {
261+
throw new Exception("Please set environment variables ORACLE_SUPPORT_USERNAME and ORACLE_SUPPORT_PASSWORD" +
262+
" for Oracle Support credentials to download the patches.");
263+
}
264+
265+
String httpProxy = System.getenv("HTTP_PROXY");
266+
String httpsProxy = System.getenv("HTTPS_PROXY");
267+
if(httpProxy == null || httpsProxy == null) {
268+
throw new Exception("Please set environment variable HTTP_PROXY and HTTPS_PROXY");
269+
}
270+
271+
// add fmw installer to the cache
272+
String fmwPath = getInstallerCacheDir() + FS + FMW_INSTALLER;
273+
addInstallerToCache("fmw", WLS_VERSION, fmwPath);
274+
275+
// add jdk installer to the cache
276+
String jdkPath = getInstallerCacheDir() + FS + JDK_INSTALLER;
277+
addInstallerToCache("jdk", JDK_VERSION, jdkPath);
278+
279+
String command = imagetool + " create --version=" + WLS_VERSION + " --tag imagetool:" + testMethodName +
280+
" --latestPSU --user " + user + " --passwordEnv ORACLE_SUPPORT_PASSWORD --httpProxyUrl " +
281+
httpProxy + " --httpsProxyUrl " + httpsProxy + " --type fmw";
282+
logger.info("Executing command: " + command);
283+
ExecCommand.exec(command, true);
284+
285+
// verify the docker image is created
286+
verifyDockerImages(testMethodName);
287+
logTestEnd(testMethodName);
288+
}
246289
}
-1.48 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
#
3+
#Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
4+
#
5+
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
#
7+
8+
rm -Rf src/test/resources/wdt/archive
9+
mkdir -p src/test/resources/wdt/archive/wlsdeploy/applications
10+
cd src/test/resources/wdt/simple-app
11+
jar cvf ../archive/wlsdeploy/applications/simple-app.war *
12+
cd ../archive
13+
jar cvf ../archive.zip *

imagetool/src/test/resources/wdt/domain.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at
3+
# http://oss.oracle.com/licenses/upl.
4+
15
# These variables are used for substitution in the WDT model file.
26
# Any port that will be exposed through Docker is put in this file.
37
# The sample Dockerfile will get the ports from this file and not the WDT model.
@@ -29,10 +33,5 @@ dbpassword=dba1
2933
dstestquery=SQL SELECT 1 FROM SYS.SYSTABLES
3034
dsinitalcapacity=1
3135
dsmaxcapacity=15
32-
33-
34-
35-
36-
3736
#Derby Data Source parameters
3837
dsname=DockerDS
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
5+
<welcome-file-list>
6+
<welcome-file>/simple.html</welcome-file>
7+
</welcome-file-list>
8+
</web-app>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
3+
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90">
4+
<context-root>/simple</context-root>
5+
</weblogic-web-app>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Simple Application</title>
4+
</head>
5+
<body>
6+
<h1>Simple Application</h1>
7+
<p>This is the simple application.</p>
8+
</body>
9+
</html>

0 commit comments

Comments
 (0)