blob: 2d74627f780ec59f7152e44b00018897de21df49 [file] [log] [blame]
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*
*/
package org.apache.qpid.systests.jms_1_1.message;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.junit.jupiter.api.Test;
import org.apache.qpid.systests.JmsTestBase;
public class TextMessageTest extends JmsTestBase
{
@Test
public void sendAndReceiveEmpty() throws Exception
{
Queue queue = createQueue(getTestName());
Connection connection = getConnection();
try
{
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage(null);
producer.send(message);
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
Message receivedMessage = consumer.receive(getReceiveTimeout());
assertTrue(receivedMessage instanceof TextMessage, "TextMessage should be received");
assertNull(((TextMessage) receivedMessage).getText(), "Unexpected body");
}
finally
{
connection.close();
}
}
@Test
public void sendAndReceiveAsciiBody() throws Exception
{
sendAndReceiveBody("body");
}
@Test
public void sendAndReceiveNonAsciiUTF8Body() throws Exception
{
sendAndReceiveBody("YEN\u00A5EURO\u20AC");
}
private void sendAndReceiveBody(final String text) throws Exception
{
Queue queue = createQueue(getTestName());
Connection connection = getConnection();
try
{
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage(text);
producer.send(message);
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
Message receivedMessage = consumer.receive(getReceiveTimeout());
assertTrue(receivedMessage instanceof TextMessage, "TextMessage should be received");
TextMessage receivedTextMessage = (TextMessage) receivedMessage;
assertEquals(receivedTextMessage.getText(), text, "Unexpected body");
}
finally
{
connection.close();
}
}
}