diff options
| author | Alex Rudyy <orudyy@apache.org> | 2015-04-15 09:47:28 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2015-04-15 09:47:28 +0000 |
| commit | 0a0baee45ebcff44635907d457c4ff6810b09c87 (patch) | |
| tree | 8bfb0f9eddbc23cff88af69be80ab3ce7d47011c /qpid/java/client/src/test | |
| parent | 54aa3d7070da16ce55c28ccad3f7d0871479e461 (diff) | |
| download | qpid-python-0a0baee45ebcff44635907d457c4ff6810b09c87.tar.gz | |
QPID-6481: Move java source tree to top level
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1673693 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src/test')
44 files changed, 0 insertions, 8253 deletions
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java deleted file mode 100644 index 6c6aa04ec1..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java +++ /dev/null @@ -1,106 +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.client; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import javax.jms.JMSException; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.jms.BrokerDetails; -import org.apache.qpid.jms.ConnectionURL; - -public class AMQConnectionFactoryTest extends TestCase -{ - - //URL will be returned with the password field swapped for '********' - // so ensure that these two strings are kept in sync. - public static final String URL = "amqp://guest:guest@clientID/test?brokerlist='tcp://localhost:5672'"; - public static final String URL_STAR_PWD = "amqp://guest:********@clientID/test?brokerlist='tcp://localhost:5672'"; - - public void testConnectionURLStringMasksPassword() throws Exception - { - AMQConnectionFactory factory = new AMQConnectionFactory(URL); - - //URL will be returned with the password field swapped for '********' - assertEquals("Connection URL not correctly set", URL_STAR_PWD, factory.getConnectionURLString()); - - // Further test that the processed ConnectionURL is as expected after - // the set call - ConnectionURL connectionurl = factory.getConnectionURL(); - - assertNull("Failover is set.", connectionurl.getFailoverMethod()); - assertEquals("guest", connectionurl.getUsername()); - assertEquals("guest", connectionurl.getPassword()); - assertEquals("clientID", connectionurl.getClientName()); - assertEquals("/test", connectionurl.getVirtualHost()); - - assertEquals(1, connectionurl.getBrokerCount()); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertEquals("tcp", service.getTransport()); - assertEquals("localhost", service.getHost()); - assertEquals(5672, service.getPort()); - } - - public void testInstanceCreatedWithDefaultConstructorThrowsExceptionOnCallingConnectWithoutSettingURL() throws Exception - { - AMQConnectionFactory factory = new AMQConnectionFactory(); - - try - { - factory.createConnection(); - fail("Expected exception not thrown"); - } - catch(JMSException e) - { - assertEquals("Unexpected exception", AMQConnectionFactory.NO_URL_CONFIGURED, e.getMessage()); - } - } - - public void testSerialization() throws Exception - { - AMQConnectionFactory factory = new AMQConnectionFactory(); - assertTrue(factory instanceof Serializable); - factory.setConnectionURLString("amqp://guest:guest@clientID/test?brokerlist='tcp://localhost:5672'"); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(factory); - oos.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bis); - Object deserializedObject = ois.readObject(); - ois.close(); - - AMQConnectionFactory deserialisedFactory = (AMQConnectionFactory) deserializedObject; - assertEquals(factory, deserialisedFactory); - assertEquals(factory.hashCode(), deserialisedFactory.hashCode()); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java deleted file mode 100644 index d309251b44..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionUnitTest.java +++ /dev/null @@ -1,118 +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.client; - -import java.util.concurrent.atomic.AtomicReference; - -import javax.jms.ExceptionListener; -import javax.jms.JMSException; - -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.configuration.ClientProperties; -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.test.utils.QpidTestCase; - -public class AMQConnectionUnitTest extends QpidTestCase -{ - String _url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; - - public void testVerifyQueueOnSendDefault() throws Exception - { - MockAMQConnection connection = new MockAMQConnection(_url); - assertFalse(connection.validateQueueOnSend()); - } - - public void testVerifyQueueOnSendViaSystemProperty() throws Exception - { - setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "true"); - MockAMQConnection connection = new MockAMQConnection(_url); - assertTrue(connection.validateQueueOnSend()); - - setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false"); - connection = new MockAMQConnection(_url); - assertFalse(connection.validateQueueOnSend()); - } - - public void testVerifyQueueOnSendViaURL() throws Exception - { - MockAMQConnection connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='true'"); - assertTrue(connection.validateQueueOnSend()); - - connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='false'"); - assertFalse(connection.validateQueueOnSend()); - } - - public void testVerifyQueueOnSendViaURLoverridesSystemProperty() throws Exception - { - setTestSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "false"); - MockAMQConnection connection = new MockAMQConnection(_url + "&" + ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND + "='true'"); - assertTrue(connection.validateQueueOnSend()); - } - - public void testExceptionReceived() - { - AMQInvalidArgumentException expectedException = new AMQInvalidArgumentException("Test", null); - final AtomicReference<JMSException> receivedException = new AtomicReference<JMSException>(); - try - { - MockAMQConnection connection = new MockAMQConnection(_url); - connection.setExceptionListener(new ExceptionListener() - { - - @Override - public void onException(JMSException jmsException) - { - receivedException.set(jmsException); - } - }); - connection.exceptionReceived(expectedException); - } - catch (Exception e) - { - fail("Failure to test exceptionRecived:" + e.getMessage()); - } - JMSException exception = receivedException.get(); - assertNotNull("Expected JMSException but got null", exception); - assertEquals("JMSException error code is incorrect", Integer.toString(expectedException.getErrorCode().getCode()), exception.getErrorCode()); - assertNotNull("Expected not null message for JMSException", exception.getMessage()); - assertTrue("JMSException error message is incorrect", exception.getMessage().contains(expectedException.getMessage())); - assertEquals("JMSException linked exception is incorrect", expectedException, exception.getLinkedException()); - } - - /** - * This should expand to test all the defaults. - */ - public void testDefaultStreamMessageEncoding() throws Exception - { - MockAMQConnection connection = new MockAMQConnection(_url); - assertTrue("Legacy Stream message encoding should be the default",connection.isUseLegacyStreamMessageFormat()); - } - - /** - * This should expand to test all the connection properties. - */ - public void testStreamMessageEncodingProperty() throws Exception - { - MockAMQConnection connection = new MockAMQConnection(_url + "&use_legacy_stream_msg_format='false'"); - assertFalse("Stream message encoding should be amqp/list",connection.isUseLegacyStreamMessageFormat()); - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java deleted file mode 100644 index a494192148..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java +++ /dev/null @@ -1,230 +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.client; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.Topic; - -import junit.framework.TestCase; - -public class AMQDestinationTest extends TestCase -{ - public void testEqualsAndHashCodeForAddressBasedDestinations() throws Exception - { - AMQDestination dest = new AMQQueue("ADDR:Foo; {node :{type:queue}}"); - AMQDestination dest1 = new AMQTopic("ADDR:Foo; {node :{type:topic}}"); - AMQDestination dest10 = new AMQTopic("ADDR:Foo; {node :{type:topic}, link:{name:my-topic}}"); - AMQDestination dest2 = new AMQQueue("ADDR:Foo; {create:always,node :{type:queue}}"); - String bUrl = "BURL:direct://amq.direct/test-route/Foo?routingkey='Foo'"; - AMQDestination dest3 = new AMQQueue(bUrl); - - assertTrue(dest.equals(dest)); - assertFalse(dest.equals(dest1)); - assertTrue(dest.equals(dest2)); - assertFalse(dest.equals(dest3)); - assertTrue(dest1.equals(dest10)); - - assertTrue(dest.hashCode() == dest.hashCode()); - assertTrue(dest.hashCode() != dest1.hashCode()); - assertTrue(dest.hashCode() == dest2.hashCode()); - assertTrue(dest.hashCode() != dest3.hashCode()); - assertTrue(dest1.hashCode() == dest10.hashCode()); - - AMQDestination dest4 = new AMQQueue("ADDR:Foo/Bar; {node :{type:queue}}"); - AMQDestination dest5 = new AMQQueue("ADDR:Foo/Bar2; {node :{type:queue}}"); - assertFalse(dest4.equals(dest5)); - assertTrue(dest4.hashCode() != dest5.hashCode()); - - AMQDestination dest6 = new AMQAnyDestination("ADDR:Foo; {node :{type:queue}}"); - AMQDestination dest7 = new AMQAnyDestination("ADDR:Foo; {create: always, node :{type:queue}, link:{capacity: 10}}"); - AMQDestination dest8 = new AMQAnyDestination("ADDR:Foo; {create: always, link:{capacity: 10}}"); - AMQDestination dest9 = new AMQAnyDestination("ADDR:Foo/bar"); - assertTrue(dest6.equals(dest7)); - assertFalse(dest6.equals(dest8)); //dest8 type unknown, could be a topic - assertFalse(dest7.equals(dest8)); //dest8 type unknown, could be a topic - assertFalse(dest6.equals(dest9)); - assertTrue(dest6.hashCode() == dest7.hashCode()); - assertTrue(dest6.hashCode() != dest8.hashCode()); - assertTrue(dest7.hashCode() != dest8.hashCode()); - assertTrue(dest6.hashCode() != dest9.hashCode()); - } - - /** - * Tests that destinations created with the same options string will share the same address options map. - */ - public void testCacheAddressOptionsMaps() throws Exception - { - // Create destinations 1 and 3 with the same options string, and destinations 2 and 4 with a different one - String optionsStringA = "{create: always, node: {type: topic}}"; - String optionsStringB = "{}"; // empty options - AMQDestination dest1 = createDestinationWithOptions("testDest1", optionsStringA); - AMQDestination dest2 = createDestinationWithOptions("testDest2", optionsStringB); - AMQDestination dest3 = createDestinationWithOptions("testDest3", optionsStringA); - AMQDestination dest4 = createDestinationWithOptions("testDest4", optionsStringB); - - // Destinations 1 and 3 should refer to the same address options map - assertSame("Destinations 1 and 3 were created with the same options and should refer to the same options map.", - dest1.getAddress().getOptions(), dest3.getAddress().getOptions()); - // Destinations 2 and 4 should refer to the same address options map - assertSame("Destinations 2 and 4 were created with the same options and should refer to the same options map.", - dest2.getAddress().getOptions(), dest4.getAddress().getOptions()); - // Destinations 1 and 2 should have a different options map - assertNotSame("Destinations 1 and 2 should not have the same options map.", - dest1.getAddress().getOptions(), dest2.getAddress().getOptions()); - - // Verify the contents of the shared map are as expected - Map<String, Object> optionsA = new HashMap<String, Object>(); - optionsA.put("create", "always"); - optionsA.put("node", Collections.singletonMap("type", "topic")); - assertEquals("Contents of the shared address options map are not as expected.", - optionsA, dest1.getAddress().getOptions()); - assertEquals("Contents of the empty shared address options map are not as expected.", - Collections.emptyMap(), dest2.getAddress().getOptions()); - - // Verify that address options map is immutable - try - { - dest1.getAddress().getOptions().put("testKey", "testValue"); - fail("Should not be able able to modify an address's options map."); - } - catch (UnsupportedOperationException e) - { - // expected - } - } - - private AMQDestination createDestinationWithOptions(String destName, String optionsString) throws Exception - { - String addr = "ADDR:" + destName + "; " + optionsString; - return new AMQAnyDestination(addr); - } - - /** - * Tests that when a queue has no link subscription arguments and no link bindings, its Subscription - * arguments and its bindings list refer to constant empty collections. - */ - public void testEmptyLinkBindingsAndSubscriptionArgs() throws Exception - { - // no link properties - assertEmptyLinkBindingsAndSubscriptionArgs(new AMQAnyDestination("ADDR:testQueue")); - - // has link properties but no x-bindings; has link x-subscribes but no arguments - String xSubscribeAddr = "ADDR:testQueueWithXSubscribes; {link: {x-subscribes: {exclusive: true}}}"; - assertEmptyLinkBindingsAndSubscriptionArgs(new AMQAnyDestination(xSubscribeAddr)); - } - - private void assertEmptyLinkBindingsAndSubscriptionArgs(AMQDestination dest) - { - assertEquals("Default link subscription arguments should be the constant Collections empty map.", - Collections.emptyMap(), dest.getLink().getSubscription().getArgs()); - assertSame("Defaultl link bindings should be the constant Collections empty list.", - Collections.emptyList(), dest.getLink().getBindings()); - } - - /** - * Tests that when a node has no bindings specified, its bindings list refers to a constant empty list, - * so that we are not consuming extra memory unnecessarily. - */ - public void testEmptyNodeBindings() throws Exception - { - // no node properties - assertEmptyNodeBindings(new AMQAnyDestination("ADDR:testDest1")); - // has node properties but no x-bindings - assertEmptyNodeBindings(new AMQAnyDestination("ADDR:testDest2; {node: {type: queue}}")); - assertEmptyNodeBindings(new AMQAnyDestination("ADDR:testDest3; {node: {type: topic}}")); - } - - public void testSerializeAMQQueue_BURL() throws Exception - { - Queue queue = new AMQQueue("BURL:direct://amq.direct/test-route/Foo?routingkey='Foo'"); - assertTrue(queue instanceof Serializable); - - Queue deserialisedQueue = (Queue) serialiseDeserialiseDestination(queue); - - assertEquals(queue, deserialisedQueue); - assertEquals(queue.hashCode(), deserialisedQueue.hashCode()); - } - - public void testSerializeAMQQueue_ADDR() throws Exception - { - Queue queue = new AMQQueue("ADDR:testDest2; {node: {type: queue}}"); - assertTrue(queue instanceof Serializable); - - Queue deserialisedQueue = (Queue) serialiseDeserialiseDestination(queue); - - assertEquals(queue, deserialisedQueue); - assertEquals(queue.hashCode(), deserialisedQueue.hashCode()); - } - - public void testSerializeAMQTopic_BURL() throws Exception - { - Topic topic = new AMQTopic("BURL:topic://amq.topic/mytopic/?routingkey='mytopic'"); - assertTrue(topic instanceof Serializable); - - Topic deserialisedTopic = (Topic) serialiseDeserialiseDestination(topic); - - assertEquals(topic, deserialisedTopic); - assertEquals(topic.hashCode(), deserialisedTopic.hashCode()); - } - - public void testSerializeAMQTopic_ADDR() throws Exception - { - Topic topic = new AMQTopic("ADDR:my-topic; {assert: always, node:{ type: topic }}"); - assertTrue(topic instanceof Serializable); - - Topic deserialisedTopic = (Topic) serialiseDeserialiseDestination(topic); - - assertEquals(topic, deserialisedTopic); - assertEquals(topic.hashCode(), deserialisedTopic.hashCode()); - } - - private void assertEmptyNodeBindings(AMQDestination dest) - { - assertSame("Empty node bindings should refer to the constant Collections empty list.", - Collections.emptyList(), dest.getNode().getBindings()); - } - - private Destination serialiseDeserialiseDestination(final Destination dest) throws Exception - { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(dest); - oos.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bis); - Object deserializedObject = ois.readObject(); - ois.close(); - return (Destination)deserializedObject; - } - - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQQueueTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQQueueTest.java deleted file mode 100644 index bc48ee8895..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQQueueTest.java +++ /dev/null @@ -1,42 +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.client; - -import junit.framework.TestCase; - -import org.apache.qpid.framing.AMQShortString; - -public class AMQQueueTest extends TestCase -{ - private AMQShortString exchange = new AMQShortString("test.exchange"); - private AMQShortString routingkey = new AMQShortString("test-route"); - private AMQShortString qname = new AMQShortString("test-queue"); - private AMQShortString[] oneBinding = new AMQShortString[]{new AMQShortString("bindingA")}; - private AMQShortString[] bindings = new AMQShortString[]{new AMQShortString("bindingB"), - new AMQShortString("bindingC")}; - - public void testToURLNoBindings() - { - AMQQueue dest = new AMQQueue(exchange, routingkey, qname); - String url = dest.toURL(); - assertEquals("direct://test.exchange/test-route/test-queue?routingkey='test-route'", url); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java deleted file mode 100644 index 2543c5b500..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_10Test.java +++ /dev/null @@ -1,697 +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.client; - -import java.util.ArrayList; -import java.util.List; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.StreamMessage; - -import org.apache.qpid.client.message.AMQPEncodedListMessage; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.*; -import org.apache.qpid.transport.Connection.SessionFactory; -import org.apache.qpid.transport.Connection.State; - -/** - * Tests AMQSession_0_10 methods. - * <p> - * The main purpose of the tests in this test suite is to check that - * {@link SessionException} is not thrown from methods of - * {@link AMQSession_0_10}. - */ -public class AMQSession_0_10Test extends QpidTestCase -{ - - public void testExceptionOnCommit() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - session.commit(); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testExceptionOnCreateMessageProducer() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - session.createMessageProducer(createDestination(), true, true, 1l); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected but got:" + e, e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testExceptionOnRollback() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - session.rollback(); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - } - } - - public void testExceptionOnRecover() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(javax.jms.Session.AUTO_ACKNOWLEDGE); - try - { - session.recover(); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - } - } - - public void testExceptionOnCreateBrowser() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - AMQQueue destination = createQueue(); - try - { - session.createBrowser(destination); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testExceptionOnCreateConsumer() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - AMQAnyDestination destination = createDestination(); - try - { - session.createConsumer(destination); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testExceptionOnCreateSubscriber() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - AMQAnyDestination destination = createDestination(); - try - { - session.createSubscriber(destination); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testExceptionOnUnsubscribe() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - session.unsubscribe("whatever"); - fail("JMSExceptiuon should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testCommit() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.commit(); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, TxCommit.class, false); - assertNotNull("TxCommit was not sent", event); - } - - public void testRollback() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.rollback(); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, TxRollback.class, false); - assertNotNull("TxRollback was not sent", event); - } - - public void testRecover() - { - AMQSession_0_10 session = createAMQSession_0_10(javax.jms.Session.AUTO_ACKNOWLEDGE); - try - { - session.recover(); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, MessageRelease.class, false); - assertNotNull("MessageRelease was not sent", event); - } - - public void testCreateProducer() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.createProducer(createQueue()); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, ExchangeDeclare.class, false); - assertNotNull("ExchangeDeclare was not sent", event); - } - - public void testCreateConsumer() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.createConsumer(createQueue()); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, MessageSubscribe.class, false); - assertNotNull("MessageSubscribe was not sent", event); - } - - public void testSync() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.sync(); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, ExecutionSync.class, false); - assertNotNull("ExecutionSync was not sent", event); - } - - public void testSendQueueDelete() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.sendQueueDelete(new AMQShortString("test")); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, QueueDelete.class, false); - assertNotNull("QueueDelete event was not sent", event); - QueueDelete exchangeDelete = (QueueDelete) event; - assertEquals("test", exchangeDelete.getQueue()); - } - - public void testSendConsume() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false, - null, null, false, true); - session.sendConsume(consumer, new AMQShortString("test"), true, 1); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, MessageSubscribe.class, false); - assertNotNull("MessageSubscribe event was not sent", event); - } - - public void testCreateMessageProducer() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.createMessageProducer(createDestination(), true, true, 1l); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, ExchangeDeclare.class, false); - assertNotNull("ExchangeDeclare event was not sent", event); - } - - public void testSendExchangeDelete() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - session.sendExchangeDelete("test", true); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, ExchangeDelete.class, false); - assertNotNull("ExchangeDelete event was not sent", event); - ExchangeDelete exchangeDelete = (ExchangeDelete) event; - assertEquals("test", exchangeDelete.getExchange()); - } - - public void testExceptionOnMessageConsumerReceive() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false, - null, null, false, true); - session.start(); - consumer.receive(1); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testMessageConsumerReceive() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false, - null, null, false, true); - session.start(); - consumer.receive(1); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, MessageFlow.class, false); - assertNotNull("MessageFlow event was not sent", event); - } - - public void testExceptionOnMessageConsumerReceiveNoWait() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false, - null, null, false, true); - session.start(); - consumer.receiveNoWait(); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testMessageConsumerClose() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false, - null, null, false, true); - consumer.close(); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, MessageCancel.class, false); - assertNotNull("MessageCancel event was not sent", event); - } - - public void testExceptionOnMessageConsumerClose() - { - AMQSession_0_10 session = createThrowingExceptionAMQSession_0_10(); - try - { - BasicMessageConsumer_0_10 consumer = session.createMessageConsumer(createDestination(), 1, 1, true, false, - null, null, false, true); - consumer.close(); - fail("JMSException should be thrown"); - } - catch (Exception e) - { - assertTrue("JMSException is expected", e instanceof JMSException); - assertEquals("541 error code is expected", "541", ((JMSException) e).getErrorCode()); - } - } - - public void testMessageProducerSend() - { - AMQSession_0_10 session = createAMQSession_0_10(); - try - { - MessageProducer producer = session.createProducer(createQueue()); - producer.send(session.createTextMessage("Test")); - session.commit(); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent event = findSentProtocolEventOfClass(session, MessageTransfer.class, false); - assertNotNull("MessageTransfer event was not sent", event); - event = findSentProtocolEventOfClass(session, ExchangeDeclare.class, false); - assertNotNull("ExchangeDeclare event was not sent", event); - } - - public void testCreateStreamMessage() throws Exception - { - AMQSession_0_10 session = createAMQSession_0_10(); - StreamMessage m = session.createStreamMessage(); - assertTrue("Legacy Stream message encoding should be the default" + m.getClass(),!(m instanceof AMQPEncodedListMessage)); - } - - public void testGetQueueDepthWithSync() - { - // slow down a flush thread - setTestSystemProperty("qpid.session.max_ack_delay", "10000"); - AMQSession_0_10 session = createAMQSession_0_10(false, javax.jms.Session.DUPS_OK_ACKNOWLEDGE); - try - { - session.acknowledgeMessage(-1, false); - session.getQueueDepth(createDestination(), true); - } - catch (Exception e) - { - fail("Unexpected exception is caught:" + e.getMessage()); - } - ProtocolEvent command = findSentProtocolEventOfClass(session, MessageAccept.class, false); - assertNotNull("MessageAccept command was not sent", command); - command = findSentProtocolEventOfClass(session, ExecutionSync.class, false); - assertNotNull("ExecutionSync command was not sent", command); - command = findSentProtocolEventOfClass(session, QueueQuery.class, false); - assertNotNull("QueueQuery command was not sent", command); - } - - private AMQAnyDestination createDestination() - { - AMQAnyDestination destination = null; - try - { - destination = new AMQAnyDestination(new AMQShortString("amq.direct"), new AMQShortString("direct"), - new AMQShortString("test"), false, true, new AMQShortString("test"), true, null); - } - catch (Exception e) - { - fail("Failued to create destination:" + e.getMessage()); - } - return destination; - } - - private AMQQueue createQueue() - { - AMQQueue destination = null; - try - { - destination = new AMQQueue(new AMQShortString("amq.direct"), new AMQShortString("test"), - new AMQShortString("test")); - } - catch (Exception e) - { - fail("Failued to create destination:" + e.getMessage()); - } - return destination; - } - - private AMQSession_0_10 createThrowingExceptionAMQSession_0_10() - { - return createAMQSession_0_10(true, javax.jms.Session.SESSION_TRANSACTED); - } - - private AMQSession_0_10 createThrowingExceptionAMQSession_0_10(int akcnowledgeMode) - { - return createAMQSession_0_10(true, akcnowledgeMode); - } - - private ProtocolEvent findSentProtocolEventOfClass(AMQSession_0_10 session, Class<? extends ProtocolEvent> class1, - boolean isLast) - { - ProtocolEvent found = null; - List<ProtocolEvent> events = ((MockSession) session.getQpidSession()).getSender().getSendEvents(); - assertNotNull("Events list should not be null", events); - assertFalse("Events list should not be empty", events.isEmpty()); - if (isLast) - { - ProtocolEvent event = events.get(events.size() - 1); - if (event.getClass().isAssignableFrom(class1)) - { - found = event; - } - } - else - { - for (ProtocolEvent protocolEvent : events) - { - if (protocolEvent.getClass().isAssignableFrom(class1)) - { - found = protocolEvent; - break; - } - } - - } - return found; - } - - private AMQSession_0_10 createAMQSession_0_10() - { - return createAMQSession_0_10(false, javax.jms.Session.SESSION_TRANSACTED); - } - - private AMQSession_0_10 createAMQSession_0_10(int acknowledgeMode) - { - return createAMQSession_0_10(false, acknowledgeMode); - } - - private AMQSession_0_10 createAMQSession_0_10(boolean throwException, int acknowledgeMode) - { - AMQConnection amqConnection = null; - try - { - amqConnection = new MockAMQConnection( - "amqp://guest:guest@client/test?brokerlist='tcp://localhost:1'&maxprefetch='0'"); - } - catch (Exception e) - { - fail("Failure to create a mock connection:" + e.getMessage()); - } - boolean isTransacted = acknowledgeMode == javax.jms.Session.SESSION_TRANSACTED ? true : false; - AMQSession_0_10 session = new AMQSession_0_10(createConnection(throwException), amqConnection, 1, isTransacted, acknowledgeMode, - 10, 10, "test"); - return session; - } - - private Connection createConnection(final boolean throwException) - { - MockTransportConnection connection = new MockTransportConnection(); - connection.setState(State.OPEN); - connection.setSender(new MockSender()); - connection.setSessionFactory(new SessionFactory() - { - - public Session newSession(Connection conn, Binary name, long expiry, boolean isNoReplay) - { - return new MockSession(conn, new SessionDelegate(), name, expiry, throwException); - } - }); - return connection; - } - - private final class MockMessageListener implements MessageListener - { - public void onMessage(Message arg0) - { - } - } - - class MockSession extends Session - { - private final boolean _throwException; - private final Connection _connection; - private final SessionDelegate _delegate; - - protected MockSession(Connection connection, SessionDelegate delegate, Binary name, long expiry, - boolean throwException) - { - super(connection, delegate, name, expiry); - _throwException = throwException; - setState(State.OPEN); - _connection = connection; - _delegate = delegate; - } - - public void invoke(Method m, Runnable postIdSettingAction) - { - if (_throwException) - { - if (m instanceof SessionAttach || m instanceof SessionRequestTimeout || m instanceof TxSelect) - { - // do not throw exception for SessionAttach, - // SessionRequestTimeout and TxSelect - // session needs to be instantiated - return; - } - ExecutionException e = new ExecutionException(); - e.setErrorCode(ExecutionErrorCode.INTERNAL_ERROR); - throw new SessionException(e); - } - else - { - super.invoke(m, postIdSettingAction); - if (m instanceof SessionDetach) - { - setState(State.CLOSED); - } - } - } - - public void sync() - { - // to avoid recursive calls - setAutoSync(false); - // simply send sync command - super.executionSync(Option.SYNC); - } - - protected <T> Future<T> invoke(Method m, Class<T> klass) - { - int commandId = getCommandsOut(); - Future<T> future = super.invoke(m, klass); - ExecutionResult result = new ExecutionResult(); - result.setCommandId(commandId); - if (m instanceof ExchangeBound) - { - ExchangeBoundResult struc = new ExchangeBoundResult(); - result.setValue(struc); - } - else if (m instanceof ExchangeQuery) - { - ExchangeQueryResult struc = new ExchangeQueryResult(); - result.setValue(struc); - } - else if (m instanceof QueueQuery) - { - QueueQueryResult struc = new QueueQueryResult(); - result.setValue(struc); - } - _delegate.executionResult(this, result); - return future; - } - - public MockSender getSender() - { - return (MockSender) _connection.getSender(); - } - } - - class MockTransportConnection extends Connection - { - public void setState(State state) - { - super.setState(state); - } - } - - class MockSender implements ProtocolEventSender - { - private List<ProtocolEvent> _sendEvents = new ArrayList<ProtocolEvent>(); - - private void setIdleTimeout(int i) - { - } - - public void send(ProtocolEvent msg) - { - _sendEvents.add(msg); - } - - public void flush() - { - } - - public void close() - { - } - - public List<ProtocolEvent> getSendEvents() - { - return _sendEvents; - } - - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java deleted file mode 100644 index 2a8ab22b81..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java +++ /dev/null @@ -1,73 +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.client; - -import org.apache.qpid.AMQException; -import org.apache.qpid.client.transport.TestNetworkConnection; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.QueueDeclareOkBody; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.network.NetworkConnection; -import org.apache.qpid.url.AMQBindingURL; - -public class AMQSession_0_8Test extends QpidTestCase -{ - private AMQConnection _connection; - - public void setUp() throws Exception - { - _connection = new MockAMQConnection("amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"); - NetworkConnection network = new TestNetworkConnection(); - _connection.getProtocolHandler().setNetworkConnection(network); - } - - public void testQueueNameIsGeneratedOnDeclareQueueWithEmptyQueueName() throws Exception - { - final AMQShortString testQueueName = AMQShortString.valueOf("tmp_127_0_0_1_1_1"); - - _connection.setConnectionListener(new ConnectionListenerSupport() - { - @Override - public void bytesSent(long count) - { - try - { - _connection.getProtocolHandler().methodBodyReceived(1, new QueueDeclareOkBody(testQueueName, 0, 0)); - } - catch (AMQException e) - { - throw new RuntimeException(e); - } - } - }); - - AMQSession_0_8 session = new AMQSession_0_8(_connection, 1, true, 0, 1, 1); - - AMQBindingURL bindingURL = new AMQBindingURL("topic://amq.topic//?routingkey='testTopic'"); - AMQQueue queue = new AMQQueue(bindingURL); - - assertEquals("Unexpected queue name", AMQShortString.EMPTY_STRING, queue.getAMQQueueName()); - - session.declareQueue(queue, true); - - assertEquals("Unexpected queue name", testQueueName, queue.getAMQQueueName()); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java b/qpid/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java deleted file mode 100644 index 066ece7ed1..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/BasicMessageConsumer_0_8_Test.java +++ /dev/null @@ -1,107 +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.client; - -import junit.framework.TestCase; - -import org.apache.qpid.test.unit.message.TestAMQSession; -import org.apache.qpid.url.AMQBindingURL; - -import javax.jms.Session; - -public class BasicMessageConsumer_0_8_Test extends TestCase -{ - /** - * Test that if there is a value for Reject Behaviour specified for the Destination - * used to create the Consumer, it overrides the value for the Connection. - */ - public void testDestinationRejectBehaviourOverridesDefaultConnection() throws Exception - { - /* - * Check that when the connection does not have a value applied that this - * is successfully overridden with a specific value by the consumer. - */ - String connUrlString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; - AMQConnection conn = new MockAMQConnection(connUrlString); - - String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='server'"; - AMQBindingURL burl = new AMQBindingURL(url); - AMQDestination queue = new AMQQueue(burl); - - TestAMQSession testSession = new TestAMQSession(conn); - BasicMessageConsumer_0_8 consumer = - new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false); - - assertEquals("Reject behaviour was was not as expected", RejectBehaviour.SERVER, consumer.getRejectBehaviour()); - } - - /** - * Check that when the connection does have a specific value applied that this - * is successfully overridden with another specific value by the consumer. - */ - public void testDestinationRejectBehaviourSpecified() throws Exception - { - final String connUrlString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&rejectbehaviour='server'"; - final AMQConnection conn = new MockAMQConnection(connUrlString); - - final String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='normal'"; - final AMQBindingURL burl = new AMQBindingURL(url); - final AMQDestination queue = new AMQQueue(burl); - - final TestAMQSession testSession = new TestAMQSession(conn); - final BasicMessageConsumer_0_8 consumer = - new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false); - - assertEquals("Reject behaviour was was not as expected", RejectBehaviour.NORMAL, consumer.getRejectBehaviour()); - } - - /** - * Test that if no value for Reject Behaviour is applied to the Destination, then the value - * from the connection is used and acts as expected. - */ - public void testRejectBehaviourDetectedFromConnection() throws Exception - { - /* - * Check that when the connection does have a specific value applied that this - * is successfully detected by the consumer. - */ - String connUrlString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&rejectbehaviour='normal'"; - AMQConnection conn = new MockAMQConnection(connUrlString); - - String url = "exchangeClass://exchangeName/Destination/Queue"; - AMQBindingURL burl = new AMQBindingURL(url); - AMQDestination queue = new AMQQueue(burl); - - assertNull("Reject behaviour should have been null", queue.getRejectBehaviour()); - - TestAMQSession testSession = new TestAMQSession(conn); - BasicMessageConsumer_0_8 consumer = - new BasicMessageConsumer_0_8(0, conn, queue, "", false, null, testSession, null, 10, 5, false, Session.SESSION_TRANSACTED, false, false); - - assertEquals("Reject behaviour was was not as expected", RejectBehaviour.NORMAL, consumer.getRejectBehaviour()); - } - - - protected RejectBehaviour getRejectBehaviour(AMQDestination destination) - { - return destination.getRejectBehaviour(); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/ConnectionListenerSupport.java b/qpid/java/client/src/test/java/org/apache/qpid/client/ConnectionListenerSupport.java deleted file mode 100644 index fc66e60bc0..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/ConnectionListenerSupport.java +++ /dev/null @@ -1,55 +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.client; - -import org.apache.qpid.jms.ConnectionListener; - -public class ConnectionListenerSupport implements ConnectionListener -{ - - @Override - public void bytesSent(long count) - { - } - - @Override - public void bytesReceived(long count) - { - } - - @Override - public boolean preFailover(boolean redirect) - { - return true; - } - - @Override - public boolean preResubscribe() - { - return false; - } - - @Override - public void failoverComplete() - { - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/DispatcherDaemonTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/DispatcherDaemonTest.java deleted file mode 100644 index b9c4bfc676..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/DispatcherDaemonTest.java +++ /dev/null @@ -1,67 +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.client; - -import javax.jms.Session; - -import org.apache.qpid.AMQException; -import org.apache.qpid.configuration.ClientProperties; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.url.URLSyntaxException; - -public class DispatcherDaemonTest extends QpidTestCase -{ - private AMQSession<?,?> _session; - - public void tearDown() throws Exception - { - super.tearDown(); - if (_session != null && _session.getDispatcherThread() != null) - { - _session.getDispatcherThread().interrupt(); - } - } - - public void testDispatcherIsRunInDaemonThreadWithNoMessageListener() throws Exception - { - _session = createSession(); - _session.startDispatcherIfNecessary(); - assertFalse("Dispatcher thread should be non daemon as qpid.jms.daemon.dispatcher is not set", - _session.getDispatcherThread().isDaemon()); - } - - public void testDispatcherIsRunInDaemonThreadWithConsumerMessageListenerAndDaemonFlagOn() throws Exception - { - setTestSystemProperty(ClientProperties.DAEMON_DISPATCHER, "true"); - _session = createSession(); - _session.startDispatcherIfNecessary(); - assertTrue("Dispatcher thread should be daemon as qpid.jms.daemon.dispatcher is set to true", - _session.getDispatcherThread().isDaemon()); - } - - private AMQSession<?,?> createSession() throws AMQException, URLSyntaxException - { - AMQConnection amqConnection = new MockAMQConnection( - "amqp://guest:guest@client/test?brokerlist='tcp://localhost:1'&maxprefetch='0'"); - - AMQSession_0_8 session = new AMQSession_0_8(amqConnection, 1, true, Session.SESSION_TRANSACTED, 1, 1); - return session; - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java b/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java deleted file mode 100644 index ceb2a323ca..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java +++ /dev/null @@ -1,69 +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.client; - -import java.io.IOException; - -import org.apache.qpid.AMQException; -import org.apache.qpid.client.state.AMQState; -import org.apache.qpid.framing.ProtocolVersion; -import org.apache.qpid.jms.BrokerDetails; -import org.apache.qpid.url.URLSyntaxException; - -public class MockAMQConnection extends AMQConnection -{ - public MockAMQConnection(String broker, String username, String password, String clientName, String virtualHost) - throws AMQException, URLSyntaxException - { - super(broker, username, password, clientName, virtualHost); - } - - public MockAMQConnection(String host, int port, String username, String password, String clientName, String virtualHost) - throws AMQException, URLSyntaxException - { - super(host, port, username, password, clientName, virtualHost); - } - - public MockAMQConnection(String connection) - throws AMQException, URLSyntaxException - { - super(connection); - } - - @Override - public ProtocolVersion makeBrokerConnection(BrokerDetails brokerDetail) throws IOException - { - setConnected(true); - getProtocolHandler().getStateManager().changeState(AMQState.CONNECTION_OPEN); - return null; - } - - public AMQConnectionDelegate getDelegate() - { - return super.getDelegate(); - } - - @Override - public void performConnectionTask(final Runnable task) - { - task.run(); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelperTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelperTest.java deleted file mode 100644 index f1d7a76c75..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/handler/CloseWhenNoRouteSettingsHelperTest.java +++ /dev/null @@ -1,77 +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.client.handler; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.properties.ConnectionStartProperties; -import org.apache.qpid.test.utils.QpidTestCase; - -public class CloseWhenNoRouteSettingsHelperTest extends QpidTestCase -{ - private static final String FALSE_STR = Boolean.toString(false); - private static final String TRUE_STR = Boolean.toString(true); - - private final CloseWhenNoRouteSettingsHelper _closeWhenNoRouteSettingsHelper = new CloseWhenNoRouteSettingsHelper(); - - public void testCloseWhenNoRouteNegotiation() - { - test("Nothing should be set if option not in URL", - null, - true, - null); - test("Client should disable broker's enabled option", - FALSE_STR, - true, - false); - test("Client should be able to disable broker's enabled option", - TRUE_STR, - false, - true); - test("Client should not enable option if unsupported by broker", - TRUE_STR, - null, - null); - test("Malformed client option should evaluate to false", - "malformed boolean", - true, - false); - } - - private void test(String message, String urlOption, Boolean serverOption, Boolean expectedClientProperty) - { - ConnectionURL url = mock(ConnectionURL.class); - when(url.getOption(ConnectionURL.OPTIONS_CLOSE_WHEN_NO_ROUTE)).thenReturn(urlOption); - - FieldTable serverProperties = new FieldTable(); - if(serverOption != null) - { - serverProperties.setBoolean(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE, serverOption); - } - - FieldTable clientProperties = new FieldTable(); - - _closeWhenNoRouteSettingsHelper.setClientProperties(clientProperties, url, serverProperties); - - assertEquals(message, expectedClientProperty, clientProperties.getBoolean(ConnectionStartProperties.QPID_CLOSE_WHEN_NO_ROUTE)); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10Test.java b/qpid/java/client/src/test/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10Test.java deleted file mode 100644 index 2edd38ea55..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10Test.java +++ /dev/null @@ -1,140 +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.client.message; - -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; - -import javax.jms.Destination; - -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.DeliveryProperties; -import org.apache.qpid.transport.MessageProperties; -import org.apache.qpid.transport.ReplyTo; - -public class AMQMessageDelegate_0_10Test extends QpidTestCase -{ - - private static final String MAX_SHORT = "maxShort"; - private static final String MIN_SHORT = "minShort"; - private static final String MAX_INT = "maxInt"; - private static final String MIN_INT = "minInt"; - private static final String MAX_LONG = "maxLong"; - private static final String MIN_LONG = "minLong"; - - /** - * Tests that when two messages arrive with the same ReplyTo exchange and routingKey values, - * the cache returns the same Destination object from getJMSReplyTo instead of a new one. - */ - public void testDestinationCache() throws Exception - { - //create a message delegate and retrieve the replyTo Destination - AMQMessageDelegate_0_10 delegate1 = generateMessageDelegateWithReplyTo(); - Destination dest1 = delegate1.getJMSReplyTo(); - - //create a new message delegate with the same details, and retrieve the replyTo Destination - AMQMessageDelegate_0_10 delegate2 = generateMessageDelegateWithReplyTo(); - Destination dest2 = delegate2.getJMSReplyTo(); - - //verify that the destination cache means these are the same Destination object - assertSame("Should have received the same Destination objects", dest1, dest2); - } - - - private AMQMessageDelegate_0_10 generateMessageDelegateWithReplyTo() - { - MessageProperties mesProps = new MessageProperties(); - ReplyTo reply = new ReplyTo("amq.direct", "myReplyQueue"); - mesProps.setReplyTo(reply); - - DeliveryProperties delProps = new DeliveryProperties(); - delProps.setExchange("amq.direct"); - delProps.setRoutingKey("myRequestQueue"); - - AMQMessageDelegate_0_10 delegate = new AMQMessageDelegate_0_10(mesProps,delProps,1L); - return delegate; - } - - public void testMessageProperties() throws Exception - { - MessageProperties msgProps = new MessageProperties(); - - Map<String, Object> appHeaders = new HashMap<String, Object>(); - appHeaders.put(MAX_SHORT, String.valueOf(Short.MAX_VALUE)); - appHeaders.put(MIN_SHORT, String.valueOf(Short.MIN_VALUE)); - appHeaders.put(MAX_INT, String.valueOf(Integer.MAX_VALUE)); - appHeaders.put(MIN_INT, String.valueOf(Integer.MIN_VALUE)); - appHeaders.put(MAX_LONG, String.valueOf(Long.MAX_VALUE)); - appHeaders.put(MIN_LONG, String.valueOf(Long.MIN_VALUE)); - - msgProps.setApplicationHeaders(appHeaders); - - AMQMessageDelegate_0_10 delegate = new AMQMessageDelegate_0_10(msgProps,new DeliveryProperties(),1L); - - assertEquals("Max long value not retrieved successfully", Long.MAX_VALUE, delegate.getLongProperty(MAX_LONG)); - assertEquals("Min long value not retrieved successfully", Long.MIN_VALUE, delegate.getLongProperty(MIN_LONG)); - assertEquals("Max int value not retrieved successfully as long", (long) Integer.MAX_VALUE, delegate.getLongProperty(MAX_INT)); - assertEquals("Min int value not retrieved successfully as long", (long) Integer.MIN_VALUE, delegate.getLongProperty(MIN_INT)); - assertEquals("Max short value not retrieved successfully as long", (long) Short.MAX_VALUE, delegate.getLongProperty(MAX_SHORT)); - assertEquals("Min short value not retrieved successfully as long", (long) Short.MIN_VALUE, delegate.getLongProperty(MIN_SHORT)); - - assertEquals("Max int value not retrieved successfully", Integer.MAX_VALUE, delegate.getIntProperty(MAX_INT)); - assertEquals("Min int value not retrieved successfully", Integer.MIN_VALUE, delegate.getIntProperty(MIN_INT)); - assertEquals("Max short value not retrieved successfully as int", (int) Short.MAX_VALUE, delegate.getIntProperty(MAX_SHORT)); - assertEquals("Min short value not retrieved successfully as int", (int) Short.MIN_VALUE, delegate.getIntProperty(MIN_SHORT)); - - assertEquals("Max short value not retrieved successfully", Short.MAX_VALUE, delegate.getShortProperty(MAX_SHORT)); - assertEquals("Min short value not retrieved successfully", Short.MIN_VALUE, delegate.getShortProperty(MIN_SHORT)); - } - - // See QPID_3838 - public void testJMSComplainceForQpidProviderProperties() throws Exception - { - MessageProperties msgProps = new MessageProperties(); - Map<String, Object> appHeaders = new HashMap<String, Object>(); - appHeaders.put(QpidMessageProperties.QPID_SUBJECT, "Hello"); - msgProps.setApplicationHeaders(appHeaders); - - System.setProperty("strict-jms", "true"); - try - { - AMQMessageDelegate_0_10 delegate = new AMQMessageDelegate_0_10(AMQDestination.DestSyntax.ADDR,msgProps,new DeliveryProperties(),1L); - - boolean propFound = false; - for (Enumeration props = delegate.getPropertyNames(); props.hasMoreElements();) - { - String key = (String)props.nextElement(); - if (key.equals(QpidMessageProperties.QPID_SUBJECT_JMS_PROPERTY)) - { - propFound = true; - } - } - assertTrue("qpid.subject was not prefixed with 'JMS_' as expected",propFound); - assertEquals("qpid.subject should still return the correct value","Hello",delegate.getStringProperty(QpidMessageProperties.QPID_SUBJECT)); - } - finally - { - System.setProperty("strict-jms", "false"); - } - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java deleted file mode 100644 index e131ab3dd2..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/message/AMQPEncodedListMessageUnitTest.java +++ /dev/null @@ -1,153 +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.client.message; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import javax.jms.MessageFormatException; - -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.codec.BBEncoder; - -public class AMQPEncodedListMessageUnitTest extends QpidTestCase -{ - - Map<String,String> _map = new HashMap<String,String>(); - List<Object> _list = new ArrayList<Object>(); - UUID _uuid = UUID.randomUUID(); - - @Override - public void setUp() throws Exception - { - super.setUp(); - _map.put("Key1","String1"); - _map.put("Key2","String2"); - _map.put("Key3","String3"); - - _list.add(1); - _list.add(2); - _list.add(3); - } - - /** - * Test whether we accept the correct types while rejecting invalid types. - */ - public void testAddObject() throws Exception - { - AMQPEncodedListMessage m = new AMQPEncodedListMessage(AMQMessageDelegateFactory.FACTORY_0_10); - m.add(true); - m.add((byte)256); - m.add(Short.MAX_VALUE); - m.add(Integer.MAX_VALUE); - m.add(Long.MAX_VALUE); - m.add(10.22); - m.add("Msg"); - m.add("Msg".getBytes()); - m.add(_list); - m.add(_map); - m.add(_uuid); - - try - { - m.add(new Object()); - fail("Validation for element type failed"); - } - catch (MessageFormatException e) - { - } - } - - public void testListBehaviorForIncommingMsg() throws Exception - { - BBEncoder encoder = new BBEncoder(1024); - encoder.writeList(_list); - AMQPEncodedListMessage m = new AMQPEncodedListMessage(new AMQMessageDelegate_0_10(),encoder.segment()); - - assertTrue("contains(Object) method did not return true as expected",m.contains(1)); - assertFalse("contains(Object) method did not return false as expected",m.contains(5)); - assertEquals("get(index) method returned incorrect value",((Integer)m.get(1)).intValue(),2); - assertEquals("indexOf(Object) method returned incorrect index",m.indexOf(2),1); - try - { - m.get(10); - } - catch (MessageFormatException e) - { - assertTrue("Incorrect exception type. Expected IndexOutOfBoundsException", e.getCause() instanceof IndexOutOfBoundsException); - } - } - - public void testStreamMessageInterfaceForIncommingMsg() throws Exception - { - BBEncoder encoder = new BBEncoder(1024); - encoder.writeList(getList()); - AMQPEncodedListMessage m = new AMQPEncodedListMessage(new AMQMessageDelegate_0_10(),encoder.segment()); - - assertEquals(true,m.readBoolean()); - assertEquals((byte)256,m.readByte()); - assertEquals(Short.MAX_VALUE,m.readShort()); - assertEquals(Integer.MAX_VALUE,m.readInt()); - assertEquals(Long.MAX_VALUE,m.readLong()); - assertEquals(10.22,m.readDouble()); - assertEquals("Msg",m.readString()); - assertEquals(_list,(List)m.readObject()); - assertEquals(_map,(Map)m.readObject()); - assertEquals(_uuid,(UUID)m.readObject()); - } - - public void testMapMessageInterfaceForIncommingMsg() throws Exception - { - BBEncoder encoder = new BBEncoder(1024); - encoder.writeList(getList()); - AMQPEncodedListMessage m = new AMQPEncodedListMessage(new AMQMessageDelegate_0_10(),encoder.segment()); - - assertEquals(true,m.getBoolean("0")); - assertEquals((byte)256,m.getByte("1")); - assertEquals(Short.MAX_VALUE,m.getShort("2")); - assertEquals(Integer.MAX_VALUE,m.getInt("3")); - assertEquals(Long.MAX_VALUE,m.getLong("4")); - assertEquals(10.22,m.getDouble("5")); - assertEquals("Msg",m.getString("6")); - assertEquals(_list,(List)m.getObject("7")); - assertEquals(_map,(Map)m.getObject("8")); - assertEquals(_uuid,(UUID)m.getObject("9")); - } - - public List<Object> getList() - { - List<Object> myList = new ArrayList<Object>(); - myList.add(true); - myList.add((byte)256); - myList.add(Short.MAX_VALUE); - myList.add(Integer.MAX_VALUE); - myList.add(Long.MAX_VALUE); - myList.add(10.22); - myList.add("Msg"); - myList.add(_list); - myList.add(_map); - myList.add(_uuid); - return myList; - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java deleted file mode 100644 index c535fdd705..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java +++ /dev/null @@ -1,57 +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.client.message; - - -import junit.framework.TestCase; - -import javax.jms.JMSException; - -public class AbstractJMSMessageTest extends TestCase -{ - - public void testSetNullJMSReplyTo08() throws JMSException - { - JMSTextMessage message = new JMSTextMessage(AMQMessageDelegateFactory.FACTORY_0_8); - try - { - message.setJMSReplyTo(null); - } - catch (IllegalArgumentException e) - { - fail("Null destination should be allowed"); - } - } - - public void testSetNullJMSReplyTo10() throws JMSException - { - JMSTextMessage message = new JMSTextMessage(AMQMessageDelegateFactory.FACTORY_0_10); - try - { - message.setJMSReplyTo(null); - } - catch (IllegalArgumentException e) - { - fail("Null destination should be allowed"); - } - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java b/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java deleted file mode 100644 index b5c31e7c5e..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java +++ /dev/null @@ -1,51 +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.client.message; - -import javax.jms.JMSException; - -public class TestMessageHelper -{ - public static JMSTextMessage newJMSTextMessage() throws JMSException - { - return new JMSTextMessage(AMQMessageDelegateFactory.FACTORY_0_8); - } - - public static JMSBytesMessage newJMSBytesMessage() throws JMSException - { - return new JMSBytesMessage(AMQMessageDelegateFactory.FACTORY_0_8); - } - - public static JMSMapMessage newJMSMapMessage() throws JMSException - { - return new JMSMapMessage(AMQMessageDelegateFactory.FACTORY_0_8); - } - - public static JMSStreamMessage newJMSStreamMessage() - { - return new JMSStreamMessage(AMQMessageDelegateFactory.FACTORY_0_8); - } - - public static JMSObjectMessage newJMSObjectMessage() - { - return new JMSObjectMessage(AMQMessageDelegateFactory.FACTORY_0_8); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java deleted file mode 100644 index 7401168978..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/messaging/address/AddressHelperTest.java +++ /dev/null @@ -1,146 +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.client.messaging.address; - -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.client.AMQDestination.AddressOption; -import org.apache.qpid.client.AMQDestination.Binding; -import org.apache.qpid.client.messaging.address.Link.Reliability; -import org.apache.qpid.messaging.Address; -import org.apache.qpid.test.utils.QpidTestCase; - -public class AddressHelperTest extends QpidTestCase -{ - public void testAddressOptions() throws Exception - { - Address addr = Address.parse("queue/test;{create:sender, assert:always, delete:receiver, mode:browse}"); - AddressHelper helper = new AddressHelper(addr); - assertEquals(AddressOption.SENDER,AddressOption.getOption(helper.getCreate())); - assertEquals(AddressOption.ALWAYS,AddressOption.getOption(helper.getAssert())); - assertEquals(AddressOption.RECEIVER,AddressOption.getOption(helper.getDelete())); - assertTrue("'mode' option wasn't read properly",helper.isBrowseOnly()); - } - - public void testNodeProperties() throws Exception - { - Address addr = Address.parse("my-queue;{" + - "node: " + - "{" + - "type: queue ," + - "durable: true ," + - "x-declare: " + - "{" + - "exclusive: true," + - "auto-delete: true," + - "alternate-exchange: 'amq.fanout'," + - "arguments: {" + - "'qpid.max_size': 1000," + - "'qpid.max_count': 100" + - "}" + - "}, " + - "x-bindings: [{exchange : 'amq.direct', queue:my-queue, key : test}, " + - "{exchange : 'amq.fanout', queue:my-queue}," + - "{exchange: 'amq.match', queue:my-queue, arguments: {x-match: any, dep: sales, loc: CA}}," + - "{exchange : 'amq.topic',queue:my-queue, key : 'a.#'}" + - "]" + - - "}" + - "}"); - AddressHelper helper = new AddressHelper(addr); - Node node = helper.getNode(); - assertEquals("'type' property wasn't read properly",AMQDestination.QUEUE_TYPE,helper.getNodeType()); - assertTrue("'durable' property wasn't read properly",node.isDurable()); - assertTrue("'auto-delete' property wasn't read properly",node.isAutoDelete()); - assertTrue("'exclusive' property wasn't read properly",node.isExclusive()); - assertEquals("'alternate-exchange' property wasn't read properly","amq.fanout",node.getAlternateExchange()); - assertEquals("'arguments' in 'x-declare' property wasn't read properly",2,node.getDeclareArgs().size()); - assertEquals("'bindings' property wasn't read properly",4,node.getBindings().size()); - for (Binding binding: node.getBindings()) - { - assertTrue("property 'exchange' in bindings wasn't read properly",binding.getExchange().startsWith("amq.")); - assertEquals("property 'queue' in bindings wasn't read properly","my-queue",binding.getQueue()); - if (binding.getExchange().equals("amq.direct")) - { - assertEquals("'key' property in bindings wasn't read properly","test",binding.getBindingKey()); - } - if (binding.getExchange().equals("amq.match")) - { - assertEquals("'arguments' property in bindings wasn't read properly",3,binding.getArgs().size()); - } - } - } - - public void testLinkProperties() throws Exception - { - Address addr = Address.parse("my-queue;{" + - "link: " + - "{" + - "name: my-queue ," + - "durable: true ," + - "reliability: at-least-once," + - "capacity: {source:10, target:15}," + - "x-declare: " + - "{" + - "exclusive: true," + - "auto-delete: true," + - "alternate-exchange: 'amq.fanout'," + - "arguments: {" + - "'qpid.max_size': 1000," + - "'qpid.max_count': 100" + - "}" + - "}, " + - "x-bindings: [{exchange : 'amq.direct', queue:my-queue, key : test}, " + - "{exchange : 'amq.fanout', queue:my-queue}," + - "{exchange: 'amq.match', queue:my-queue, arguments: {x-match: any, dep: sales, loc: CA}}," + - "{exchange : 'amq.topic',queue:my-queue, key : 'a.#'}" + - "]," + - "x-subscribes:{exclusive: true, arguments: {a:b,x:y}}" + - "}" + - "}"); - - AddressHelper helper = new AddressHelper(addr); - Link link = helper.getLink(); - assertEquals("'name' property wasn't read properly","my-queue",link.getName()); - assertTrue("'durable' property wasn't read properly",link.isDurable()); - assertEquals("'reliability' property wasn't read properly",Reliability.AT_LEAST_ONCE,link.getReliability()); - assertTrue("'auto-delete' property in 'x-declare' wasn't read properly",link.getSubscriptionQueue().isAutoDelete()); - assertTrue("'exclusive' property in 'x-declare' wasn't read properly",link.getSubscriptionQueue().isExclusive()); - assertEquals("'alternate-exchange' property in 'x-declare' wasn't read properly","amq.fanout",link.getSubscriptionQueue().getAlternateExchange()); - assertEquals("'arguments' in 'x-declare' property wasn't read properly",2,link.getSubscriptionQueue().getDeclareArgs().size()); - assertEquals("'bindings' property wasn't read properly",4,link.getBindings().size()); - for (Binding binding: link.getBindings()) - { - assertTrue("property 'exchange' in bindings wasn't read properly",binding.getExchange().startsWith("amq.")); - assertEquals("property 'queue' in bindings wasn't read properly","my-queue",binding.getQueue()); - if (binding.getExchange().equals("amq.direct")) - { - assertEquals("'key' property in bindings wasn't read properly","test",binding.getBindingKey()); - } - if (binding.getExchange().equals("amq.match")) - { - assertEquals("'arguments' property in bindings wasn't read properly",3,binding.getArgs().size()); - } - } - assertTrue("'exclusive' property in 'x-subscribe' wasn't read properly",link.getSubscription().isExclusive()); - assertEquals("'arguments' in 'x-subscribe' property wasn't read properly",2,link.getSubscription().getArgs().size()); - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java deleted file mode 100644 index 61e5247ead..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java +++ /dev/null @@ -1,291 +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.client.protocol; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import junit.framework.TestCase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.AMQException; -import org.apache.qpid.client.AMQAuthenticationException; -import org.apache.qpid.client.MockAMQConnection; -import org.apache.qpid.client.state.AMQState; -import org.apache.qpid.client.transport.TestNetworkConnection; -import org.apache.qpid.framing.AMQBody; -import org.apache.qpid.framing.AMQFrame; -import org.apache.qpid.framing.AMQMethodBody; -import org.apache.qpid.framing.BasicRecoverSyncOkBody; -import org.apache.qpid.framing.ProtocolVersion; -import org.apache.qpid.protocol.AMQConstant; - -/** - * This is a test address QPID-1431 where frame listeners would fail to be notified of an incomming exception. - * - * Currently we do checks at the Session level to ensure that the connection/session are open. However, it is possible - * for the connection to close AFTER this check has been performed. - * - * Performing a similar check at the frameListener level in AMQProtocolHandler makes most sence as this will prevent - * listening when there can be no returning frames. - * - * With the correction in place it also means that the new listener will either make it on to the list for notification - * or it will be notified of any existing exception due to the connection being closed. - * - * There may still be an issue in this space if the client utilises a second thread to close the session as there will - * be no exception set to throw and so the wait will occur. That said when the session is closed the framelisteners - * should be notified. Not sure this is tested. - */ -public class AMQProtocolHandlerTest extends TestCase -{ - private static final Logger _logger = LoggerFactory.getLogger(AMQProtocolHandlerTest.class); - - // The handler to test - private AMQProtocolHandler _handler; - - // A frame to block upon whilst waiting the exception - private AMQFrame _blockFrame; - - // Latch to know when the listener receives an exception - private CountDownLatch _handleCountDown; - // The listener that will receive an exception - private BlockToAccessFrameListener _listener; - - @Override - public void setUp() throws Exception - { - //Create a new ProtocolHandler with a fake connection. - _handler = new AMQProtocolHandler(new MockAMQConnection("amqp://guest:guest@client/test?brokerlist='tcp://localhost:1'")); - _handler.setNetworkConnection(new TestNetworkConnection()); - AMQBody body = new BasicRecoverSyncOkBody(ProtocolVersion.v8_0); - _blockFrame = new AMQFrame(0, body); - - _handleCountDown = new CountDownLatch(1); - - _logger.info("Creating _Listener that should also receive the thrown exception."); - _listener = new BlockToAccessFrameListener(1); - } - - /** - * There are two paths based on the type of exception thrown. - * - * This tests that when an AMQException is thrown we get the same type of AMQException back with the real exception - * wrapped as the cause. - * - * @throws InterruptedException - if we are unable to wait for the test signals - */ - public void testFrameListenerUpdateWithAMQException() throws InterruptedException - { - AMQException trigger = new AMQAuthenticationException(AMQConstant.ACCESS_REFUSED, - "AMQPHTest", new RuntimeException()); - - performWithException(trigger); - - - AMQException receivedException = (AMQException) _listener.getReceivedException(); - - assertEquals("Return exception was not the expected type", - AMQAuthenticationException.class, receivedException.getClass()); - - assertEquals("The _Listener did not receive the correct error code", - trigger.getErrorCode(), receivedException.getErrorCode()); - } - - /** - * There are two paths based on the type of exception thrown. - * - * This tests that when a generic Exception is thrown we get the exception back wrapped in a AMQException - * as the cause. - * @throws InterruptedException - if we are unable to wait for the test signals - */ - public void testFrameListenerUpdateWithException() throws InterruptedException - { - - Exception trigger = new Exception(new RuntimeException()); - - performWithException(trigger); - - assertEquals("The _Listener did not receive the correct error code", - AMQConstant.INTERNAL_ERROR, ((AMQException)_listener.getReceivedException()).getErrorCode()); - } - - /** - * This is the main test method for both test cases. - * - * What occurs is that we create a new thread that will block (<30s[DEFAULT]) for a frame or exception to occur . - * - * We use a CountDownLatch to ensure that the new thread is running before we then yield and sleep to help ensure - * the new thread has entered the synchronized block in the writeCommandFrameAndWaitForReply. - * - * We can then ack like an the incomming exception handler in (ConnectionCloseMethodHandler). - * - * We fire the error to the stateManager, which in this case will recored the error as there are no state listeners. - * - * We then set the connection to be closed, as we would normally close the socket at this point. - * - * Then fire the exception in to any frameListeners. - * - * The blocked listener (created above) when receiving the error simulates the user by creating a new request to - * block for a frame. - * - * This request should fail. Prior to the fix this will fail with a NPE as we are attempting to use a null listener - * in the writeCommand.... call L:268. - * - * This highlights that the listener would be added dispite there being a pending error state that the listener will - * miss as it is not currently part of the _frameListeners set that is being notified by the iterator. - * - * The method waits to ensure that an exception is received before returning. - * - * The calling methods validate that exception that was received based on the one they sent in. - * - * @param trigger The exception to throw through the handler - */ - private void performWithException(Exception trigger) throws InterruptedException - { - - final CountDownLatch callingWriteCommand = new CountDownLatch(1); - - //Set an initial listener that will allow us to create a new blocking method - new Thread(new Runnable() - { - public void run() - { - - try - { - - _logger.info("At initial block, signalling to fire new exception"); - callingWriteCommand.countDown(); - - _handler.writeCommandFrameAndWaitForReply(_blockFrame, _listener); - } - catch (Exception e) - { - _logger.error(e.getMessage(), e); - fail(e.getMessage()); - } - } - }).start(); - - _logger.info("Waiting for 'initial block' to start "); - if (!callingWriteCommand.await(1000, TimeUnit.MILLISECONDS)) - { - fail("Failed to start new thread to block for frame"); - } - - // Do what we can to ensure that this thread does not continue before the above thread has hit the synchronized - // block in the writeCommandFrameAndWaitForReply - Thread.yield(); - Thread.sleep(1000); - - _logger.info("Firing Erorr through state manager. There should be not state waiters here."); - _handler.getStateManager().error(trigger); - - _logger.info("Setting state to be CONNECTION_CLOSED."); - - _handler.getStateManager().changeState(AMQState.CONNECTION_CLOSED); - - _logger.info("Firing exception"); - _handler.propagateExceptionToFrameListeners(trigger); - - _logger.info("Awaiting notifcation from handler that exception arrived."); - - if (!_handleCountDown.await(2000, TimeUnit.MILLISECONDS)) - { - fail("Failed to handle exception and timeout has not occured"); - } - - - assertNotNull("The _Listener did not receive the exception", _listener.getReceivedException()); - - assertTrue("Received exception not an AMQException", - _listener.getReceivedException() instanceof AMQException); - - AMQException receivedException = (AMQException) _listener.getReceivedException(); - - assertTrue("The _Listener did not receive the correct message", - receivedException.getMessage().startsWith(trigger.getMessage())); - - - assertEquals("The _Listener did not receive the correct cause", - trigger, receivedException.getCause()); - - assertEquals("The _Listener did not receive the correct sub cause", - trigger.getCause(), receivedException.getCause().getCause()); - - } - - class BlockToAccessFrameListener extends BlockingMethodFrameListener - { - private Exception _receivedException = null; - - /** - * Creates a new method listener, that filters incoming method to just those that match the specified channel id. - * - * @param channelId The channel id to filter incoming methods with. - */ - public BlockToAccessFrameListener(int channelId) - { - super(channelId); - _logger.info("Creating a listener:" + this); - } - - public boolean processMethod(int channelId, AMQMethodBody frame) - { - return true; - } - - @Override - public void error(Exception e) - { - _logger.info("Exception(" + e + ") Received by:" + this); - // Create a new Thread to start the blocking registration. - new Thread(new Runnable() - { - - public void run() - { - //Set an initial listener that will allow us to create a new blocking method - try - { - _handler.writeCommandFrameAndWaitForReply(_blockFrame, null, 2000L); - _logger.info("listener(" + this + ") Wait completed"); - } - catch (Exception e) - { - _logger.info("listener(" + this + ") threw exception:" + e.getMessage()); - _receivedException = e; - } - - _logger.info("listener(" + this + ") completed"); - _handleCountDown.countDown(); - } - }).start(); - } - - public Exception getReceivedException() - { - return _receivedException; - } - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/security/CallbackHandlerRegistryTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/security/CallbackHandlerRegistryTest.java deleted file mode 100644 index b451ad630f..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/security/CallbackHandlerRegistryTest.java +++ /dev/null @@ -1,184 +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.client.security; - -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.test.utils.QpidTestCase; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.UnsupportedCallbackException; -import java.io.IOException; -import java.util.Properties; - - -/** - * Tests the ability of {@link CallbackHandlerRegistry} to correctly parse - * the properties describing the available callback handlers. Ensures also - * that it is able to select the mechanism and create an implementation - * given a variety of starting conditions. - * - */ -public class CallbackHandlerRegistryTest extends QpidTestCase -{ - private CallbackHandlerRegistry _registry; // Object under test - - public void testCreateHandlerSuccess() - { - final Properties props = new Properties(); - props.put("TESTA.1", TestACallbackHandler.class.getName()); - - _registry = new CallbackHandlerRegistry(props); - assertEquals(1,_registry.getMechanisms().size()); - - final CallbackHandler handler = _registry.createCallbackHandler("TESTA"); - assertTrue(handler instanceof TestACallbackHandler); - } - - public void testCreateHandlerForUnknownMechanismName() - { - final Properties props = new Properties(); - props.put("TEST1.1", TestACallbackHandler.class.getName()); - - _registry = new CallbackHandlerRegistry(props); - - try - { - _registry.createCallbackHandler("NOTFOUND"); - fail("Exception not thrown"); - } - catch (IllegalArgumentException iae) - { - // PASS - } - } - - public void testSelectMechanism() - { - final Properties props = new Properties(); - props.put("TESTA.1", TestACallbackHandler.class.getName()); - props.put("TESTB.2", TestBCallbackHandler.class.getName()); - - _registry = new CallbackHandlerRegistry(props); - assertEquals(2,_registry.getMechanisms().size()); - - final String selectedMechanism = _registry.selectMechanism("TESTA"); - assertEquals("TESTA", selectedMechanism); - } - - public void testSelectReturnsFirstMutallyAvailableMechanism() - { - final Properties props = new Properties(); - props.put("TESTA.1", TestACallbackHandler.class.getName()); - props.put("TESTB.2", TestBCallbackHandler.class.getName()); - - _registry = new CallbackHandlerRegistry(props); - - final String selectedMechanism = _registry.selectMechanism("TESTD TESTB TESTA"); - // TESTA should be returned as it is higher than TESTB in the properties file. - assertEquals("Selected mechanism should respect the ordinal", "TESTA", selectedMechanism); - } - - public void testRestrictedSelectReturnsMechanismFromRestrictedList() - { - final Properties props = new Properties(); - props.put("TESTA.1", TestACallbackHandler.class.getName()); - props.put("TESTB.2", TestBCallbackHandler.class.getName()); - props.put("TESTC.3", TestCCallbackHandler.class.getName()); - - _registry = new CallbackHandlerRegistry(props); - - final String selectedMechanism = _registry.selectMechanism("TESTC TESTB TESTA", "TESTB TESTC"); - // TESTB should be returned as client has restricted the mechanism list to TESTB and TESTC - assertEquals("Selected mechanism should respect the ordinal and be limitted by restricted list","TESTB", selectedMechanism); - } - - public void testOldPropertyFormatRejected() - { - final Properties props = new Properties(); - props.put("CallbackHandler.TESTA", TestACallbackHandler.class.getName()); - - try - { - new CallbackHandlerRegistry(props); - fail("exception not thrown"); - } - catch(IllegalArgumentException iae) - { - // PASS - } - } - - public void testPropertyWithNonnumericalOrdinal() - { - final Properties props = new Properties(); - props.put("TESTA.z", TestACallbackHandler.class.getName()); - try - { - new CallbackHandlerRegistry(props); - fail("exception not thrown"); - } - catch(IllegalArgumentException iae) - { - // PASS - } - } - - public void testUnexpectedCallbackImplementationsIgnored() - { - final Properties props = new Properties(); - props.put("TESTA.1", TestACallbackHandler.class.getName()); - props.put("TESTB.2", "NotFound"); - props.put("TESTC.3", "java.lang.String"); - - _registry = new CallbackHandlerRegistry(props); - - assertEquals(1,_registry.getMechanisms().size()); - } - - static class TestACallbackHandler extends TestCallbackHandler - { - } - - static class TestBCallbackHandler extends TestCallbackHandler - { - } - - static class TestCCallbackHandler extends TestCallbackHandler - { - } - - static abstract class TestCallbackHandler implements AMQCallbackHandler - { - @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException - { - throw new UnsupportedOperationException(); - } - - @Override - public void initialise(ConnectionURL connectionURL) - { - throw new UnsupportedOperationException(); - } - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.java deleted file mode 100644 index 4281984212..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/security/DynamicSaslRegistrarTest.java +++ /dev/null @@ -1,140 +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.client.security; - -import java.io.File; -import java.security.Provider; -import java.security.Security; - -import org.apache.qpid.client.security.DynamicSaslRegistrar.ProviderRegistrationResult; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.test.utils.TestFileUtils; - -public class DynamicSaslRegistrarTest extends QpidTestCase -{ - private Provider _registeredProvider; - - public void setUp() throws Exception - { - super.setUp(); - - //If the client provider is already registered, remove it for the duration of the test - _registeredProvider = DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME); - if (_registeredProvider != null) - { - Security.removeProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME); - } - } - - public void tearDown() throws Exception - { - //Remove any provider left behind by the test. - Security.removeProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME); - try - { - //If the client provider was already registered before the test, restore it. - if (_registeredProvider != null) - { - Security.insertProviderAt(_registeredProvider, 1); - } - } - finally - { - super.tearDown(); - } - } - - public void testRegisterDefaultProvider() - { - assertNull("Provider should not yet be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - ProviderRegistrationResult firstRegistrationResult = DynamicSaslRegistrar.registerSaslProviders(); - assertEquals("Unexpected registration result", ProviderRegistrationResult.SUCCEEDED, firstRegistrationResult); - assertNotNull("Providers should now be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - } - - public void testRegisterDefaultProviderTwice() - { - assertNull("Provider should not yet be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - DynamicSaslRegistrar.registerSaslProviders(); - assertNotNull("Providers should now be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders(); - assertEquals("Unexpected registration result when trying to re-register", ProviderRegistrationResult.EQUAL_ALREADY_REGISTERED, result); - assertNotNull("Providers should still be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - } - - @SuppressWarnings("serial") - public void testRegisterDefaultProviderWhenAnotherIsAlreadyPresentWithDifferentFactories() - { - assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - //Add a test provider with the same name, version, info as the default client provider, but with different factory properties (none). - Provider testProvider = new Provider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME, - JCAProvider.QPID_CLIENT_SASL_PROVIDER_VERSION, - JCAProvider.QPID_CLIENT_SASL_PROVIDER_INFO){}; - Security.addProvider(testProvider); - assertSame("Test provider should be registered", testProvider, DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - //Try to register the default provider now that another with the same name etc (but different factories) - //is already registered, expect it not to be registered as a result. - ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders(); - assertEquals("Unexpected registration result", ProviderRegistrationResult.DIFFERENT_ALREADY_REGISTERED, result); - - //Verify the test provider is still registered - assertSame("Test provider should still be registered", testProvider, DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - } - - public void testRegisterWithNoFactories() - { - File emptyTempFile = TestFileUtils.createTempFile(this); - - assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - //Adjust the location of the properties file to point at an empty file, so no factories are found to register. - setTestSystemProperty("amq.dynamicsaslregistrar.properties", emptyTempFile.getPath()); - - //Try to register the default provider, expect it it not to be registered because there were no factories. - ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders(); - assertEquals("Unexpected registration result", ProviderRegistrationResult.NO_SASL_FACTORIES, result); - - assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - } - - public void testRegisterWithMissingFileGetsDefault() - { - //Create a temp file and then delete it, such that we get a path which doesn't exist - File tempFile = TestFileUtils.createTempFile(this); - assertTrue("Failed to delete file", tempFile.delete()); - - assertNull("Provider should not be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - - //Adjust the location of the properties file to point at non-existent file. - setTestSystemProperty("amq.dynamicsaslregistrar.properties", tempFile.getPath()); - - //Try to register the default provider, expect it to fall back to the default in the jar and succeed. - ProviderRegistrationResult result = DynamicSaslRegistrar.registerSaslProviders(); - assertEquals("Unexpected registration result", ProviderRegistrationResult.SUCCEEDED, result); - - assertNotNull("Provider should be registered", DynamicSaslRegistrar.findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME)); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java deleted file mode 100644 index 290ef7420a..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java +++ /dev/null @@ -1,94 +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.client.security; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQConnectionURL; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import java.security.MessageDigest; -import java.util.Arrays; - -/** - * Unit tests for the UsernameHashPasswordCallbackHandler. This callback handler is - * used by the CRAM-MD5-HASHED SASL mechanism. - * - */ -public class UsernameHashedPasswordCallbackHandlerTest extends TestCase -{ - private AMQCallbackHandler _callbackHandler = new UsernameHashedPasswordCallbackHandler(); // Class under test - private static final String PROMPT_UNUSED = "unused"; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - final String url = "amqp://username:password@client/test?brokerlist='tcp://localhost:1'"; - _callbackHandler.initialise(new AMQConnectionURL(url)); - } - - /** - * Tests that the callback handler can correctly retrieve the username from the connection url. - */ - public void testNameCallback() throws Exception - { - final String expectedName = "username"; - NameCallback nameCallback = new NameCallback(PROMPT_UNUSED); - - assertNull("Unexpected name before test", nameCallback.getName()); - _callbackHandler.handle(new Callback[] {nameCallback}); - assertEquals("Unexpected name", expectedName, nameCallback.getName()); - } - - /** - * Tests that the callback handler can correctly retrieve the password from the connection url - * and calculate a MD5. - */ - public void testDigestedPasswordCallback() throws Exception - { - final char[] expectedPasswordDigested = getHashPassword("password"); - - PasswordCallback passwordCallback = new PasswordCallback(PROMPT_UNUSED, false); - assertNull("Unexpected password before test", passwordCallback.getPassword()); - _callbackHandler.handle(new Callback[] {passwordCallback}); - assertTrue("Unexpected password", Arrays.equals(expectedPasswordDigested, passwordCallback.getPassword())); - } - - private char[] getHashPassword(final String password) throws Exception - { - MessageDigest md5Digester = MessageDigest.getInstance("MD5"); - final byte[] digest = md5Digester.digest(password.getBytes("UTF-8")); - - char[] hash = new char[digest.length]; - - int index = 0; - for (byte b : digest) - { - hash[index++] = (char) b; - } - - return hash; - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java deleted file mode 100644 index 70f279d53c..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java +++ /dev/null @@ -1,74 +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.client.security; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQConnectionURL; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; - -/** - * Unit tests for the UsernamePasswordCallbackHandler. - * - */ -public class UsernamePasswordCallbackHandlerTest extends TestCase -{ - private AMQCallbackHandler _callbackHandler = new UsernamePasswordCallbackHandler(); // Class under test - private static final String PROMPT_UNUSED = "unused"; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - final String url = "amqp://username:password@client/test?brokerlist='tcp://localhost:1'"; - - _callbackHandler.initialise(new AMQConnectionURL(url)); - } - - /** - * Tests that the callback handler can correctly retrieve the username from the connection url. - */ - public void testNameCallback() throws Exception - { - final String expectedName = "username"; - NameCallback nameCallback = new NameCallback(PROMPT_UNUSED); - - assertNull("Unexpected name before test", nameCallback.getName()); - _callbackHandler.handle(new Callback[] {nameCallback}); - assertEquals("Unexpected name", expectedName, nameCallback.getName()); - } - - /** - * Tests that the callback handler can correctly retrieve the password from the connection url. - */ - public void testPasswordCallback() throws Exception - { - final String expectedPassword = "password"; - PasswordCallback passwordCallback = new PasswordCallback(PROMPT_UNUSED, false); - assertNull("Unexpected password before test", passwordCallback.getPassword()); - _callbackHandler.handle(new Callback[] {passwordCallback}); - assertEquals("Unexpected password", expectedPassword, new String(passwordCallback.getPassword())); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java b/qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java deleted file mode 100644 index ee6704bb39..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java +++ /dev/null @@ -1,44 +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.client.transport; - -import java.nio.ByteBuffer; - -import org.apache.qpid.transport.ByteBufferSender; - -public class MockSender implements ByteBufferSender -{ - - public void send(ByteBuffer msg) - { - - } - - public void flush() - { - - } - - public void close() - { - - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java b/qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java deleted file mode 100644 index cdfa83571b..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java +++ /dev/null @@ -1,158 +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.client.transport; - -import java.net.BindException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.security.Principal; - -import org.apache.qpid.protocol.ProtocolEngineFactory; -import org.apache.qpid.ssl.SSLContextFactory; -import org.apache.qpid.transport.ByteBufferSender; -import org.apache.qpid.transport.NetworkTransportConfiguration; -import org.apache.qpid.transport.network.NetworkConnection; - -/** - * Test implementation of IoSession, which is required for some tests. Methods not being used are not implemented, - * so if this class is being used and some methods are to be used, then please update those. - */ -public class TestNetworkConnection implements NetworkConnection -{ - private String _remoteHost = "127.0.0.1"; - private String _localHost = "127.0.0.1"; - private int _port = 1; - private SocketAddress _localAddress = null; - private SocketAddress _remoteAddress = null; - private final MockSender _sender; - - public TestNetworkConnection() - { - _sender = new MockSender(); - } - - - - public void bind(int port, InetAddress[] addresses, ProtocolEngineFactory protocolFactory, - NetworkTransportConfiguration config, SSLContextFactory sslFactory) throws BindException - { - - } - - public SocketAddress getLocalAddress() - { - return (_localAddress != null) ? _localAddress : new InetSocketAddress(_localHost, _port); - } - - public SocketAddress getRemoteAddress() - { - return (_remoteAddress != null) ? _remoteAddress : new InetSocketAddress(_remoteHost, _port); - } - - public void setMaxReadIdle(int idleTime) - { - - } - - @Override - public Principal getPeerPrincipal() - { - return null; - } - - @Override - public int getMaxReadIdle() - { - return 0; - } - - @Override - public int getMaxWriteIdle() - { - return 0; - } - - public void setMaxWriteIdle(int idleTime) - { - - } - - public void close() - { - - } - - public void flush() - { - - } - - public void send(ByteBuffer msg) - { - - } - - public void setIdleTimeout(int i) - { - - } - - public void setPort(int port) - { - _port = port; - } - - public int getPort() - { - return _port; - } - - public void setLocalHost(String host) - { - _localHost = host; - } - - public void setRemoteHost(String host) - { - _remoteHost = host; - } - - public void setLocalAddress(SocketAddress address) - { - _localAddress = address; - } - - public void setRemoteAddress(SocketAddress address) - { - _remoteAddress = address; - } - - public ByteBufferSender getSender() - { - return _sender; - } - - public void start() - { - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java deleted file mode 100644 index 91460ab4e7..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java +++ /dev/null @@ -1,86 +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.client.util; - -import org.apache.qpid.test.utils.QpidTestCase; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.ObjectOutputStream; -import java.util.Arrays; -import java.util.List; - -public class ClassLoadingAwareObjectInputStreamTest extends QpidTestCase -{ - private InputStream _in; - private ClassLoadingAwareObjectInputStream _claOIS; - - protected void setUp() throws Exception - { - //Create a viable input stream for instantiating the CLA OIS - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject("testString"); - out.flush(); - out.close(); - - - _in = new ByteArrayInputStream(baos.toByteArray()); - - _claOIS = new ClassLoadingAwareObjectInputStream(_in); - } - - /** - * Test that the resolveProxyClass method returns a proxy class implementing the desired interface - */ - public void testResolveProxyClass() throws Exception - { - //try to proxy an interface - Class<?> clazz = _claOIS.resolveProxyClass(new String[]{"java.lang.CharSequence"}); - - //verify the proxy supports the expected interface (only) - List<Class<?>> interfaces = Arrays.asList(clazz.getInterfaces()); - assertTrue("Unexpected interfaces supported by proxy", interfaces.contains(CharSequence.class)); - assertEquals("Unexpected interfaces supported by proxy", 1, interfaces.size()); - } - - /** - * Test that the resolveProxyClass method throws a ClassNotFoundException wrapping an - * IllegalArgumentException if it is provided arguments which violate the restrictions allowed - * by Proxy.getProxyClass (as required by the ObjectInputStream.resolveProxyClass javadoc). - */ - public void testResolveProxyClassThrowsCNFEWrappingIAE() throws Exception - { - try - { - //try to proxy a *class* rather than an interface, which is illegal - _claOIS.resolveProxyClass(new String[]{"java.lang.String"}); - fail("should have thrown an exception"); - } - catch(ClassNotFoundException cnfe) - { - //expected, but must verify it is wrapping an IllegalArgumentException - assertTrue(cnfe.getCause() instanceof IllegalArgumentException); - } - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java b/qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java deleted file mode 100644 index 8782b92ee9..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java +++ /dev/null @@ -1,110 +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.filter; - -import junit.framework.TestCase; - -import org.apache.qpid.AMQInternalException; -import org.apache.qpid.client.filter.JMSSelectorFilter; -import org.apache.qpid.client.filter.MessageFilter; -import org.apache.qpid.client.message.JMSTextMessage; -import org.apache.qpid.client.message.TestMessageHelper; - -public class JMSSelectorFilterTest extends TestCase -{ - - public void testEmptySelectorFilter() throws Exception - { - try - { - new JMSSelectorFilter(""); - fail("Should not be able to create a JMSSelectorFilter with an empty selector"); - } - catch (IllegalArgumentException iae) - { - // pass - } - } - - public void testNullSelectorFilter() throws Exception - { - try - { - new JMSSelectorFilter(null); - fail("Should not be able to create a JMSSelectorFilter with a null selector"); - } - catch (IllegalArgumentException iae) - { - // pass - } - } - - public void testInvalidSelectorFilter() throws Exception - { - try - { - new JMSSelectorFilter("$%^"); - fail("Unparsable selector so expected AMQInternalException to be thrown"); - } - catch (AMQInternalException amqie) - { - // pass - } - } - - public void testSimpleSelectorFilter() throws Exception - { - MessageFilter simpleSelectorFilter = new JMSSelectorFilter("select=5"); - - assertNotNull("Filter object is null", simpleSelectorFilter); - assertNotNull("Selector string is null", simpleSelectorFilter.getSelector()); - assertEquals("Unexpected selector", "select=5", simpleSelectorFilter.getSelector()); - assertTrue("Filter object is invalid", simpleSelectorFilter != null); - - final JMSTextMessage message = TestMessageHelper.newJMSTextMessage(); - - message.setIntProperty("select", 4); - assertFalse("Selector did match when not expected", simpleSelectorFilter.matches(message)); - message.setIntProperty("select", 5); - assertTrue("Selector didnt match when expected", simpleSelectorFilter.matches(message)); - message.setIntProperty("select", 6); - assertFalse("Selector did match when not expected", simpleSelectorFilter.matches(message)); - } - - public void testFailedMatchingFilter() throws Exception - { - MessageFilter simpleSelectorFilter = new JMSSelectorFilter("select>4"); - - assertNotNull("Filter object is null", simpleSelectorFilter); - assertNotNull("Selector string is null", simpleSelectorFilter.getSelector()); - assertEquals("Unexpected selector", "select>4", simpleSelectorFilter.getSelector()); - assertTrue("Filter object is invalid", simpleSelectorFilter != null); - - final JMSTextMessage message = TestMessageHelper.newJMSTextMessage(); - - message.setStringProperty("select", "5"); - assertFalse("Selector matched when not expected", simpleSelectorFilter.matches(message)); - message.setStringProperty("select", "elephant"); - assertFalse("Selector matched when not expected", simpleSelectorFilter.matches(message)); - message.setBooleanProperty("select", false); - assertFalse("Selector matched when not expected", simpleSelectorFilter.matches(message)); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/jms/FailoverPolicyTest.java b/qpid/java/client/src/test/java/org/apache/qpid/jms/FailoverPolicyTest.java deleted file mode 100644 index cb9623237c..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/jms/FailoverPolicyTest.java +++ /dev/null @@ -1,338 +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.jms; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.jms.failover.FailoverExchangeMethod; -import org.apache.qpid.jms.failover.FailoverMethod; -import org.apache.qpid.jms.failover.FailoverRoundRobinServers; -import org.apache.qpid.jms.failover.FailoverSingleServer; -import org.apache.qpid.jms.failover.NoFailover; - -import javax.jms.ConnectionConsumer; -import javax.jms.ConnectionMetaData; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.ServerSessionPool; -import javax.jms.Topic; - -/** - * Tests the ability of FailoverPolicy to instantiate the correct FailoverMethod. - * - * This test presently does <i>not</i> test {@link FailoverPolicy#FailoverPolicy(FailoverMethod) or - * {@link FailoverPolicy#addMethod(FailoverMethod)} as it appears that this functionality - * is no longer in use. - * - */ -public class FailoverPolicyTest extends TestCase -{ - private FailoverPolicy _failoverPolicy = null; // class under test - private String _url; - private Connection _connection = null; - private ConnectionURL _connectionUrl = null; - - /** - * Tests single server method is selected for a brokerlist with one broker when - * the failover option is not specified. - */ - public void testBrokerListWithOneBrokerDefaultsToSingleServerPolicy() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverSingleServer); - } - - /** - * Tests round robin method is selected for a brokerlist with two brokers when - * the failover option is not specified. - */ - public void testBrokerListWithTwoBrokersDefaultsToRoundRobinPolicy() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverRoundRobinServers); - } - - /** - * Tests single server method is selected for a brokerlist with one broker when - * the failover option passed as 'singlebroker'. - */ - public void testExplictFailoverOptionSingleBroker() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='singlebroker'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverSingleServer); - } - - /** - * Tests round robin method is selected for a brokerlist with two brokers when - * the failover option passed as 'roundrobin'. - */ - public void testExplictFailoverOptionRoundrobin() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'&failover='roundrobin'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverRoundRobinServers); - } - - /** - * Tests no failover method is selected for a brokerlist with one broker when - * the failover option passed as 'nofailover'. - */ - public void testExplictFailoverOptionNofailover() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='nofailover'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof NoFailover); - } - - /** - * Tests failover exchange method is selected for a brokerlist with one broker when - * the failover option passed as 'failover_exchange'. - */ - public void testExplictFailoverOptionFailoverExchange() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='failover_exchange'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverExchangeMethod); - } - - /** - * Tests that a custom method can be selected for a brokerlist with one brokers when - * the failover option passed as a qualified class-name. - */ - public void testExplictFailoverOptionDynamicallyLoadedFailoverMethod() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='org.apache.qpid.jms.FailoverPolicyTest$MyFailoverMethod'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof MyFailoverMethod); - } - - /** - * Tests that an unknown method caused an exception. - */ - public void testUnknownFailoverMethod() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='unknown'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - try - { - new FailoverPolicy(_connectionUrl, _connection); - fail("Exception not thrown"); - } - catch(IllegalArgumentException iae) - { - // PASS - } - } - - private Connection createStubConnection() - { - return new Connection() - { - - @Override - public Session createSession(boolean transacted, - int acknowledgeMode, int prefetch) throws JMSException - { - return null; - } - - @Override - public Session createSession(boolean transacted, - int acknowledgeMode, int prefetchHigh, int prefetchLow) - throws JMSException - { - return null; - } - - @Override - public ConnectionListener getConnectionListener() - { - return null; - } - - @Override - public long getMaximumChannelCount() throws JMSException - { - return 0; - } - - @Override - public void setConnectionListener(ConnectionListener listener) - { - } - - @Override - public void close() throws JMSException - { - } - - @Override - public ConnectionConsumer createConnectionConsumer( - Destination arg0, String arg1, ServerSessionPool arg2, - int arg3) throws JMSException - { - return null; - } - - @Override - public ConnectionConsumer createDurableConnectionConsumer( - Topic arg0, String arg1, String arg2, - ServerSessionPool arg3, int arg4) throws JMSException - { - return null; - } - - @Override - public javax.jms.Session createSession(boolean arg0, int arg1) - throws JMSException - { - return null; - } - - @Override - public String getClientID() throws JMSException - { - return null; - } - - @Override - public ExceptionListener getExceptionListener() throws JMSException - { - return null; - } - - @Override - public ConnectionMetaData getMetaData() throws JMSException - { - return null; - } - - @Override - public void setClientID(String arg0) throws JMSException - { - } - - @Override - public void setExceptionListener(ExceptionListener arg0) - throws JMSException - { - } - - @Override - public void start() throws JMSException - { - } - - @Override - public void stop() throws JMSException - { - } - }; - } - - // Class used to test the ability of FailoverPolicy to load an implementation. - static class MyFailoverMethod implements FailoverMethod - { - public MyFailoverMethod(ConnectionURL connectionDetails) - { - } - - @Override - public void attainedConnection() - { - } - - @Override - public boolean failoverAllowed() - { - return false; - } - - @Override - public BrokerDetails getCurrentBrokerDetails() - { - return null; - } - - @Override - public BrokerDetails getNextBrokerDetails() - { - return null; - } - - @Override - public String methodName() - { - return null; - } - - @Override - public void reset() - { - } - - @Override - public void setBroker(BrokerDetails broker) - { - } - - @Override - public void setRetries(int maxRetries) - { - } - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/jndi/JNDITest.properties b/qpid/java/client/src/test/java/org/apache/qpid/jndi/JNDITest.properties deleted file mode 100644 index 07017a05a6..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/jndi/JNDITest.properties +++ /dev/null @@ -1,28 +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. -# -java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory - -# Queue name with spaces -queue.QueueNameWithSpace = QueueNameWithSpace - -# Topic name with spaces -topic.TopicNameWithSpace = TopicNameWithSpace - -# Multiple topic names with spaces -topic.MultipleTopicNamesWithSpace = Topic1WithSpace , Topic2WithSpace , Topic3WithSpace diff --git a/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java b/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java deleted file mode 100644 index 2914244103..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java +++ /dev/null @@ -1,137 +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.jndi; - - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.Topic; -import javax.naming.ConfigurationException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.configuration.ClientProperties; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.test.utils.QpidTestCase; - -public class PropertiesFileInitialContextFactoryTest extends QpidTestCase -{ - private static final String CONNECTION_URL = "amqp://username:password@clientid/test?brokerlist='tcp://testContextFromProviderURL:5672'"; - - public void testQueueNamesWithTrailingSpaces() throws Exception - { - Context ctx = prepareContext(); - Queue queue = (Queue)ctx.lookup("QueueNameWithSpace"); - assertEquals("QueueNameWithSpace",queue.getQueueName()); - } - - public void testTopicNamesWithTrailingSpaces() throws Exception - { - Context ctx = prepareContext(); - Topic topic = (Topic)ctx.lookup("TopicNameWithSpace"); - assertEquals("TopicNameWithSpace",topic.getTopicName()); - } - - public void testMultipleTopicNamesWithTrailingSpaces() throws Exception - { - Context ctx = prepareContext(); - Topic topic = (Topic)ctx.lookup("MultipleTopicNamesWithSpace"); - int i = 0; - for (AMQShortString bindingKey: ((AMQDestination)topic).getBindingKeys()) - { - i++; - assertEquals("Topic" + i + "WithSpace",bindingKey.asString()); - } - } - - public void testConfigurationErrors() throws Exception - { - Properties properties = new Properties(); - properties.put("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"); - properties.put("destination.my-queue","amq.topic/test;create:always}"); - - try - { - new InitialContext(properties); - fail("A configuration exception should be thrown with details about the address syntax error"); - } - catch(ConfigurationException e) - { - assertTrue("Incorrect exception", e.getMessage().contains("Failed to parse entry: amq.topic/test;create:always}")); - } - } - - private InitialContext prepareContext() throws IOException, NamingException - { - Properties properties = new Properties(); - properties.load(this.getClass().getResourceAsStream("JNDITest.properties")); - - return new InitialContext(properties); - } - - /** - * Test loading of a JNDI properties file through use of a file:// URL - * supplied via the InitialContext.PROVIDER_URL system property. - */ - public void testContextFromProviderURL() throws Exception - { - Properties properties = new Properties(); - properties.put("connectionfactory.qpidConnectionfactory", CONNECTION_URL); - properties.put("destination.topicExchange", "destName"); - - File f = File.createTempFile(getTestName(), ".properties"); - try - { - FileOutputStream fos = new FileOutputStream(f); - properties.store(fos, null); - fos.close(); - - setTestSystemProperty(ClientProperties.DEST_SYNTAX, "ADDR"); - setTestSystemProperty(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"); - setTestSystemProperty(InitialContext.PROVIDER_URL, f.toURI().toURL().toString()); - - InitialContext context = new InitialContext(); - Destination dest = (Destination) context.lookup("topicExchange"); - assertNotNull("Lookup from URI based context should not be null", dest); - assertTrue("Unexpected value from lookup", dest.toString().contains("destName")); - - ConnectionFactory factory = (ConnectionFactory) context.lookup("qpidConnectionfactory"); - assertTrue("ConnectionFactory was not an instance of AMQConnectionFactory", factory instanceof AMQConnectionFactory); - assertEquals("Unexpected ConnectionURL value", CONNECTION_URL.replaceAll("password", "********"), - ((AMQConnectionFactory)factory).getConnectionURLString()); - - context.close(); - } - finally - { - f.delete(); - } - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java deleted file mode 100644 index b5a4166b55..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java +++ /dev/null @@ -1,95 +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.test.unit.basic; - -import junit.framework.TestCase; - -import org.apache.qpid.client.message.JMSTextMessage; -import org.apache.qpid.client.message.TestMessageHelper; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.framing.FieldTableFactory; - -import javax.jms.JMSException; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.NoSuchElementException; - -public class FieldTableKeyEnumeratorTest extends TestCase -{ - public void testTrue() - { - - } - public void testKeyEnumeration() - { - FieldTable result = FieldTableFactory.newFieldTable(); - result.setObject("one", 1L); - result.setObject("two", 2L); - result.setObject("three", 3L); - result.setObject("four", 4L); - result.setObject("five", 5L); - - Iterator iterator = result.keys().iterator(); - - try - { - assertTrue("one".equals(iterator.next())); - assertTrue("two".equals(iterator.next())); - assertTrue("three".equals(iterator.next())); - assertTrue("four".equals(iterator.next())); - assertTrue("five".equals(iterator.next())); - } - catch (NoSuchElementException e) - { - fail("All elements should be found."); - } - - } - - public void testPropertyEnum() - { - try - { - JMSTextMessage text = TestMessageHelper.newJMSTextMessage(); - - text.setBooleanProperty("Boolean1", true); - text.setBooleanProperty("Boolean2", true); - text.setIntProperty("Int", 2); - text.setLongProperty("Long", 2); - - Enumeration e = text.getPropertyNames(); - - assertTrue("Boolean1".equals(e.nextElement())); - assertTrue("Boolean2".equals(e.nextElement())); - assertTrue("Int".equals(e.nextElement())); - assertTrue("Long".equals(e.nextElement())); - } - catch (JMSException e) - { - - } - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(FieldTableKeyEnumeratorTest.class); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTablePropertyTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTablePropertyTest.java deleted file mode 100644 index e27c684adc..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/FieldTablePropertyTest.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.test.unit.basic; - -import junit.framework.TestCase; - -import org.apache.qpid.client.message.JMSTextMessage; -import org.apache.qpid.client.message.TestMessageHelper; - -import javax.jms.JMSException; -import java.util.Enumeration; - -public class FieldTablePropertyTest extends TestCase -{ - public void testPropertyNames() - { - try - { - JMSTextMessage text = TestMessageHelper.newJMSTextMessage(); - - text.setBooleanProperty("Boolean1", true); - text.setBooleanProperty("Boolean2", true); - text.setIntProperty("Int", 2); - text.setLongProperty("Long", 2); - - Enumeration e = text.getPropertyNames(); - - assertEquals("Boolean1", e.nextElement()); - assertTrue("Boolean2".equals(e.nextElement())); - assertTrue("Int".equals(e.nextElement())); - assertTrue("Long".equals(e.nextElement())); - } - catch (JMSException e) - { - - } - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(FieldTablePropertyTest.class); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java deleted file mode 100644 index 2733d7bf6d..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java +++ /dev/null @@ -1,227 +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.test.unit.client.BrokerDetails; - -import org.apache.qpid.client.AMQBrokerDetails; -import org.apache.qpid.configuration.ClientProperties; -import org.apache.qpid.jms.BrokerDetails; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.ConnectionSettings; -import org.apache.qpid.url.URLSyntaxException; - -public class BrokerDetailsTest extends QpidTestCase -{ - public void testDefaultTCP_NODELAY() throws URLSyntaxException - { - String brokerURL = "tcp://localhost:5672"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - - assertNull("default value should be null", broker.getProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY)); - } - - public void testOverridingTCP_NODELAY() throws URLSyntaxException - { - String brokerURL = "tcp://localhost:5672?tcp_nodelay='true'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - - assertTrue("value should be true", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY))); - - brokerURL = "tcp://localhost:5672?tcp_nodelay='false''&maxprefetch='1'"; - broker = new AMQBrokerDetails(brokerURL); - - assertFalse("value should be false", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY))); - } - - public void testDefaultConnectTimeout() throws URLSyntaxException - { - String brokerURL = "tcp://localhost:5672"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - - ConnectionSettings settings = broker.buildConnectionSettings(); - - assertEquals("unexpected default connect timeout value", BrokerDetails.DEFAULT_CONNECT_TIMEOUT, settings.getConnectTimeout()); - } - - public void testOverridingConnectTimeout() throws URLSyntaxException - { - int timeout = 2 * BrokerDetails.DEFAULT_CONNECT_TIMEOUT; - assertTrue(timeout != BrokerDetails.DEFAULT_CONNECT_TIMEOUT); - - String brokerURL = "tcp://localhost:5672?" + BrokerDetails.OPTIONS_CONNECT_TIMEOUT + "='" + timeout + "'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - - ConnectionSettings settings = broker.buildConnectionSettings(); - - assertEquals("unexpected connect timeout value", timeout, settings.getConnectTimeout()); - } - - public void testMultiParameters() throws URLSyntaxException - { - String url = "tcp://localhost:5672?timeout='200',immediatedelivery='true'"; - - AMQBrokerDetails broker = new AMQBrokerDetails(url); - - assertTrue(broker.getProperty("timeout").equals("200")); - assertTrue(broker.getProperty("immediatedelivery").equals("true")); - } - - public void testTransportsDefaultToTCP() throws URLSyntaxException - { - String url = "localhost:5672"; - - AMQBrokerDetails broker = new AMQBrokerDetails(url); - assertTrue(broker.getTransport().equals("tcp")); - } - - public void testCheckDefaultPort() throws URLSyntaxException - { - String url = "tcp://localhost"; - - AMQBrokerDetails broker = new AMQBrokerDetails(url); - assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); - } - - public void testBothDefaults() throws URLSyntaxException - { - String url = "localhost"; - - AMQBrokerDetails broker = new AMQBrokerDetails(url); - - assertTrue(broker.getTransport().equals("tcp")); - assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); - } - - public void testWrongOptionSeparatorInBroker() - { - String url = "tcp://localhost:5672+option='value'"; - try - { - new AMQBrokerDetails(url); - } - catch (URLSyntaxException urise) - { - assertTrue(urise.getReason().equals("Illegal character in port number")); - } - } - - public void testToStringMasksKeyStorePassword() throws Exception - { - String url = "tcp://localhost:5672?key_store_password='password'"; - BrokerDetails details = new AMQBrokerDetails(url); - - String expectedToString = "tcp://localhost:5672?key_store_password='********'"; - String actualToString = details.toString(); - - assertEquals("Unexpected toString", expectedToString, actualToString); - } - - public void testToStringMasksTrustStorePassword() throws Exception - { - String url = "tcp://localhost:5672?trust_store_password='password'"; - BrokerDetails details = new AMQBrokerDetails(url); - - String expectedToString = "tcp://localhost:5672?trust_store_password='********'"; - String actualToString = details.toString(); - - assertEquals("Unexpected toString", expectedToString, actualToString); - } - - public void testDefaultSsl() throws URLSyntaxException - { - String brokerURL = "tcp://localhost:5672"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - - assertNull("default value should be null", broker.getProperty(BrokerDetails.OPTIONS_SSL)); - } - - public void testOverridingSsl() throws URLSyntaxException - { - String brokerURL = "tcp://localhost:5672?ssl='true'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - - assertTrue("value should be true", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_SSL))); - - brokerURL = "tcp://localhost:5672?ssl='false''&maxprefetch='1'"; - broker = new AMQBrokerDetails(brokerURL); - - assertFalse("value should be false", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_SSL))); - } - - public void testHeartbeatDefaultsToNull() throws Exception - { - String brokerURL = "tcp://localhost:5672"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - assertNull("unexpected default value for " + BrokerDetails.OPTIONS_HEARTBEAT, broker.getProperty(BrokerDetails.OPTIONS_HEARTBEAT)); - } - - public void testOverriddingHeartbeat() throws Exception - { - String brokerURL = "tcp://localhost:5672?heartbeat='60'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - assertEquals(60, Integer.parseInt(broker.getProperty(BrokerDetails.OPTIONS_HEARTBEAT))); - - assertEquals(Integer.valueOf(60), broker.buildConnectionSettings().getHeartbeatInterval08()); - } - - @SuppressWarnings("deprecation") - public void testLegacyHeartbeat() throws Exception - { - String brokerURL = "tcp://localhost:5672?idle_timeout='60000'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - assertEquals(60000, Integer.parseInt(broker.getProperty(BrokerDetails.OPTIONS_IDLE_TIMEOUT))); - - assertEquals(Integer.valueOf(60), broker.buildConnectionSettings().getHeartbeatInterval08()); - } - - public void testSslVerifyHostNameIsTurnedOnByDefault() throws Exception - { - String brokerURL = "tcp://localhost:5672?ssl='true'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - ConnectionSettings connectionSettings = broker.buildConnectionSettings(); - assertTrue(String.format("Unexpected '%s' option value", BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME), - connectionSettings.isVerifyHostname()); - assertNull(String.format("Unexpected '%s' property value", BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME), - broker.getProperty(BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME)); - } - - public void testSslVerifyHostNameIsTurnedOff() throws Exception - { - String brokerURL = "tcp://localhost:5672?ssl='true'&ssl_verify_hostname='false'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - ConnectionSettings connectionSettings = broker.buildConnectionSettings(); - assertFalse(String.format("Unexpected '%s' option value", BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME), - connectionSettings.isVerifyHostname()); - assertEquals(String.format("Unexpected '%s' property value", BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME), - "false", broker.getProperty(BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME)); - } - - public void testSslVerifyHostNameTurnedOffViaSystemProperty() throws Exception - { - setTestSystemProperty(ClientProperties.CONNECTION_OPTION_SSL_VERIFY_HOST_NAME, "false"); - String brokerURL = "tcp://localhost:5672?ssl='true'"; - AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL); - ConnectionSettings connectionSettings = broker.buildConnectionSettings(); - assertFalse(String.format("Unexpected '%s' option value", BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME), - connectionSettings.isVerifyHostname()); - assertNull(String.format("Unexpected '%s' property value", BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME), - broker.getProperty(BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME)); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java deleted file mode 100644 index 0bdd3062ea..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseMethodHandlerNoCloseOk.java +++ /dev/null @@ -1,97 +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.test.unit.client.channelclose; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.AMQChannelClosedException; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQInvalidArgumentException; -import org.apache.qpid.AMQInvalidRoutingKeyException; -import org.apache.qpid.client.AMQNoConsumersException; -import org.apache.qpid.client.AMQNoRouteException; -import org.apache.qpid.client.protocol.AMQProtocolSession; -import org.apache.qpid.client.state.StateAwareMethodListener; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.ChannelCloseBody; -import org.apache.qpid.protocol.AMQConstant; - -public class ChannelCloseMethodHandlerNoCloseOk implements StateAwareMethodListener<ChannelCloseBody> -{ - private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseMethodHandlerNoCloseOk.class); - - private static ChannelCloseMethodHandlerNoCloseOk _handler = new ChannelCloseMethodHandlerNoCloseOk(); - - public static ChannelCloseMethodHandlerNoCloseOk getInstance() - { - return _handler; - } - - public void methodReceived(AMQProtocolSession session, ChannelCloseBody method, int channelId) - throws AMQException - { - _logger.debug("ChannelClose method received"); - - AMQConstant errorCode = AMQConstant.getConstant(method.getReplyCode()); - AMQShortString reason = method.getReplyText(); - if (_logger.isDebugEnabled()) - { - _logger.debug("Channel close reply code: " + errorCode + ", reason: " + reason); - } - - // For this test Method Handler .. don't send Close-OK - // // TODO: Be aware of possible changes to parameter order as versions change. - // AMQFrame frame = ChannelCloseOkBody.createAMQFrame(evt.getChannelId(), method.getMajor(), method.getMinor()); - // protocolSession.writeFrame(frame); - if (errorCode != AMQConstant.REPLY_SUCCESS) - { - _logger.error("Channel close received with errorCode " + errorCode + ", and reason " + reason); - if (errorCode == AMQConstant.NO_CONSUMERS) - { - throw new AMQNoConsumersException("Error: " + reason, null, null); - } - else if (errorCode == AMQConstant.NO_ROUTE) - { - throw new AMQNoRouteException("Error: " + reason, null, null); - } - else if (errorCode == AMQConstant.ARGUMENT_INVALID) - { - _logger.debug("Broker responded with Invalid Argument."); - - throw new AMQInvalidArgumentException(String.valueOf(reason), null); - } - else if (errorCode == AMQConstant.INVALID_ROUTING_KEY) - { - _logger.debug("Broker responded with Invalid Routing Key."); - - throw new AMQInvalidRoutingKeyException(String.valueOf(reason), null); - } - else - { - throw new AMQChannelClosedException(errorCode, "Error: " + reason, null); - } - - } - - session.channelClosed(channelId, errorCode, String.valueOf(reason)); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java deleted file mode 100644 index 3498045601..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/NoCloseOKStateManager.java +++ /dev/null @@ -1,36 +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.test.unit.client.channelclose; - -import org.apache.qpid.client.protocol.AMQProtocolSession; -import org.apache.qpid.client.state.AMQStateManager; - -public class NoCloseOKStateManager extends AMQStateManager -{ - public NoCloseOKStateManager(AMQProtocolSession protocolSession) - { - super(protocolSession); - } - - - - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java deleted file mode 100644 index c14ea3a101..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java +++ /dev/null @@ -1,654 +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.test.unit.client.connectionurl; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQBrokerDetails; -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.jms.BrokerDetails; -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.url.URLSyntaxException; - -public class ConnectionURLTest extends TestCase -{ - public void testFailoverURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin?cyclecount='100''"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); - assertEquals("100", connectionurl.getFailoverOption(ConnectionURL.OPTIONS_FAILOVER_CYCLE)); - assertTrue(connectionurl.getUsername().equals("ritchiem")); - assertTrue(connectionurl.getPassword().equals("bob")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 2); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - - service = connectionurl.getBrokerDetails(1); - - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("fancyserver")); - assertTrue(service.getPort() == 3000); - - } - - public void testSingleTransportUsernamePasswordURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("ritchiem")); - assertTrue(connectionurl.getPassword().equals("bob")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - } - - public void testSingleTransportUsernameBlankPasswordURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:@/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("ritchiem")); - assertTrue(connectionurl.getPassword().equals("")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - } - - public void testFailedURLNullPassword() - { - String url = "amqp://ritchiem@/test?brokerlist='tcp://localhost:5672'"; - - try - { - new AMQConnectionURL(url); - fail("URL has null password"); - } - catch (URLSyntaxException e) - { - assertTrue(e.getReason().equals("Null password in user information not allowed.")); - assertTrue(e.getIndex() == 7); - } - } - - - public void testSingleTransportURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - - assertTrue(connectionurl.getBrokerCount() == 1); - - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - } - - public void testSingleTransportWithClientURLURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@clientname/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - assertTrue(connectionurl.getClientName().equals("clientname")); - - - assertTrue(connectionurl.getBrokerCount() == 1); - - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - } - - public void testSingleTransport1OptionURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672',routingkey='jim'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - assertTrue(connectionurl.getOption("routingkey").equals("jim")); - } - - public void testSingleTransportDefaultedBroker() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='localhost'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - } - - public void testSingleTransportDefaultedBrokerWithPort() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='localhost:1234'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 1234); - } - - public void testSingleTransportDefaultedBrokerWithIP() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='127.0.0.1'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - - assertTrue(service.getHost().equals("127.0.0.1")); - assertTrue(service.getPort() == 5672); - } - - public void testConnectionURLOptionToStringMasksPassword() throws URLSyntaxException - { - String url = "amqp://guest:guest@client/localhost?brokerlist='tcp://localhost:1234'"; - ConnectionURL connectionurl = new AMQConnectionURL(url); - - String expectedToString = "amqp://guest:********@client/localhost?brokerlist='tcp://localhost:1234'"; - String actualToString = connectionurl.toString(); - assertEquals("Unexpected toString form", expectedToString, actualToString); - } - - public void testConnectionURLOptionToStringMasksSslTrustStorePassword() throws URLSyntaxException - { - String url = "amqp://guest:guest@client/vhost?brokerlist='tcp://host:1234?trust_store_password='truststorepassword''"; - ConnectionURL connectionurl = new AMQConnectionURL(url); - - String expectedToString = "amqp://guest:********@client/vhost?brokerlist='tcp://host:1234?trust_store_password='********''"; - String actualToString = connectionurl.toString(); - assertEquals("Unexpected toString form", expectedToString, actualToString); - } - - public void testConnectionURLOptionToStringMasksSslKeyStorePassword() throws URLSyntaxException - { - String url = "amqp://guest:guest@client/vhost?brokerlist='tcp://host:1234?key_store_password='keystorepassword1';tcp://host:1235?key_store_password='keystorepassword2''"; - ConnectionURL connectionurl = new AMQConnectionURL(url); - - String expectedToString = "amqp://guest:********@client/vhost?brokerlist='tcp://host:1234?key_store_password='********';tcp://host:1235?key_store_password='********''"; - String actualToString = connectionurl.toString(); - assertEquals("Unexpected toString form", expectedToString, actualToString); - } - - /** - * Test for QPID-3662 to ensure the {@code toString()} representation is correct. - */ - public void testConnectionURLOptionToStringWithMaxPreftech() throws URLSyntaxException - { - String url = "amqp://guest:guest@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''"; - ConnectionURL connectionurl = new AMQConnectionURL(url); - - String expectedToString = "amqp://guest:********@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''"; - String actualToString = connectionurl.toString(); - assertEquals("Unexpected toString form", expectedToString, actualToString); - } - - public void testSingleTransportMultiOptionURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672?foo='jim'&bar='bob'&fred='jimmy'',routingkey='jim',timeout='200',immediatedelivery='true'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - - assertTrue(connectionurl.getOption("routingkey").equals("jim")); - assertTrue(connectionurl.getOption("timeout").equals("200")); - assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); - } - - public void testNoVirtualHostURL() - { - String url = "amqp://user@?brokerlist='tcp://localhost:5672'"; - - try - { - new AMQConnectionURL(url); - fail("URL has no virtual host should not parse"); - } - catch (URLSyntaxException e) - { - // This should occur. - } - } - - public void testNoClientID() throws URLSyntaxException - { - String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getUsername().equals("user")); - assertTrue(connectionurl.getPassword().equals("")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - } - - public void testClientIDWithUnderscore() throws URLSyntaxException - { - String url = "amqp://user:pass@client_id/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getUsername().equals("user")); - assertTrue(connectionurl.getPassword().equals("pass")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - assertTrue(connectionurl.getClientName().equals("client_id")); - - assertTrue(connectionurl.getBrokerCount() == 1); - } - - public void testWrongOptionSeparatorInOptions() - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'+failover='roundrobin'"; - try - { - new AMQConnectionURL(url); - fail("URL Should not parse"); - } - catch (URLSyntaxException urise) - { - assertTrue(urise.getReason().equals("Unterminated option. Possible illegal option separator:'+'")); - } - - } - - - public void testNoUserDetailsProvidedWithClientID() - - { - String url = "amqp://clientID/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; - try - { - new AMQConnectionURL(url); - } - catch (URLSyntaxException urise) - { - fail("User information is optional in url"); - } - - } - - public void testNoUserDetailsProvidedNOClientID() - - { - String url = "amqp:///test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; - try - { - new AMQConnectionURL(url); - } - catch (URLSyntaxException urise) - { - fail("User information is optional in url"); - } - - } - - public void testCheckVirtualhostFormat() throws URLSyntaxException - { - String url = "amqp://guest:guest@/t.-_+!=:?brokerlist='tcp://localhost:5672'"; - - AMQConnectionURL connection = new AMQConnectionURL(url); - assertTrue(connection.getVirtualHost().equals("/t.-_+!=:")); - } - - public void testCheckDefaultPort() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test=:?brokerlist='tcp://localhost'"; - - AMQConnectionURL connection = new AMQConnectionURL(url); - - BrokerDetails broker = connection.getBrokerDetails(0); - assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); - - } - - public void testCheckMissingFinalQuote() throws URLSyntaxException - { - String url = "amqp://guest:guest@id/test" + "?brokerlist='tcp://localhost:5672"; - - try - { - new AMQConnectionURL(url); - } - catch (URLSyntaxException e) - { - assertEquals(e.getMessage(), "Unterminated option at index 32: brokerlist='tcp://localhost:5672"); - } - } - - - public void testDefaultExchanges() throws URLSyntaxException - { - String url = "amqp://guest:guest@id/test" + "?defaultQueueExchange='test.direct'&defaultTopicExchange='test.topic'&temporaryQueueExchange='tmp.direct'&temporaryTopicExchange='tmp.topic'"; - - AMQConnectionURL conn = new AMQConnectionURL(url); - - assertEquals(conn.getDefaultQueueExchangeName().asString(),"test.direct"); - - assertEquals(conn.getDefaultTopicExchangeName().asString(),"test.topic"); - - assertEquals(conn.getTemporaryQueueExchangeName().asString(),"tmp.direct"); - - assertEquals(conn.getTemporaryTopicExchangeName().asString(),"tmp.topic"); - - } - - public void testSingleTransportMultiOptionOnBrokerURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672?foo='jim'&bar='bob'&fred='jimmy'',routingkey='jim',timeout='200',immediatedelivery='true'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - assertTrue(service.getTransport().equals("tcp")); - - assertTrue(service.getHost().equals("localhost")); - assertTrue(service.getPort() == 5672); - assertEquals("jim",service.getProperty("foo")); - assertEquals("bob",service.getProperty("bar")); - assertEquals("jimmy",service.getProperty("fred")); - - assertTrue(connectionurl.getOption("routingkey").equals("jim")); - assertTrue(connectionurl.getOption("timeout").equals("200")); - assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); - } - - /** - * Test that options other than failover and brokerlist are returned in the string representation. - * <p> - * QPID-2697 - */ - public void testOptionToString() throws Exception - { - ConnectionURL url = new AMQConnectionURL("amqp://user:pass@temp/test?maxprefetch='12345'&brokerlist='tcp://localhost:5672'"); - - assertTrue("String representation should contain options and values", url.toString().contains("maxprefetch='12345'")); - } - - public void testHostNamesWithUnderScore() throws URLSyntaxException - { - String url = "amqp://guest:guest@clientid/test?brokerlist='tcp://under_score:6672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - BrokerDetails service = connectionurl.getBrokerDetails(0); - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("under_score")); - assertTrue(service.getPort() == 6672); - - url = "amqp://guest:guest@clientid/test?brokerlist='tcp://under_score'"; - - connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - service = connectionurl.getBrokerDetails(0); - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("under_score")); - assertTrue(service.getPort() == 5672); - } - - - public void testRejectBehaviourPresent() throws Exception - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&rejectbehaviour='server'"; - - ConnectionURL connectionURL = new AMQConnectionURL(url); - - assertTrue(connectionURL.getFailoverMethod() == null); - assertTrue(connectionURL.getUsername().equals("guest")); - assertTrue(connectionURL.getPassword().equals("guest")); - assertTrue(connectionURL.getVirtualHost().equals("/test")); - - //check that the reject behaviour option is returned as expected - assertEquals("Reject behaviour option was not as expected", "server", - connectionURL.getOption(ConnectionURL.OPTIONS_REJECT_BEHAVIOUR)); - } - - public void testRejectBehaviourNotPresent() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getFailoverMethod() == null); - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - //check that the reject behaviour option is null as expected - assertNull("Reject behaviour option was not as expected", - connectionurl.getOption(ConnectionURL.OPTIONS_REJECT_BEHAVIOUR)); - } - - /** - * Verify that when the ssl option is not specified, asking for the option returns null, - * such that this can later be used to verify it wasnt specified. - */ - public void testDefaultSsl() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'"; - ConnectionURL connectionURL = new AMQConnectionURL(url); - - assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL)); - } - - /** - * Verify that when the ssl option is specified, asking for the option returns the value, - * such that this can later be used to verify what value it was specified as. - */ - public void testOverridingSsl() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&ssl='true'"; - ConnectionURL connectionURL = new AMQConnectionURL(url); - - assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL))); - - url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&ssl='false'"; - connectionURL = new AMQConnectionURL(url); - - assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL))); - } - - /** - * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is not - * specified, asking for the option returns null, such that this can later be used to - * verify it wasn't specified. - */ - public void testDefaultVerifyQueueOnSend() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'"; - ConnectionURL connectionURL = new AMQConnectionURL(url); - - assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL)); - } - - /** - * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is - * specified, asking for the option returns the value, such that this can later be used - * to verify what value it was specified as. - */ - public void testOverridingVerifyQueueOnSend() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='true'"; - ConnectionURL connectionURL = new AMQConnectionURL(url); - - assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND))); - - url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='false'"; - connectionURL = new AMQConnectionURL(url); - - assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND))); - } - - public void testSerialization() throws Exception - { - String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672'"; - ConnectionURL connectionurl = new AMQConnectionURL(url); - - - assertTrue(connectionurl instanceof Serializable); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(connectionurl); - oos.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bis); - Object deserializedObject = ois.readObject(); - ois.close(); - - ConnectionURL deserialisedConnectionUrl = (AMQConnectionURL) deserializedObject; - assertEquals(connectionurl, deserialisedConnectionUrl); - assertEquals(connectionurl.hashCode(), deserialisedConnectionUrl.hashCode()); - - } -} - diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java deleted file mode 100644 index 9c9664931a..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java +++ /dev/null @@ -1,410 +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.test.unit.client.destinationurl; - -import junit.framework.TestCase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.client.RejectBehaviour; -import org.apache.qpid.exchange.ExchangeDefaults; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.url.AMQBindingURL; -import org.apache.qpid.url.BindingURL; - -import java.net.URISyntaxException; - -public class DestinationURLTest extends TestCase -{ - private static final Logger _logger = LoggerFactory.getLogger(DestinationURLTest.class); - - public void testFullURL() throws URISyntaxException - { - - String url = "exchange.Class://exchangeName/Destination/Queue"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(url.equals(dest.toString())); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchange.Class")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("Destination")); - assertTrue(dest.getQueueName().equalsCharSequence("Queue")); - } - - public void testQueue() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName//Queue"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(url.equals(dest.toString())); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("")); - assertTrue(dest.getQueueName().equalsCharSequence("Queue")); - } - - public void testQueueWithOption() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName//Queue?option='value'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(url.equals(dest.toString())); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("")); - assertTrue(dest.getQueueName().equalsCharSequence("Queue")); - assertTrue(dest.getOption("option").equals("value")); - } - - - public void testDestination() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(url.equals(dest.toString())); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("Destination")); - assertTrue(dest.getQueueName().equalsCharSequence("")); - } - - public void testDestinationWithOption() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/?option='value'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(url.equals(dest.toString())); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("Destination")); - assertTrue(dest.getQueueName().equalsCharSequence("")); - - assertTrue(dest.getOption("option").equals("value")); - } - - public void testDestinationWithMultiOption() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/?option='value',option2='value2'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("Destination")); - assertTrue(dest.getQueueName().equalsCharSequence("")); - - assertTrue(dest.getOption("option").equals("value")); - assertTrue(dest.getOption("option2").equals("value2")); - } - - public void testDestinationWithNoExchangeDefaultsToDirect() throws URISyntaxException - { - - String url = "IBMPerfQueue1?durable='true'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(dest.getExchangeClass().equals(AMQShortString.valueOf(ExchangeDefaults.DIRECT_EXCHANGE_CLASS))); - assertTrue(dest.getExchangeName().equalsCharSequence("")); - assertTrue(dest.getDestinationName().equalsCharSequence("")); - assertTrue(dest.getQueueName().equalsCharSequence("IBMPerfQueue1")); - - assertTrue(dest.getOption("durable").equals("true")); - } - - public void testDestinationWithMultiBindingKeys() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/?bindingkey='key1',bindingkey='key2'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - assertTrue(dest.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(dest.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(dest.getDestinationName().equalsCharSequence("Destination")); - assertTrue(dest.getQueueName().equalsCharSequence("")); - - assertTrue(dest.getBindingKeys().length == 2); - } - - // You can only specify only a routing key or binding key, but not both. - public void testDestinationIfOnlyRoutingKeyOrBindingKeyIsSpecified() throws URISyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/?bindingkey='key1',routingkey='key2'"; - boolean exceptionThrown = false; - try - { - - new AMQBindingURL(url); - } - catch(URISyntaxException e) - { - exceptionThrown = true; - _logger.info("Exception thrown",e); - } - - assertTrue("Failed to throw an URISyntaxException when both the bindingkey and routingkey is specified",exceptionThrown); - } - - public void testExchangeOptionsNotPresent() throws URISyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue"; - - AMQBindingURL burl = new AMQBindingURL(url); - - assertTrue(url.equals(burl.toString())); - - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL)); - - class MyTestAMQDestination extends AMQDestination - { - public MyTestAMQDestination(BindingURL url) - { - super(url); - } - public boolean isNameRequired() - { - return false; - } - }; - - AMQDestination dest = new MyTestAMQDestination(burl); - assertFalse(dest.isExchangeAutoDelete()); - assertFalse(dest.isExchangeDurable()); - assertFalse(dest.isExchangeInternal()); - } - - public void testExchangeAutoDeleteOptionPresent() throws URISyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_AUTODELETE + "='true'"; - - AMQBindingURL burl = new AMQBindingURL(url); - - assertTrue(url.equals(burl.toString())); - - assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL)); - - class MyTestAMQDestination extends AMQDestination - { - public MyTestAMQDestination(BindingURL url) - { - super(url); - } - public boolean isNameRequired() - { - return false; - } - }; - - AMQDestination dest = new MyTestAMQDestination(burl); - assertTrue(dest.isExchangeAutoDelete()); - assertFalse(dest.isExchangeDurable()); - assertFalse(dest.isExchangeInternal()); - } - - public void testExchangeDurableOptionPresent() throws URISyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_DURABLE + "='true'"; - - AMQBindingURL burl = new AMQBindingURL(url); - - assertTrue(url.equals(burl.toString())); - - assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL)); - - class MyTestAMQDestination extends AMQDestination - { - public MyTestAMQDestination(BindingURL url) - { - super(url); - } - public boolean isNameRequired() - { - return false; - } - }; - - AMQDestination dest = new MyTestAMQDestination(burl); - assertTrue(dest.isExchangeDurable()); - assertFalse(dest.isExchangeAutoDelete()); - assertFalse(dest.isExchangeInternal()); - } - - public void testExchangeInternalOptionPresent() throws URISyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_INTERNAL + "='true'"; - - AMQBindingURL burl = new AMQBindingURL(url); - - assertTrue(url.equals(burl.toString())); - - assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE)); - assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE)); - - class MyTestAMQDestination extends AMQDestination - { - public MyTestAMQDestination(BindingURL url) - { - super(url); - } - public boolean isNameRequired() - { - return false; - } - }; - - AMQDestination dest = new MyTestAMQDestination(burl); - assertTrue(dest.isExchangeInternal()); - assertFalse(dest.isExchangeDurable()); - assertFalse(dest.isExchangeAutoDelete()); - } - - public void testRejectBehaviourPresent() throws URISyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='server'"; - - AMQBindingURL burl = new AMQBindingURL(url); - - assertTrue(url.equals(burl.toString())); - assertTrue(burl.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(burl.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(burl.getDestinationName().equalsCharSequence("Destination")); - assertTrue(burl.getQueueName().equalsCharSequence("Queue")); - - //check that the MaxDeliveryCount property has the right value - assertEquals("server",burl.getOption(BindingURL.OPTION_REJECT_BEHAVIOUR)); - - //check that the MaxDeliveryCount value is correctly returned from an AMQDestination - class MyTestAMQDestination extends AMQDestination - { - public MyTestAMQDestination(BindingURL url) - { - super(url); - } - public boolean isNameRequired() - { - return false; - } - }; - - AMQDestination dest = new MyTestAMQDestination(burl); - assertEquals("Reject behaviour is unexpected", RejectBehaviour.SERVER, dest.getRejectBehaviour()); - } - - public void testRejectBehaviourNotPresent() throws URISyntaxException - { - String url = "exchangeClass://exchangeName/Destination/Queue"; - - AMQBindingURL burl = new AMQBindingURL(url); - - assertTrue(url.equals(burl.toString())); - - assertTrue(burl.getExchangeClass().equalsCharSequence("exchangeClass")); - assertTrue(burl.getExchangeName().equalsCharSequence("exchangeName")); - assertTrue(burl.getDestinationName().equalsCharSequence("Destination")); - assertTrue(burl.getQueueName().equalsCharSequence("Queue")); - - class MyTestAMQDestination extends AMQDestination - { - public MyTestAMQDestination(BindingURL url) - { - super(url); - } - public boolean isNameRequired() - { - return false; - } - }; - - AMQDestination dest = new MyTestAMQDestination(burl); - assertNull("Reject behaviour is unexpected", dest.getRejectBehaviour()); - } - - public void testBindingUrlWithoutDestinationAndQueueName() throws Exception - { - AMQBindingURL bindingURL = new AMQBindingURL("topic://amq.topic//?routingkey='testTopic'"); - assertEquals("Unexpected queue name", AMQShortString.EMPTY_STRING, bindingURL.getQueueName()); - assertEquals("Unexpected destination", AMQShortString.EMPTY_STRING, bindingURL.getDestinationName()); - assertEquals("Unexpected routing key", AMQShortString.valueOf("testTopic"), bindingURL.getRoutingKey()); - } - - public void testBindingUrlWithoutDestinationAndMissedQueueName() throws Exception - { - AMQBindingURL bindingURL = new AMQBindingURL("topic://amq.topic/?routingkey='testTopic'"); - assertEquals("Unexpected queue name", AMQShortString.EMPTY_STRING, bindingURL.getQueueName()); - assertEquals("Unexpected destination", AMQShortString.EMPTY_STRING, bindingURL.getDestinationName()); - assertEquals("Unexpected routing key", AMQShortString.valueOf("testTopic"), bindingURL.getRoutingKey()); - } - - public void testBindingUrlWithoutQueueName() throws Exception - { - AMQBindingURL bindingURL = new AMQBindingURL("topic://amq.topic/destination/?routingkey='testTopic'"); - assertEquals("Unexpected queue name", AMQShortString.EMPTY_STRING, bindingURL.getQueueName()); - assertEquals("Unexpected destination", AMQShortString.valueOf("destination"), bindingURL.getDestinationName()); - assertEquals("Unexpected routing key", AMQShortString.valueOf("testTopic"), bindingURL.getRoutingKey()); - } - - public void testBindingUrlWithQueueNameWithoutDestination() throws Exception - { - AMQBindingURL bindingURL = new AMQBindingURL("topic://amq.topic//queueName?routingkey='testTopic'"); - assertEquals("Unexpected queue name", AMQShortString.valueOf("queueName"), bindingURL.getQueueName()); - assertEquals("Unexpected destination", AMQShortString.EMPTY_STRING, bindingURL.getDestinationName()); - assertEquals("Unexpected routing key", AMQShortString.valueOf("testTopic"), bindingURL.getRoutingKey()); - } - - public void testBindingUrlWithQueueNameAndDestination() throws Exception - { - AMQBindingURL bindingURL = new AMQBindingURL("topic://amq.topic/destination/queueName?routingkey='testTopic'"); - assertEquals("Unexpected queue name", AMQShortString.valueOf("queueName"), bindingURL.getQueueName()); - assertEquals("Unexpected destination", AMQShortString.valueOf("destination"), bindingURL.getDestinationName()); - assertEquals("Unexpected routing key", AMQShortString.valueOf("testTopic"), bindingURL.getRoutingKey()); - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(DestinationURLTest.class); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java deleted file mode 100644 index 1ab3ad0573..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/BytesMessageTest.java +++ /dev/null @@ -1,568 +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.test.unit.client.message; - -import junit.framework.TestCase; - -import org.apache.qpid.client.message.JMSBytesMessage; -import org.apache.qpid.client.message.TestMessageHelper; - -import javax.jms.MessageEOFException; -import javax.jms.MessageFormatException; -import javax.jms.MessageNotReadableException; -import javax.jms.MessageNotWriteableException; -import java.util.HashMap; - -public class BytesMessageTest extends TestCase -{ - /** - * Tests that on creation a call to getBodyLength() throws an exception - * if null was passed in during creation - */ - public void testNotReadableOnCreationWithNull() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.getBodyLength(); - fail("expected exception did not occur"); - } - catch (MessageNotReadableException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageNotReadableException, got " + e); - } - } - - public void testResetMakesReadble() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - bm.writeInt(12); - fail("expected exception did not occur"); - } - catch (MessageNotWriteableException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageNotWriteableException, got " + e); - } - } - - public void testClearBodyMakesWritable() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - bm.clearBody(); - bm.writeInt(10); - } - - public void testWriteBoolean() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeBoolean(true); - bm.writeBoolean(false); - bm.reset(); - boolean val = bm.readBoolean(); - assertEquals(true, val); - val = bm.readBoolean(); - assertEquals(false, val); - } - - public void testWriteInt() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - long len = bm.getBodyLength(); - assertTrue(len == 4); - int val = bm.readInt(); - assertTrue(val == 10); - } - - public void testWriteString() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeUTF("Bananas"); - bm.reset(); - String res = bm.readUTF(); - assertEquals("Bananas", res); - } - - public void testWriteBytes() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - byte[] bytes = {1,2,3,4}; - bm.writeBytes(bytes, 1, 2); - bm.reset(); - bytes = new byte[2]; - bm.readBytes(bytes); - assertEquals(2, bytes[0]); - assertEquals(3, bytes[1]); - } - - public void testWriteObject() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeObject(new Boolean(true)); - bm.writeObject(new Boolean(false)); - bm.writeObject(new Byte((byte)2)); - bm.writeObject(new byte[]{1,2,3,4}); - bm.writeObject(new Character('g')); - bm.writeObject(new Short((short) 29)); - bm.writeObject(new Integer(101)); - bm.writeObject(new Long(50003222L)); - bm.writeObject("Foobar"); - bm.writeObject(new Float(1.7f)); - bm.writeObject(new Double(8.7d)); - bm.reset(); - assertTrue(bm.readBoolean()); - assertTrue(!bm.readBoolean()); - assertEquals((byte)2, bm.readByte()); - byte[] bytes = new byte[4]; - bm.readBytes(bytes); - assertEquals('g', bm.readChar()); - assertEquals((short) 29, bm.readShort()); - assertEquals(101, bm.readInt()); - assertEquals(50003222L, bm.readLong()); - assertEquals("Foobar", bm.readUTF()); - assertEquals(1.7f, bm.readFloat()); - assertEquals(8.7d, bm.readDouble()); - } - - public void testWriteObjectRejectsNonPrimitives() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeObject(new HashMap()); - fail("expected MessageFormatException was not thrown"); - } - catch (MessageFormatException e) - { - // pass - } - } - - public void testWriteObjectThrowsNPE() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeObject(null); - fail("expected exception did not occur"); - } - catch (NullPointerException n) - { - // ok - } - catch (Exception e) - { - fail("expected NullPointerException, got " + e); - } - } - - public void testReadBoolean() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeBoolean(true); - bm.reset(); - boolean result = bm.readBoolean(); - assertTrue(result); - } - - public void testReadUnsignedByte() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte) 9); - bm.reset(); - int result = bm.readUnsignedByte(); - assertEquals(9, result); - } - - public void testReadUnsignedShort() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeShort((byte) 9); - bm.reset(); - int result = bm.readUnsignedShort(); - assertEquals(9, result); - } - - public void testReadBytesChecksNull() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.readBytes(null); - } - catch (IllegalArgumentException e) - { - // pass - } - - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.readBytes(null, 1); - } - catch (IllegalArgumentException e) - { - // pass - } - } - - public void testReadBytesChecksMaxSize() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - byte[] bytes = new byte[100]; - bm.readBytes(bytes, 120); - } - catch (IllegalArgumentException e) - { - // pass - } - } - - public void testReadBytesReturnsCorrectLengths() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - byte[] bytes = {2, 3}; - bm.writeBytes(bytes); - bm.reset(); - int len = bm.readBytes(bytes); - assertEquals(2, len); - len = bm.readBytes(bytes); - assertEquals(-1, len); - len = bm.readBytes(bytes, 2); - assertEquals(-1, len); - bm.reset(); - len = bm.readBytes(bytes, 2); - assertEquals(2, len); - bm.reset(); - len = bm.readBytes(bytes, 1); - assertEquals(1, len); - - } - - public void testEOFByte() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readByte(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFUnsignedByte() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readUnsignedByte(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFBoolean() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeBoolean(true); - bm.reset(); - bm.readBoolean(); - // should throw - bm.readBoolean(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFChar() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeChar('A'); - bm.reset(); - bm.readChar(); - // should throw - bm.readChar(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFDouble() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeDouble(1.3d); - bm.reset(); - bm.readDouble(); - // should throw - bm.readDouble(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFFloat() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeFloat(1.3f); - bm.reset(); - bm.readFloat(); - // should throw - bm.readFloat(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFInt() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeInt(99); - bm.reset(); - bm.readInt(); - // should throw - bm.readInt(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFLong() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeLong(4L); - bm.reset(); - bm.readLong(); - // should throw - bm.readLong(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFShort() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readShort(); - // should throw - bm.readShort(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFUnsignedShort() throws Exception - { - try - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readUnsignedShort(); - // should throw - bm.readUnsignedShort(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - /** - * Tests that the readBytes() method populates the passed in array - * correctly - * @throws Exception - */ - public void testReadBytes() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.reset(); - byte[] result = new byte[2]; - int count = bm.readBytes(result); - assertEquals((byte)3, result[0]); - assertEquals((byte)4, result[1]); - assertEquals(2, count); - } - - public void testReadBytesEOF() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.reset(); - byte[] result = new byte[2]; - bm.readBytes(result); - int count = bm.readBytes(result); - assertEquals(-1, count); - } - - public void testReadBytesWithLargerArray() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.reset(); - byte[] result = new byte[3]; - int count = bm.readBytes(result); - assertEquals(2, count); - assertEquals((byte)3, result[0]); - assertEquals((byte)4, result[1]); - assertEquals((byte)0, result[2]); - } - - public void testReadBytesWithCount() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.writeByte((byte)5); - bm.reset(); - byte[] result = new byte[3]; - int count = bm.readBytes(result, 2); - assertEquals(2, count); - assertEquals((byte)3, result[0]); - assertEquals((byte)4, result[1]); - assertEquals((byte)0, result[2]); - } - - public void testToBodyStringWithNull() throws Exception - { - JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); - bm.reset(); - String result = bm.toBodyString(); - assertEquals("\"\"", result); - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(BytesMessageTest.class); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java deleted file mode 100644 index 41cf79e963..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/MapMessageTest.java +++ /dev/null @@ -1,383 +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.test.unit.client.message; - -import org.junit.Assert; -import junit.framework.TestCase; - -import org.apache.qpid.client.message.JMSMapMessage; -import org.apache.qpid.client.message.TestMessageHelper; - -import javax.jms.JMSException; -import javax.jms.MessageFormatException; - - -public class MapMessageTest extends TestCase -{ - - //Test Lookups - - public void testBooleanLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - - mm.setBoolean("value", true); - Assert.assertEquals(true, mm.getBoolean("value")); - Assert.assertEquals("true", mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testByteLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setByte("value", Byte.MAX_VALUE); - - Assert.assertEquals(Byte.MAX_VALUE, mm.getByte("value")); - Assert.assertEquals((short) Byte.MAX_VALUE, mm.getShort("value")); - Assert.assertEquals(Byte.MAX_VALUE, mm.getInt("value")); - Assert.assertEquals((long) Byte.MAX_VALUE, mm.getLong("value")); - Assert.assertEquals("" + Byte.MAX_VALUE, mm.getString("value")); - - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testShortLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setShort("value", Short.MAX_VALUE); - Assert.assertEquals(Short.MAX_VALUE, mm.getShort("value")); - Assert.assertEquals((int) Short.MAX_VALUE, mm.getInt("value")); - Assert.assertEquals((long) Short.MAX_VALUE, mm.getLong("value")); - Assert.assertEquals("" + Short.MAX_VALUE, mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - - public void testCharLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - - mm.setChar("value", 'c'); - Assert.assertEquals('c', mm.getChar("value")); - Assert.assertEquals("c", mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - - mm.setString("value", null); - mm.getChar("value"); - fail("Expected NullPointerException"); - - } - catch (NullPointerException e) - { - ; // pass - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - - - - } - - public void testDoubleLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setDouble("value", Double.MAX_VALUE); - Assert.assertEquals(Double.MAX_VALUE, mm.getDouble("value"), 0d); - Assert.assertEquals("" + Double.MAX_VALUE, mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testFloatLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setFloat("value", Float.MAX_VALUE); - Assert.assertEquals(Float.MAX_VALUE, mm.getFloat("value"), 0f); - Assert.assertEquals(Double.valueOf(Float.MAX_VALUE), mm.getDouble("value"), 0d); - Assert.assertEquals("" + Float.MAX_VALUE, mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testIntLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setInt("value", Integer.MAX_VALUE); - Assert.assertEquals(Integer.MAX_VALUE, mm.getInt("value")); - Assert.assertEquals((long) Integer.MAX_VALUE, mm.getLong("value")); - Assert.assertEquals("" + Integer.MAX_VALUE, mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testLongLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setLong("value", Long.MAX_VALUE); - Assert.assertEquals(Long.MAX_VALUE, mm.getLong("value")); - Assert.assertEquals("" + Long.MAX_VALUE, mm.getString("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testBytesLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - byte[] bytes = {99, 98, 97, 96, 95}; - mm.setBytes("bytes", bytes); - assertBytesEqual(bytes, mm.getBytes("bytes")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - // Failed Lookups - - public void testFailedBooleanLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - Assert.assertEquals(false, mm.getBoolean("int")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testFailedByteLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getByte("random"); - Assert.fail("NumberFormatException expected"); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - - } - - public void testFailedBytesLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getBytes("random"); - Assert.fail("MessageFormatException expected"); - } - catch (MessageFormatException mfe) - { - //normal path - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedCharLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getChar("random"); - Assert.fail("MessageFormatException expected"); - } - catch (MessageFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedDoubleLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getDouble("random"); - Assert.fail("NullPointerException should be received."); - } - catch (NullPointerException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedFloatLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getFloat("random"); - Assert.fail("NullPointerException should be received."); - } - catch (NullPointerException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedIntLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getInt("random"); - Assert.fail("NumberFormatException should be received."); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedLongLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getLong("random"); - Assert.fail("NumberFormatException should be received."); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedShortLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getShort("random"); - Assert.fail("NumberFormatException should be received."); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - - private void assertBytesEqual(byte[] expected, byte[] actual) - { - Assert.assertEquals(expected.length, actual.length); - - for (int index = 0; index < expected.length; index++) - { - Assert.assertEquals(expected[index], actual[index]); - } - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(MapMessageTest.class); - } - - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java deleted file mode 100644 index a2c5bf624f..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java +++ /dev/null @@ -1,105 +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.test.unit.client.message; - -import org.apache.qpid.client.message.JMSObjectMessage; -import org.apache.qpid.client.message.TestMessageHelper; -import org.apache.qpid.test.utils.QpidTestCase; - -import java.util.ArrayList; -import java.util.Arrays; - -public class ObjectMessageUnitTest extends QpidTestCase -{ - private JMSObjectMessage _om; - - protected void setUp() throws Exception - { - super.setUp(); - _om = TestMessageHelper.newJMSObjectMessage(); - } - - /** - * Test that setObject with a primitive works - */ - public void testSetObjectWithBooleanPrimitive() throws Exception - { - _om.setObject(true); - - //make the message readable - Object object = _om.getObject(); - - assertTrue("Unexpected type returned", object instanceof Boolean); - assertEquals("Unexpected value returned", true, object); - } - - /** - * Test that setObject with a serializable Object works - */ - public void testSetObjectWithString() throws Exception - { - _om.setObject("test string"); - - //make the message readable - Object object = _om.getObject(); - - assertTrue("Unexpected type returned", object instanceof String); - assertEquals("Unexpected value returned", "test string", object); - } - - /** - * Test that setObject with a Collection of serializable's works, returning - * the items in the list when deserialized and ignoring any values - * added to the collection after setObject() is called on the message. - */ - public void testSetObjectWithArrayListOfInteger() throws Exception - { - ArrayList<Integer> list = new ArrayList<Integer>(); - list.add(1234); - list.add(Integer.MIN_VALUE); - list.add(Integer.MAX_VALUE); - - _om.setObject(list); - - //add something extra to the list now, and check it isn't in the value read back - list.add(0); - - //make the message readable - - //retrieve the Object - Object object = _om.getObject(); - - ArrayList<?> returnedList = null; - if(object instanceof ArrayList<?>) - { - returnedList = (ArrayList<?>) object; - } - else - { - fail("returned object was not an ArrayList"); - } - - //verify the extra added Integer was not present, then remove it from original list again and compare contents with the returned list - assertFalse("returned list should not have had the value added after setObject() was used", returnedList.contains(0)); - list.remove(Integer.valueOf(0)); - assertTrue("list contents were not equal", Arrays.equals(list.toArray(), returnedList.toArray())); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/StreamMessageTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/StreamMessageTest.java deleted file mode 100644 index 648e4b0c83..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/StreamMessageTest.java +++ /dev/null @@ -1,622 +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.test.unit.client.message; - -import junit.framework.TestCase; - -import org.apache.qpid.client.message.JMSStreamMessage; -import org.apache.qpid.client.message.TestMessageHelper; - -import javax.jms.JMSException; -import javax.jms.MessageEOFException; -import javax.jms.MessageFormatException; -import javax.jms.MessageNotReadableException; -import javax.jms.MessageNotWriteableException; -import javax.jms.StreamMessage; -import java.util.HashMap; - -/** - * @author Apache Software Foundation - */ -public class StreamMessageTest extends TestCase -{ - /** - * Tests that on creation a call to getBodyLength() throws an exception - * if null was passed in during creation - */ - public void testNotReadableOnCreationWithNull() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.readByte(); - fail("expected exception did not occur"); - } - catch (MessageNotReadableException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageNotReadableException, got " + e); - } - } - - public void testResetMakesReadble() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeInt(10); - bm.reset(); - bm.writeInt(12); - fail("expected exception did not occur"); - } - catch (MessageNotWriteableException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageNotWriteableException, got " + e); - } - } - - public void testClearBodyMakesWritable() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeInt(10); - bm.reset(); - bm.clearBody(); - bm.writeInt(10); - } - - public void testWriteBoolean() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeBoolean(true); - bm.writeBoolean(false); - bm.reset(); - boolean val = bm.readBoolean(); - assertEquals(true, val); - val = bm.readBoolean(); - assertEquals(false, val); - } - - public void testWriteInt() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeInt(10); - bm.reset(); - int val = bm.readInt(); - assertTrue(val == 10); - } - - public void testWriteString() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeString("Bananas"); - bm.reset(); - String res = bm.readString(); - assertEquals("Bananas", res); - } - - public void testWriteBytes() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - byte[] bytes = {1,2,3,4}; - bm.writeBytes(bytes, 1, 2); - bm.reset(); - bytes = new byte[2]; - bm.readBytes(bytes); - assertEquals(2, bytes[0]); - assertEquals(3, bytes[1]); - } - - public void testWriteObject() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeObject(new Boolean(true)); - bm.writeObject(new Boolean(false)); - bm.writeObject(new Byte((byte)2)); - bm.writeObject(new byte[]{1,2,3,4}); - bm.writeObject(new Character('g')); - bm.writeObject(new Short((short) 29)); - bm.writeObject(new Integer(101)); - bm.writeObject(new Long(50003222L)); - bm.writeObject("Foobar"); - bm.writeObject(new Float(1.7f)); - bm.writeObject(new Double(8.7d)); - bm.reset(); - assertTrue(bm.readBoolean()); - assertTrue(!bm.readBoolean()); - assertEquals((byte)2, bm.readByte()); - byte[] bytes = new byte[4]; - bm.readBytes(bytes); - assertEquals('g', bm.readChar()); - assertEquals((short) 29, bm.readShort()); - assertEquals(101, bm.readInt()); - assertEquals(50003222L, bm.readLong()); - assertEquals("Foobar", bm.readString()); - assertEquals(1.7f, bm.readFloat()); - assertEquals(8.7d, bm.readDouble()); - } - - public void testWriteObjectRejectsNonPrimitives() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeObject(new HashMap()); - fail("expected MessageFormatException was not thrown"); - } - catch (MessageFormatException e) - { - // pass - } - } - - public void testReadBoolean() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeBoolean(true); - bm.reset(); - boolean result = bm.readBoolean(); - assertTrue(result); - } - - public void testReadBytesChecksNull() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.readBytes(null); - } - catch (IllegalArgumentException e) - { - // pass - } - } - - public void testReadBytesReturnsCorrectLengths() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - byte[] bytes = {2, 3}; - bm.writeBytes(bytes); - bm.writeBytes(null); - bm.writeBytes(new byte[]{}); - bm.reset(); - int len = bm.readBytes(bytes); - assertEquals(2, len); - len = bm.readBytes(bytes); - assertEquals(-1, len); - len = bm.readBytes(bytes); - assertEquals(-1, len); - len = bm.readBytes(bytes); - assertEquals(0, len); - } - - public void testReadBytesFollowedByPrimitive() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeBytes(new byte[]{2, 3, 4, 5, 6, 7, 8}); - bm.writeBytes(new byte[]{2, 3, 4, 5, 6, 7}); - bm.writeString("Foo"); - bm.reset(); - int len; - do - { - len = bm.readBytes(new byte[2]); - } - while (len == 2); - - do - { - len = bm.readBytes(new byte[2]); - } - while (len == 2); - - assertEquals("Foo", bm.readString()); - } - - public void testReadMultipleByteArrays() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - byte[] bytes = {2, 3, 4}; - bm.writeBytes(bytes); - bm.writeBytes(bytes); - bm.reset(); - byte[] result = new byte[2]; - int len = bm.readBytes(result); - assertEquals(2, len); - len = bm.readBytes(result); - assertEquals(1, len); - len = bm.readBytes(result); - assertEquals(2, len); - } - - public void testEOFByte() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readByte(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFBoolean() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeBoolean(true); - bm.reset(); - bm.readBoolean(); - // should throw - bm.readBoolean(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFChar() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeChar('A'); - bm.reset(); - bm.readChar(); - // should throw - bm.readChar(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFDouble() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeDouble(1.3d); - bm.reset(); - bm.readDouble(); - // should throw - bm.readDouble(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFFloat() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeFloat(1.3f); - bm.reset(); - bm.readFloat(); - // should throw - bm.readFloat(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFInt() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeInt(99); - bm.reset(); - bm.readInt(); - // should throw - bm.readInt(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFLong() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeLong(4L); - bm.reset(); - bm.readLong(); - // should throw - bm.readLong(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testEOFShort() throws Exception - { - try - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readShort(); - // should throw - bm.readShort(); - fail("expected exception did not occur"); - } - catch (MessageEOFException m) - { - // ok - } - catch (Exception e) - { - fail("expected MessageEOFException, got " + e); - } - } - - public void testToBodyStringWithNull() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.reset(); - String result = bm.toBodyString(); - assertEquals("\"\"", result); - } - - private void checkConversionsFail(StreamMessage sm, int[] conversions) throws JMSException - { - for (int conversion : conversions) - { - try - { - switch (conversion) - { - case 0: - sm.readBoolean(); - break; - case 1: - sm.readByte(); - break; - case 2: - sm.readShort(); - break; - case 3: - sm.readChar(); - break; - case 4: - sm.readInt(); - break; - case 5: - sm.readLong(); - break; - case 6: - sm.readFloat(); - break; - case 7: - sm.readDouble(); - break; - case 8: - sm.readString(); - break; - case 9: - sm.readBytes(new byte[3]); - break; - } - fail("MessageFormatException was not thrown"); - } - catch (MessageFormatException e) - { - // PASS - } - sm.reset(); - } - } - public void testBooleanConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeBoolean(true); - bm.reset(); - String result = bm.readString(); - assertEquals("true", result); - bm.reset(); - checkConversionsFail(bm, new int[]{1,2,3,4,5,6,7,9}); - } - - public void testByteConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeByte((byte) 43); - bm.reset(); - assertEquals(43, bm.readShort()); - bm.reset(); - assertEquals(43, bm.readInt()); - bm.reset(); - assertEquals(43, bm.readLong()); - bm.reset(); - String result = bm.readString(); - assertEquals("43", result); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 3, 6, 7, 9}); - } - - public void testShortConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeShort((short) 87); - bm.reset(); - assertEquals(87, bm.readInt()); - bm.reset(); - assertEquals(87, bm.readLong()); - bm.reset(); - assertEquals("87", bm.readString()); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 1, 3, 6, 7, }); - } - - public void testCharConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeChar('d'); - bm.reset(); - assertEquals("d", bm.readString()); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 1, 2, 4, 5, 6, 7, 9}); - } - - public void testIntConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeInt(167); - bm.reset(); - assertEquals(167, bm.readLong()); - bm.reset(); - assertEquals("167", bm.readString()); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 1, 2, 3, 6, 7, 9}); - } - - public void testLongConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeLong(1678); - bm.reset(); - assertEquals("1678", bm.readString()); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 1, 2, 3, 4, 6, 7, 9}); - } - - public void testFloatConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeFloat(6.2f); - bm.reset(); - assertEquals(6.2d, bm.readDouble(), 0.01); - bm.reset(); - assertEquals("6.2", bm.readString()); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 1, 2, 3, 4, 5, 9}); - } - - public void testDoubleConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeDouble(88.35d); - bm.reset(); - assertEquals("88.35", bm.readString()); - bm.reset(); - checkConversionsFail(bm, new int[]{0, 1, 2, 3, 4, 5, 6, 9}); - } - - public void testStringConversions() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeString("true"); - bm.reset(); - assertEquals(true, bm.readBoolean()); - bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeString("2"); - bm.reset(); - assertEquals((byte)2, bm.readByte()); - bm.reset(); - assertEquals((short)2, bm.readShort()); - bm.reset(); - assertEquals(2, bm.readInt()); - bm.reset(); - assertEquals((long)2, bm.readLong()); - bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeString("5.7"); - bm.reset(); - assertEquals(5.7f, bm.readFloat()); - bm.reset(); - assertEquals(5.7d, bm.readDouble()); - } - - public void testNulls() throws Exception - { - JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage(); - bm.writeString(null); - bm.writeObject(null); - bm.reset(); - assertNull(bm.readObject()); - assertNull(bm.readObject()); - } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(StreamMessageTest.class); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java deleted file mode 100644 index 78c018840c..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/TextMessageTest.java +++ /dev/null @@ -1,300 +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.test.unit.client.message; - -import org.junit.Assert; -import junit.framework.TestCase; - -import org.apache.qpid.client.message.JMSMapMessage; -import org.apache.qpid.client.message.JMSTextMessage; -import org.apache.qpid.client.message.TestMessageHelper; - -import javax.jms.JMSException; - -public class TextMessageTest extends TestCase -{ - public void testTextOnConstruction() throws Exception - { - JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); - tm.setText("pies"); - String val = tm.getText(); - assertEquals(val, "pies"); - } - - public void testClearBody() throws Exception - { - JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); - tm.setText("pies"); - tm.clearBody(); - String val = tm.getText(); - assertNull(val); - tm.setText("Banana"); - val = tm.getText(); - assertEquals(val, "Banana"); - } - - - public void testBooleanPropertyLookup() - { - try - { - JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); - - tm.setBooleanProperty("value", true); - Assert.assertEquals(true, tm.getBooleanProperty("value")); - Assert.assertEquals("true", tm.getStringProperty("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testBytePropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setByteProperty("value", Byte.MAX_VALUE); - - Assert.assertEquals(Byte.MAX_VALUE, mm.getByteProperty("value")); - Assert.assertEquals((short) Byte.MAX_VALUE, mm.getShortProperty("value")); - Assert.assertEquals(Byte.MAX_VALUE, mm.getIntProperty("value")); - Assert.assertEquals((long) Byte.MAX_VALUE, mm.getLongProperty("value")); - Assert.assertEquals("" + Byte.MAX_VALUE, mm.getStringProperty("value")); - - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testShortPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setShortProperty("value", Short.MAX_VALUE); - Assert.assertEquals(Short.MAX_VALUE, mm.getShortProperty("value")); - Assert.assertEquals((int) Short.MAX_VALUE, mm.getIntProperty("value")); - Assert.assertEquals((long) Short.MAX_VALUE, mm.getLongProperty("value")); - Assert.assertEquals("" + Short.MAX_VALUE, mm.getStringProperty("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testDoublePropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setDoubleProperty("value", Double.MAX_VALUE); - Assert.assertEquals(Double.MAX_VALUE, mm.getDoubleProperty("value"), 0d); - Assert.assertEquals("" + Double.MAX_VALUE, mm.getStringProperty("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testFloatPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setFloatProperty("value", Float.MAX_VALUE); - Assert.assertEquals(Float.MAX_VALUE, mm.getFloatProperty("value"), 0f); - Assert.assertEquals(Double.valueOf(Float.MAX_VALUE), mm.getDoubleProperty("value"), 0d); - Assert.assertEquals("" + Float.MAX_VALUE, mm.getStringProperty("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testIntPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setIntProperty("value", Integer.MAX_VALUE); - Assert.assertEquals(Integer.MAX_VALUE, mm.getIntProperty("value")); - Assert.assertEquals((long) Integer.MAX_VALUE, mm.getLongProperty("value")); - Assert.assertEquals("" + Integer.MAX_VALUE, mm.getStringProperty("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testLongPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.setLongProperty("value", Long.MAX_VALUE); - Assert.assertEquals(Long.MAX_VALUE, mm.getLongProperty("value")); - Assert.assertEquals("" + Long.MAX_VALUE, mm.getStringProperty("value")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - - // Failed Lookups - - public void testFailedBooleanPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - Assert.assertEquals(false, mm.getBooleanProperty("int")); - } - catch (JMSException e) - { - Assert.fail("JMSException received." + e); - } - } - - public void testFailedBytePropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getByteProperty("random"); - Assert.fail("NumberFormatException expected"); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - - } - - public void testFailedDoublePropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getDoubleProperty("random"); - Assert.fail("NullPointerException should be received."); - } - catch (NullPointerException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedFloatPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getFloatProperty("random"); - Assert.fail("NullPointerException should be received."); - } - catch (NullPointerException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedIntPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getIntProperty("random"); - Assert.fail("NumberFormatException should be received."); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedLongPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getLongProperty("random"); - Assert.fail("NumberFormatException should be received."); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - public void testFailedShortPropertyLookup() - { - try - { - JMSMapMessage mm = TestMessageHelper.newJMSMapMessage(); - mm.getShortProperty("random"); - Assert.fail("NumberFormatException should be received."); - } - catch (NumberFormatException e) - { - //normal execution - } - catch (JMSException e) - { - Assert.fail("JMSException received:" + e); - } - } - - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(TextMessageTest.class); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/MessageConverterTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/MessageConverterTest.java deleted file mode 100644 index 4607755767..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/MessageConverterTest.java +++ /dev/null @@ -1,151 +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.test.unit.message; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.Message; -import javax.jms.TextMessage; - -import junit.framework.TestCase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQSession; -import org.apache.qpid.client.MockAMQConnection; -import org.apache.qpid.client.message.AMQMessageDelegateFactory; -import org.apache.qpid.client.message.AbstractJMSMessage; -import org.apache.qpid.client.message.JMSMapMessage; -import org.apache.qpid.client.message.JMSTextMessage; -import org.apache.qpid.client.message.MessageConverter; -import org.apache.qpid.exchange.ExchangeDefaults; - - -public class MessageConverterTest extends TestCase -{ - private static final Logger _logger = LoggerFactory.getLogger(MessageConverterTest.class); - public static final String JMS_CORR_ID = "QPIDID_01"; - public static final int JMS_DELIV_MODE = 1; - public static final String JMS_TYPE = "test.jms.type"; - public static final Destination JMS_REPLY_TO = new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME,"my.replyto"); - - protected JMSTextMessage testTextMessage; - - protected JMSMapMessage testMapMessage; - private AMQConnection _connection; - private AMQSession _session; - - - protected void setUp() throws Exception - { - super.setUp(); - - _connection = new MockAMQConnection("amqp://guest:guest@client/test?brokerlist='tcp://localhost:1'"); - _session = new TestAMQSession(_connection); - - testTextMessage = new JMSTextMessage(AMQMessageDelegateFactory.FACTORY_0_8); - - //Set Message Text - testTextMessage.setText("testTextMessage text"); - setMessageProperties(testTextMessage); - - testMapMessage = new JMSMapMessage(AMQMessageDelegateFactory.FACTORY_0_8); - testMapMessage.setString("testMapString", "testMapStringValue"); - testMapMessage.setDouble("testMapDouble", Double.MAX_VALUE); - } - - public void testSetProperties() throws Exception - { - AbstractJMSMessage newMessage = new MessageConverter(_session, (TextMessage) testTextMessage).getConvertedMessage(); - mesagePropertiesTest(testTextMessage, newMessage); - } - - public void testJMSTextMessageConversion() throws Exception - { - AbstractJMSMessage newMessage = new MessageConverter(_session, (TextMessage) testTextMessage).getConvertedMessage(); - assertEquals("Converted message text mismatch", ((JMSTextMessage) newMessage).getText(), testTextMessage.getText()); - } - - public void testJMSMapMessageConversion() throws Exception - { - AbstractJMSMessage newMessage = new MessageConverter(_session, (MapMessage) testMapMessage).getConvertedMessage(); - assertEquals("Converted map message String mismatch", ((JMSMapMessage) newMessage).getString("testMapString"), - testMapMessage.getString("testMapString")); - assertEquals("Converted map message Double mismatch", ((JMSMapMessage) newMessage).getDouble("testMapDouble"), - testMapMessage.getDouble("testMapDouble")); - - } - - public void testMessageConversion() throws Exception - { - Message newMessage = new NonQpidMessage(); - setMessageProperties(newMessage); - mesagePropertiesTest(testTextMessage, newMessage); - } - - private void setMessageProperties(Message message) throws JMSException - { - message.setJMSCorrelationID(JMS_CORR_ID); - message.setJMSDeliveryMode(JMS_DELIV_MODE); - message.setJMSType(JMS_TYPE); - message.setJMSReplyTo(JMS_REPLY_TO); - - //Add non-JMS properties - message.setStringProperty("testProp1", "testValue1"); - message.setDoubleProperty("testProp2", Double.MIN_VALUE); - } - - - private void mesagePropertiesTest(Message expectedMessage, Message actualMessage) - { - try - { - //check JMS prop values on newMessage match - assertEquals("JMS Correlation ID mismatch", expectedMessage.getJMSCorrelationID(), actualMessage.getJMSCorrelationID()); - assertEquals("JMS Delivery mode mismatch", expectedMessage.getJMSDeliveryMode(), actualMessage.getJMSDeliveryMode()); - assertEquals("JMS Type mismatch", expectedMessage.getJMSType(), actualMessage.getJMSType()); - assertEquals("JMS Reply To mismatch", expectedMessage.getJMSReplyTo(), actualMessage.getJMSReplyTo()); - - //check non-JMS standard props ok too - assertEquals("Test String prop value mismatch", expectedMessage.getStringProperty("testProp1"), - actualMessage.getStringProperty("testProp1")); - - assertEquals("Test Double prop value mismatch", expectedMessage.getDoubleProperty("testProp2"), - actualMessage.getDoubleProperty("testProp2")); - } - catch (JMSException e) - { - _logger.error("An error occured testing the property values", e); - fail("An error occured testing the property values" + e.getCause()); - } - } - - protected void tearDown() throws Exception - { - super.tearDown(); - testTextMessage = null; - } - - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java deleted file mode 100644 index d93ba23a25..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java +++ /dev/null @@ -1,419 +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.test.unit.message; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageFormatException; -import java.util.Enumeration; -import java.util.Hashtable; - -public class NonQpidMessage implements Message -{ - private String _JMSMessageID; - private long _JMSTimestamp; - private byte[] _JMSCorrelationIDAsBytes; - private String _JMSCorrelationID; - private Destination _JMSReplyTo; - private Destination _JMSDestination; - private int _JMSDeliveryMode; - private boolean _JMSRedelivered; - private String _JMSType; - private long _JMSExpiration; - private int _JMSPriority; - private Hashtable _properties; - - public NonQpidMessage() - { - _properties = new Hashtable(); - _JMSPriority = javax.jms.Message.DEFAULT_PRIORITY; - _JMSDeliveryMode = javax.jms.Message.DEFAULT_DELIVERY_MODE; - } - - public String getJMSMessageID() throws JMSException - { - return _JMSMessageID; - } - - public void setJMSMessageID(String string) throws JMSException - { - _JMSMessageID = string; - } - - public long getJMSTimestamp() throws JMSException - { - return _JMSTimestamp; - } - - public void setJMSTimestamp(long l) throws JMSException - { - _JMSTimestamp = l; - } - - public byte[] getJMSCorrelationIDAsBytes() throws JMSException - { - return _JMSCorrelationIDAsBytes; - } - - public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException - { - _JMSCorrelationIDAsBytes = bytes; - } - - public void setJMSCorrelationID(String string) throws JMSException - { - _JMSCorrelationID = string; - } - - public String getJMSCorrelationID() throws JMSException - { - return _JMSCorrelationID; - } - - public Destination getJMSReplyTo() throws JMSException - { - return _JMSReplyTo; - } - - public void setJMSReplyTo(Destination destination) throws JMSException - { - _JMSReplyTo = destination; - } - - public Destination getJMSDestination() throws JMSException - { - return _JMSDestination; - } - - public void setJMSDestination(Destination destination) throws JMSException - { - _JMSDestination = destination; - } - - public int getJMSDeliveryMode() throws JMSException - { - return _JMSDeliveryMode; - } - - public void setJMSDeliveryMode(int i) throws JMSException - { - _JMSDeliveryMode = i; - } - - public boolean getJMSRedelivered() throws JMSException - { - return _JMSRedelivered; - } - - public void setJMSRedelivered(boolean b) throws JMSException - { - _JMSRedelivered = b; - } - - public String getJMSType() throws JMSException - { - return _JMSType; - } - - public void setJMSType(String string) throws JMSException - { - _JMSType = string; - } - - public long getJMSExpiration() throws JMSException - { - return _JMSExpiration; - } - - public void setJMSExpiration(long l) throws JMSException - { - _JMSExpiration = l; - } - - public int getJMSPriority() throws JMSException - { - return _JMSPriority; - } - - public void setJMSPriority(int i) throws JMSException - { - _JMSPriority = i; - } - - public void clearProperties() throws JMSException - { - _properties.clear(); - } - - public boolean propertyExists(String string) throws JMSException - { - return _properties.containsKey(string); - } - - public boolean getBooleanProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Boolean) - { - return (Boolean) o; - } - else - { - return Boolean.valueOf(null); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public byte getByteProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Byte) - { - return (Byte) o; - } - else - { - return Byte.valueOf(null); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public short getShortProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Short) - { - return (Short) o; - } - else - { - return Short.valueOf(null); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public int getIntProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Integer) - { - return (Integer) o; - } - else - { - return Integer.valueOf(null); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public long getLongProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Long) - { - return (Long) o; - } - else - { - return Long.valueOf(null); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public float getFloatProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Float) - { - return (Float) o; - } - else if(o instanceof String) - { - return Float.valueOf((String)o); - } - else if(o == null) - { - throw new NullPointerException("No such property: " + string); - } - else - { - throw new MessageFormatException("getFloatProperty(\""+string+"\") failed as value is not a float: " + o); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public double getDoubleProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Double) - { - return (Double) o; - } - else - { - return getFloatProperty(string); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public String getStringProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof String) - { - return (String) o; - } - else - { - return null; - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public Object getObjectProperty(String string) throws JMSException - { - if (propertyExists(string)) - { - Object o = _properties.get(string); - if (o instanceof Boolean) - { - return (Boolean) o; - } - else - { - return Boolean.valueOf(null); - } - } - else - { - throw new JMSException("property does not exist: " + string); - } - } - - public Enumeration getPropertyNames() throws JMSException - { - return _properties.keys(); - } - - public void setBooleanProperty(String string, boolean b) throws JMSException - { - _properties.put(string, b); - } - - public void setByteProperty(String string, byte b) throws JMSException - { - _properties.put(string, b); - } - - public void setShortProperty(String string, short i) throws JMSException - { - _properties.put(string, i); - } - - public void setIntProperty(String string, int i) throws JMSException - { - _properties.put(string, i); - } - - public void setLongProperty(String string, long l) throws JMSException - { - _properties.put(string, l); - } - - public void setFloatProperty(String string, float v) throws JMSException - { - _properties.put(string, v); - } - - public void setDoubleProperty(String string, double v) throws JMSException - { - _properties.put(string, v); - } - - public void setStringProperty(String string, String string1) throws JMSException - { - _properties.put(string, string1); - } - - public void setObjectProperty(String string, Object object) throws JMSException - { - _properties.put(string, object); - } - - public void acknowledge() throws JMSException - { - - } - - public void clearBody() throws JMSException - { - - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java deleted file mode 100644 index 4ad9069ba0..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java +++ /dev/null @@ -1,208 +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.test.unit.message; - -import org.apache.qpid.AMQException; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQDestination; -import org.apache.qpid.client.AMQSession_0_8; -import org.apache.qpid.client.BasicMessageConsumer_0_8; -import org.apache.qpid.client.BasicMessageProducer_0_8; -import org.apache.qpid.client.failover.FailoverException; -import org.apache.qpid.client.message.AMQMessageDelegateFactory; -import org.apache.qpid.client.protocol.AMQProtocolHandler; -import org.apache.qpid.framing.AMQShortString; -import org.apache.qpid.framing.FieldTable; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.TemporaryQueue; -import javax.jms.Topic; -import javax.jms.TopicSubscriber; -import java.util.Map; - -public class TestAMQSession extends AMQSession_0_8 -{ - - public TestAMQSession(AMQConnection connection) - { - super(connection, 0, false, AUTO_ACKNOWLEDGE, null, 0, 0); - } - - public void acknowledgeMessage(long deliveryTag, boolean multiple) - { - - } - - public void sendQueueBind(AMQShortString queueName, AMQShortString routingKey, FieldTable arguments, - AMQShortString exchangeName, AMQDestination destination, - boolean nowait) throws AMQException, FailoverException - { - - } - - public void sendClose(long timeout) throws AMQException, FailoverException - { - - } - - public void commitImpl() throws AMQException, FailoverException - { - - } - - public void acknowledgeImpl() - { - - } - - public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException - { - return null; - } - - public void sendCreateQueue(AMQShortString name, boolean autoDelete, boolean durable, boolean exclusive, Map<String, Object> arguments) throws AMQException, FailoverException - { - - } - - public TemporaryQueue createTemporaryQueue() throws JMSException - { - return null; - } - - public void sendRecover() throws AMQException, FailoverException - { - - } - - public void rejectMessage(long deliveryTag, boolean requeue) - { - - } - - public void releaseForRollback() - { - - } - - public void sendRollback() throws AMQException, FailoverException - { - - } - - public BasicMessageConsumer_0_8 createMessageConsumer(AMQDestination destination, int prefetchHigh, int prefetchLow, boolean noLocal, boolean exclusive, String selector, FieldTable arguments, boolean noConsume, boolean autoClose) throws JMSException - { - return null; - } - - public boolean isQueueBound(AMQShortString exchangeName, AMQShortString queueName, AMQShortString routingKey) throws JMSException - { - return false; - } - - public boolean isQueueBound(AMQDestination destination) throws JMSException - { - return false; - } - - public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, boolean nowait, int tag) throws AMQException, FailoverException - { - - } - - public BasicMessageProducer_0_8 createMessageProducer(Destination destination, boolean mandatory, boolean immediate, long producerId) - { - return null; - } - - protected Long requestQueueDepth(AMQDestination amqd) throws AMQException, FailoverException - { - return null; - } - - public void sendExchangeDeclare(AMQShortString name, AMQShortString type, boolean nowait, boolean durable, boolean autoDelete, boolean internal) throws AMQException, FailoverException - { - - } - - public void sendQueueDeclare(AMQDestination amqd, AMQProtocolHandler protocolHandler, - boolean passive) throws AMQException, FailoverException - { - - } - - public void sendQueueDelete(AMQShortString queueName) throws AMQException, FailoverException - { - - } - - public void sendSuspendChannel(boolean suspend) throws AMQException, FailoverException - { - - } - - protected boolean tagLE(long tag1, long tag2) - { - return false; - } - - protected boolean updateRollbackMark(long current, long deliveryTag) - { - return false; - } - - public AMQMessageDelegateFactory getMessageDelegateFactory() - { - return AMQMessageDelegateFactory.FACTORY_0_8; - } - - protected Object getFailoverMutex() - { - return this; - } - - public void checkNotClosed() - { - - } - - public void sync() - { - } - - @Override - protected void flushAcknowledgments() - { - } - - public boolean isQueueBound(String exchangeName, String queueName, - String bindingKey, Map<String, Object> args) throws JMSException - { - return false; - } - - @Override - public AMQException getLastException() - { - return null; - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties deleted file mode 100644 index 2fd961a078..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/tests.properties +++ /dev/null @@ -1,45 +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. - - -java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory - -# use the following property to configure the default connector -#java.naming.provider.url - ignored. - -# register some connection factories -# connectionfactory.[jndiname] = [ConnectionURL] -connectionfactory.local = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5672' -#qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672 - - -# register some queues in JNDI using the form -# queue.[jndiName] = [physicalName] -queue.MyQueue = example.MyQueue -queue.queue = example.queue -queue.xaQueue = xaQueue - -# register some topics in JNDI using the form -# topic.[jndiName] = [physicalName] -#topic.ibmStocks = stocks.nyse.ibm -topic.xaTopic = xaTopic -topic.durableSubscriberTopic = durableSubscriberTopic - -# Register an AMQP destination in JNDI -# NOTE: Qpid currently only supports direct,topics and headers -# destination.[jniName] = [BindingURL] -#destination.direct = direct://amq.direct//directQueue |
