1
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.
2
+ // Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4
3
5
4
package com .oracle .weblogic .imagetool .integration ;
6
5
7
- import com .oracle .weblogic .imagetool .integration .utils .ExecCommand ;
8
- import com .oracle .weblogic .imagetool .integration .utils .ExecResult ;
9
6
import java .io .File ;
10
7
import java .nio .file .Files ;
11
8
import java .nio .file .Path ;
12
9
import java .nio .file .Paths ;
13
10
import java .util .logging .Logger ;
14
11
12
+ import com .oracle .weblogic .imagetool .integration .utils .ExecCommand ;
13
+ import com .oracle .weblogic .imagetool .integration .utils .ExecResult ;
14
+
15
15
public class BaseTest {
16
16
17
17
protected static final Logger logger = Logger .getLogger (ITImagetool .class .getName ());
@@ -38,22 +38,22 @@ protected static void initialize() throws Exception {
38
38
39
39
projectRoot = System .getProperty ("user.dir" );
40
40
41
- if (System .getenv ("WLSIMG_BLDDIR" ) != null ) {
41
+ if (System .getenv ("WLSIMG_BLDDIR" ) != null ) {
42
42
wlsImgBldDir = System .getenv ("WLSIMG_BLDDIR" );
43
43
} else {
44
44
wlsImgBldDir = System .getenv ("HOME" );
45
45
}
46
- if (System .getenv ("WLSIMG_CACHEDIR" ) != null ) {
46
+ if (System .getenv ("WLSIMG_CACHEDIR" ) != null ) {
47
47
wlsImgCacheDir = System .getenv ("WLSIMG_CACHEDIR" );
48
48
} else {
49
49
wlsImgCacheDir = System .getenv ("HOME" ) + FS + "cache" ;
50
50
}
51
51
52
- imagetool = "java -cp \" " + getImagetoolHome () + FS + "lib" + FS + "*\" -Djava.util.logging.config.file=" +
53
- getImagetoolHome () + FS + "bin" + FS + "logging.properties com.oracle.weblogic.imagetool.cli.CLIDriver" ;
52
+ imagetool = "java -cp \" " + getImagetoolHome () + FS + "lib" + FS + "*\" -Djava.util.logging.config.file="
53
+ + getImagetoolHome () + FS + "bin" + FS + "logging.properties com.oracle.weblogic.imagetool.cli.CLIDriver" ;
54
54
55
55
build_tag = System .getenv ("BUILD_TAG" );
56
- if (build_tag != null ) {
56
+ if (build_tag != null ) {
57
57
build_tag = build_tag .toLowerCase ();
58
58
} else {
59
59
build_tag = "imagetool" ;
@@ -78,7 +78,7 @@ protected static void setup() throws Exception {
78
78
command = "source " + getImagetoolHome () + FS + "bin" + FS + "setup.sh" ;
79
79
executeNoVerify (command );
80
80
81
- if (!(new File (wlsImgBldDir )).exists ()) {
81
+ if (!(new File (wlsImgBldDir )).exists ()) {
82
82
logger .info (wlsImgBldDir + " does not exist, creating it" );
83
83
(new File (wlsImgBldDir )).mkdir ();
84
84
}
@@ -95,8 +95,8 @@ protected static void cleanup() throws Exception {
95
95
// clean up the docker images
96
96
command = "docker stop " + dbContainerName ;
97
97
executeNoVerify (command );
98
- command = "docker rmi -f " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " " + ORACLE_DB_IMG + ":" +
99
- ORACLE_DB_IMG_TAG ;
98
+ command = "docker rmi -f " + BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " " + ORACLE_DB_IMG + ":"
99
+ + ORACLE_DB_IMG_TAG ;
100
100
executeNoVerify (command );
101
101
102
102
command = "docker rmi -f $(docker images | grep " + build_tag + " | tr -s ' ' | cut -d ' ' -f 3)" ;
@@ -120,23 +120,23 @@ protected static void pullOracleDBDockerImage() throws Exception {
120
120
protected static void downloadInstallers (String ... installers ) throws Exception {
121
121
// create the cache dir for downloading installers if not exists
122
122
File cacheDir = new File (getInstallerCacheDir ());
123
- if ( !cacheDir .exists ()) {
123
+ if ( !cacheDir .exists ()) {
124
124
cacheDir .mkdir ();
125
125
}
126
126
127
127
boolean missingInstaller = false ;
128
128
StringBuffer errorMsg = new StringBuffer ();
129
129
errorMsg .append ("The test installers are missing. Please download: \n " );
130
130
// check the required installer is downloaded
131
- for (String installer : installers ) {
131
+ for (String installer : installers ) {
132
132
File installFile = new File (getInstallerCacheDir () + FS + installer );
133
- if (!installFile .exists ()) {
133
+ if (!installFile .exists ()) {
134
134
missingInstaller = true ;
135
- errorMsg .append ( " " + installer + "\n " );
135
+ errorMsg .append (" " + installer + "\n " );
136
136
}
137
137
}
138
138
errorMsg .append ("and put them in " + getInstallerCacheDir ());
139
- if (missingInstaller ) {
139
+ if (missingInstaller ) {
140
140
throw new Exception (errorMsg .toString ());
141
141
}
142
142
}
@@ -168,23 +168,23 @@ protected static void executeNoVerify(String command) throws Exception {
168
168
}
169
169
170
170
protected void verifyResult (ExecResult result , String matchString ) throws Exception {
171
- if (result .exitValue () != 0 || !result .stdout ().contains (matchString )) {
171
+ if (result .exitValue () != 0 || !result .stdout ().contains (matchString )) {
172
172
throw new Exception ("verifying test result failed." );
173
173
}
174
174
}
175
175
176
176
protected void verifyExitValue (ExecResult result , String command ) throws Exception {
177
- if (result .exitValue () != 0 ) {
177
+ if (result .exitValue () != 0 ) {
178
178
logger .info (result .stderr ());
179
179
throw new Exception ("executing the following command failed: " + command );
180
180
}
181
181
}
182
182
183
183
protected void verifyDockerImages (String imageTag ) throws Exception {
184
184
// verify the docker image is created
185
- ExecResult result = ExecCommand .exec ("docker images | grep " + build_tag + " | grep " + imageTag +
186
- "| wc -l" );
187
- if (Integer .parseInt (result .stdout ().trim ()) != 1 ) {
185
+ ExecResult result = ExecCommand .exec ("docker images | grep " + build_tag + " | grep " + imageTag
186
+ + "| wc -l" );
187
+ if (Integer .parseInt (result .stdout ().trim ()) != 1 ) {
188
188
throw new Exception ("wls docker image is not created as expected" );
189
189
}
190
190
}
@@ -205,14 +205,14 @@ protected ExecResult listItemsInCache() throws Exception {
205
205
}
206
206
207
207
protected ExecResult addInstallerToCache (String type , String version , String path ) throws Exception {
208
- String command = imagetool + " cache addInstaller --type " + type + " --version " + version +
209
- " --path " + path ;
208
+ String command = imagetool + " cache addInstaller --type " + type + " --version " + version
209
+ + " --path " + path ;
210
210
return executeAndVerify (command , false );
211
211
}
212
212
213
213
protected ExecResult addPatchToCache (String type , String patchId , String version , String path ) throws Exception {
214
- String command = imagetool + " cache addPatch --type " + type + " --patchId " + patchId + "_" +
215
- version + " --path " + path ;
214
+ String command = imagetool + " cache addPatch --type " + type + " --patchId " + patchId + "_"
215
+ + version + " --path " + path ;
216
216
return executeAndVerify (command , false );
217
217
}
218
218
@@ -236,9 +236,9 @@ protected void createDBContainer() throws Exception {
236
236
logger .info ("Creating an Oracle db docker container ..." );
237
237
String command = "docker rm -f " + dbContainerName ;
238
238
ExecCommand .exec (command );
239
- command = "docker run -d --name " + dbContainerName + " --env=\" DB_PDB=InfraPDB1\" " +
240
- " --env=\" DB_DOMAIN=us.oracle.com\" --env=\" DB_BUNDLE=basic\" " + ORACLE_DB_IMG + ":" +
241
- ORACLE_DB_IMG_TAG ;
239
+ command = "docker run -d --name " + dbContainerName + " --env=\" DB_PDB=InfraPDB1\" "
240
+ + " --env=\" DB_DOMAIN=us.oracle.com\" --env=\" DB_BUNDLE=basic\" " + ORACLE_DB_IMG + ":"
241
+ + ORACLE_DB_IMG_TAG ;
242
242
ExecCommand .exec (command );
243
243
244
244
// wait for the db is ready
@@ -268,10 +268,10 @@ private static void pullDockerImage(String imagename, String imagetag) throws Ex
268
268
ExecCommand .exec ("docker pull " + imagename + ":" + imagetag );
269
269
270
270
// verify the docker image is pulled
271
- ExecResult result = ExecCommand .exec ("docker images | grep " + imagename + " | grep " +
272
- imagetag + "| wc -l" );
271
+ ExecResult result = ExecCommand .exec ("docker images | grep " + imagename + " | grep "
272
+ + imagetag + "| wc -l" );
273
273
String resultString = result .stdout ();
274
- if (Integer .parseInt (resultString .trim ()) != 1 ) {
274
+ if (Integer .parseInt (resultString .trim ()) != 1 ) {
275
275
throw new Exception ("docker image " + imagename + ":" + imagetag + " is not pulled as expected."
276
276
+ " Expected 1 image, found " + resultString );
277
277
}
0 commit comments