From afb17f1e189c5a8c788b2dc64202c7c74e88e530 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 18 Feb 2009 19:30:07 +0000 Subject: [PATCH] Added StubProducer. --- .../integration/jms/StubProducer.java | 121 ++++++++++++++++++ .../integration/jms/StubSession.java | 6 +- .../integration/jms/StubTextMessage.java | 10 +- 3 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubProducer.java diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubProducer.java b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubProducer.java new file mode 100644 index 0000000000..59aaa5b709 --- /dev/null +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubProducer.java @@ -0,0 +1,121 @@ +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed 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.springframework.integration.jms; + +import javax.jms.Destination; +import javax.jms.InvalidDestinationException; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageProducer; + +/** + * @author Mark Fisher + */ +public class StubProducer implements MessageProducer { + + private Message lastMessageSent; + + private Destination staticDestination; + + + public StubProducer(Destination destination) { + this.staticDestination = destination; + } + + + public Message getLastMessageSent() { + return this.lastMessageSent; + } + + public void close() throws JMSException { + } + + public int getDeliveryMode() throws JMSException { + return 0; + } + + public Destination getDestination() throws JMSException { + return null; + } + + public boolean getDisableMessageID() throws JMSException { + return false; + } + + public boolean getDisableMessageTimestamp() throws JMSException { + return false; + } + + public int getPriority() throws JMSException { + return 0; + } + + public long getTimeToLive() throws JMSException { + return 0; + } + + public void send(Message message) throws JMSException { + if (this.staticDestination == null) { + throw new UnsupportedOperationException("producer was not created with a static Destination"); + } + this.lastMessageSent = message; + } + + public void send(Destination destination, Message message) throws JMSException { + if (this.staticDestination != null) { + throw new UnsupportedOperationException("producer was created with a static Destination"); + } + if (destination == null) { + throw new InvalidDestinationException("null destination"); + } + this.lastMessageSent = message; + } + + public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { + if (this.staticDestination == null) { + throw new UnsupportedOperationException("producer was not created with a static Destination"); + } + this.lastMessageSent = message; + } + + public void send(Destination destination, Message message, + int deliveryMode, int priority, long timeToLive) throws JMSException { + if (this.staticDestination != null) { + throw new UnsupportedOperationException("producer was created with a static Destination"); + } + if (destination == null) { + throw new InvalidDestinationException("null destination"); + } + this.lastMessageSent = message; + } + + public void setDeliveryMode(int deliveryMode) throws JMSException { + } + + public void setDisableMessageID(boolean value) throws JMSException { + } + + public void setDisableMessageTimestamp(boolean value) throws JMSException { + } + + public void setPriority(int defaultPriority) throws JMSException { + } + + public void setTimeToLive(long timeToLive) throws JMSException { + } + +} diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubSession.java b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubSession.java index a31b49ad3e..b3995afe87 100644 --- a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubSession.java +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -107,7 +107,7 @@ public class StubSession implements Session { } public MessageProducer createProducer(Destination destination) throws JMSException { - return null; + return new StubProducer(destination); } public Queue createQueue(String queueName) throws JMSException { @@ -131,7 +131,7 @@ public class StubSession implements Session { } public TextMessage createTextMessage(String text) throws JMSException { - return null; + return new StubTextMessage(text); } public Topic createTopic(String topicName) throws JMSException { diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubTextMessage.java b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubTextMessage.java index 3a26831c3d..a633e08e9c 100644 --- a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubTextMessage.java +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/StubTextMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,14 @@ public class StubTextMessage implements TextMessage { private ConcurrentHashMap properties = new ConcurrentHashMap(); + public StubTextMessage() { + } + + public StubTextMessage(String text) { + this.text = text; + } + + public String getText() throws JMSException { return this.text; }