6
6
import static oracle .kubernetes .operator .BaseTest .initialize ;
7
7
import static oracle .kubernetes .operator .BaseTest .logger ;
8
8
9
+ import java .io .IOException ;
10
+ import java .nio .charset .Charset ;
11
+ import java .nio .charset .StandardCharsets ;
12
+ import java .nio .file .Files ;
13
+ import java .nio .file .Path ;
14
+ import java .nio .file .Paths ;
15
+ import java .nio .file .StandardOpenOption ;
9
16
import java .util .*;
10
17
import java .util .logging .Level ;
11
18
import oracle .kubernetes .operator .utils .Domain ;
@@ -27,7 +34,9 @@ public class ITSitConfig extends BaseTest {
27
34
private static final String DOMAINUID = "customsitconfigdomain" ;
28
35
private static final String ADMINPORT = "30710" ;
29
36
private static final int T3CHANNELPORT = 30091 ;
30
- private static String fqdn = "" ;
37
+ private static final String MYSQL_DB_PORT = "31306" ;
38
+ private static String fqdn ;
39
+ private static String JDBC_URL ;
31
40
32
41
private static Domain domain = null ;
33
42
private static Operator operator1 ;
@@ -50,6 +59,10 @@ public static void staticPrepare() throws Exception {
50
59
operator1 = TestUtils .createOperator (OPERATOR1_YAML );
51
60
}
52
61
TESTSCRIPTDIR = BaseTest .getProjectRoot () + "/integration-tests/src/test/resources/" ;
62
+ manageMySqlDB (TESTSCRIPTDIR + "/sitconfig/mysql/mysql-dbservices.yml" , "create" );
63
+ fqdn = TestUtils .getHostName ();
64
+ JDBC_URL = "jdbc:mysql://" + fqdn + ":" + MYSQL_DB_PORT + "/" ;
65
+ copySitConfigFiles ();
53
66
domain = createSitConfigDomain ();
54
67
Assert .assertNotNull (domain );
55
68
ADMINPODNAME = domain .getDomainUid () + "-" + domain .getAdminServerName ();
@@ -63,7 +76,6 @@ public static void staticPrepare() throws Exception {
63
76
"runSitConfigTests.sh" ,
64
77
ADMINPODNAME ,
65
78
domain .getDomainNS ());
66
- fqdn = TestUtils .getHostName ();
67
79
}
68
80
}
69
81
@@ -81,6 +93,7 @@ public static void staticUnPrepare() throws Exception {
81
93
82
94
destroySitConfigDomain ();
83
95
tearDown ();
96
+ manageMySqlDB (TESTSCRIPTDIR + "/sitconfig/mysql-dbservices.yml" , "delete" );
84
97
logger .info ("SUCCESS" );
85
98
}
86
99
}
@@ -128,7 +141,7 @@ public void testCustomSitConfigOverridesForJdbc() throws Exception {
128
141
String stdout =
129
142
callShellScriptByExecToPod (
130
143
"runSitConfigTests.sh" ,
131
- fqdn + " " + T3CHANNELPORT + " weblogic welcome1 " + testMethod ,
144
+ fqdn + " " + T3CHANNELPORT + " weblogic welcome1 " + testMethod + " " + JDBC_URL ,
132
145
ADMINPODNAME ,
133
146
domain .getDomainNS ());
134
147
Assert .assertFalse (stdout .toLowerCase ().contains ("error" ));
@@ -188,8 +201,7 @@ private static Domain createSitConfigDomain() throws Exception {
188
201
// load input yaml to map and add configOverrides
189
202
Map <String , Object > domainMap = TestUtils .loadYaml (DOMAINONPV_WLST_YAML );
190
203
domainMap .put ("configOverrides" , "sitconfigcm" );
191
- domainMap .put (
192
- "configOverridesFile" , "/integration-tests/src/test/resources/sitconfig/configoverrides" );
204
+ domainMap .put ("configOverridesFile" , sitconfigDir );
193
205
domainMap .put ("domainUID" , DOMAINUID );
194
206
domainMap .put ("adminNodePort" , new Integer (ADMINPORT ));
195
207
domainMap .put ("t3ChannelPort" , new Integer (T3CHANNELPORT ));
@@ -199,7 +211,6 @@ private static Domain createSitConfigDomain() throws Exception {
199
211
domainMap .put (
200
212
"javaOptions" ,
201
213
"-Dweblogic.debug.DebugSituationalConfig=true -Dweblogic.debug.DebugSituationalConfigDumpXml=true" );
202
-
203
214
domain = TestUtils .createDomain (domainMap );
204
215
domain .verifyDomainCreated ();
205
216
return domain ;
@@ -234,4 +245,48 @@ private static String callShellScriptByExecToPod(
234
245
logger .log (Level .INFO , result .stdout ().trim ());
235
246
return result .stdout ().trim ();
236
247
}
248
+
249
+ /**
250
+ * create mysql crd
251
+ *
252
+ * @throws Exception
253
+ */
254
+ public static void manageMySqlDB (String dbYaml , String task ) throws Exception {
255
+ StringBuffer cmd = new StringBuffer ("kubectl " + task + " -f " );
256
+ cmd .append (dbYaml );
257
+ logger .info ("Running " + cmd );
258
+ ExecResult result = ExecCommand .exec (cmd .toString ());
259
+ if (result .exitValue () != 0 ) {
260
+ logger .log (Level .INFO , result .stdout ().trim ());
261
+ throw new RuntimeException (
262
+ "FAILURE: command "
263
+ + cmd
264
+ + " failed, returned "
265
+ + result .stdout ()
266
+ + "\n "
267
+ + result .stderr ());
268
+ }
269
+ String outputStr = result .stdout ().trim ();
270
+ logger .info ("Command returned " + outputStr );
271
+ }
272
+
273
+ private static void copySitConfigFiles () throws IOException {
274
+ String src_dir = TESTSCRIPTDIR + "/sitconfig/configoverrides" ;
275
+ String dst_dir = sitconfigDir ;
276
+ String files [] = {
277
+ "config.xml" ,
278
+ "jdbc-JdbcTestDataSource-0.xml" ,
279
+ "diagnostics-WLDF-MODULE-0.xml" ,
280
+ "jms-ClusterJmsSystemResource.xml" ,
281
+ "version.txt"
282
+ };
283
+ for (String file : files ) {
284
+ Path path = Paths .get (src_dir , file );
285
+ Charset charset = StandardCharsets .UTF_8 ;
286
+ String content = new String (Files .readAllBytes (path ), charset );
287
+ content = content .replaceAll ("JDBC_URL" , JDBC_URL );
288
+ path = Paths .get (dst_dir , file );
289
+ Files .write (path , content .getBytes (charset ), StandardOpenOption .TRUNCATE_EXISTING );
290
+ }
291
+ }
237
292
}
0 commit comments