Author: slaws
Date: Tue Oct 9 06:53:58 2007
New Revision: 583171
URL: http://svn.apache.org/viewvc?rev=583171&view=rev
Log:
TUSCANY-1836
Make JMS binding conform to spec when creating JMS queues
Thanks to Mark Combellack for the patch
Added:
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactory.java
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceQueueCreateModeTestCase.java
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceQueueCreateModeTestCase.java
Modified:
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
Modified:
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java?rev=583171&r1=583170&r2=583171&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java
Tue Oct 9 06:53:58 2007
@@ -67,7 +67,7 @@
// </destination>?
private String destinationName =
JMSBindingConstants.DEFAULT_DESTINATION_NAME;
private String destinationType =
JMSBindingConstants.DESTINATION_TYPE_QUEUE;
- private String destinationCreate =
JMSBindingConstants.CREATE_NEVER;
+ private String destinationCreate =
JMSBindingConstants.CREATE_IF_NOT_EXIST;
//
// <connectionFactory name="xs:anyURI" Not yet implemented
in binding
// create="string"?> Not yet implemented
in binding
@@ -75,7 +75,7 @@
// type="NMTOKEN">* Not yet implemented
in binding
// </connectionFactory>?
private String connectionFactoryName =
JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME;
- private String connectionFactoryCreate =
JMSBindingConstants.CREATE_NEVER;
+ private String connectionFactoryCreate =
JMSBindingConstants.CREATE_IF_NOT_EXIST;
//
// <activationSpec name="xs:anyURI" Not yet implemented
in binding
// create="string"?> Not yet implemented
in binding
@@ -94,7 +94,7 @@
// </destination>?
private String responseDestinationName =
JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME;
private String responseDestinationType =
JMSBindingConstants.DESTINATION_TYPE_QUEUE;
- private String responseDestinationCreate =
JMSBindingConstants.CREATE_NEVER;
+ private String responseDestinationCreate =
JMSBindingConstants.CREATE_IF_NOT_EXIST;
//
// <connectionFactory name="xs:anyURI" Not yet implemented
in binding
// create="string"?> Not yet implemented
in binding
@@ -102,7 +102,7 @@
// type="NMTOKEN">* Not yet implemented
in binding
// </connectionFactory>?
private String responseConnectionFactoryName =
JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME;
- private String responseConnectionFactoryCreate =
JMSBindingConstants.CREATE_NEVER;
+ private String responseConnectionFactoryCreate =
JMSBindingConstants.CREATE_IF_NOT_EXIST;
//
// <activationSpec name="xs:anyURI" Not yet implemented
in binding
// create="string"?> Not yet implemented
in binding
@@ -483,7 +483,7 @@
* No desitnation name has been set so make sure that
* the runtime is able to create one automatically
*/
- setDestinationCreate(JMSBindingConstants.CREATE_ALLWAYS);
+ setDestinationCreate(JMSBindingConstants.CREATE_IF_NOT_EXIST);
}
if
(getResponseDestinationName().equals(JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME)){
@@ -491,7 +491,7 @@
* No repsonse desitination name has been set so make sure that
* the runtime is able to create one automatically
*/
- setResponseDestinationCreate(JMSBindingConstants.CREATE_ALLWAYS);
+
setResponseDestinationCreate(JMSBindingConstants.CREATE_IF_NOT_EXIST);
}
Modified:
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java?rev=583171&r1=583170&r2=583171&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
Tue Oct 9 06:53:58 2007
@@ -43,8 +43,9 @@
public final static String DESTINATION_TYPE_TOPIC = "topic"; //1
public final static List<String> VALID_DESTINATION_TYPES =
Arrays.asList(new String[] {DESTINATION_TYPE_QUEUE,
DESTINATION_TYPE_TOPIC});
- public final static String CREATE_ALLWAYS = "always";
+ public final static String CREATE_ALWAYS = "always";
public final static String CREATE_NEVER = "never";
+ public final static String CREATE_IF_NOT_EXIST =
"ifnotexist";
public final static String DEFAULT_DESTINATION_NAME =
"NODESTINATION";
public final static String DEFAULT_RESPONSE_DESTINATION_NAME =
"NORESPONSEDESTINATION";
public final static String DEFAULT_CONNECTION_FACTORY_NAME =
"ConnectionFactory";
Modified:
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java?rev=583171&r1=583170&r2=583171&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java
Tue Oct 9 06:53:58 2007
@@ -62,39 +62,116 @@
requestMessageProcessor = jmsBinding.getRequestMessageProcessor();
responseMessageProcessor = jmsBinding.getResponseMessageProcessor();
try {
- requestDest =
jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName());
-
- if (requestDest == null){
- if
(jmsBinding.getDestinationCreate().equals(JMSBindingConstants.CREATE_ALLWAYS)) {
- requestDest =
jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
- } else {
- throw new JMSBindingException("JMS Destination " +
-
jmsBinding.getDestinationName() +
- " not found while
registering binding " +
- jmsBinding.getName() +
- " invoker");
- }
- }
-
- replyDest =
jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName());
-
- if (replyDest == null){
- if
(jmsBinding.getResponseDestinationCreate().equals(JMSBindingConstants.CREATE_ALLWAYS))
{
- replyDest =
jmsResourceFactory.createDestination(jmsBinding.getResponseDestinationName());
- } else {
- throw new JMSBindingException("JMS Response Destination "
+
-
jmsBinding.getDestinationName() +
- " not found while
registering binding " +
- jmsBinding.getName() +
- " invoker");
- }
- }
+ requestDest = lookupDestination();
+ replyDest = lookupResponseDestination();
} catch (NamingException e) {
throw new JMSBindingException(e);
}
}
+ /**
+ * Looks up the Destination Queue for the JMS Binding
+ *
+ * @return The Destination Queue
+ * @throws NamingException Failed to lookup Destination Queue
+ * @throws JMSBindingException Failed to lookup Destination Queue
+ *
+ * @see #lookupDestinationQueue(boolean)
+ */
+ private Destination lookupDestination() throws NamingException,
JMSBindingException {
+ return lookupDestinationQueue(false);
+ }
+
+ /**
+ * Looks up the Destination Response Queue for the JMS Binding
+ *
+ * @return The Destination Response Queue
+ * @throws NamingException Failed to lookup Destination Response Queue
+ * @throws JMSBindingException Failed to lookup Destination Response Queue
+ *
+ * @see #lookupDestinationQueue(boolean)
+ */
+ private Destination lookupResponseDestination() throws NamingException,
JMSBindingException {
+ return lookupDestinationQueue(true);
+ }
+
+ /**
+ * Looks up the Destination Queue for the JMS Binding.
+ * <p>
+ * What happens in the look up will depend on the create mode specified
for the JMS Binding:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the
queue already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is
not an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue
does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ * <p>
+ * @param isReponseQueue <code>true</code> if we are creating a response
queue. <code>false</code> if we are
+ * creating a request queue
+ * @return The Destination queue.
+ * @throws NamingException Failed to lookup JMS queue
+ * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause
is that the JMS queue's current
+ * existance/non-existance is not compatible with the create mode
specified on the binding
+ */
+ private Destination lookupDestinationQueue(boolean isReponseQueue) throws
NamingException, JMSBindingException {
+ String queueName;
+ String queueType;
+ String qCreateMode;
+ if (isReponseQueue) {
+ queueName = jmsBinding.getResponseDestinationName();
+ queueType = "JMS Response Destination ";
+ qCreateMode = jmsBinding.getResponseDestinationCreate();
+ } else {
+ queueName = jmsBinding.getDestinationName();
+ queueType = "JMS Destination ";
+ qCreateMode = jmsBinding.getDestinationCreate();
+ }
+
+ Destination dest =
jmsResourceFactory.lookupDestination(queueName);
+
+ if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
+ // In this mode, the queue must not already exist as we are
creating it
+ if (dest != null) {
+ throw new JMSBindingException(queueType +
+ queueName +
+ " already exists but has create mode of \"" +
qCreateMode + "\" while registering binding " +
+ jmsBinding.getName() +
+ " invoker");
+ }
+ // Create the queue
+ dest = jmsResourceFactory.createDestination(queueName);
+
+ } else if
(qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
+ // In this mode, the queue may nor may not exist. It will be
created if it does not exist
+ if (dest == null) {
+ dest = jmsResourceFactory.createDestination(queueName);
+ }
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
+ // In this mode, the queue must have already been created.
+ if (dest == null) {
+ throw new JMSBindingException(queueType +
+ queueName +
+ " not found but create mode of \"" + qCreateMode + "\"
while registering binding " +
+ jmsBinding.getName() +
+ " invoker");
+ }
+ }
+
+
+ // Make sure we ended up with a queue
+ if (dest == null) {
+ throw new JMSBindingException(queueType +
+ queueName +
+ " not found with create mode of \"" + qCreateMode + "\"
while registering binding " +
+ jmsBinding.getName() +
+ " invoker");
+ }
+
+ return dest;
+ }
+
public org.apache.tuscany.sca.invocation.Message
invoke(org.apache.tuscany.sca.invocation.Message msg) {
try {
Object resp = invokeTarget((Object[])msg.getBody(), (short)0);
Modified:
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java?rev=583171&r1=583170&r2=583171&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
Tue Oct 9 06:53:58 2007
@@ -94,20 +94,8 @@
private void registerListerner() throws NamingException, JMSException {
Session session = jmsResourceFactory.createSession();
- Destination destination =
jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName());
-
- if (destination == null){
- if
(jmsBinding.getDestinationCreate().equals(JMSBindingConstants.CREATE_ALLWAYS)) {
- destination =
jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
- } else {
- throw new JMSBindingException("JMS Destination " +
- jmsBinding.getDestinationName() +
- "not found while registering
service " +
- service.getName() +
- " listener");
- }
- }
-
+ Destination destination = lookupDestinationQueue();
+
consumer = session.createConsumer(destination);
// TODO - We assume the target is a Java class here!!!
@@ -118,5 +106,67 @@
jmsResourceFactory.startConnection();
+ }
+
+ /**
+ * Looks up the Destination Queue for the JMS Binding.
+ * <p>
+ * What happens in the look up will depend on the create mode specified
for the JMS Binding:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the
queue already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is
not an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue
does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ * <p>
+ * @return The Destination queue.
+ * @throws NamingException Failed to lookup JMS queue
+ * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause
is that the JMS queue's current
+ * existance/non-existance is not compatible with the create mode
specified on the binding
+ */
+ private Destination lookupDestinationQueue() throws NamingException,
JMSBindingException {
+ Destination destination =
jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName());
+
+ String qCreateMode = jmsBinding.getDestinationCreate();
+ if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
+ // In this mode, the queue must not already exist as we are
creating it
+ if (destination != null) {
+ throw new JMSBindingException("JMS Destination " +
+ jmsBinding.getDestinationName() +
+ " already exists but has create mode of \"" +
qCreateMode + "\" while registering service " +
+ service.getName() +
+ " listener");
+ }
+
+ // Create the queue
+ destination =
jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
+
+ } else if
(qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
+ // In this mode, the queue may nor may not exist. It will be
created if it does not exist
+ if (destination == null) {
+ destination =
jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
+ }
+
+ } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
+ // In this mode, the queue must have already been created.
+ if (destination == null) {
+ throw new JMSBindingException("JMS Destination " +
+ jmsBinding.getDestinationName() +
+ " not found but create mode of \"" + qCreateMode + "\"
while registering service " +
+ service.getName() +
+ " listener");
+ }
+ }
+
+ // Make sure we ended up with a queue
+ if (destination == null) {
+ throw new JMSBindingException("JMS Destination " +
+ jmsBinding.getDestinationName() +
+ " not found with create mode of \"" + qCreateMode + "\"
while registering service " +
+ service.getName() +
+ " listener");
+ }
+
+ return destination;
}
}
Added:
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactory.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactory.java?rev=583171&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactory.java
(added)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactory.java
Tue Oct 9 06:53:58 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.tuscany.sca.binding.jms.mock;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.provider.JMSResourceFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Mock JMSResourceFactory base class for testing purposes.
+ */
+public abstract class MockJMSResourceFactory implements JMSResourceFactory {
+
+ /**
+ * Throws UnsupportedOperationException
+ */
+ public void closeConnection() throws JMSException, NamingException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Creates a Mock Destination
+ *
+ * @param jndiName Ignored
+ * @return A Mock Destination
+ */
+ public Destination createDestination(String jndiName) throws
NamingException {
+ final Destination d = EasyMock.createMock(Destination.class);
+ EasyMock.replay(d);
+ return d;
+ }
+
+ /**
+ * Creates a Mock Session.
+ *
+ * @return A Mock Session
+ */
+ public Session createSession() throws JMSException, NamingException {
+ final Session session = EasyMock.createMock(Session.class);
+ final MessageConsumer consumer =
EasyMock.createMock(MessageConsumer.class);
+ final MessageListener listener =
EasyMock.createMock(MessageListener.class);
+ EasyMock.expect(session.createConsumer((Destination)
EasyMock.anyObject())).andReturn(consumer);
+ consumer.setMessageListener((MessageListener) EasyMock.anyObject());
+ EasyMock.replay(session);
+ EasyMock.replay(consumer);
+ EasyMock.replay(listener);
+ return session;
+ }
+
+ /**
+ * Throws UnsupportedOperationException
+ */
+ public Connection getConnection() throws NamingException, JMSException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Throws UnsupportedOperationException
+ *
+ * @param jndiName Ignored
+ */
+ public Destination lookupDestination(String jndiName) throws
NamingException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Does nothing
+ */
+ public void startConnection() throws JMSException, NamingException {
+ }
+}
Added:
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java?rev=583171&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java
(added)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java
Tue Oct 9 06:53:58 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.tuscany.sca.binding.jms.mock;
+
+import javax.jms.Destination;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+import org.easymock.EasyMock;
+
+/**
+ * This mock JMSResourceFactory will create a mock Destination when the
+ * lookupDestination() method is called
+ */
+public class MockJMSResourceFactoryQueueExist extends MockJMSResourceFactory
+{
+ /**
+ * Constructor
+ *
+ * @param jmsBinding Ignored
+ */
+ public MockJMSResourceFactoryQueueExist(JMSBinding jmsBinding) {
+ }
+
+ /**
+ * Return a mock Destination object
+ */
+ public Destination lookupDestination(String jndiName) throws
NamingException {
+ final Destination d = EasyMock.createMock(Destination.class);
+ EasyMock.replay(d);
+ return d;
+ }
+}
Added:
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java?rev=583171&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java
(added)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java
Tue Oct 9 06:53:58 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.tuscany.sca.binding.jms.mock;
+
+import javax.jms.Destination;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+
+/**
+ * This mock JMSResourceFactory will always return <code>null</code> when the
+ * lookupDestination() method is called
+ */
+public class MockJMSResourceFactoryQueueNotExist extends
MockJMSResourceFactory
+{
+ /**
+ * Constructor
+ *
+ * @param jmsBinding Ignored
+ */
+ public MockJMSResourceFactoryQueueNotExist(JMSBinding jmsBinding) {
+ }
+
+ /**
+ * Always returns null
+ */
+ public Destination lookupDestination(String jndiName) throws
NamingException {
+ return null;
+ }
+}
Added:
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceQueueCreateModeTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceQueueCreateModeTestCase.java?rev=583171&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceQueueCreateModeTestCase.java
(added)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceQueueCreateModeTestCase.java
Tue Oct 9 06:53:58 2007
@@ -0,0 +1,304 @@
+/*
+ * 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.tuscany.sca.binding.jms.provider;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
+import
org.apache.tuscany.sca.binding.jms.mock.MockJMSResourceFactoryQueueExist;
+import
org.apache.tuscany.sca.binding.jms.mock.MockJMSResourceFactoryQueueNotExist;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.junit.Test;
+
+/**
+ * This unit test tests various combinations of the JMS Binding create modes
for both request and response
+ * queues.
+ * <p>
+ * The SCA JMS Binding specification lists 3 create modes:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the queue
already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is not
an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue
does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ */
+public class JMSBindingReferenceQueueCreateModeTestCase {
+
+ /**
+ * Test creating a request queue in "never" mode
+ * where the queue does not exist.
+ * We are expecting an exception
+ */
+ @Test
+ public void testRequestCreateNeverQueueNotExist() {
+ String requestCreateMode = "never";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = false;
+ boolean expectingRequestException = true;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a request queue in "never" mode
+ * where the queue exists.
+ * We are expecting this to work
+ */
+ @Test
+ public void testRequestCreateNeverQueueExists() {
+ String requestCreateMode = "never";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = true;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+
+ /**
+ * Test creating a request queue in "ifnotexist" mode
+ * where the queue does not exist.
+ * We are expecting this to work
+ */
+ @Test
+ public void testRequestCreateIfNotExistQueueNotExist() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = false;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a request queue in "ifnotexist" mode
+ * where the queue exists.
+ * We are expecting this to work
+ */
+ @Test
+ public void testRequestCreateIfNotExistQueueExist() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = true;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+
+ /**
+ * Test creating a request queue in "always" mode
+ * where the queue does not exist.
+ * We are expecting this to work
+ */
+ @Test
+ public void testRequestCreateAlwaysQueueNotExist() {
+ String requestCreateMode = "always";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = false;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a request queue in "always" mode
+ * where the queue exists.
+ * We are expecting an exception
+ */
+ @Test
+ public void testRequestCreateAlwaysQueueExists() {
+ String requestCreateMode = "always";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = true;
+ boolean expectingRequestException = true;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a response queue in "never" mode
+ * where the queue does not exist.
+ * We are expecting an exception
+ */
+ @Test
+ public void testResponseCreateNeverQueueNotExist() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "never";
+ boolean preCreateQueue = false;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = true;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a response queue in "never" mode
+ * where the queue exists.
+ * We are expecting this to work
+ */
+ @Test
+ public void testResponseCreateNeverQueueExists() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "never";
+ boolean preCreateQueue = true;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+
+ /**
+ * Test creating a response queue in "ifnotexist" mode
+ * where the queue does not exist.
+ * We are expecting this to work
+ */
+ @Test
+ public void testResponseCreateIfNotExistQueueNotExist() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = false;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a response queue in "ifnotexist" mode
+ * where the queue not exists.
+ * We are expecting this to work
+ */
+ @Test
+ public void testResponseCreateIfNotExistQueueExist() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "ifnotexist";
+ boolean preCreateQueue = true;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+
+ /**
+ * Test creating a response queue in "always" mode
+ * where the queue does not exist.
+ * We are expecting this to work
+ */
+ @Test
+ public void testResponseCreateAlwaysQueueNotExist() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "always";
+ boolean preCreateQueue = false;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = false;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * Test creating a response queue in "always" mode
+ * where the queue exists.
+ * We are expecting an exception
+ */
+ @Test
+ public void testResponseCreateAlwaysQueueExists() {
+ String requestCreateMode = "ifnotexist";
+ String responseCreateMode = "always";
+ boolean preCreateQueue = true;
+ boolean expectingRequestException = false;
+ boolean expectingResponseException = true;
+
+ doTestCase(requestCreateMode, responseCreateMode, preCreateQueue,
expectingRequestException, expectingResponseException);
+ }
+
+ /**
+ * This is the main test method for the various test scenarios for the JMS
Binding.
+ *
+ * @param requestCreateMode The required create mode for the request
destination queue
+ * @param responseCreateMode The required create mode for the response
destination queue
+ * @param preCreateQueue Whether the queue should be pre-created.
+ * @param expectingRequestException true if we are expecting an exception
because the
+ * request queue configuration is invalid; false otherwise
+ * @param expectingResponseException true if we are expecting an exception
because the
+ * request queue configuration is invalid; false otherwise
+ */
+ private void doTestCase(String requestCreateMode, String
responseCreateMode, boolean preCreateQueue,
+ boolean expectingRequestException, boolean
expectingResponseException) {
+ String requestDestinationName = "SomeRequestDestination";
+ String responseDestinationName = "SomeResponseDestination";
+ String jmsBindingName = "MyJMSBinding";
+
+ // Create a JMS Binding with the required test parameters
+ JMSBinding jmsBinding = new JMSBinding();
+ jmsBinding.setDestinationCreate(requestCreateMode);
+ jmsBinding.setResponseDestinationCreate(responseCreateMode);
+ if (preCreateQueue) {
+
jmsBinding.setJmsResourceFactoryName(MockJMSResourceFactoryQueueExist.class.getName());
+ } else {
+
jmsBinding.setJmsResourceFactoryName(MockJMSResourceFactoryQueueNotExist.class.getName());
+ }
+ jmsBinding.setDestinationName(requestDestinationName);
+ jmsBinding.setResponseDestinationName(responseDestinationName);
+ jmsBinding.setName(jmsBindingName);
+
+ // Create the operation
+ Operation operation = new OperationImpl();
+ operation.setName("OperationName");
+
+ // Try and create the JMS Binding Invoker for the JMS Binding
+ try {
+ new JMSBindingInvoker(jmsBinding, operation);
+
+ // Check whether we were expecting an exception
+ if (expectingRequestException || expectingResponseException) {
+ // We were expecting an exception
+ Assert.fail("This binding should have failed as it is
invalid");
+ }
+ } catch (JMSBindingException ex) {
+ // Were we expecting an exception
+ if (!expectingRequestException && !expectingResponseException) {
+ // No we were not expecting an exception
+ Assert.fail("Unexpected exception of " + ex);
+ }
+
+ // Validate that the expected exception has the text we expect
+ if (expectingRequestException) {
+ Assert.assertTrue(ex.getMessage().indexOf("JMS Destination")
!= -1);
+ Assert.assertTrue(ex.getMessage().indexOf(requestCreateMode)
!= -1);
+
Assert.assertTrue(ex.getMessage().indexOf(requestDestinationName) != -1);
+ } else if (expectingResponseException) {
+ Assert.assertTrue(ex.getMessage().indexOf("JMS Response
Destination") != -1);
+ Assert.assertTrue(ex.getMessage().indexOf(responseCreateMode)
!= -1);
+
Assert.assertTrue(ex.getMessage().indexOf(responseDestinationName) != -1);
+ }
+ Assert.assertTrue(ex.getMessage().indexOf("registering binding " +
jmsBindingName + " invoker") != -1);
+ }
+ }
+}
Added:
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceQueueCreateModeTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceQueueCreateModeTestCase.java?rev=583171&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceQueueCreateModeTestCase.java
(added)
+++
incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceQueueCreateModeTestCase.java
Tue Oct 9 06:53:58 2007
@@ -0,0 +1,184 @@
+/*
+ * 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.tuscany.sca.binding.jms.provider;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
+import
org.apache.tuscany.sca.binding.jms.mock.MockJMSResourceFactoryQueueExist;
+import
org.apache.tuscany.sca.binding.jms.mock.MockJMSResourceFactoryQueueNotExist;
+import org.apache.tuscany.sca.core.assembly.RuntimeComponentServiceImpl;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.junit.Test;
+
+/**
+ * This method tests various combinations of the JMS Binding create modes.
+ * <p>
+ * The SCA JMS Binding specification lists 3 create modes:
+ * <ul>
+ * <li>always - the JMS queue is always created. It is an error if the queue
already exists
+ * <li>ifnotexist - the JMS queue is created if it does not exist. It is not
an error if the queue already exists
+ * <li>never - the JMS queue is never created. It is an error if the queue
does not exist
+ * </ul>
+ * See the SCA JMS Binding specification for more information.
+ */
+public class JMSBindingServiceQueueCreateModeTestCase
+{
+ /**
+ * Test creating a queue in "never" mode
+ * where the queue does not exist.
+ * We are expecting an exception
+ */
+ @Test
+ public void testCreateNeverQueueNotExist() {
+ String createMode = "never";
+ boolean preCreateQueue = false;
+ boolean expectingException = true;
+
+ doTestCase(createMode, preCreateQueue, expectingException);
+ }
+
+ /**
+ * Test creating a queue in "never" mode
+ * where the queue exists.
+ * We are expecting this to work
+ */
+ @Test
+ public void testCreateNeverQueueExist() {
+ String createMode = "never";
+ boolean preCreateQueue = true;
+ boolean expectingException = false;
+
+ doTestCase(createMode, preCreateQueue, expectingException);
+ }
+
+ /**
+ * Test creating a queue in "ifnotexist" mode
+ * where the queue does not exist.
+ * We are expecting this to work
+ */
+ @Test
+ public void testCreateIfNotExistQueueNotExist() {
+ String createMode = "ifnotexist";
+ boolean preCreateQueue = false;
+ boolean expectingException = false;
+
+ doTestCase(createMode, preCreateQueue, expectingException);
+ }
+
+ /**
+ * Test creating a queue in "ifnotexist" mode
+ * where the queue exists.
+ * We are expecting this to work
+ */
+ @Test
+ public void testCreateIfNotExistQueueExist() {
+ String createMode = "ifnotexist";
+ boolean preCreateQueue = true;
+ boolean expectingException = false;
+
+ doTestCase(createMode, preCreateQueue, expectingException);
+ }
+
+ /**
+ * Test creating a queue in "always" mode
+ * where the queue does not exist.
+ * We are expecting this to work
+ */
+ @Test
+ public void testCreateAlwaysQueueNotExist() {
+ String createMode = "always";
+ boolean preCreateQueue = false;
+ boolean expectingException = false;
+
+ doTestCase(createMode, preCreateQueue, expectingException);
+ }
+
+ /**
+ * Test creating a queue in "always" mode
+ * where the queue exists.
+ * We are expecting an exception
+ */
+ @Test
+ public void testCreateAlwaysQueueExist() {
+ String createMode = "always";
+ boolean preCreateQueue = true;
+ boolean expectingException = true;
+
+ doTestCase(createMode, preCreateQueue, expectingException);
+ }
+
+ /**
+ * This is the main test method for the various test scenarios for the JMS
Binding.
+ *
+ * @param createMode The required create mode for the destination queue
+ * @param preCreateQueue Whether the queue should be pre-created.
+ * @param expectingException true if test should throw an exception
+ */
+ private void doTestCase(String createMode, boolean preCreateQueue,
+ boolean expectingException) {
+ String destinationName = "SomeDestination";
+ String jmsBindingName = "MyJMSBinding";
+ String serviceName = "MyServiceName";
+
+ // Create a JMS Binding with the required test parameters
+ JMSBinding jmsBinding = new JMSBinding();
+ jmsBinding.setDestinationCreate(createMode);
+ if (preCreateQueue) {
+
jmsBinding.setJmsResourceFactoryName(MockJMSResourceFactoryQueueExist.class.getName());
+ } else {
+
jmsBinding.setJmsResourceFactoryName(MockJMSResourceFactoryQueueNotExist.class.getName());
+ }
+ jmsBinding.setDestinationName(destinationName);
+ jmsBinding.setName(jmsBindingName);
+
+ RuntimeComponentService service = new RuntimeComponentServiceImpl();
+ service.setName(serviceName);
+
+ // Try and create the JMS Binding Service for the JMS Binding
+ try {
+ JMSBindingServiceBindingProvider jmsService = new
JMSBindingServiceBindingProvider(null, service, jmsBinding);
+ jmsService.start();
+
+ // Check whether we were expecting an exception
+ if (expectingException) {
+ // We were expecting an exception
+ Assert.fail("This binding should have failed as it is
invalid");
+ }
+ } catch (JMSBindingException ex) {
+ // Were we expecting an exception
+ if (!expectingException) {
+ ex.printStackTrace();
+ // No we were not expecting an exception
+ Assert.fail("Unexpected exception of " + ex);
+ }
+
+ // We should get a JMSBindingException
+ Assert.assertTrue(ex.getMessage().indexOf("Error starting
JMSServiceBinding") != -1);
+
+ // Validate that the expected chained exception exception has the
text we expect
+ Assert.assertNotNull(ex.getCause());
+ Assert.assertTrue(ex.getCause().getMessage().indexOf("JMS
Destination") != -1);
+ Assert.assertTrue(ex.getCause().getMessage().indexOf(createMode)
!= -1);
+
Assert.assertTrue(ex.getCause().getMessage().indexOf(destinationName) != -1);
+ Assert.assertTrue(ex.getCause().getMessage().indexOf("registering
service " + serviceName + " listener") != -1);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]