AMQP-127: align parsers and XSD and defaults in domain
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.amqp.core;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,11 @@ import java.util.UUID;
|
||||
public class AnonymousQueue extends Queue {
|
||||
|
||||
public AnonymousQueue() {
|
||||
super(UUID.randomUUID().toString(), false, true, true);
|
||||
this(null);
|
||||
}
|
||||
|
||||
public AnonymousQueue(Map<String,Object> arguments) {
|
||||
super(UUID.randomUUID().toString(), false, true, true, arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ public class Binding {
|
||||
|
||||
private Map<String, Object> arguments;
|
||||
|
||||
|
||||
public Binding(Queue queue, FanoutExchange exchange) {
|
||||
this.queue = queue.getName();
|
||||
this.exchange = exchange.getName();
|
||||
@@ -63,13 +62,12 @@ public class Binding {
|
||||
this.routingKey = routingKey;
|
||||
}
|
||||
|
||||
public Binding(Queue queue, TopicExchange exchange, String routingKey) {
|
||||
public Binding(Queue queue, TopicExchange exchange, String routingPattern) {
|
||||
this.queue = queue.getName();
|
||||
this.exchange = exchange.getName();
|
||||
this.routingKey = routingKey;
|
||||
this.routingKey = routingPattern;
|
||||
}
|
||||
|
||||
|
||||
public String getQueue() {
|
||||
return this.queue;
|
||||
}
|
||||
@@ -86,8 +84,4 @@ public class Binding {
|
||||
return this.arguments;
|
||||
}
|
||||
|
||||
public void setArguments(Map<String, Object> arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.amqp.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple container collecting information to describe a direct exchange.
|
||||
* Used in conjunction with administrative operations.
|
||||
@@ -23,6 +25,7 @@ package org.springframework.amqp.core;
|
||||
* @see AmqpAdmin
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class DirectExchange extends AbstractExchange {
|
||||
|
||||
@@ -37,6 +40,9 @@ public class DirectExchange extends AbstractExchange {
|
||||
super(name, durable, autoDelete);
|
||||
}
|
||||
|
||||
public DirectExchange(String name, boolean durable, boolean autoDelete, Map<String,Object> arguments) {
|
||||
super(name, durable, autoDelete, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getType() {
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.amqp.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple container collecting information to describe a fanout exchange.
|
||||
* Used in conjunction with administrative operations.
|
||||
* @see AmqpAdmin
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class FanoutExchange extends AbstractExchange {
|
||||
|
||||
@@ -33,6 +36,9 @@ public class FanoutExchange extends AbstractExchange {
|
||||
super(name, durable, autoDelete);
|
||||
}
|
||||
|
||||
public FanoutExchange(String name, boolean durable, boolean autoDelete, Map<String,Object> arguments) {
|
||||
super(name, durable, autoDelete, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getType() {
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.springframework.amqp.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class HeadersExchange extends AbstractExchange {
|
||||
|
||||
@@ -25,6 +28,13 @@ public class HeadersExchange extends AbstractExchange {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public HeadersExchange(String name, boolean durable, boolean autoDelete) {
|
||||
super(name, durable, autoDelete);
|
||||
}
|
||||
|
||||
public HeadersExchange(String name, boolean durable, boolean autoDelete, Map<String,Object> arguments) {
|
||||
super(name, durable, autoDelete, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.springframework.amqp.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple container collecting information to describe a topic exchange.
|
||||
* Used in conjunction with administrative operations.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Dave Syer
|
||||
* @see AmqpAdmin
|
||||
*/
|
||||
public class TopicExchange extends AbstractExchange {
|
||||
@@ -33,6 +36,9 @@ public class TopicExchange extends AbstractExchange {
|
||||
super(name, durable, autoDelete);
|
||||
}
|
||||
|
||||
public TopicExchange(String name, boolean durable, boolean autoDelete, Map<String,Object> arguments) {
|
||||
super(name, durable, autoDelete, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getType() {
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
@@ -29,6 +31,12 @@ import org.w3c.dom.Element;
|
||||
*/
|
||||
public abstract class AbstractExchangeParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
private static final String ARGUMENTS_ELEMENT = "exchange-arguments";
|
||||
|
||||
private static final String DURABLE_ATTRIBUTE = "durable";
|
||||
|
||||
private static final String AUTO_DELETE_ATTRIBUTE = "auto-delete";
|
||||
|
||||
private static String BINDINGS_ELE = "bindings";
|
||||
|
||||
private static String BINDING_ELE = "binding";
|
||||
@@ -53,6 +61,18 @@ public abstract class AbstractExchangeParser extends AbstractSingleBeanDefinitio
|
||||
.generateBeanName(beanDefinition)), parserContext.getRegistry());
|
||||
}
|
||||
}
|
||||
|
||||
NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, true);
|
||||
NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE,
|
||||
false);
|
||||
|
||||
Element argumentsElement = DomUtils.getChildElementByTagName(element, ARGUMENTS_ELEMENT);
|
||||
if (argumentsElement != null) {
|
||||
Map<?, ?> map = parserContext.getDelegate().parseMapElement(argumentsElement,
|
||||
builder.getRawBeanDefinition());
|
||||
builder.addConstructorArgValue(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract AbstractBeanDefinition parseBinding(BeanMetadataElement exchange, Element binding,
|
||||
|
||||
@@ -103,6 +103,25 @@ public abstract class NamespaceUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the bean definition constructor argument with the boolean value of that attribute if it is defined in the given
|
||||
* element or else uses the default provided.
|
||||
*
|
||||
* @param builder the bean definition builder to be configured
|
||||
* @param element the XML element where the attribute should be defined
|
||||
* @param attributeName the name of the attribute whose value will be used as a constructor argument
|
||||
* @param defaultValue the default value to use if the attirbute is not set
|
||||
*/
|
||||
public static void addConstructorArgBooleanValueIfAttributeDefined(BeanDefinitionBuilder builder, Element element,
|
||||
String attributeName, boolean defaultValue) {
|
||||
String value = element.getAttribute(attributeName);
|
||||
if (StringUtils.hasText(value)) {
|
||||
builder.addConstructorArgValue(new TypedStringValue(value));
|
||||
} else {
|
||||
builder.addConstructorArgValue(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the bean definition constructor argument with a reference to a bean with id equal to the attribute if
|
||||
* it is defined in the given element.
|
||||
|
||||
@@ -1,54 +1,96 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.amqp.core.AnonymousQueue;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class QueueParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
private static final String ARGUMENTS_ELEMENT = "queue-arguments";
|
||||
private static final String DURABLE_ATTRIBUTE = "durable";
|
||||
private static final String EXCLUSIVE_ATTRIBUTE = "exclusive";
|
||||
private static final String AUTO_DELETE_ATTRIBUTE = "auto-delete";
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
if (NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) {
|
||||
if (NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) {
|
||||
return Queue.class;
|
||||
} else {
|
||||
return AnonymousQueue.class;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE) && !NamespaceUtils.isAttributeDefined(element, ID_ATTRIBUTE)) {
|
||||
|
||||
if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)
|
||||
&& !NamespaceUtils.isAttributeDefined(element, ID_ATTRIBUTE)) {
|
||||
parserContext.getReaderContext().error("Queue must have either id or name (or both)", element);
|
||||
}
|
||||
|
||||
NamespaceUtils.addConstructorArgValueIfAttributeDefined(builder, element, NAME_ATTRIBUTE);
|
||||
|
||||
if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) {
|
||||
|
||||
if (attributeHasIllegalOverride(element, DURABLE_ATTRIBUTE, "false")
|
||||
|| attributeHasIllegalOverride(element, EXCLUSIVE_ATTRIBUTE, "true")
|
||||
|| attributeHasIllegalOverride(element, AUTO_DELETE_ATTRIBUTE, "true")) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Anonymous queue cannot specify durable='true', exclusive='false' or auto-delete='false'",
|
||||
element);
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, false);
|
||||
NamespaceUtils
|
||||
.addConstructorArgBooleanValueIfAttributeDefined(builder, element, EXCLUSIVE_ATTRIBUTE, false);
|
||||
NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE,
|
||||
false);
|
||||
|
||||
}
|
||||
|
||||
Element argumentsElement = DomUtils.getChildElementByTagName(element, ARGUMENTS_ELEMENT);
|
||||
if (argumentsElement != null) {
|
||||
Map<?, ?> map = parserContext.getDelegate().parseMapElement(argumentsElement,
|
||||
builder.getRawBeanDefinition());
|
||||
builder.addConstructorArgValue(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean attributeHasIllegalOverride(Element element, String name, String allowed) {
|
||||
return element.getAttributeNode(name) != null && element.getAttributeNode(name).getSpecified()
|
||||
&& !allowed.equals(element.getAttribute(name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,19 +37,24 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="autodelete" use="optional" type="xsd:boolean"
|
||||
default="false">
|
||||
<xsd:attribute name="auto-delete" use="optional" type="xsd:boolean" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Flag indicating that an queue will be deleted when it is no longer in use. Default is false.
|
||||
Flag indicating that an queue will be deleted when it is no longer in use, i.e. the connection that declared it is closed. Default is false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="durable" use="optional" type="xsd:boolean"
|
||||
default="true">
|
||||
<xsd:attribute name="exclusive" use="optional" type="xsd:boolean" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Flag indicating that the queue is durable. Default is true.
|
||||
Flag indicating that the queue is exclusive to this connection. Default is false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="durable" use="optional" type="xsd:boolean" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Flag indicating that the queue is durable, meaning that it will survive broker restarts (not that the messages in it will, although they might if they are persistent). Default is false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
@@ -231,6 +236,13 @@
|
||||
<xsd:element ref="exchange-arguments" minOccurs="0"
|
||||
maxOccurs="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The id of the exchange bean definition in case it is different than the name.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
@@ -239,19 +251,19 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="autodelete" use="optional" type="xsd:boolean"
|
||||
<xsd:attribute name="auto-delete" use="optional" type="xsd:boolean"
|
||||
default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Flag indicating that an exchange will be deleted when no longer in use. Default is false.
|
||||
Flag indicating that an exchange will be deleted when no longer in use, i.e. the connection that declared it is closed. Default is false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="durable" use="optional" type="xsd:boolean"
|
||||
default="true">
|
||||
default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Flag indicating that the exchange is durable. Default is true
|
||||
Flag indicating that the exchange is durable, i.e. will survive broker restart. Default is false.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
@@ -569,7 +581,7 @@
|
||||
<xsd:attribute name="id" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Unique ID for this rabbit admin.
|
||||
Unique name for this rabbit admin used as a bean definition identifier.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
@@ -587,21 +599,10 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="phase" type="xsd:int">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The lifecycle phase within which this admin should start and stop. The lower
|
||||
the value the earlier this admin will start and the later it will stop. The
|
||||
default is Integer.MIN_VALUE meaning the admin will start as early as possible
|
||||
and stop as late as possible.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="auto-startup" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies if the rabbit admin should be started automatically when ApplicationContext
|
||||
is refreshed. Default value is 'true'.
|
||||
Specifies if the queues, exchanges and bindings in the context should be automatically declared (lazily on first connection to the broker). Default value is 'true'.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.amqp.core.HeadersExchange;
|
||||
import org.springframework.amqp.core.TopicExchange;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public final class ExchangeParserTests {
|
||||
|
||||
private XmlBeanFactory beanFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName()+"-context.xml", getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirectExchange() throws Exception {
|
||||
DirectExchange exchange = beanFactory.getBean("direct", DirectExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("direct", exchange.getName());
|
||||
assertFalse(exchange.isDurable());
|
||||
assertFalse(exchange.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasDirectExchange() throws Exception {
|
||||
DirectExchange exchange = beanFactory.getBean("alias", DirectExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("direct-alias", exchange.getName());
|
||||
assertFalse(exchange.isDurable());
|
||||
assertFalse(exchange.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTopicExchange() throws Exception {
|
||||
TopicExchange exchange = beanFactory.getBean("topic", TopicExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("topic", exchange.getName());
|
||||
assertFalse(exchange.isDurable());
|
||||
assertFalse(exchange.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFanoutExchange() throws Exception {
|
||||
FanoutExchange exchange = beanFactory.getBean("fanout", FanoutExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("fanout", exchange.getName());
|
||||
assertFalse(exchange.isDurable());
|
||||
assertFalse(exchange.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeadersExchange() throws Exception {
|
||||
HeadersExchange exchange = beanFactory.getBean("headers", HeadersExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("headers", exchange.getName());
|
||||
assertFalse(exchange.isDurable());
|
||||
assertFalse(exchange.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirectExchangeOverride() throws Exception {
|
||||
DirectExchange exchange = beanFactory.getBean("direct-override", DirectExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("direct-override", exchange.getName());
|
||||
assertTrue(exchange.isDurable());
|
||||
assertTrue(exchange.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirectExchangeWithArguments() throws Exception {
|
||||
DirectExchange exchange = beanFactory.getBean("direct-arguments", DirectExchange.class);
|
||||
assertNotNull(exchange);
|
||||
assertEquals("direct-arguments", exchange.getName());
|
||||
assertEquals("bar", exchange.getArguments().get("foo"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.amqp.rabbit.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.amqp.core.AnonymousQueue;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
public final class QueueParserTests {
|
||||
|
||||
private XmlBeanFactory beanFactory;
|
||||
|
||||
@Before
|
||||
public void setUpDefaultBeanFactory() throws Exception {
|
||||
beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("foo", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertEquals("foo", queue.getName());
|
||||
assertFalse(queue.isDurable());
|
||||
assertFalse(queue.isAutoDelete());
|
||||
assertFalse(queue.isExclusive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliasQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("alias", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertEquals("spam", queue.getName());
|
||||
assertNotSame("alias", queue.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("override", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertEquals("override", queue.getName());
|
||||
assertTrue(queue.isDurable());
|
||||
assertTrue(queue.isExclusive());
|
||||
assertTrue(queue.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideAliasQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("overrideAlias", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertEquals("bar", queue.getName());
|
||||
assertTrue(queue.isDurable());
|
||||
assertTrue(queue.isExclusive());
|
||||
assertTrue(queue.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnonymousQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("anonymous", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertNotSame("anonymous", queue.getName());
|
||||
assertTrue(queue instanceof AnonymousQueue);
|
||||
assertFalse(queue.isDurable());
|
||||
assertTrue(queue.isExclusive());
|
||||
assertTrue(queue.isAutoDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgumentsQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("arguments", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertEquals("bar", queue.getArguments().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnonymousArgumentsQueue() throws Exception {
|
||||
Queue queue = beanFactory.getBean("anonymousArguments", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertEquals("spam", queue.getArguments().get("foo"));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testIllegalAnonymousQueue() throws Exception {
|
||||
beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName()
|
||||
+ "IllegalAnonymous-context.xml", getClass()));
|
||||
Queue queue = beanFactory.getBean("anonymous", Queue.class);
|
||||
assertNotNull(queue);
|
||||
assertNotSame("bucket", queue.getName());
|
||||
assertTrue(queue instanceof AnonymousQueue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,6 @@
|
||||
class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory" />
|
||||
|
||||
<!-- Valid configuration -->
|
||||
<rabbit:admin id="admin-test" connection-factory="connectionFactory" phase="12" auto-startup="false"/>
|
||||
<rabbit:admin id="admin-test" connection-factory="connectionFactory" auto-startup="false"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<rabbit:direct-exchange name="direct" />
|
||||
|
||||
<rabbit:direct-exchange id="alias" name="direct-alias" />
|
||||
|
||||
<rabbit:direct-exchange name="direct-override" auto-delete="true" durable="true"/>
|
||||
|
||||
<direct-exchange name="direct-arguments" xmlns="http://www.springframework.org/schema/rabbit">
|
||||
<exchange-arguments>
|
||||
<beans:entry key="foo" value="bar" />
|
||||
</exchange-arguments>
|
||||
</direct-exchange>
|
||||
|
||||
<rabbit:topic-exchange name="topic" />
|
||||
|
||||
<rabbit:fanout-exchange name="fanout"/>
|
||||
|
||||
<rabbit:headers-exchange name="headers" xmlns="http://www.springframework.org/schema/rabbit"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<rabbit:queue id="anonymous" durable="true" auto-delete="true" exclusive="true"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<rabbit:queue name="foo" />
|
||||
|
||||
<rabbit:queue name="override" durable="true" auto-delete="true" exclusive="true" />
|
||||
|
||||
<rabbit:queue id="alias" name="spam" />
|
||||
|
||||
<rabbit:queue id="overrideAlias" name="bar" durable="true" auto-delete="true" exclusive="true" />
|
||||
|
||||
<rabbit:queue id="anonymous" />
|
||||
|
||||
<rabbit:queue name="arguments">
|
||||
<rabbit:queue-arguments>
|
||||
<beans:entry key="foo" value="bar" />
|
||||
</rabbit:queue-arguments>
|
||||
</rabbit:queue>
|
||||
|
||||
<rabbit:queue id="anonymousArguments">
|
||||
<rabbit:queue-arguments>
|
||||
<beans:entry key="foo" value="spam" />
|
||||
</rabbit:queue-arguments>
|
||||
</rabbit:queue>
|
||||
|
||||
<rabbit:queue id="anonymousOverride" durable="false" auto-delete="true" exclusive="true" />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user