received jms message is typed

This commit is contained in:
Radek Davidek 2026-03-17 16:34:39 +01:00
parent 97b77a911f
commit 486950c2b4
2 changed files with 57 additions and 16 deletions

View File

@ -83,22 +83,22 @@ public final class ImqRequest {
/** /**
* Set message format to JSON (default). * Set message format to JSON (default).
*/ */
PayloadPhase asJson(); QueuePhase asJson();
/** /**
* Set message format to XML. * Set message format to XML.
*/ */
PayloadPhase asXml(); QueuePhase asXml();
/** /**
* Set message format to EBCDIC (IBM-870). * Set message format to EBCDIC (IBM-870).
*/ */
PayloadPhase asEbcdic(); QueuePhase asEbcdic();
/** /**
* Set message format to UTF-8 (CCSID 1208). * Set message format to UTF-8 (CCSID 1208).
*/ */
PayloadPhase asUtf8(); QueuePhase asUtf8();
/** /**
* Set message payload as JSON string. * Set message payload as JSON string.
@ -159,6 +159,26 @@ public final class ImqRequest {
* Browse messages from queue with selector (non-destructive). * Browse messages from queue with selector (non-destructive).
*/ */
List<ReceivedMessage> browse(String selector, int maxMessages); List<ReceivedMessage> browse(String selector, int maxMessages);
/**
* Set message format to JSON (default) when receiving.
*/
QueuePhase asJson();
/**
* Set message format to XML when receiving.
*/
QueuePhase asXml();
/**
* Set message format to EBCDIC (IBM-870) when receiving.
*/
QueuePhase asEbcdic();
/**
* Set message format to UTF-8 (CCSID 1208) when receiving.
*/
QueuePhase asUtf8();
} }
/** /**
@ -212,25 +232,25 @@ public final class ImqRequest {
} }
@Override @Override
public PayloadPhase asJson() { public QueuePhase asJson() {
this.format = MqMessageFormat.JSON; this.format = MqMessageFormat.JSON;
return this; return this;
} }
@Override @Override
public PayloadPhase asXml() { public QueuePhase asXml() {
this.format = MqMessageFormat.XML; this.format = MqMessageFormat.XML;
return this; return this;
} }
@Override @Override
public PayloadPhase asEbcdic() { public QueuePhase asEbcdic() {
this.format = MqMessageFormat.EBCDIC_870; this.format = MqMessageFormat.EBCDIC_870;
return this; return this;
} }
@Override @Override
public PayloadPhase asUtf8() { public QueuePhase asUtf8() {
this.format = MqMessageFormat.UTF8_1208; this.format = MqMessageFormat.UTF8_1208;
return this; return this;
} }

View File

@ -1,5 +1,7 @@
package cz.moneta.test.system.messaging; package cz.moneta.test.system.messaging;
import java.util.concurrent.TimeUnit;
import cz.moneta.test.dsl.Harness; import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.TestCase; import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario; import cz.moneta.test.harness.annotations.TestScenario;
@ -8,14 +10,33 @@ import cz.moneta.test.harness.endpoints.imq.ImqFirstVisionQueue;
/** /**
* Unit tests for IBM MQ First Vision DSL methods. * Unit tests for IBM MQ First Vision DSL methods.
*/ */
@TestScenario(name = "Send MQ message") @TestScenario(name = "IBM MQ First Vision DSL Tests")
public class ImqFirstVisionTest { public class ImqFirstVisionTest {
@TestCase(name = "Send JSON message") @TestCase(name = "Send JSON message")
public void sendJsonMessage(Harness harness) { public void sendJsonMessage(Harness harness) {
harness.withImqFirstVision() harness.withImqFirstVision().toQueue(ImqFirstVisionQueue.PAYMENT_NOTIFICATIONS).asJson()
.toQueue(ImqFirstVisionQueue.PAYMENT_NOTIFICATIONS) .withPayload("{\"paymentId\": \"PAY-456\", \"result\": \"OK\"}").send();
.withPayload("{\"paymentId\": \"PAY-456\", \"result\": \"OK\"}") }
.send();
} @TestCase(name = "Receive JSON message")
public void receiveJsonMessage(Harness harness) {
harness.withImqFirstVision().fromQueue(ImqFirstVisionQueue.PAYMENT_NOTIFICATIONS).asJson()
.receiveWhere(msg -> msg.extract("paymentId").equals("PAY-456")).withTimeout(10, TimeUnit.SECONDS)
.andAssertFieldValue("result", "OK");
}
@TestCase(name = "Send XML message")
public void sendXmlMessage(Harness harness) {
harness.withImqFirstVision().toQueue(ImqFirstVisionQueue.MF_REQUESTS).asXml()
.withPayload("<request><accountId>12345</accountId><balance>50000</balance></request>").send();
}
@TestCase(name = "Receive XML message")
public void receiveXmlMessage(Harness harness) {
harness.withImqFirstVision().fromQueue(ImqFirstVisionQueue.MF_RESPONSES).asXml()
.receiveWhere(msg -> msg.extract("/request/accountId").equals("12345"))
.withTimeout(15, TimeUnit.SECONDS).andAssertFieldValue("/request/balance", "50000");
}
} }