package org.darkphoenixs.activemq.listener;

import java.util.concurrent.Executors;

import org.darkphoenixs.activemq.consumer.MessageConsumer;
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");

		MessageConsumerImpl consumerImpl = new MessageConsumerImpl();
		listener.setConsumer(consumerImpl);
		Assert.assertNull(listener.getThreadPool());
		listener.setThreadPool(Executors.newFixedThreadPool(3));

		listener.onMessage("test with thread pool");
		
		Thread.sleep(5000);
	}

	private class MessageConsumerImpl extends MessageConsumer<String> {

		@Override
		public void receive(String message) throws MQException {

			throw new MQException("Test");
		}
	}
}

@@ -864,110 +864,10 @@
 %22);%0A
-%0A
 %09%09
-MessageConsumerImpl consumerImpl = new MessageConsumerImpl();%0A%09%09listener.setConsumer(consumerImpl);
 %0A%09%09A
@@ -952,11 +952,12 @@
 .new
-Fix
+Cach
 edTh
@@ -969,14 +969,12 @@
 ool(
-3
 ));%0A
-%0A
 %09%09li
@@ -1019,16 +1019,166 @@
 l%22);%0A%09%09%0A
+%09%09MessageConsumerImpl consumerImpl = new MessageConsumerImpl();%0A%09%09listener.setConsumer(consumerImpl);%0A%09%09listener.onMessage(%22test with exception%22);%0A%09%09%0A
 %09%09Thread
@@ -1188,9 +1188,9 @@
 eep(
-5
+2
 000)

fix testcase