removed priority enumeration from the 2.0 and 2.1 schema

fixed documentation, added tests
This commit is contained in:
Oleg Zhurakousky
2012-02-01 09:36:53 -05:00
committed by Mark Fisher
parent 8789d850b3
commit 76f6c0877e
8 changed files with 70 additions and 47 deletions

View File

@@ -324,6 +324,10 @@ public final class MessageBuilder<T> {
Assert.isTrue(Integer.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName
+ "' header value must be an Integer.");
}
else if (MessageHeaders.PRIORITY.equals(headerName)) {
Assert.isTrue(Integer.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName
+ "' header value must be an Integer.");
}
}
}

View File

@@ -1413,14 +1413,16 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:element name="priority">
<xsd:annotation>
<xsd:documentation>
Shortcut to specify value for 'priority' header when using PriotityChannel
Shortcut to specify value for 'priority' header when using PriorityChannel
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="value">
<xsd:simpleType>
<xsd:union memberTypes="priorityEnumeration xsd:string" />
</xsd:simpleType>
<xsd:annotation>
<xsd:documentation>
Integer value identifying the value of the 'priority' header.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="overwrite">
<xsd:annotation>
@@ -1515,16 +1517,6 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:attribute>
</xsd:complexType>
<xsd:simpleType name="priorityEnumeration">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="HIGHEST" />
<xsd:enumeration value="HIGH" />
<xsd:enumeration value="NORMAL" />
<xsd:enumeration value="LOW" />
<xsd:enumeration value="LOWEST" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="userDefinedHeaderType">
<xsd:annotation>
<xsd:documentation>

View File

@@ -1638,14 +1638,16 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:element name="priority">
<xsd:annotation>
<xsd:documentation>
Shortcut to specify value for 'priority' header when using PriotityChannel
Shortcut to specify value for 'priority' header when using PriorityChannel
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="value">
<xsd:simpleType>
<xsd:union memberTypes="priorityEnumeration xsd:string" />
</xsd:simpleType>
<xsd:annotation>
<xsd:documentation>
Integer value identifying the value of the 'priority' header.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="overwrite">
<xsd:annotation>
@@ -1654,7 +1656,7 @@ endpoint itself is a Polling Consumer for a channel with a queue.
an existing header
value
for the same name.
</xsd:documentation>
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="xsd:boolean xsd:string" />
@@ -1740,16 +1742,6 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:attribute>
</xsd:complexType>
<xsd:simpleType name="priorityEnumeration">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="HIGHEST" />
<xsd:enumeration value="HIGH" />
<xsd:enumeration value="NORMAL" />
<xsd:enumeration value="LOW" />
<xsd:enumeration value="LOWEST" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="userDefinedHeaderType">
<xsd:annotation>
<xsd:documentation>

View File

@@ -22,5 +22,13 @@
<header-enricher id="headerEnricherWithShouldSkipNullsFalse" input-channel="input" should-skip-nulls="false">
<header name="foo" value="bar"/>
</header-enricher>
<header-enricher id="headerEnricherWithPriorityAsString" input-channel="input" >
<header name="priority" value="1"/>
</header-enricher>
<header-enricher id="headerEnricherWithPriorityAsStringAndType" input-channel="input" >
<header name="priority" value="1" type="java.lang.Integer"/>
</header-enricher>
</beans:beans>

View File

@@ -16,17 +16,25 @@
package org.springframework.integration.config.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.transformer.MessageTransformationException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
* @since 2.0
@@ -73,5 +81,26 @@ public class HeaderEnricherParserTests {
Boolean shouldSkipNulls = TestUtils.getPropertyValue(endpoint, "handler.transformer.shouldSkipNulls", Boolean.class);
assertEquals(Boolean.TRUE, shouldSkipNulls);
}
@Test(expected=MessageTransformationException.class)
public void testStringPriorityHeader() {
MessageHandler messageHandler =
TestUtils.getPropertyValue(context.getBean("headerEnricherWithPriorityAsString"), "handler", MessageHandler.class);
Message<?> message = new GenericMessage<String>("hello");
messageHandler.handleMessage(message);
}
@Test
public void testStringPriorityHeaderWithType() {
MessageHandler messageHandler =
TestUtils.getPropertyValue(context.getBean("headerEnricherWithPriorityAsStringAndType"), "handler", MessageHandler.class);
QueueChannel replyChannel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build();
messageHandler.handleMessage(message);
Message<?> transformed = replyChannel.receive(1000);
assertNotNull(transformed);
Object priority = transformed.getHeaders().get("priority");
assertNotNull(priority);
assertTrue(priority instanceof Integer);
}
}

View File

@@ -35,6 +35,11 @@ import org.springframework.integration.support.MessageBuilder;
* @author Mark Fisher
*/
public class MessageBuilderTests {
@Test(expected= IllegalArgumentException.class) // priority must be an Integer
public void testPriorityHeader(){
MessageBuilder.withPayload("ha").setHeader("priority", "10").build();
}
@Test
public void testSimpleMessageCreation() {

View File

@@ -596,7 +596,7 @@ payload to an Integer.
<programlisting language="xml"><![CDATA[<int:channel id="priorityChannel">
<int:priority-queue capacity="20"/>
</int:channel>]]></programlisting>
By default, the channel will consult the <classname>MessagePriority</classname> header of the
By default, the channel will consult the <code>priority</code> header of the
message. However, a custom <interfacename>Comparator</interfacename> reference may be
provided instead. Also, note that the <classname>PriorityChannel</classname> (like the other types)
does support the <code>datatype</code> attribute. As with the QueueChannel, it also supports a <code>capacity</code> attribute.

View File

@@ -106,7 +106,7 @@
</row>
<row>
<entry>PRIORITY</entry>
<entry>MessagePriority (an <emphasis>enum</emphasis>)</entry>
<entry>java.lang.Integer</entry>
</row>
</tbody>
</tgroup>
@@ -190,28 +190,21 @@ assertEquals(123, message4.getHeaders().get("foo"));</programlisting>
Finally, there are set methods available for the predefined headers as well as a non-destructive method for
setting any header (MessageHeaders also defines constants for the pre-defined header names).
<programlisting language="java">Message&lt;Integer&gt; importantMessage = MessageBuilder.withPayload(99)
.setPriority(MessagePriority.HIGHEST)
.setPriority(5)
.build();
assertEquals(MessagePriority.HIGHEST, importantMessage.getHeaders().getPriority());
assertEquals(5, importantMessage.getHeaders().getPriority());
Message&lt;Integer&gt; anotherMessage = MessageBuilder.fromMessage(importantMessage)
.setHeaderIfAbsent(MessageHeaders.PRIORITY, MessagePriority.LOW)
Message&lt;Integer&gt; lessImportantMessage = MessageBuilder.fromMessage(importantMessage)
.setHeaderIfAbsent(MessageHeaders.PRIORITY, 2)
.build();
assertEquals(MessagePriority.LOW, anotherMessage.getHeaders().getPriority());
assertEquals(2, lessImportantMessage.getHeaders().getPriority());
</programlisting>
</para>
<para>
The <classname>MessagePriority</classname> is only considered when using a <classname>PriorityChannel</classname>
(as described in the next chapter). It is defined as an <emphasis>enum</emphasis> with five possible values:
<programlisting language="java">public enum MessagePriority {
HIGHEST,
HIGH,
NORMAL,
LOW,
LOWEST
}</programlisting>
The <code>priority</code> header is only considered when using a <classname>PriorityChannel</classname>
(as described in the next chapter). It is defined as <emphasis>java.lang.Integer</emphasis>.
</para>
</section>