|
| 1 | +package com.ibm.eventstreams.connect.mqsink.builders; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.Map; |
| 7 | + |
| 8 | +import javax.jms.Message; |
| 9 | + |
| 10 | +import org.apache.kafka.connect.sink.SinkRecord; |
| 11 | +import org.junit.Test; |
| 12 | + |
| 13 | +import com.ibm.eventstreams.connect.mqsink.AbstractJMSContextIT; |
| 14 | +import com.ibm.mq.jms.MQQueue; |
| 15 | + |
| 16 | +public class DestinationBuilderIT extends AbstractJMSContextIT { |
| 17 | + |
| 18 | + |
| 19 | + @Test |
| 20 | + public void verifyReplyQueueProperty() throws Exception { |
| 21 | + String replyQueue = "queue://QM1/REPLY.Q"; |
| 22 | + |
| 23 | + Map<String, String> props = new HashMap<>(); |
| 24 | + props.put("mq.reply.queue", replyQueue); |
| 25 | + |
| 26 | + DefaultMessageBuilder builder = new DefaultMessageBuilder(); |
| 27 | + builder.configure(props); |
| 28 | + |
| 29 | + SinkRecord record = new SinkRecord("topic", 0, null, null, null, "msg", 0); |
| 30 | + |
| 31 | + Message message = builder.fromSinkRecord(getJmsContext(), record); |
| 32 | + assertEquals("msg", message.getBody(String.class)); |
| 33 | + |
| 34 | + MQQueue destination = (MQQueue) message.getJMSReplyTo(); |
| 35 | + assertEquals(replyQueue, destination.getQueueName()); |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + @Test |
| 40 | + public void verifyTopicNameProperty() throws Exception { |
| 41 | + String topicProperty = "PutTopicNameHere"; |
| 42 | + String TOPIC = "MY.TOPIC"; |
| 43 | + |
| 44 | + Map<String, String> props = new HashMap<>(); |
| 45 | + props.put("mq.message.builder.topic.property", topicProperty); |
| 46 | + |
| 47 | + DefaultMessageBuilder builder = new DefaultMessageBuilder(); |
| 48 | + builder.configure(props); |
| 49 | + |
| 50 | + SinkRecord record = new SinkRecord(TOPIC, 0, null, null, null, "message", 0); |
| 51 | + |
| 52 | + Message message = builder.fromSinkRecord(getJmsContext(), record); |
| 53 | + assertEquals("message", message.getBody(String.class)); |
| 54 | + assertEquals(TOPIC, message.getStringProperty(topicProperty)); |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + @Test |
| 59 | + public void verifyTopicPartitionProperty() throws Exception { |
| 60 | + String topicProperty = "PutTopicPartitionHere"; |
| 61 | + int PARTITION = 4; |
| 62 | + |
| 63 | + Map<String, String> props = new HashMap<>(); |
| 64 | + props.put("mq.message.builder.partition.property", topicProperty); |
| 65 | + |
| 66 | + DefaultMessageBuilder builder = new DefaultMessageBuilder(); |
| 67 | + builder.configure(props); |
| 68 | + |
| 69 | + SinkRecord record = new SinkRecord("topic", PARTITION, null, null, null, "message", 0); |
| 70 | + |
| 71 | + Message message = builder.fromSinkRecord(getJmsContext(), record); |
| 72 | + assertEquals("message", message.getBody(String.class)); |
| 73 | + assertEquals(PARTITION, message.getIntProperty(topicProperty)); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + @Test |
| 78 | + public void verifyMessageOffsetProperty() throws Exception { |
| 79 | + String topicProperty = "PutOffsetHere"; |
| 80 | + long OFFSET = 91; |
| 81 | + |
| 82 | + Map<String, String> props = new HashMap<>(); |
| 83 | + props.put("mq.message.builder.offset.property", topicProperty); |
| 84 | + |
| 85 | + DefaultMessageBuilder builder = new DefaultMessageBuilder(); |
| 86 | + builder.configure(props); |
| 87 | + |
| 88 | + SinkRecord record = new SinkRecord("topic", 0, null, null, null, "message", OFFSET); |
| 89 | + |
| 90 | + Message message = builder.fromSinkRecord(getJmsContext(), record); |
| 91 | + assertEquals("message", message.getBody(String.class)); |
| 92 | + assertEquals(OFFSET, message.getLongProperty(topicProperty)); |
| 93 | + } |
| 94 | +} |
0 commit comments