You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2016/11/22 00:00:08 UTC
qpid-jms git commit: QPIDJMS-225 Add additional testing of missed
code paths
Repository: qpid-jms
Updated Branches:
refs/heads/master 83f5507cc -> 1a08b4409
QPIDJMS-225 Add additional testing of missed code paths
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/1a08b440
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/1a08b440
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/1a08b440
Branch: refs/heads/master
Commit: 1a08b4409e9b97dcc858f2f565ad2f558b4b0350
Parents: 83f5507
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Nov 21 18:59:59 2016 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Nov 21 18:59:59 2016 -0500
----------------------------------------------------------------------
.../java/org/apache/qpid/jms/JmsContext.java | 42 ++-
.../org/apache/qpid/jms/JmsMessageConsumer.java | 6 +-
.../AmqpAcknowledgementsIntegrationTest.java | 72 ++++-
.../ZeroPrefetchIntegrationTest.java | 7 +
.../amqp/message/AmqpJmsMessageFacadeTest.java | 30 ++
.../qpid/jms/util/PriorityMessageQueueTest.java | 36 +++
.../apache/qpid/jms/util/PropertyUtilTest.java | 9 +
.../jms/util/TypeConversionSupportTest.java | 311 +++++++++++++++++++
.../apache/qpid/jms/util/URISupportTest.java | 33 ++
9 files changed, 518 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
index 2efe8e0..e5d0f18 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
@@ -83,25 +83,23 @@ public class JmsContext implements JMSContext, AutoCloseable {
}
@Override
- public void close() {
+ public synchronized void close() {
JMSRuntimeException failure = null;
- synchronized (this) {
- try {
- if (session != null) {
- session.close();
- }
- } catch (JMSException jmse) {
- failure = JmsExceptionSupport.createRuntimeException(jmse);
+ try {
+ if (session != null) {
+ session.close();
}
+ } catch (JMSException jmse) {
+ failure = JmsExceptionSupport.createRuntimeException(jmse);
+ }
- if (connectionRefCount.decrementAndGet() == 0) {
- try {
- connection.close();
- } catch (JMSException jmse) {
- if (failure == null) {
- failure = JmsExceptionSupport.createRuntimeException(jmse);
- }
+ if (connectionRefCount.decrementAndGet() == 0) {
+ try {
+ connection.close();
+ } catch (JMSException jmse) {
+ if (failure == null) {
+ failure = JmsExceptionSupport.createRuntimeException(jmse);
}
}
}
@@ -275,16 +273,14 @@ public class JmsContext implements JMSContext, AutoCloseable {
//----- JMSContext factory methods --------------------------------------//
@Override
- public JMSContext createContext(int sessionMode) {
- synchronized (this) {
- if (connectionRefCount.get() == 0) {
- throw new IllegalStateRuntimeException("The Connection is closed");
- }
+ public synchronized JMSContext createContext(int sessionMode) {
+ if (connectionRefCount.get() == 0) {
+ throw new IllegalStateRuntimeException("The Connection is closed");
+ }
- connectionRefCount.incrementAndGet();
+ connectionRefCount.incrementAndGet();
- return new JmsContext(connection, sessionMode, connectionRefCount);
- }
+ return new JmsContext(connection, sessionMode, connectionRefCount);
}
//----- JMSProducer factory methods --------------------------------------//
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
index 3d2fba9..9eb332d 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
@@ -119,7 +119,7 @@ public class JmsMessageConsumer implements AutoCloseable, MessageConsumer, JmsMe
}
public void init() throws JMSException {
- if(!isPullConsumer()){
+ if (!isPullConsumer()){
startConsumerResource();
}
}
@@ -592,9 +592,9 @@ public class JmsMessageConsumer implements AutoCloseable, MessageConsumer, JmsMe
public void setMessageListener(MessageListener listener) throws JMSException {
checkClosed();
this.messageListener = listener;
- if(listener != null) {
+ if (listener != null) {
consumerInfo.setListener(true);
- if(isPullConsumer()){
+ if (isPullConsumer()){
startConsumerResource();
}
drainMessageQueueToListener();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/AmqpAcknowledgementsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/AmqpAcknowledgementsIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/AmqpAcknowledgementsIntegrationTest.java
index 3a212df..2360ced 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/AmqpAcknowledgementsIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/AmqpAcknowledgementsIntegrationTest.java
@@ -21,12 +21,14 @@ package org.apache.qpid.jms.integration;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.jms.Connection;
+import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
@@ -47,10 +49,45 @@ import org.junit.Test;
public class AmqpAcknowledgementsIntegrationTest extends QpidJmsTestCase {
private static final int SKIP = -1;
+ private static final int INVALID = 99;
private final IntegrationTestFixture testFixture = new IntegrationTestFixture();
@Test(timeout = 20000)
+ public void testAcknowledgeFailsAfterSessionIsClosed() throws Exception {
+ try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+ Connection connection = testFixture.establishConnecton(testPeer);
+ connection.start();
+
+ testPeer.expectBegin();
+
+ Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ Queue queue = session.createQueue("myQueue");
+
+ testPeer.expectReceiverAttach();
+ testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, new AmqpValueDescribedType(null), 1);
+ testPeer.expectEnd();
+
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+
+ Message receivedMessage = messageConsumer.receive(6000);
+ assertNotNull("Message was not recieved", receivedMessage);
+
+ session.close();
+
+ try {
+ receivedMessage.acknowledge();
+ fail("Should not be able to acknowledge the message after session closed");
+ } catch (JMSException jmsex) {}
+
+ testPeer.expectClose();
+ connection.close();
+
+ testPeer.waitForAllHandlersToComplete(3000);
+ }
+ }
+
+ @Test(timeout = 20000)
public void testDefaultAcceptMessages() throws Exception {
doTestAmqpAcknowledgementTestImpl(SKIP, new AcceptedMatcher(), false);
}
@@ -85,6 +122,11 @@ public class AmqpAcknowledgementsIntegrationTest extends QpidJmsTestCase {
doTestAmqpAcknowledgementTestImpl(JmsMessageSupport.MODIFIED_FAILED_UNDELIVERABLE, new ModifiedMatcher().withDeliveryFailed(equalTo(true)).withUndeliverableHere(equalTo(true)), false);
}
+ @Test(timeout = 20000)
+ public void testRequestAcknowledgeMessagesWithInvalidDisposition() throws Exception {
+ doTestAmqpAcknowledgementTestImpl(INVALID, new AcceptedMatcher(), false);
+ }
+
private void doTestAmqpAcknowledgementTestImpl(int disposition, Matcher<?> descriptorMatcher, boolean clearPropsFirst) throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
@@ -114,10 +156,21 @@ public class AmqpAcknowledgementsIntegrationTest extends QpidJmsTestCase {
if (clearPropsFirst) {
lastReceivedMessage.clearProperties();
}
+
lastReceivedMessage.setIntProperty(JmsMessageSupport.JMS_AMQP_ACK_TYPE, disposition);
}
- lastReceivedMessage.acknowledge();
+ if (disposition == INVALID) {
+ try {
+ lastReceivedMessage.acknowledge();
+ fail("Should throw exception due to invalid ack type");
+ } catch (JMSException jmsex) {}
+
+ lastReceivedMessage.setIntProperty(JmsMessageSupport.JMS_AMQP_ACK_TYPE, JmsMessageSupport.ACCEPTED);
+ lastReceivedMessage.acknowledge();
+ } else {
+ lastReceivedMessage.acknowledge();
+ }
testPeer.expectClose();
connection.close();
@@ -161,6 +214,11 @@ public class AmqpAcknowledgementsIntegrationTest extends QpidJmsTestCase {
doTestAmqpAcknowledgementAsyncTestImpl(JmsMessageSupport.MODIFIED_FAILED_UNDELIVERABLE, new ModifiedMatcher().withDeliveryFailed(equalTo(true)).withUndeliverableHere(equalTo(true)), false);
}
+ @Test(timeout = 20000)
+ public void testRequestAcknowledgeMessagesWithInvalidDispositionWithMessageListener() throws Exception {
+ doTestAmqpAcknowledgementAsyncTestImpl(INVALID, new AcceptedMatcher(), false);
+ }
+
private void doTestAmqpAcknowledgementAsyncTestImpl(int disposition, Matcher<?> descriptorMatcher, boolean clearPropsFirst) throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
@@ -201,7 +259,17 @@ public class AmqpAcknowledgementsIntegrationTest extends QpidJmsTestCase {
lastReceivedMessage.get().setIntProperty(JmsMessageSupport.JMS_AMQP_ACK_TYPE, disposition);
}
- lastReceivedMessage.get().acknowledge();
+ if (disposition == INVALID) {
+ try {
+ lastReceivedMessage.get().acknowledge();
+ fail("Should throw exception due to invalid ack type");
+ } catch (JMSException jmsex) {}
+
+ lastReceivedMessage.get().setIntProperty(JmsMessageSupport.JMS_AMQP_ACK_TYPE, JmsMessageSupport.ACCEPTED);
+ lastReceivedMessage.get().acknowledge();
+ } else {
+ lastReceivedMessage.get().acknowledge();
+ }
testPeer.expectClose();
connection.close();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
index 24e133b..d902fdc 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
@@ -21,6 +21,7 @@ package org.apache.qpid.jms.integration;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Date;
@@ -191,6 +192,12 @@ public class ZeroPrefetchIntegrationTest extends QpidJmsTestCase {
// Wait for the resulting flow to be received
testPeer.waitForAllHandlersToComplete(2000);
+ // Should not flow more credit after consumer removed and a receive should drain
+ testPeer.expectLinkFlow(true, true, equalTo(UnsignedInteger.ONE));
+ consumer.setMessageListener(null);
+
+ assertNull(consumer.receiveNoWait());
+
testPeer.expectClose();
connection.close();
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
index 22eef19..f82d136 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
@@ -1493,6 +1493,21 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
assertEquals("Incorrect messageId value received", userIdString, amqpMessageFacade.getUserId());
}
+ @Test
+ public void testGetUserIdOnReceievedMessageWithEmptyBinaryValue() throws Exception {
+ byte[] bytes = new byte[0];
+
+ Message message = Proton.message();
+
+ Properties props = new Properties();
+ props.setUserId(new Binary(bytes));
+ message.setProperties(props);
+
+ AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
+
+ assertNull("Expected a userid on received message", amqpMessageFacade.getUserId());
+ }
+
/**
* Check that setting UserId on the message causes creation of the underlying properties
* section with the expected value. New messages lack the properties section section,
@@ -1849,6 +1864,21 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
assertEquals("JMSType value was not as expected", myJMSType, amqpMessageFacade.getType());
}
+ // ====== Content Type =======
+
+ @Test
+ public void testGetContentTypeIsNullOnNewMessage() throws Exception {
+ AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
+ assertNull("did not expect a JMSType value to be present", amqpMessageFacade.getContentType());
+ }
+
+ @Test
+ public void testGetContentTypeIsNullOnMessageWithEmptyPropertiesObject() throws Exception {
+ AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
+ amqpMessageFacade.setProperties(new Properties());
+ assertNull("did not expect a JMSType value to be present", amqpMessageFacade.getContentType());
+ }
+
// ====== AMQP Application Properties =======
// ==========================================
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PriorityMessageQueueTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PriorityMessageQueueTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PriorityMessageQueueTest.java
index d9df585..2c38dfa 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PriorityMessageQueueTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PriorityMessageQueueTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
@@ -29,12 +30,14 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.jms.JMSException;
+import javax.jms.MessageNotReadableException;
import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
import org.apache.qpid.jms.message.JmsMessage;
import org.apache.qpid.jms.message.facade.test.JmsTestMessageFacade;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
/**
* Test for the priority based message Queue
@@ -390,6 +393,29 @@ public class PriorityMessageQueueTest {
assertNull(queue.dequeue(1L));
}
+ @Test
+ public void testUnreadablePrioirtyIsStillEnqueued() throws JMSException {
+ JmsInboundMessageDispatch message = createEnvelopeWithMessageThatCannotReadPriority();
+ queue.enqueue(createEnvelope(9));
+ queue.enqueue(message);
+ queue.enqueue(createEnvelope(1));
+
+ JmsInboundMessageDispatch envelope = queue.peek();
+ assertEquals(9, envelope.getMessage().getJMSPriority());
+ queue.dequeueNoWait();
+ envelope = queue.peek();
+ try {
+ envelope.getMessage().getJMSPriority();
+ fail("Unreadable priority message should sit at default level");
+ } catch (MessageNotReadableException mnre) {}
+ queue.dequeueNoWait();
+ envelope = queue.peek();
+ assertEquals(1, envelope.getMessage().getJMSPriority());
+ queue.dequeueNoWait();
+
+ assertTrue(queue.isEmpty());
+ }
+
private List<JmsInboundMessageDispatch> createFullRangePrioritySet() {
List<JmsInboundMessageDispatch> messages = new ArrayList<JmsInboundMessageDispatch>();
for (int i = 0; i < 10; ++i) {
@@ -404,6 +430,16 @@ public class PriorityMessageQueueTest {
return envelope;
}
+ private JmsInboundMessageDispatch createEnvelopeWithMessageThatCannotReadPriority() throws JMSException {
+ JmsInboundMessageDispatch envelope = new JmsInboundMessageDispatch(sequence++);
+
+ JmsMessage message = Mockito.mock(JmsMessage.class);
+ Mockito.when(message.getJMSPriority()).thenThrow(new MessageNotReadableException("Message is not readable"));
+
+ envelope.setMessage(message);
+ return envelope;
+ }
+
private JmsInboundMessageDispatch createEnvelope(int priority) {
JmsInboundMessageDispatch envelope = new JmsInboundMessageDispatch(sequence++);
envelope.setMessage(createMessage(priority));
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
index 261b843..68204da 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
@@ -441,6 +441,15 @@ public class PropertyUtilTest {
assertEquals("bar", configObject.getLastName());
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetPropertiesThrowsOnNullObject() throws Exception {
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("firstName", "foo");
+ properties.put("lastName", "bar");
+
+ PropertyUtil.setProperties(null, properties);
+ }
+
@Test
public void testSetPropertiesUsingPropertiesObject() throws Exception {
Options configObject = new Options();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/TypeConversionSupportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/TypeConversionSupportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/TypeConversionSupportTest.java
new file mode 100644
index 0000000..753b7be
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/TypeConversionSupportTest.java
@@ -0,0 +1,311 @@
+/*
+ * 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.jms.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+import java.util.UUID;
+
+import org.junit.Test;
+
+public class TypeConversionSupportTest {
+
+ @Test
+ public void testConversionStringToUUID() {
+ String result = (String) TypeConversionSupport.convert("42", UUID.class);
+ assertNull(result);
+ }
+
+ @Test
+ public void testConversionUUIDToString() {
+ String result = (String) TypeConversionSupport.convert(UUID.randomUUID(), String.class);
+ assertNull(result);
+ }
+
+ //----- String conversion from some other type ---------------------------//
+
+ @Test
+ public void testConversionStringToString() {
+ String result = (String) TypeConversionSupport.convert("42", String.class);
+ assertNotNull(result);
+ assertEquals("42", result);
+ }
+
+ @Test
+ public void testConversionByteToString() {
+ String result = (String) TypeConversionSupport.convert((byte) 42, String.class);
+ assertNotNull(result);
+ assertEquals("42", result);
+ }
+
+ @Test
+ public void testConversionShortToString() {
+ String result = (String) TypeConversionSupport.convert((short) 42, String.class);
+ assertNotNull(result);
+ assertEquals("42", result);
+ }
+
+ @Test
+ public void testConversionIntToString() {
+ String result = (String) TypeConversionSupport.convert(42, String.class);
+ assertNotNull(result);
+ assertEquals("42", result);
+ }
+
+ @Test
+ public void testConversionLongToString() {
+ String result = (String) TypeConversionSupport.convert((long) 42, String.class);
+ assertNotNull(result);
+ assertEquals("42", result);
+ }
+
+ @Test
+ public void testConversionFloatToString() {
+ String result = (String) TypeConversionSupport.convert(42.0f, String.class);
+ assertNotNull(result);
+ assertEquals("42.0", result);
+ }
+
+ @Test
+ public void testConversionDoubleToString() {
+ String result = (String) TypeConversionSupport.convert(42.0, String.class);
+ assertNotNull(result);
+ assertEquals("42.0", result);
+ }
+
+ //----- Byte conversion from some other type ---------------------------//
+
+ @Test
+ public void testConversionStringToByte() {
+ byte result = (byte) TypeConversionSupport.convert("42", Byte.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveByte() {
+ byte result = (byte) TypeConversionSupport.convert("42", byte.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionByteToByte() {
+ byte result = (byte) TypeConversionSupport.convert((byte) 42, Byte.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ //----- Short conversion from some other type ----------------------------//
+
+ @Test
+ public void testConversionStringToShort() {
+ short result = (short) TypeConversionSupport.convert("42", Short.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveShort() {
+ short result = (short) TypeConversionSupport.convert("42", short.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionByteToShort() {
+ short result = (short) TypeConversionSupport.convert((byte) 42, Short.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionShortToShort() {
+ short result = (short) TypeConversionSupport.convert((short) 42, Short.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ //----- Integer conversion from some other type --------------------------//
+
+ @Test
+ public void testConversionStringToInt() {
+ int result = (int) TypeConversionSupport.convert("42", Integer.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveInt() {
+ int result = (int) TypeConversionSupport.convert("42", int.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionByteToInt() {
+ int result = (int) TypeConversionSupport.convert((byte) 42, Integer.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionShortToInt() {
+ int result = (int) TypeConversionSupport.convert((short) 42, Integer.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionIntToInt() {
+ int result = (int) TypeConversionSupport.convert(42, Integer.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ //----- Long conversion from some other type --------------------------//
+
+ @Test
+ public void testConversionStringToLong() {
+ long result = (long) TypeConversionSupport.convert("42", Long.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveLong() {
+ long result = (long) TypeConversionSupport.convert("42", long.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionByteToLong() {
+ long result = (long) TypeConversionSupport.convert((byte) 42, Long.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionShortToLong() {
+ long result = (long) TypeConversionSupport.convert((short) 42, Long.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionIntToLong() {
+ long result = (long) TypeConversionSupport.convert(42, Long.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionLongToLong() {
+ long result = (long) TypeConversionSupport.convert((long) 42, Long.class);
+ assertNotNull(result);
+ assertEquals(42, result);
+ }
+
+ @Test
+ public void testConversionDateToLong() {
+ Date now = new Date(System.currentTimeMillis());
+ long result = (long) TypeConversionSupport.convert(now, Long.class);
+ assertNotNull(result);
+ assertEquals(now.getTime(), result);
+ }
+
+ //----- Float conversion from some other type --------------------------//
+
+ @Test
+ public void testConversionStringToFloat() {
+ float result = (float) TypeConversionSupport.convert("42.0", Float.class);
+ assertNotNull(result);
+ assertEquals(42.0, result, 0.5f);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveFloat() {
+ float result = (float) TypeConversionSupport.convert("42.0", float.class);
+ assertNotNull(result);
+ assertEquals(42.0, result, 0.5f);
+ }
+
+ @Test
+ public void testConversionFloatToFloat() {
+ float result = (float) TypeConversionSupport.convert(42.0f, Float.class);
+ assertNotNull(result);
+ assertEquals(42f, result, 0.5f);
+ }
+
+ //----- Float conversion from some other type --------------------------//
+
+ @Test
+ public void testConversionStringToDouble() {
+ double result = (double) TypeConversionSupport.convert("42.0", Double.class);
+ assertNotNull(result);
+ assertEquals(42.0, result, 0.5f);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveDouble() {
+ double result = (double) TypeConversionSupport.convert("42.0", double.class);
+ assertNotNull(result);
+ assertEquals(42.0, result, 0.5f);
+ }
+
+ @Test
+ public void testConversionFloatToDouble() {
+ double result = (double) TypeConversionSupport.convert(42.0f, Double.class);
+ assertNotNull(result);
+ assertEquals(42, result, 0.5);
+ }
+
+ @Test
+ public void testConversionDoubleToDouble() {
+ double result = (double) TypeConversionSupport.convert(42.0, Double.class);
+ assertNotNull(result);
+ assertEquals(42, result, 0.5);
+ }
+
+ //----- Boolean conversion from some other type --------------------------//
+
+ @Test
+ public void testConversionStringToBoolean() {
+ boolean result = (boolean) TypeConversionSupport.convert("true", Boolean.class);
+ assertNotNull(result);
+ assertTrue(result);
+ }
+
+ @Test
+ public void testConversionStringToPrimitiveBoolean() {
+ boolean result = (boolean) TypeConversionSupport.convert("true", boolean.class);
+ assertNotNull(result);
+ assertTrue(result);
+ }
+
+ @Test
+ public void testConversionBooleanToBoolean() {
+ boolean result = (boolean) TypeConversionSupport.convert(true, Boolean.class);
+ assertNotNull(result);
+ assertTrue(result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1a08b440/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
index 1ccc878..5880ae6 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
@@ -62,6 +62,16 @@ public class URISupportTest {
}
@Test
+ public void testParseCompositeWithMismatchedParends() throws Exception {
+ URI uri = new URI("test:(part1://host,part2://(sub1://part,sube2:part)");
+ try {
+ URISupport.parseComposite(uri);
+ fail("Should not parse when parends don't match.");
+ } catch (URISyntaxException ex) {
+ }
+ }
+
+ @Test
public void testEmptyCompositeWithParenthesisInParam() throws Exception {
URI uri = new URI("failover://()?updateURIsURL=file:/C:/Dir(1)/a.csv");
CompositeData data = URISupport.parseComposite(uri);
@@ -167,6 +177,10 @@ public class URISupportTest {
verifyParams(parameters);
uri = new URI("http://0.0.0.0:61616");
parameters = URISupport.parseParameters(uri);
+ assertTrue(parameters.isEmpty());
+ uri = new URI("failover:(http://0.0.0.0:61616)");
+ parameters = URISupport.parseParameters(uri);
+ assertTrue(parameters.isEmpty());
}
@Test
@@ -215,6 +229,19 @@ public class URISupportTest {
verifyParams(URISupport.parseParameters(uri));
}
+ @Test
+ public void testApplyParametersPreservesOriginalParameters() throws Exception {
+ URI uri = new URI("http://0.0.0.0:61616?timeout=1000");
+
+ Map<String,String> parameters = new HashMap<String, String>();
+ parameters.put("t.proxyHost", "localhost");
+ parameters.put("t.proxyPort", "80");
+
+ uri = URISupport.applyParameters(uri, parameters);
+ Map<String,String> appliedParameters = URISupport.parseParameters(uri);
+ assertEquals("all params applied with no prefix", 3, appliedParameters.size());
+ }
+
private void verifyParams(Map<String,String> parameters) {
assertEquals(parameters.get("proxyHost"), "localhost");
assertEquals(parameters.get("proxyPort"), "80");
@@ -245,6 +272,12 @@ public class URISupportTest {
}
@Test
+ public void testIsCompositeWhenURIHasUnmatchedParends() throws Exception {
+ URI uri = new URI("test:(part1://host,part2://(sub1://part,sube2:part)");
+ assertFalse(URISupport.isCompositeURI(uri));
+ }
+
+ @Test
public void testIndexOfParenthesisMatchExceptions() throws URISyntaxException {
try {
URISupport.indexOfParenthesisMatch(null, -1);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org