
package it.mice.voila.runtime.runtime.jms.test;
import static org.junit.Assert.assertEquals;
import it.mice.voila.runtime.runtime.jms.JMSMessageService;

import javax.jms.JMSException;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Unit tests for <code>MessageService</code>.
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/applicationContext-jmsMqSeries-exampleMessage.xml")
public class MessageServiceExample
{
	@Autowired
	private JMSMessageService messageService;
	private String message;
	
	/**
	 * Test setup.
	 */
	@Before
	public void setUp() {
		message = "TestSpringJMSMQ test message.";
	}
	
	/**
	 * Test that sends a message to a queue.
	 */
	@Test
	public void testSendMessage() {
		messageService.sendMessage(message);
	}
	
	/**
	 * Test that receives a message from a queue.
	 * 
	 * @throws JMSException
	 */
	@Test
	public void testReadMessage() throws JMSException {
		String readMessage = messageService.readMessage();
		
		assertEquals(readMessage, message);
	}
}