diff --git a/.github/workflows/test-JMS.yml b/.github/workflows/test-JMS.yml new file mode 100644 index 00000000..08ef4cde --- /dev/null +++ b/.github/workflows/test-JMS.yml @@ -0,0 +1,97 @@ +# +# Copyright 2025 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +name: Run JMS Tests + +on: + pull_request: + branches: + - master + paths: + - 'JMS/**' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Podman + run: | + sudo apt-get update + sudo apt-get install -y podman + + - name: Pull IBM MQ image + run: podman pull icr.io/ibm-messaging/mq:latest + + - name: Run IBM MQ container (QM1) + run: | + podman run \ + --env LICENSE=accept \ + --env MQ_QMGR_NAME=QM1 \ + --env MQ_APP_USER=app \ + --env MQ_APP_PASSWORD=passw0rd \ + --env MQ_ADMIN_USER=admin \ + --env MQ_ADMIN_PASSWORD=passw0rd \ + --volume qm1data:/mnt/mqm \ + --publish 1414:1414 \ + --publish 9443:9443 \ + --detach \ + --name QM1 \ + icr.io/ibm-messaging/mq:latest + + - name: Wait for QMGR to be running + run: | + for i in {1..12}; do + STATUS=$(podman exec QM1 bash -c "dspmq -nm QM1" | grep -o 'STATUS([^)]*)' | cut -d'(' -f2 | cut -d')' -f1) + echo "QMGR state: $STATUS" + if [ "$STATUS" = "RUNNING" ]; then + echo "QM1 is running" + break + fi + echo "Waiting for QMGR to start..." + sleep 5 + done + + - name: Create env.json + working-directory: JMS + run: | + cat << EOF > env.json + { + "MQ_ENDPOINTS": [{ + "HOST": "127.0.0.1", + "PORT": "1414", + "CHANNEL": "DEV.APP.SVRCONN", + "QMGR": "QM1", + "APP_USER": "app", + "APP_PASSWORD": "passw0rd", + "QUEUE_NAME": "DEV.QUEUE.1", + "BACKOUT_QUEUE": "DEV.QUEUE.2", + "MODEL_QUEUE_NAME": "DEV.APP.MODEL.QUEUE", + "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", + "TOPIC_NAME": "dev/" + }] + } + EOF + echo "env.json path: $(pwd)" + cat env.json + + - name: Run the JMS tests + working-directory: JMS + run: | + mvn -Dmaven.test.skip=false test -DEnvFile="$(pwd)/env.json" + \ No newline at end of file diff --git a/.github/workflows/test-JMSSecrets.yml b/.github/workflows/test-JMSSecrets.yml new file mode 100644 index 00000000..d08f3ff1 --- /dev/null +++ b/.github/workflows/test-JMSSecrets.yml @@ -0,0 +1,63 @@ +# +# Copyright 2025 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +name: Run JMS Tests using git actions secrets + +on: + pull_request: + branches: + - master + paths: + - 'JMS/**' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Create env.json from secrets + working-directory: JMS + run: | + cat << EOF > env.json + { + "MQ_ENDPOINTS": [{ + "HOST": "${{ secrets.HOST }}", + "PORT": "${{ secrets.PORT }}", + "CHANNEL": "CLOUD.APP.SVRCONN", + "QMGR": "QMHE", + "APP_USER": "${{ secrets.APP_USER }}", + "APP_PASSWORD": "${{ secrets.APP_PASSWORD }}", + "QUEUE_NAME": "DEV.QUEUE.1", + "BACKOUT_QUEUE": "DEV.QUEUE.2", + "MODEL_QUEUE_NAME": "CLOUD.APP.MODEL.QUEUE", + "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", + "TOPIC_NAME": "dev/", + "CIPHER": "TLS_AES_256_GCM_SHA384", + "CIPHER_SUITE": "TLS_AES_256_GCM_SHA384", + "KEY_REPOSITORY": "../serverless/codeengine/clientapp/keys/clientkey" + }] + } + EOF + + echo "env.json path: $(pwd)/env.json" + cat env.json + + - name: Run the tests + working-directory: JMS + run: | + mvn -Dmaven.test.skip=false test -DEnvFile="$(pwd)/env.json" \ No newline at end of file diff --git a/.github/workflows/test-Node.yml b/.github/workflows/test-Node.yml new file mode 100644 index 00000000..e34791b1 --- /dev/null +++ b/.github/workflows/test-Node.yml @@ -0,0 +1,103 @@ +# +# Copyright 2025 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +name: Run Node Tests + +on: + pull_request: + branches: + - master + paths: + - 'Node.js/**' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Podman + run: | + sudo apt-get update + sudo apt-get install -y podman + + - name: Pull IBM MQ image + run: podman pull icr.io/ibm-messaging/mq:latest + + - name: Run IBM MQ container (QM1) + run: | + podman run \ + --env LICENSE=accept \ + --env MQ_QMGR_NAME=QM1 \ + --env MQ_APP_USER=app \ + --env MQ_APP_PASSWORD=passw0rd \ + --env MQ_ADMIN_USER=admin \ + --env MQ_ADMIN_PASSWORD=passw0rd \ + --volume qm1data:/mnt/mqm \ + --publish 1414:1414 \ + --publish 9443:9443 \ + --detach \ + --name QM1 \ + icr.io/ibm-messaging/mq:latest + + - name: Wait for QMGR to be running + run: | + for i in {1..12}; do + STATUS=$(podman exec QM1 bash -c "dspmq -nm QM1" | grep -o 'STATUS([^)]*)' | cut -d'(' -f2 | cut -d')' -f1) + echo "QMGR state: $STATUS" + if [ "$STATUS" = "RUNNING" ]; then + echo "QM1 is running" + break + fi + echo "Waiting for QMGR to start..." + sleep 5 + done + + - name: Create env.json + working-directory: Node.js + run: | + cat << EOF > env.json + { + "MQ_ENDPOINTS": [{ + "HOST": "127.0.0.1", + "PORT": "1414", + "CHANNEL": "DEV.APP.SVRCONN", + "QMGR": "QM1", + "APP_USER": "app", + "APP_PASSWORD": "passw0rd", + "QUEUE_NAME": "DEV.QUEUE.1", + "BACKOUT_QUEUE": "DEV.QUEUE.2", + "MODEL_QUEUE_NAME": "DEV.APP.MODEL.QUEUE", + "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", + "TOPIC_NAME": "dev/" + }] + } + EOF + echo "env.json path: $(pwd)/env.json" + cat env.json + + - name: Install dependencies + working-directory: Node.js + run: | + npm install + npm install --global mocha + + - name: Run Node.js tests + working-directory: Node.js + env: + EnvFile: "/home/runner/work/mq-dev-patterns/mq-dev-patterns/Node.js/env.json" + run: mocha \ No newline at end of file diff --git a/.github/workflows/test-NodeSecrets.yml b/.github/workflows/test-NodeSecrets.yml new file mode 100644 index 00000000..b807eb85 --- /dev/null +++ b/.github/workflows/test-NodeSecrets.yml @@ -0,0 +1,71 @@ +# +# Copyright 2025 IBM Corp. +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +name: Run Node tests using git actions secrets + +on: + pull_request: + branches: + - master + paths: + - 'Node.js/**' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Create env.json from secrets + working-directory: Node.js + run: | + cat << EOF > env.json + { + "MQ_ENDPOINTS": [{ + "HOST": "${{ secrets.HOST }}", + "PORT": "${{ secrets.PORT }}", + "CHANNEL": "CLOUD.APP.SVRCONN", + "QMGR": "QMHE", + "APP_USER": "${{ secrets.APP_USER }}", + "APP_PASSWORD": "${{ secrets.APP_PASSWORD }}", + "QUEUE_NAME": "DEV.QUEUE.1", + "BACKOUT_QUEUE": "DEV.QUEUE.2", + "MODEL_QUEUE_NAME": "CLOUD.APP.MODEL.QUEUE", + "DYNAMIC_QUEUE_PREFIX": "APP.REPLIES.*", + "TOPIC_NAME": "dev/", + "CIPHER": "TLS_AES_256_GCM_SHA384", + "CIPHER_SUITE": "TLS_AES_256_GCM_SHA384", + "KEY_REPOSITORY": "../serverless/codeengine/clientapp/keys/clientkey" + }] + } + EOF + + echo "env.json path: $(pwd)/env.json" + cat env.json + + - name: Install dependencies + working-directory: Node.js + run: | + npm install + npm install --global mocha + + - name: Run Node.js tests + working-directory: Node.js + env: + EnvFile: "/home/runner/work/mq-dev-patterns/mq-dev-patterns/Node.js/env.json" + run: mocha + diff --git a/JMS/com/ibm/mq/samples/jms/JmsGet.java b/JMS/com/ibm/mq/samples/jms/JmsGet.java index 6140cd8e..ca467b0b 100644 --- a/JMS/com/ibm/mq/samples/jms/JmsGet.java +++ b/JMS/com/ibm/mq/samples/jms/JmsGet.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019, 2024 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ import com.ibm.mq.samples.jms.SampleEnvSetter; import com.ibm.mq.samples.jms.JwtHelper; +import com.ibm.mq.samples.jms.LoggingHelper; public class JmsGet { @@ -77,7 +78,7 @@ public class JmsGet { public static void main(String[] args) { logger.info("Get application is starting"); - initialiseLogging(); + LoggingHelper.init(logger); SampleEnvSetter env = new SampleEnvSetter(); int limit = env.getCount(); @@ -256,21 +257,6 @@ private static void recordFailure(Exception ex) { return; } - private static void initialiseLogging() { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } - - Handler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(LOGLEVEL); - logger.addHandler(consoleHandler); - - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); - } - private static void waitAWhile(int duration) { try { Thread.sleep(duration); diff --git a/JMS/com/ibm/mq/samples/jms/JmsPub.java b/JMS/com/ibm/mq/samples/jms/JmsPub.java index 3b31e947..ed0e6ffa 100644 --- a/JMS/com/ibm/mq/samples/jms/JmsPub.java +++ b/JMS/com/ibm/mq/samples/jms/JmsPub.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019, 2024 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ import com.ibm.mq.samples.jms.SampleEnvSetter; import com.ibm.mq.samples.jms.JwtHelper; +import com.ibm.mq.samples.jms.LoggingHelper; public class JmsPub { private static final String DEFAULT_APP_NAME = "Dev Experience JmsPub"; @@ -73,7 +74,7 @@ public class JmsPub { private static String accessToken = null; public static void main(String[] args) { - initialiseLogging(); + LoggingHelper.init(logger); SampleEnvSetter env = new SampleEnvSetter(); jh = new JwtHelper(env); if (jh.isJwtEnabled()) { @@ -109,7 +110,7 @@ public static void main(String[] args) { logger.info("Publishing messages.\n"); try { - publisher.send(destination, "this is a message"); + publisher.send(destination, "this is a message " + i); logger.info("message was sent"); Thread.sleep(2000); } catch (JMSRuntimeException jmsex) { @@ -218,21 +219,6 @@ private static void recordFailure(Exception ex) { return; } - private static void initialiseLogging() { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } - - Handler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(LOGLEVEL); - logger.addHandler(consoleHandler); - - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); - } - private static void setUserCredentials(JmsConnectionFactory cf) { try { if (accessToken != null) { diff --git a/JMS/com/ibm/mq/samples/jms/JmsPut.java b/JMS/com/ibm/mq/samples/jms/JmsPut.java index 36447c63..ab5f793b 100644 --- a/JMS/com/ibm/mq/samples/jms/JmsPut.java +++ b/JMS/com/ibm/mq/samples/jms/JmsPut.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019, 2024 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ import com.ibm.mq.samples.jms.SampleEnvSetter; import com.ibm.mq.samples.jms.JwtHelper; +import com.ibm.mq.samples.jms.LoggingHelper; public class JmsPut { @@ -73,7 +74,7 @@ public class JmsPut { private static String accessToken = null; public static void main(String[] args) { - initialiseLogging(); + LoggingHelper.init(logger); SampleEnvSetter env = new SampleEnvSetter(); jh = new JwtHelper(env); if (jh.isJwtEnabled()) { @@ -206,21 +207,6 @@ private static void recordFailure(Exception ex) { return; } - private static void initialiseLogging() { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } - - Handler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(LOGLEVEL); - logger.addHandler(consoleHandler); - - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); - } - private static void setUserCredentials(JmsConnectionFactory cf) { try { if (accessToken != null) { diff --git a/JMS/com/ibm/mq/samples/jms/JmsRequest.java b/JMS/com/ibm/mq/samples/jms/JmsRequest.java index f49a03e1..7bdbf06c 100644 --- a/JMS/com/ibm/mq/samples/jms/JmsRequest.java +++ b/JMS/com/ibm/mq/samples/jms/JmsRequest.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019, 2024 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,6 +58,7 @@ import com.ibm.mq.samples.jms.SampleEnvSetter; import com.ibm.mq.samples.jms.JwtHelper; +import com.ibm.mq.samples.jms.LoggingHelper; public class JmsRequest { @@ -91,7 +92,7 @@ public class JmsRequest { public static void main(String[] args) { - initialiseLogging(); + LoggingHelper.init(logger); SampleEnvSetter env = new SampleEnvSetter(); jh = new JwtHelper(env); if (jh.isJwtEnabled()) { @@ -328,21 +329,6 @@ private static void recordFailure(Exception ex) { return; } - private static void initialiseLogging() { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } - - Handler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(LOGLEVEL); - logger.addHandler(consoleHandler); - - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); - } - private static void setUserCredentials(JmsConnectionFactory cf) { try { if (accessToken != null) { diff --git a/JMS/com/ibm/mq/samples/jms/JmsResponse.java b/JMS/com/ibm/mq/samples/jms/JmsResponse.java index c5092b20..11640c59 100644 --- a/JMS/com/ibm/mq/samples/jms/JmsResponse.java +++ b/JMS/com/ibm/mq/samples/jms/JmsResponse.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019, 2024 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +62,7 @@ import com.ibm.mq.samples.jms.SampleEnvSetter; import com.ibm.mq.samples.jms.JwtHelper; +import com.ibm.mq.samples.jms.LoggingHelper; public class JmsResponse { private static final String DEFAULT_APP_NAME = "Dev Experience JmsResponse"; @@ -87,7 +88,7 @@ public class JmsResponse { private static Long HOUR = 60 * 60 * SECOND; public static void main(String[] args) { - initialiseLogging(); + LoggingHelper.init(logger); SampleEnvSetter env = new SampleEnvSetter(); jh = new JwtHelper(env); if (jh.isJwtEnabled()) { @@ -409,21 +410,6 @@ private static void recordFailure(Exception ex) { return; } - private static void initialiseLogging() { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } - - Handler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(LOGLEVEL); - logger.addHandler(consoleHandler); - - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); - } - private static void setUserCredentials(JmsConnectionFactory cf) { try { if (accessToken != null) { diff --git a/JMS/com/ibm/mq/samples/jms/JmsSub.java b/JMS/com/ibm/mq/samples/jms/JmsSub.java index 5334caa5..bf88a39c 100644 --- a/JMS/com/ibm/mq/samples/jms/JmsSub.java +++ b/JMS/com/ibm/mq/samples/jms/JmsSub.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019, 2024 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,7 @@ import com.ibm.mq.samples.jms.SampleEnvSetter; import com.ibm.mq.samples.jms.JwtHelper; +import com.ibm.mq.samples.jms.LoggingHelper; public class JmsSub { private static final String DEFAULT_APP_NAME = "Dev Experience JmsSub"; @@ -69,7 +70,7 @@ public class JmsSub { private static String accessToken = null; public static void main(String[] args) { - initialiseLogging(); + LoggingHelper.init(logger); SampleEnvSetter env = new SampleEnvSetter(); jh = new JwtHelper(env); if (jh.isJwtEnabled()) { @@ -209,21 +210,6 @@ private static void recordFailure(Exception ex) { return; } - private static void initialiseLogging() { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } - - Handler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(LOGLEVEL); - logger.addHandler(consoleHandler); - - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); - } - private static void setUserCredentials(JmsConnectionFactory cf) { try { if (accessToken != null) { diff --git a/JMS/com/ibm/mq/samples/jms/LoggingHelper.java b/JMS/com/ibm/mq/samples/jms/LoggingHelper.java index 2855ec1f..741c5e95 100644 --- a/JMS/com/ibm/mq/samples/jms/LoggingHelper.java +++ b/JMS/com/ibm/mq/samples/jms/LoggingHelper.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2019 +* (c) Copyright IBM Corporation 2019, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,20 +19,25 @@ import java.util.logging.*; public class LoggingHelper { + private static boolean isLoggingInitialized = false; private static final Level LOGLEVEL = Level.ALL; public static void init(Logger logger) { - Logger defaultLogger = Logger.getLogger(""); - Handler[] handlers = defaultLogger.getHandlers(); - if (handlers != null && handlers.length > 0) { - defaultLogger.removeHandler(handlers[0]); - } + if (isLoggingInitialized) + return; + // avoid duplicate logs + logger.setUseParentHandlers(false); - Handler consoleHandler = new ConsoleHandler(); + for (Handler handler : logger.getHandlers()) { + if (handler instanceof ConsoleHandler) { + logger.removeHandler(handler); + } + } + ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(LOGLEVEL); logger.addHandler(consoleHandler); - logger.setLevel(LOGLEVEL); - logger.finest("Logging initialised"); + logger.finest("Logging initialized"); + isLoggingInitialized = true; } } \ No newline at end of file diff --git a/JMS/src/test/java/com/ibm/mq/samples/jms/JmsPubSubTest.java b/JMS/src/test/java/com/ibm/mq/samples/jms/JmsPubSubTest.java index 110b2f40..6eccf6db 100644 --- a/JMS/src/test/java/com/ibm/mq/samples/jms/JmsPubSubTest.java +++ b/JMS/src/test/java/com/ibm/mq/samples/jms/JmsPubSubTest.java @@ -1,5 +1,5 @@ /* -* (c) Copyright IBM Corporation 2024 +* (c) Copyright IBM Corporation 2024, 2025 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ public void testJmsPubSub(){ subThread.start(); //Wait for subscription to take place before publishing try { - Thread.sleep(2000); + Thread.sleep(5000); } catch (Exception e) { e.printStackTrace(); } diff --git a/JMS/src/test/java/com/ibm/mq/samples/jms/SampleEnvSetterTest.java b/JMS/src/test/java/com/ibm/mq/samples/jms/SampleEnvSetterTest.java index deec6ccb..993cf083 100644 --- a/JMS/src/test/java/com/ibm/mq/samples/jms/SampleEnvSetterTest.java +++ b/JMS/src/test/java/com/ibm/mq/samples/jms/SampleEnvSetterTest.java @@ -19,9 +19,11 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterAll; public class SampleEnvSetterTest { + private static String originalEnvFile; private static SampleEnvSetter envSetter; @BeforeAll @@ -30,6 +32,16 @@ public static void setUp(){ envSetter = new SampleEnvSetter(); } + @AfterAll + public static void tearDown() { + // Restore the original value so other tests are unaffected + if (originalEnvFile != null) { + System.setProperty(SampleEnvSetter.ENV_FILE, originalEnvFile); + } else { + System.clearProperty(SampleEnvSetter.ENV_FILE); + } + } + @Test public void testGetEnvValueWithoutEnv() { @@ -51,6 +63,7 @@ public void testGetEnvValueWithEnv() { // Test for non-existing key but existing Environment variable String value = envSetter.getEnvValue("APP_USER", 1); assertEquals("testUser", value); + System.clearProperty("APP_USER"); } @Test @@ -84,6 +97,7 @@ public void testGEBVWithEnv(){ //Test for Non existing but existing env key Boolean value = envSetter.getEnvBooleanValue("BINDINGS", 0); assertTrue(value); + System.clearProperty("BINDINGS"); } @Test @@ -102,6 +116,7 @@ public void testGetCheckCCDT(){ value = envSetter.getCheckForCCDT(); //Test for getCheckForCCDT with MQCCDTURL set to incorrect ccdt file location assertNull(value); + System.clearProperty("MQCCDTURL"); } @Test