7474import static oracle .weblogic .kubernetes .actions .TestActions .createDomainCustomResource ;
7575import static oracle .weblogic .kubernetes .actions .TestActions .createSecret ;
7676import static oracle .weblogic .kubernetes .actions .TestActions .execCommand ;
77+ import static oracle .weblogic .kubernetes .actions .TestActions .getDomainCustomResource ;
7778import static oracle .weblogic .kubernetes .actions .TestActions .getJob ;
7879import static oracle .weblogic .kubernetes .actions .TestActions .getPodLog ;
7980import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
@@ -191,7 +192,7 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
191192 logger .info ("Create database secret" );
192193 final String dbSecretName = domainUid + "-db-secret" ;
193194 assertDoesNotThrow (() -> createDatabaseSecret (dbSecretName , "scott" ,
194- "tiger " , "jdbc:oracle:thin:localhost:/ORCLCDB" , domainNamespace ),
195+ "##W%*}! \" ' \" `'] \\ \\ //1$$~x " , "jdbc:oracle:thin:localhost:/ORCLCDB" , domainNamespace ),
195196 String .format ("createSecret failed for %s" , dbSecretName ));
196197 String configMapName = "jdbc-jms-wldf-configmap" ;
197198
@@ -248,15 +249,62 @@ public void beforeEach() {
248249 }
249250 }
250251
252+ /**
253+ * Check the environment variable with special characters.
254+ */
255+ @ Test
256+ @ Order (0 )
257+ @ DisplayName ("Check environment variable with special characters" )
258+ public void testMiiCustomEnv () {
259+ Domain domain1 = assertDoesNotThrow (() -> getDomainCustomResource (domainUid , domainNamespace ),
260+ String .format ("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s" ,
261+ domainUid , domainNamespace ));
262+ List <V1EnvVar > envList = domain1 .getSpec ().getServerPod ().getEnv ();
263+
264+ boolean found = false ;
265+ for (int i = 0 ; i < envList .size (); i ++) {
266+ logger .info ("The name is: {0}, value is: {1}" , envList .get (i ).getName (), envList .get (i ).getValue ());
267+ if (envList .get (i ).getName ().equalsIgnoreCase ("CUSTOM_ENV" )) {
268+ assertTrue (
269+ envList .get (i ).getValue ().equalsIgnoreCase ("${DOMAIN_UID}~##!'%*$(ls)" ),
270+ "Expected value for CUSTOM_ENV variable does not mtach" );
271+ found = true ;
272+ }
273+ }
274+ assertTrue (found , "Couldn't find CUSTOM_ENV variable in domain resource" );
275+
276+ int adminServiceNodePort
277+ = getServiceNodePort (domainNamespace , getExternalServicePodName (adminServerPodName ), "default" );
278+ StringBuffer curlString = new StringBuffer ("curl --user weblogic:welcome1 " );
279+ curlString .append ("\" http://" + K8S_NODEPORT_HOST + ":" + adminServiceNodePort )
280+ .append ("/management/weblogic/latest/domainConfig" )
281+ .append ("/JMSServers/TestClusterJmsServer" )
282+ .append ("?fields=notes&links=none\" " )
283+ .append (" --silent " );
284+ logger .info ("checkJmsServerConfig: curl command {0}" , new String (curlString ));
285+ ExecResult result = null ;
286+ try {
287+ result = exec (new String (curlString ), true );
288+ getLogger ().info ("The command returned exit value: "
289+ + result .exitValue () + " command output: "
290+ + result .stderr () + "\n " + result .stdout ());
291+ assertTrue ((result .exitValue () == 0 ),
292+ "curl command returned non zero value" );
293+ assertTrue ((result .stdout ().contains ("${DOMAIN_UID}~##!'%*$(ls)" )),
294+ "Custom environment variable is not reflected in domin config" );
295+ } catch (Exception e ) {
296+ getLogger ().info ("Got exception, command failed with errors " + e .getMessage ());
297+ }
298+ }
299+
251300 /**
252301 * Check server logs are written on PersistentVolume(PV).
253- * The test looks for the string RUNNING in server log
302+ * The test looks for the string RUNNING in the server log
254303 */
255304 @ Test
256305 @ Order (1 )
257306 @ DisplayName ("Check the server logs are written to PersistentVolume" )
258307 public void testMiiServerLogsAreOnPV () {
259-
260308 // check server logs are written on PV and look for string RUNNING in log
261309 checkLogsOnPV ("grep RUNNING /shared/logs/" + adminServerName + ".log" , adminServerPodName );
262310 }
@@ -296,12 +344,12 @@ public void testMiiHttpServerLogsAreOnPV() {
296344 }
297345
298346 /**
299- * Create a WebLogic domain with a defined configmap in configuration/model
300- * section of the domain resource.
347+ * Create a WebLogic domain with a defined configmap in the
348+ * configuration/model section of the domain resource.
301349 * The configmap has multiple sparse WDT model files that define
302350 * a JDBCSystemResource, a JMSSystemResource and a WLDFSystemResource.
303351 * Verify all the SystemResource configurations using the rest API call
304- * using the public nodeport of the administration server.
352+ * using the public node port of the administration server.
305353 */
306354 @ Test
307355 @ Order (3 )
@@ -475,15 +523,15 @@ public void testMiiAddSystemResources() {
475523 * Update the restart version of the domain resource.
476524 * Verify rolling restart of the domain by comparing PodCreationTimestamp
477525 * before and after rolling restart.
478- * Verify servers from new cluster are not in running state, because
526+ * Verify servers from the new cluster are not in running state, because
479527 * the spec level replica count to zero(default).
480528 */
481529 @ Test
482530 @ Order (6 )
483531 @ DisplayName ("Add a dynamic cluster to the domain with default replica count" )
484532 public void testMiiAddDynmicClusteriWithNoReplica () {
485533
486- // This test uses the WebLogic domain created in BeforeAll method
534+ // This test uses the WebLogic domain created in the BeforeAll method
487535 // BeforeEach method ensures that the server pods are running
488536
489537 String configMapName = "noreplicaconfigmap" ;
@@ -518,8 +566,8 @@ public void testMiiAddDynmicClusteriWithNoReplica() {
518566 assertTrue (verifyRollingRestartOccurred (pods , 1 , domainNamespace ),
519567 "Rolling restart failed" );
520568
521- // The ServerNamePrefix for the new configured cluster is config-server
522- // Make sure the managed server from new cluster is not running
569+ // The ServerNamePrefix for the newly configured cluster is config-server
570+ // Make sure the managed server from the new cluster is not running
523571
524572 String newServerPodName = domainUid + "-config-server1" ;
525573 checkPodNotCreated (newServerPodName , domainUid , domainNamespace );
@@ -536,14 +584,14 @@ public void testMiiAddDynmicClusteriWithNoReplica() {
536584 * Update the restart version of the domain resource.
537585 * Verify rolling restart of the domain by comparing PodCreationTimestamp
538586 * before and after rolling restart.
539- * Verify servers from new cluster are in running state .
587+ * Verify servers from the new cluster are running.
540588 */
541589 @ Test
542590 @ Order (7 )
543591 @ DisplayName ("Add a dynamic cluster to domain with non-zero replica count" )
544592 public void testMiiAddDynamicCluster () {
545593
546- // This test uses the WebLogic domain created in BeforeAll method
594+ // This test uses the WebLogic domain created in the BeforeAll method
547595 // BeforeEach method ensures that the server pods are running
548596
549597 String configMapName = "dynamicclusterconfigmap" ;
@@ -613,14 +661,14 @@ public void testMiiAddDynamicCluster() {
613661 * Update the restart version of the domain resource.
614662 * Verify rolling restart of the domain by comparing PodCreationTimestamp
615663 * before and after rolling restart.
616- * Verify servers from new cluster are in running state .
664+ * Verify servers from the new cluster are running.
617665 */
618666 @ Test
619667 @ Order (8 )
620668 @ DisplayName ("Add a configured cluster to the domain" )
621669 public void testMiiAddConfiguredCluster () {
622670
623- // This test uses the WebLogic domain created in BeforeAll method
671+ // This test uses the WebLogic domain created in the BeforeAll method
624672 // BeforeEach method ensures that the server pods are running
625673
626674 String configMapName = "configclusterconfigmap" ;
@@ -681,7 +729,7 @@ public void testMiiAddConfiguredCluster() {
681729 }
682730
683731 /**
684- * Start a WebLogic domain with model-in-imge .
732+ * Start a WebLogic domain with model-in-image .
685733 * Patch the domain CRD with a new credentials secret.
686734 * Update domainRestartVersion to trigger a rolling restart of server pods.
687735 * Make sure all the server pods are re-started in a rolling fashion.
@@ -749,10 +797,10 @@ public void testMiiUpdateWebLogicCredential() {
749797 * Set allowReplicasBelowMinDynClusterSize to false.
750798 * Make sure that the cluster can be scaled up to 5 servers and
751799 * scaled down to 1 server.
752- * Create a configmap with a sparse model file with following attributes for
800+ * Create a configmap with a sparse model file with the following attributes
753801 * Cluster/cluster-1/DynamicServers
754802 * MaxDynamicClusterSize(4) and MinDynamicClusterSize(2)
755- * Patch the domain resource with the configmap and update restartVersion.
803+ * Patch the domain resource with the configmap and update the restartVersion.
756804 * Make sure a rolling restart is triggered.
757805 * Now with the modified value
758806 * Make sure that the cluster can be scaled up to 4 servers.
@@ -970,6 +1018,8 @@ private static void createDomainSecret(String secretName, String username, Strin
9701018 assertTrue (secretCreated , String .format ("create secret failed for %s in namespace %s" , secretName , domNamespace ));
9711019 }
9721020
1021+ // Add an environmental variable with special character
1022+ // Make sure the variable is available in domain resource with right value
9731023 private static void createDomainResource (
9741024 String domainUid , String domNamespace , String adminSecretName ,
9751025 String repoSecretName , String encryptionSecretName ,
@@ -1004,6 +1054,9 @@ private static void createDomainResource(
10041054 .addEnvItem (new V1EnvVar ()
10051055 .name ("USER_MEM_ARGS" )
10061056 .value ("-Djava.security.egd=file:/dev/./urandom " ))
1057+ .addEnvItem (new V1EnvVar ()
1058+ .name ("CUSTOM_ENV" )
1059+ .value ("${DOMAIN_UID}~##!'%*$(ls)" ))
10071060 .addVolumesItem (new V1Volume ()
10081061 .name (pvName )
10091062 .persistentVolumeClaim (new V1PersistentVolumeClaimVolumeSource ()
0 commit comments