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+
15package com .oracle .weblogic .imagetool .integration ;
26
37import com .oracle .weblogic .imagetool .integration .utils .ExecCommand ;
1216@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
1317public class ITImagetool extends BaseTest {
1418
15-
19+ private static final String JDK_INSTALLER = "jdk-8u212-linux-x64.tar.gz" ;
20+ private static final String WLS_INSTALLER = "fmw_12.2.1.3.0_wls_Disk1_1of1.zip" ;
21+ private static final String P27342434_INSTALLER = "p27342434_122130_Generic.zip" ;
22+ private static final String P28186730_INSTALLER = "p28186730_139400_Generic.zip" ;
23+ private static final String TEST_ENTRY_KEY = "mytestEntryKey" ;
24+ private static final String P27342434_ID = "27342434" ;
25+ private static final String P28186730_ID = "28186730" ;
26+ private static final String WLS_VERSION = "12.2.1.3.0" ;
27+ private static final String JDK_VERSION = "8u212" ;
1628
1729 @ BeforeClass
1830 public static void staticPrepare () throws Exception {
1931 logger .info ("prepare for image tool test ..." );
2032 initialize ();
2133 setup ();
34+ // pull base OS docker image used for test
35+ pullDockerImage ();
2236 }
2337
2438 @ AfterClass
@@ -45,14 +59,140 @@ public void test2CacheAddInstallerJDK() throws Exception {
4559 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
4660 logTestBegin (testMethodName );
4761
48- String jdkPath = getProjectRoot () + FS + ".." + FS + "caches" + FS + "jdk-8u212-linux-x64.tar.gz" ;
49- ExecResult result = addInstallerToCache ("jdk" , "8u212" , jdkPath );
50- logger .info (result .stderr ());
62+ String jdkPath = getProjectRoot () + FS + ".." + FS + "caches" + FS + JDK_INSTALLER ;
63+ addInstallerToCache ("jdk" , JDK_VERSION , jdkPath );
64+
65+ ExecResult result = listItemsInCache ();
66+ String expectedString = "jdk_" + JDK_VERSION + "=" + jdkPath ;
67+ verifyResult (result , expectedString );
68+
69+ logTestEnd (testMethodName );
70+ }
71+
72+ @ Test
73+ public void test3CacheAddInstallerWLS () throws Exception {
74+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
75+ logTestBegin (testMethodName );
76+
77+ String wlsPath = getProjectRoot () + FS + ".." + FS + "caches" + FS + WLS_INSTALLER ;
78+ addInstallerToCache ("wls" , WLS_VERSION , wlsPath );
79+
80+ ExecResult result = listItemsInCache ();
81+ String expectedString = "wls_" + WLS_VERSION + "=" + wlsPath ;
82+ verifyResult (result , expectedString );
83+
84+ logTestEnd (testMethodName );
85+ }
86+
87+ @ Test
88+ public void test4CreateWLSImg () throws Exception {
89+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
90+ logTestBegin (testMethodName );
91+
92+ String command = imagetool + " create --jdkVersion=" + JDK_VERSION + " --tag imagetool:" + testMethodName ;
93+ logger .info ("Executing command: " + command );
94+ ExecCommand .exec (command , true );
95+
96+ // verify the docker image is created
97+ ExecResult result = ExecCommand .exec ("docker images | grep imagetool | grep " + testMethodName +
98+ "| wc -l" );
99+ if (Integer .parseInt (result .stdout ()) != 1 ) {
100+ throw new Exception ("wls docker image is not created as expected" );
101+ }
102+
103+ logTestEnd (testMethodName );
104+ }
105+
106+ @ Test
107+ public void test5CacheAddPatch () throws Exception {
108+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
109+ logTestBegin (testMethodName );
110+
111+ String patchPath = getProjectRoot () + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER ;
112+ addPatchToCache ("wls" , "p" + P27342434_ID , WLS_VERSION , patchPath );
113+
114+ // verify the result
115+ ExecResult result = listItemsInCache ();
116+ String expectedString = P27342434_ID + "_" + WLS_VERSION + "=" + patchPath ;
117+ verifyResult (result , expectedString );
118+
119+ logTestEnd (testMethodName );
120+ }
121+
122+ @ Test
123+ public void test6CacheAddEntry () throws Exception {
124+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
125+ logTestBegin (testMethodName );
126+
127+ String mytestEntryValue = getProjectRoot () + FS + ".." + FS + "caches" + FS + P27342434_INSTALLER ;
128+ addEntryToCache (TEST_ENTRY_KEY , mytestEntryValue );
51129
52- result = listItemsInCache ();
53- String expectedString = "jdk_8u212=" + jdkPath ;
130+ // verify the result
131+ ExecResult result = listItemsInCache ();
132+ String expectedString = TEST_ENTRY_KEY .toLowerCase () + "=" + mytestEntryValue ;
54133 verifyResult (result , expectedString );
55134
56135 logTestEnd (testMethodName );
57136 }
137+
138+ @ Test
139+ public void test7CacheDeleteEntry () throws Exception {
140+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
141+ logTestBegin (testMethodName );
142+
143+ deleteEntryFromCache (TEST_ENTRY_KEY );
144+
145+ // verify the result
146+ ExecResult result = listItemsInCache ();
147+ if (result .exitValue () != 0 || result .stdout ().contains (TEST_ENTRY_KEY )) {
148+ throw new Exception ("The entry key is not deleted from the cache" );
149+ }
150+
151+ logTestEnd (testMethodName );
152+ }
153+
154+ @ Test
155+ public void test8CreateWLSImgUseCache () throws Exception {
156+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
157+ logTestBegin (testMethodName );
158+
159+ // need to add the required patches 28186730 for Opatch before create wls images
160+ String patchPath = getProjectRoot () + FS + ".." + FS + "caches" + FS + P28186730_INSTALLER ;
161+ addPatchToCache ("wls" , "p" + P28186730_ID , WLS_VERSION , patchPath );
162+
163+ String command = imagetool + " create --jdkVersion " + JDK_VERSION + " --fromImage " +
164+ BASE_OS_IMG + ":" + BASE_OS_IMG_TAG + " --tag imagetool:" + testMethodName +
165+ " --version " + WLS_VERSION + " --useCache always" ;
166+ logger .info ("Executing command: " + command );
167+ ExecCommand .exec (command , true );
168+
169+ // verify the docker image is created
170+ ExecResult result = ExecCommand .exec ("docker images | grep imagetool | grep " + testMethodName +
171+ "| wc -l" );
172+ if (Integer .parseInt (result .stdout ()) != 1 ) {
173+ throw new Exception ("wls docker image is not created as expected" );
174+ }
175+
176+ logTestEnd (testMethodName );
177+ }
178+
179+ @ Test
180+ public void test9UpdateWLSImg () throws Exception {
181+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
182+ logTestBegin (testMethodName );
183+
184+ String command = imagetool + " update --fromImage imagetool:test8CreateWLSImgUseCache --tag imagetool:" +
185+ testMethodName + " --patches " + P27342434_ID + " --useCache always" ;
186+ logger .info ("Executing command: " + command );
187+ ExecCommand .exec (command , true );
188+
189+ // verify the docker image is created
190+ ExecResult result = ExecCommand .exec ("docker images | grep imagetool | grep " + testMethodName +
191+ "| wc -l" );
192+ if (Integer .parseInt (result .stdout ()) != 1 ) {
193+ throw new Exception ("wls docker image is not created as expected" );
194+ }
195+
196+ logTestEnd (testMethodName );
197+ }
58198}
0 commit comments