11// 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.
43
54package com .oracle .weblogic .imagetool .integration ;
65
7- import com .oracle .weblogic .imagetool .integration .utils .ExecCommand ;
8- import com .oracle .weblogic .imagetool .integration .utils .ExecResult ;
96import java .io .File ;
107import java .nio .file .Files ;
118import java .nio .file .Path ;
129import java .nio .file .Paths ;
1310import java .util .logging .Logger ;
1411
12+ import com .oracle .weblogic .imagetool .integration .utils .ExecCommand ;
13+ import com .oracle .weblogic .imagetool .integration .utils .ExecResult ;
14+
1515public class BaseTest {
1616
1717 protected static final Logger logger = Logger .getLogger (ITImagetool .class .getName ());
@@ -38,22 +38,22 @@ protected static void initialize() throws Exception {
3838
3939 projectRoot = System .getProperty ("user.dir" );
4040
41- if (System .getenv ("WLSIMG_BLDDIR" ) != null ) {
41+ if (System .getenv ("WLSIMG_BLDDIR" ) != null ) {
4242 wlsImgBldDir = System .getenv ("WLSIMG_BLDDIR" );
4343 } else {
4444 wlsImgBldDir = System .getenv ("HOME" );
4545 }
46- if (System .getenv ("WLSIMG_CACHEDIR" ) != null ) {
46+ if (System .getenv ("WLSIMG_CACHEDIR" ) != null ) {
4747 wlsImgCacheDir = System .getenv ("WLSIMG_CACHEDIR" );
4848 } else {
4949 wlsImgCacheDir = System .getenv ("HOME" ) + FS + "cache" ;
5050 }
5151
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" ;
5454
5555 build_tag = System .getenv ("BUILD_TAG" );
56- if (build_tag != null ) {
56+ if (build_tag != null ) {
5757 build_tag = build_tag .toLowerCase ();
5858 } else {
5959 build_tag = "imagetool" ;
@@ -78,7 +78,7 @@ protected static void setup() throws Exception {
7878 command = "source " + getImagetoolHome () + FS + "bin" + FS + "setup.sh" ;
7979 executeNoVerify (command );
8080
81- if (!(new File (wlsImgBldDir )).exists ()) {
81+ if (!(new File (wlsImgBldDir )).exists ()) {
8282 logger .info (wlsImgBldDir + " does not exist, creating it" );
8383 (new File (wlsImgBldDir )).mkdir ();
8484 }
@@ -95,8 +95,8 @@ protected static void cleanup() throws Exception {
9595 // clean up the docker images
9696 command = "docker stop " + dbContainerName ;
9797 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 ;
100100 executeNoVerify (command );
101101
102102 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 {
120120 protected static void downloadInstallers (String ... installers ) throws Exception {
121121 // create the cache dir for downloading installers if not exists
122122 File cacheDir = new File (getInstallerCacheDir ());
123- if ( !cacheDir .exists ()) {
123+ if ( !cacheDir .exists ()) {
124124 cacheDir .mkdir ();
125125 }
126126
127127 boolean missingInstaller = false ;
128128 StringBuffer errorMsg = new StringBuffer ();
129129 errorMsg .append ("The test installers are missing. Please download: \n " );
130130 // check the required installer is downloaded
131- for (String installer : installers ) {
131+ for (String installer : installers ) {
132132 File installFile = new File (getInstallerCacheDir () + FS + installer );
133- if (!installFile .exists ()) {
133+ if (!installFile .exists ()) {
134134 missingInstaller = true ;
135- errorMsg .append ( " " + installer + "\n " );
135+ errorMsg .append (" " + installer + "\n " );
136136 }
137137 }
138138 errorMsg .append ("and put them in " + getInstallerCacheDir ());
139- if (missingInstaller ) {
139+ if (missingInstaller ) {
140140 throw new Exception (errorMsg .toString ());
141141 }
142142 }
@@ -168,23 +168,23 @@ protected static void executeNoVerify(String command) throws Exception {
168168 }
169169
170170 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 )) {
172172 throw new Exception ("verifying test result failed." );
173173 }
174174 }
175175
176176 protected void verifyExitValue (ExecResult result , String command ) throws Exception {
177- if (result .exitValue () != 0 ) {
177+ if (result .exitValue () != 0 ) {
178178 logger .info (result .stderr ());
179179 throw new Exception ("executing the following command failed: " + command );
180180 }
181181 }
182182
183183 protected void verifyDockerImages (String imageTag ) throws Exception {
184184 // 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 ) {
188188 throw new Exception ("wls docker image is not created as expected" );
189189 }
190190 }
@@ -205,14 +205,14 @@ protected ExecResult listItemsInCache() throws Exception {
205205 }
206206
207207 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 ;
210210 return executeAndVerify (command , false );
211211 }
212212
213213 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 ;
216216 return executeAndVerify (command , false );
217217 }
218218
@@ -236,9 +236,9 @@ protected void createDBContainer() throws Exception {
236236 logger .info ("Creating an Oracle db docker container ..." );
237237 String command = "docker rm -f " + dbContainerName ;
238238 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 ;
242242 ExecCommand .exec (command );
243243
244244 // wait for the db is ready
@@ -268,10 +268,10 @@ private static void pullDockerImage(String imagename, String imagetag) throws Ex
268268 ExecCommand .exec ("docker pull " + imagename + ":" + imagetag );
269269
270270 // 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" );
273273 String resultString = result .stdout ();
274- if (Integer .parseInt (resultString .trim ()) != 1 ) {
274+ if (Integer .parseInt (resultString .trim ()) != 1 ) {
275275 throw new Exception ("docker image " + imagename + ":" + imagetag + " is not pulled as expected."
276276 + " Expected 1 image, found " + resultString );
277277 }
0 commit comments