package org.darkphoenixs.activemq.listener;

import java.util.concurrent.Executors;

import org.darkphoenixs.activemq.consumer.MessageConsumer;
import org.darkphoenixs.mq.consumer.Consumer;
import org.darkphoenixs.mq.exception.MQException;
import org.junit.Assert;
import org.junit.Test;

public class MessageConsumerListenerTest {

	@Test
	public void test() throws Exception {

		MessageConsumerListener<String> listener = new MessageConsumerListener<String>();

		MessageConsumer<String> consumer = new MessageConsumer<String>();

		consumer.setTabName("TabName");
		consumer.setFuncName("FuncName");
		consumer.setIframeName("IframeName");
		consumer.setProtocolId("ProtocolId");

		try {
			listener.onMessage("test");
		} catch (Exception e) {
			Assert.assertTrue(e instanceof MQException);
		}

		Assert.assertNull(listener.getConsumer());
		listener.setConsumer(consumer);

		listener.onMessage("test");
		
		Assert.assertNull(listener.getThreadPool());
		listener.setThreadPool(Executors.newCachedThreadPool());
		listener.onMessage("test with thread pool");
		
		Thread.sleep(5000);
		
		MessageConsumerImpl consumerImpl = new MessageConsumerImpl();
		listener.setConsumer(consumerImpl);
		listener.onMessage("test with exception");
		
		Thread.sleep(5000);

	}

	private class MessageConsumerImpl implements Consumer<String> {

		@Override
		public String getConsumerKey() throws MQException {
			return null;
		}
		
		@Override
		public void receive(String message) throws MQException {
			throw new MQException("Test");
		}
	}
}

@@ -1071,31 +1071,91 @@
 %09%0A%09%09
-Thread.sleep(5000
+MessageConsumerListener%3CString%3E listener1 = new MessageConsumerListener%3CString%3E(
 );%0A
-%09%09%0A
 %09%09Me
@@ -1216,32 +1216,33 @@
 pl();%0A%09%09listener
+1
 .setConsumer(con
@@ -1255,32 +1255,33 @@
 mpl);%0A%09%09listener
+1
 .onMessage(%22test
@@ -1321,9 +1321,9 @@
 eep(
-5
+2
 000)

fix issues