Skip to content

Unit testing automation using GitHub actions #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/test-JMS.yml
Original file line number Diff line number Diff line change
@@ -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"

63 changes: 63 additions & 0 deletions .github/workflows/test-JMSSecrets.yml
Original file line number Diff line number Diff line change
@@ -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"
103 changes: 103 additions & 0 deletions .github/workflows/test-Node.yml
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions .github/workflows/test-NodeSecrets.yml
Original file line number Diff line number Diff line change
@@ -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

20 changes: 3 additions & 17 deletions JMS/com/ibm/mq/samples/jms/JmsGet.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Loading