Repository: qpid-proton Updated Branches: refs/heads/master 99a905615 -> 564a4d024
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/564a4d02/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java b/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java deleted file mode 100644 index af27a77..0000000 --- a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformer.java +++ /dev/null @@ -1,243 +0,0 @@ -/** - * 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.proton.jms; - -import org.apache.qpid.proton.amqp.messaging.Section; -import org.apache.qpid.proton.codec.CompositeWritableBuffer; -import org.apache.qpid.proton.codec.WritableBuffer; -import org.apache.qpid.proton.codec.DroppingWritableBuffer; -import org.apache.qpid.proton.message.ProtonJMessage; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.UnsignedByte; -import org.apache.qpid.proton.amqp.UnsignedInteger; -import org.apache.qpid.proton.amqp.messaging.*; - -import javax.jms.*; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; - -/** - * @author <a href="http://hiramchirino.com">Hiram Chirino</a> - */ -public class JMSMappingOutboundTransformer extends OutboundTransformer { - - public JMSMappingOutboundTransformer(JMSVendor vendor) { - super(vendor); - } - - @Override - public EncodedMessage transform(Message msg) throws Exception { - if( msg == null ) - return null; - try { - if( msg.getBooleanProperty(prefixVendor + "NATIVE") ) { - return null; - } - } catch (MessageFormatException e) { - return null; - } - ProtonJMessage amqp = convert(msg); - - long messageFormat; - try { - messageFormat = msg.getLongProperty(this.messageFormatKey); - } catch (MessageFormatException e) { - return null; - } - - ByteBuffer buffer = ByteBuffer.wrap(new byte[1024 * 4]); - final DroppingWritableBuffer overflow = new DroppingWritableBuffer(); - int c = amqp.encode(new CompositeWritableBuffer( - new WritableBuffer.ByteBufferWrapper(buffer), overflow)); - if( overflow.position() > 0 ) { - buffer = ByteBuffer.wrap(new byte[1024 * 4 + overflow.position()]); - c = amqp.encode(new WritableBuffer.ByteBufferWrapper(buffer)); - } - - return new EncodedMessage(messageFormat, buffer.array(), 0, c); - } - - /** - * Perform the conversion between JMS Message and Proton Message without re-encoding it to array. - * This is needed because some frameworks may elect to do this on their own way (Netty for instance using Nettybuffers) - * - * @param msg the supplied JMS Message - * @return the converted Proton Message - */ - public ProtonJMessage convert(Message msg) - throws JMSException, UnsupportedEncodingException { - Header header = new Header(); - Properties props=new Properties(); - HashMap<Symbol, Object> daMap = null; - HashMap<Symbol, Object> maMap = null; - HashMap apMap = null; - Section body=null; - HashMap footerMap = null; - if( msg instanceof BytesMessage ) { - BytesMessage m = (BytesMessage)msg; - byte data[] = new byte[(int) m.getBodyLength()]; - m.readBytes(data); - m.reset(); //Need to reset after readBytes or future readBytes calls (ex: redeliveries) will fail and return -1 - body = new Data(new Binary(data)); - } if( msg instanceof TextMessage ) { - body = new AmqpValue(((TextMessage) msg).getText()); - } if( msg instanceof MapMessage ) { - final HashMap map = new HashMap(); - final MapMessage m = (MapMessage) msg; - final Enumeration names = m.getMapNames(); - while (names.hasMoreElements()) { - String key = (String) names.nextElement(); - map.put(key, m.getObject(key)); - } - body = new AmqpValue(map); - } if( msg instanceof StreamMessage ) { - ArrayList list = new ArrayList(); - final StreamMessage m = (StreamMessage) msg; - try { - while(true) { - list.add(m.readObject()); - } - } catch(MessageEOFException e){} - body = new AmqpSequence(list); - } if( msg instanceof ObjectMessage ) { - body = new AmqpValue(((ObjectMessage) msg).getObject()); - } - - header.setDurable(msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT ? true : false); - header.setPriority(new UnsignedByte((byte) msg.getJMSPriority())); - if( msg.getJMSType()!=null ) { - if( maMap==null ) maMap = new HashMap<Symbol, Object>(); - maMap.put(Symbol.valueOf("x-opt-jms-type"), msg.getJMSType()); - } - if( msg.getJMSMessageID()!=null ) { - props.setMessageId(msg.getJMSMessageID()); - } - if( msg.getJMSDestination()!=null ) { - props.setTo(vendor.toAddress(msg.getJMSDestination())); - if( maMap==null ) maMap = new HashMap(); - maMap.put(Symbol.valueOf("x-opt-to-type"), destinationAttributes(msg.getJMSDestination())); - } - if( msg.getJMSReplyTo()!=null ) { - props.setReplyTo(vendor.toAddress(msg.getJMSReplyTo())); - if( maMap==null ) maMap = new HashMap(); - maMap.put(Symbol.valueOf("x-opt-reply-type"), destinationAttributes(msg.getJMSReplyTo())); - } - if( msg.getJMSCorrelationID()!=null ) { - props.setCorrelationId(msg.getJMSCorrelationID()); - } - if( msg.getJMSExpiration() != 0 ) { - long ttl = msg.getJMSExpiration() - System.currentTimeMillis(); - if (ttl < 0) { - ttl = 1; - } - header.setTtl(new UnsignedInteger((int)ttl)); - - props.setAbsoluteExpiryTime(new Date(msg.getJMSExpiration())); - } - if( msg.getJMSTimestamp()!= 0 ) { - props.setCreationTime(new Date(msg.getJMSTimestamp())); - } - - final Enumeration keys = msg.getPropertyNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - if( key.equals(messageFormatKey) || key.equals(nativeKey)) { - // skip.. - } else if( key.equals(firstAcquirerKey) ) { - header.setFirstAcquirer(msg.getBooleanProperty(key)); - } else if( key.startsWith("JMSXDeliveryCount") ) { - // The AMQP delivery-count field only includes prior failed delivery attempts, - // whereas JMSXDeliveryCount includes the first/current delivery attempt. - int amqpDeliveryCount = msg.getIntProperty(key) - 1; - if( amqpDeliveryCount > 0 ) { - header.setDeliveryCount(new UnsignedInteger(amqpDeliveryCount)); - } - } else if( key.startsWith("JMSXUserID") ) { - String value = msg.getStringProperty(key); - props.setUserId(new Binary(value.getBytes("UTF-8"))); - } else if( key.startsWith("JMSXGroupID") ) { - String value = msg.getStringProperty(key); - props.setGroupId(value); - if( apMap==null ) apMap = new HashMap(); - apMap.put(key, value); - } else if( key.startsWith("JMSXGroupSeq") ) { - UnsignedInteger value = new UnsignedInteger(msg.getIntProperty(key)); - props.setGroupSequence(value); - if( apMap==null ) apMap = new HashMap(); - apMap.put(key, value); - } else if( key.startsWith(prefixDeliveryAnnotationsKey) ) { - if( daMap == null ) daMap = new HashMap<Symbol, Object>(); - String name = key.substring(prefixDeliveryAnnotationsKey.length()); - daMap.put(Symbol.valueOf(name), msg.getObjectProperty(key)); - } else if( key.startsWith(prefixMessageAnnotationsKey) ) { - if( maMap==null ) maMap = new HashMap<Symbol, Object>(); - String name = key.substring(prefixMessageAnnotationsKey.length()); - maMap.put(Symbol.valueOf(name), msg.getObjectProperty(key)); - } else if( key.equals(subjectKey) ) { - props.setSubject(msg.getStringProperty(key)); - } else if( key.equals(contentTypeKey) ) { - props.setContentType(Symbol.getSymbol(msg.getStringProperty(key))); - } else if( key.equals(contentEncodingKey) ) { - props.setContentEncoding(Symbol.getSymbol(msg.getStringProperty(key))); - } else if( key.equals(replyToGroupIDKey) ) { - props.setReplyToGroupId(msg.getStringProperty(key)); - } else if( key.startsWith(prefixFooterKey) ) { - if( footerMap==null ) footerMap = new HashMap(); - String name = key.substring(prefixFooterKey.length()); - footerMap.put(name, msg.getObjectProperty(key)); - } else { - if( apMap==null ) apMap = new HashMap(); - apMap.put(key, msg.getObjectProperty(key)); - } - } - - - MessageAnnotations ma=null; - if( maMap!=null ) ma = new MessageAnnotations(maMap); - DeliveryAnnotations da=null; - if( daMap!=null ) da = new DeliveryAnnotations(daMap); - ApplicationProperties ap=null; - if( apMap!=null ) ap = new ApplicationProperties(apMap); - Footer footer=null; - if( footerMap!=null ) footer = new Footer(footerMap); - - return (ProtonJMessage) org.apache.qpid.proton.message.Message.Factory.create(header, da, ma, props, ap, body, footer); - } - - private static String destinationAttributes(Destination destination) { - if( destination instanceof Queue ) { - if( destination instanceof TemporaryQueue ) { - return "temporary,queue"; - } else { - return "queue"; - } - } - if( destination instanceof Topic ) { - if( destination instanceof TemporaryTopic ) { - return "temporary,topic"; - } else { - return "topic"; - } - } - return ""; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/564a4d02/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java b/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java deleted file mode 100644 index 60275bd..0000000 --- a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/JMSVendor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.proton.jms; - -import javax.jms.*; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * @author <a href="http://hiramchirino.com">Hiram Chirino</a> - */ -abstract public class JMSVendor { - - public abstract BytesMessage createBytesMessage(); - - public abstract StreamMessage createStreamMessage(); - - public abstract Message createMessage(); - - public abstract TextMessage createTextMessage(); - - public abstract ObjectMessage createObjectMessage(); - - public abstract MapMessage createMapMessage(); - - public abstract void setJMSXUserID(Message msg, String value); - - @Deprecated - public Destination createDestination(String name) { - return null; - } - - @SuppressWarnings("deprecation") - public <T extends Destination> T createDestination(String name, Class<T> kind) { - return kind.cast(createDestination(name)); - } - - public abstract void setJMSXGroupID(Message msg, String groupId); - - public abstract void setJMSXGroupSequence(Message msg, int i); - - public abstract void setJMSXDeliveryCount(Message rc, long l); - - public abstract String toAddress(Destination msgDestination); - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/564a4d02/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java b/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java deleted file mode 100644 index 09a6e15..0000000 --- a/contrib/proton-jms/src/main/java/org/apache/qpid/proton/jms/OutboundTransformer.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * 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.proton.jms; - -import org.apache.qpid.proton.engine.Delivery; - -import javax.jms.Message; - -/** -* @author <a href="http://hiramchirino.com">Hiram Chirino</a> -*/ -public abstract class OutboundTransformer { - - JMSVendor vendor; - String prefixVendor; - - String prefixDeliveryAnnotations = "DA_"; - String prefixMessageAnnotations= "MA_"; - String prefixFooter = "FT_"; - - String messageFormatKey; - String nativeKey; - String firstAcquirerKey; - String prefixDeliveryAnnotationsKey; - String prefixMessageAnnotationsKey; - String subjectKey; - String contentTypeKey; - String contentEncodingKey; - String replyToGroupIDKey; - String prefixFooterKey; - - - - public OutboundTransformer(JMSVendor vendor) { - this.vendor = vendor; - this.setPrefixVendor("JMS_AMQP_"); - } - - public abstract EncodedMessage transform(Message jms) throws Exception; - - public String getPrefixVendor() { - return prefixVendor; - } - - public void setPrefixVendor(String prefixVendor) { - this.prefixVendor = prefixVendor; - - messageFormatKey = prefixVendor + "MESSAGE_FORMAT"; - nativeKey = prefixVendor + "NATIVE"; - firstAcquirerKey = prefixVendor + "FirstAcquirer"; - prefixDeliveryAnnotationsKey = prefixVendor + prefixDeliveryAnnotations; - prefixMessageAnnotationsKey = prefixVendor + prefixMessageAnnotations; - subjectKey = prefixVendor +"Subject"; - contentTypeKey = prefixVendor +"ContentType"; - contentEncodingKey = prefixVendor +"ContentEncoding"; - replyToGroupIDKey = prefixVendor +"ReplyToGroupID"; - prefixFooterKey = prefixVendor + prefixFooter; - - } - - public JMSVendor getVendor() { - return vendor; - } - - public void setVendor(JMSVendor vendor) { - this.vendor = vendor; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/564a4d02/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java b/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java deleted file mode 100644 index 42a99ca..0000000 --- a/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingInboundTransformerTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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.proton.jms; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.Map; - -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; -import javax.jms.TextMessage; -import javax.jms.Topic; - -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.MessageAnnotations; -import org.apache.qpid.proton.message.Message; -import org.junit.Test; -import org.mockito.Mockito; - -public class JMSMappingInboundTransformerTest -{ - @Test - public void testTransformMessageWithAmqpValueStringCreatesTextMessage() throws Exception - { - TextMessage mockTextMessage = createMockTextMessage(); - JMSVendor mockVendor = createMockVendor(mockTextMessage); - JMSMappingInboundTransformer transformer = new JMSMappingInboundTransformer(mockVendor); - - String contentString = "myTextMessageContent"; - Message amqp = Message.Factory.create(); - amqp.setBody(new AmqpValue(contentString)); - - EncodedMessage em = encodeMessage(amqp); - - javax.jms.Message jmsMessage = transformer.transform(em); - - assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); - Mockito.verify(mockTextMessage).setText(contentString); - assertSame("Expected provided mock message, got a different one", mockTextMessage, jmsMessage); - } - - // ======= JMSDestination Handling ========= - // ========================================= - - @Test - public void testTransformWithNoToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithToTypeDestinationTypeAnnotationTestImpl(null, Destination.class); - } - - @Test - public void testTransformWithQueueStringToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class); - } - - @Test - public void testTransformWithTemporaryQueueStringToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class); - } - - @Test - public void testTransformWithTopicStringToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class); - } - - @Test - public void testTransformWithTemporaryTopicStringToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class); - } - - private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception - { - TextMessage mockTextMessage = createMockTextMessage(); - JMSVendor mockVendor = createMockVendor(mockTextMessage); - JMSMappingInboundTransformer transformer = new JMSMappingInboundTransformer(mockVendor); - - String toAddress = "toAddress"; - Message amqp = Message.Factory.create(); - amqp.setBody(new AmqpValue("myTextMessageContent")); - amqp.setAddress(toAddress); - if(toTypeAnnotationValue != null) - { - Map<Symbol, Object> map = new HashMap<Symbol, Object>(); - map.put(Symbol.valueOf("x-opt-to-type"), toTypeAnnotationValue); - MessageAnnotations ma = new MessageAnnotations(map); - amqp.setMessageAnnotations(ma); - } - - EncodedMessage em = encodeMessage(amqp); - - javax.jms.Message jmsMessage = transformer.transform(em); - assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); - - // Verify that createDestination was called with the provided 'to' address and 'Destination' class - Mockito.verify(mockVendor).createDestination(toAddress, expectedClass); - } - - // ======= JMSReplyTo Handling ========= - // ===================================== - - @Test - public void testTransformWithNoReplyToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(null,Destination.class); - } - - @Test - public void testTransformWithQueueStringReplyToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class); - } - - @Test - public void testTransformWithTemporaryQueueStringReplyToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class); - } - - @Test - public void testTransformWithTopicStringReplyToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class); - } - - @Test - public void testTransformWithTemporaryTopicStringReplyToTypeDestinationTypeAnnotation() throws Exception - { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class); - } - - private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue, Class<? extends Destination> expectedClass) throws Exception - { - TextMessage mockTextMessage = createMockTextMessage(); - JMSVendor mockVendor = createMockVendor(mockTextMessage); - JMSMappingInboundTransformer transformer = new JMSMappingInboundTransformer(mockVendor); - - String replyToAddress = "replyToAddress"; - Message amqp = Message.Factory.create(); - amqp.setBody(new AmqpValue("myTextMessageContent")); - amqp.setReplyTo(replyToAddress); - if(replyToTypeAnnotationValue != null) - { - Map<Symbol, Object> map = new HashMap<Symbol, Object>(); - map.put(Symbol.valueOf("x-opt-reply-type"), replyToTypeAnnotationValue); - MessageAnnotations ma = new MessageAnnotations(map); - amqp.setMessageAnnotations(ma); - } - - EncodedMessage em = encodeMessage(amqp); - - javax.jms.Message jmsMessage = transformer.transform(em); - assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); - - // Verify that createDestination was called with the provided 'replyTo' address and 'Destination' class - Mockito.verify(mockVendor).createDestination(replyToAddress,expectedClass); - } - - // ======= Utility Methods ========= - // ================================= - - private TextMessage createMockTextMessage() - { - TextMessage mockTextMessage = Mockito.mock(TextMessage.class); - - return mockTextMessage; - } - - private JMSVendor createMockVendor(TextMessage mockTextMessage) - { - JMSVendor mockVendor = Mockito.mock(JMSVendor.class); - Mockito.when(mockVendor.createTextMessage()).thenReturn(mockTextMessage); - - return mockVendor; - } - - private EncodedMessage encodeMessage(Message message) - { - byte[] encodeBuffer = new byte[1024 * 8]; - int encodedSize; - while (true) { - try { - encodedSize = message.encode(encodeBuffer, 0, encodeBuffer.length); - break; - } catch (java.nio.BufferOverflowException e) { - encodeBuffer = new byte[encodeBuffer.length * 2]; - } - } - - long messageFormat = 0; - return new EncodedMessage(messageFormat, encodeBuffer, 0, encodedSize); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/564a4d02/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java ---------------------------------------------------------------------- diff --git a/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java b/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java deleted file mode 100644 index 98dae5f..0000000 --- a/contrib/proton-jms/src/test/java/org/apache/qpid/proton/jms/JMSMappingOutboundTransformerTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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.proton.jms; - -import static org.junit.Assert.*; - -import java.util.Collections; -import java.util.Map; - -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; -import javax.jms.TextMessage; -import javax.jms.Topic; - -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.MessageAnnotations; -import org.apache.qpid.proton.message.Message; -import org.junit.Test; -import org.mockito.Mockito; - -public class JMSMappingOutboundTransformerTest -{ - @Test - public void testConvertMessageWithTextMessageCreatesAmqpValueStringBody() throws Exception - { - String contentString = "myTextMessageContent"; - TextMessage mockTextMessage = createMockTextMessage(); - Mockito.when(mockTextMessage.getText()).thenReturn(contentString); - JMSVendor mockVendor = createMockVendor(); - - JMSMappingOutboundTransformer transformer = new JMSMappingOutboundTransformer(mockVendor); - - Message amqp = transformer.convert(mockTextMessage); - - assertNotNull(amqp.getBody()); - assertTrue(amqp.getBody() instanceof AmqpValue); - assertEquals(contentString, ((AmqpValue) amqp.getBody()).getValue()); - } - - // ======= JMSDestination Handling ========= - // ========================================= - - @Test - public void testConvertMessageWithJMSDestinationNull() throws Exception - { - doTestConvertMessageWithJMSDestination(null, null); - } - - @Test - public void testConvertMessageWithJMSDestinationQueue() throws Exception - { - Queue mockDest = Mockito.mock(Queue.class); - - doTestConvertMessageWithJMSDestination(mockDest, "queue"); - } - - @Test - public void testConvertMessageWithJMSDestinationTemporaryQueue() throws Exception - { - TemporaryQueue mockDest = Mockito.mock(TemporaryQueue.class); - - doTestConvertMessageWithJMSDestination(mockDest, "temporary,queue"); - } - - @Test - public void testConvertMessageWithJMSDestinationTopic() throws Exception - { - Topic mockDest = Mockito.mock(Topic.class); - - doTestConvertMessageWithJMSDestination(mockDest, "topic"); - } - - @Test - public void testConvertMessageWithJMSDestinationTemporaryTopic() throws Exception - { - TemporaryTopic mockDest = Mockito.mock(TemporaryTopic.class); - - doTestConvertMessageWithJMSDestination(mockDest, "temporary,topic"); - } - - private void doTestConvertMessageWithJMSDestination(Destination jmsDestination, Object expectedAnnotationValue) throws Exception - { - TextMessage mockTextMessage = createMockTextMessage(); - Mockito.when(mockTextMessage.getText()).thenReturn("myTextMessageContent"); - Mockito.when(mockTextMessage.getJMSDestination()).thenReturn(jmsDestination); - JMSVendor mockVendor = createMockVendor(); - String toAddress = "someToAddress"; - if(jmsDestination != null) - { - Mockito.when(mockVendor.toAddress(Mockito.any(Destination.class))) - .thenReturn(toAddress); - } - - JMSMappingOutboundTransformer transformer = new JMSMappingOutboundTransformer(mockVendor); - - Message amqp = transformer.convert(mockTextMessage); - - MessageAnnotations ma = amqp.getMessageAnnotations(); - Map<Symbol, Object> maMap = ma == null ? null : ma.getValue(); - if(maMap != null) - { - Object actualValue = maMap.get(Symbol.valueOf("x-opt-to-type")); - assertEquals("Unexpected annotation value", expectedAnnotationValue, actualValue); - } - else if (expectedAnnotationValue != null) - { - fail("Expected annotation value, but there were no annotations"); - } - - if(jmsDestination != null) - { - assertEquals("Unexpected 'to' address", toAddress, amqp.getAddress()); - } - } - - // ======= JMSReplyTo Handling ========= - // ===================================== - - @Test - public void testConvertMessageWithJMSReplyToNull() throws Exception - { - doTestConvertMessageWithJMSReplyTo(null, null); - } - - @Test - public void testConvertMessageWithJMSReplyToQueue() throws Exception - { - Queue mockDest = Mockito.mock(Queue.class); - - doTestConvertMessageWithJMSReplyTo(mockDest, "queue"); - } - - @Test - public void testConvertMessageWithJMSReplyToTemporaryQueue() throws Exception - { - TemporaryQueue mockDest = Mockito.mock(TemporaryQueue.class); - - doTestConvertMessageWithJMSReplyTo(mockDest, "temporary,queue"); - } - - @Test - public void testConvertMessageWithJMSReplyToTopic() throws Exception - { - Topic mockDest = Mockito.mock(Topic.class); - - doTestConvertMessageWithJMSReplyTo(mockDest, "topic"); - } - - @Test - public void testConvertMessageWithJMSReplyToTemporaryTopic() throws Exception - { - TemporaryTopic mockDest = Mockito.mock(TemporaryTopic.class); - - doTestConvertMessageWithJMSReplyTo(mockDest, "temporary,topic"); - } - - private void doTestConvertMessageWithJMSReplyTo(Destination jmsReplyTo, Object expectedAnnotationValue) throws Exception - { - TextMessage mockTextMessage = createMockTextMessage(); - Mockito.when(mockTextMessage.getText()).thenReturn("myTextMessageContent"); - Mockito.when(mockTextMessage.getJMSReplyTo()).thenReturn(jmsReplyTo); - JMSVendor mockVendor = createMockVendor(); - String replyToAddress = "someReplyToAddress"; - if(jmsReplyTo != null) - { - Mockito.when(mockVendor.toAddress(Mockito.any(Destination.class))) - .thenReturn(replyToAddress); - } - - JMSMappingOutboundTransformer transformer = new JMSMappingOutboundTransformer(mockVendor); - - Message amqp = transformer.convert(mockTextMessage); - - MessageAnnotations ma = amqp.getMessageAnnotations(); - Map<Symbol, Object> maMap = ma == null ? null : ma.getValue(); - if(maMap != null) - { - Object actualValue = maMap.get(Symbol.valueOf("x-opt-reply-type")); - assertEquals("Unexpected annotation value", expectedAnnotationValue, actualValue); - } - else if (expectedAnnotationValue != null) - { - fail("Expected annotation value, but there were no annotations"); - } - - if(jmsReplyTo != null) - { - assertEquals("Unexpected 'reply-to' address", replyToAddress, amqp.getReplyTo()); - } - } - - // ======= Utility Methods ========= - // ================================= - - private TextMessage createMockTextMessage() throws Exception - { - TextMessage mockTextMessage = Mockito.mock(TextMessage.class); - Mockito.when(mockTextMessage.getPropertyNames()).thenReturn(Collections.enumeration(Collections.emptySet())); - - return mockTextMessage; - } - - private JMSVendor createMockVendor() - { - JMSVendor mockVendor = Mockito.mock(JMSVendor.class); - - return mockVendor; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/564a4d02/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 7bacd41..17c39d6 100644 --- a/pom.xml +++ b/pom.xml @@ -135,8 +135,6 @@ <modules> <module>proton-j</module> - <module>contrib/proton-jms</module> - <module>contrib/proton-hawtdispatch</module> <module>tests</module> <module>examples/engine/java</module> <module>examples/java/messenger</module> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
