Skip to content

Commit

Permalink
fix jakarta imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Nephery committed Nov 19, 2024
1 parent 6395c29 commit 4a59454
Showing 1 changed file with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
import com.solacesystems.jcsmp.XMLMessageProducer;
import com.solacesystems.jms.SolConnectionFactory;
import com.solacesystems.jms.SolJmsUtility;
import jakarta.jms.Connection;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.ObjectMessage;
import jakarta.jms.Session;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.assertj.core.api.SoftAssertions;
Expand Down Expand Up @@ -276,20 +281,19 @@ public void testPayloadFromSpringToJms(SoftAssertions softly) throws Exception {
jmsConsumer.setMessageListener(msg -> {
LOGGER.info("Got message {}", msg);
try {
if (msg instanceof javax.jms.BytesMessage) {
javax.jms.BytesMessage bytesMessage = (javax.jms.BytesMessage) msg;
if (msg instanceof jakarta.jms.BytesMessage bytesMessage) {
byte[] payload = new byte[(int) bytesMessage.getBodyLength()];
softly.assertThat(bytesMessage.readBytes(payload)).isEqualTo(bytesMessage.getBodyLength());
softly.assertThat(payload).isEqualTo("test".getBytes());
processedMessageTypes.add(BytesMessage.class);
} else if (msg instanceof javax.jms.TextMessage) {
softly.assertThat(((javax.jms.TextMessage) msg).getText()).isEqualTo("test");
} else if (msg instanceof jakarta.jms.TextMessage textMessage) {
softly.assertThat(textMessage.getText()).isEqualTo("test");
processedMessageTypes.add(TextMessage.class);
} else if (msg instanceof javax.jms.StreamMessage) {
softly.assertThat(((javax.jms.StreamMessage) msg).readString()).isEqualTo("test");
} else if (msg instanceof jakarta.jms.StreamMessage streamMessage) {
softly.assertThat(streamMessage.readString()).isEqualTo("test");
processedMessageTypes.add(StreamMessage.class);
} else if (msg instanceof javax.jms.MapMessage) {
softly.assertThat(((javax.jms.MapMessage) msg).getString("test")).isEqualTo("test");
} else if (msg instanceof jakarta.jms.MapMessage mapMessage) {
softly.assertThat(mapMessage.getString("test")).isEqualTo("test");
processedMessageTypes.add(MapMessage.class);
} else {
throw new IllegalStateException(String.format("Message type %s has no test", msg.getClass()));
Expand Down Expand Up @@ -317,20 +321,20 @@ public void testPayloadFromSpringToJms(SoftAssertions softly) throws Exception {

@Test
public void testPayloadFromJmsToSpring(JCSMPSession jcsmpSession, SoftAssertions softly) throws Exception {
List<javax.jms.Message> messages = new ArrayList<>();
List<jakarta.jms.Message> messages = new ArrayList<>();

{
javax.jms.BytesMessage bytesMessage = jmsSession.createBytesMessage();
jakarta.jms.BytesMessage bytesMessage = jmsSession.createBytesMessage();
bytesMessage.writeBytes("test".getBytes());
messages.add(bytesMessage);

messages.add(jmsSession.createTextMessage("test"));

javax.jms.StreamMessage streamMessage = jmsSession.createStreamMessage();
jakarta.jms.StreamMessage streamMessage = jmsSession.createStreamMessage();
streamMessage.writeString("test");
messages.add(streamMessage);

javax.jms.MapMessage mapMessage = jmsSession.createMapMessage();
jakarta.jms.MapMessage mapMessage = jmsSession.createMapMessage();
mapMessage.setString("test", "test");
messages.add(mapMessage);
}
Expand All @@ -353,11 +357,11 @@ public void onReceive(BytesXMLMessage bytesXMLMessage) {
} else if (msg.getPayload() instanceof String) {
softly.assertThat(msg.getPayload()).isEqualTo("test");
processedMessageTypes.add(TextMessage.class);
} else if (msg.getPayload() instanceof SDTStream) {
softly.assertThat(((SDTStream) msg.getPayload()).readString()).isEqualTo("test");
} else if (msg.getPayload() instanceof SDTStream sdtStream) {
softly.assertThat(sdtStream.readString()).isEqualTo("test");
processedMessageTypes.add(StreamMessage.class);
} else if (msg.getPayload() instanceof SDTMap) {
softly.assertThat(((SDTMap) msg.getPayload()).getString("test")).isEqualTo("test");
} else if (msg.getPayload() instanceof SDTMap sdtMap) {
softly.assertThat(sdtMap.getString("test")).isEqualTo("test");
processedMessageTypes.add(MapMessage.class);
}
} catch (Exception e) {
Expand All @@ -374,7 +378,7 @@ public void onException(JCSMPException e) {}

jcsmpSession.addSubscription(JCSMPFactory.onlyInstance().createTopic(topicName));
messageConsumer.start();
for (javax.jms.Message message : messages) {
for (jakarta.jms.Message message : messages) {
jmsProducer.send(message);
}

Expand All @@ -397,7 +401,7 @@ public void testSerializedPayloadFromSpringToJms(SoftAssertions softly) throws E
try {
softly.assertThat(msg.getBooleanProperty(SolaceBinderHeaders.SERIALIZED_PAYLOAD)).isTrue();

javax.jms.BytesMessage bytesMessage = (javax.jms.BytesMessage) msg;
jakarta.jms.BytesMessage bytesMessage = (jakarta.jms.BytesMessage) msg;
byte[] receivedPayload = new byte[(int) bytesMessage.getBodyLength()];
bytesMessage.readBytes(receivedPayload);
softly.assertThat(SerializationUtils.deserialize(receivedPayload)).isEqualTo(payload);
Expand Down

0 comments on commit 4a59454

Please sign in to comment.