INT-3384: Rework JMS/XML Module XSD Enumerations

JIRA: https://jira.spring.io/browse/INT-3384

Polishing
This commit is contained in:
David Liu
2014-08-04 11:30:27 +03:00
committed by Artem Bilan
parent 1c84305f8d
commit 9d0089d51d
31 changed files with 629 additions and 383 deletions

View File

@@ -3,24 +3,38 @@
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<beans:prop key="booleanResult">BOOLEAN_RESULT</beans:prop>
<beans:prop key="stringResult">STRING_RESULT</beans:prop>
<beans:prop key="numberResult">NUMBER_RESULT</beans:prop>
<beans:prop key="nodeResult">NODE_RESULT</beans:prop>
<beans:prop key="nodeListResult">NODE_LIST_RESULT</beans:prop>
</util:properties>
<si:channel id="output">
<si:queue/>
</si:channel>
<xpath-header-enricher input-channel="input" output-channel="output">
<header name="name" xpath-expression="/person/@name" />
<header name="age" xpath-expression="/person/@age" evaluation-type="NUMBER_RESULT" header-type="int"/>
<header name="married" xpath-expression="/person/@married = 'true'" evaluation-type="BOOLEAN_RESULT" />
<header name="node-test" xpath-expression="/person/@age" evaluation-type="NODE_RESULT" />
<header name="node-list-test" xpath-expression="/person/@*" evaluation-type="NODE_LIST_RESULT" />
<header name="ref-test" xpath-expression-ref="testExpression" evaluation-type="NUMBER_RESULT" />
<header name="age" xpath-expression="/person/@age" evaluation-type="${numberResult}" header-type="int"/>
<header name="married" xpath-expression="/person/@married = 'true'" evaluation-type="${booleanResult}" />
<header name="node-test" xpath-expression="/person/@age" evaluation-type="${nodeResult}" />
<header name="node-list-test" xpath-expression="/person/@*" evaluation-type="${nodeListResult}" />
<header name="ref-test" xpath-expression-ref="testExpression" evaluation-type="${numberResult}" />
</xpath-header-enricher>
<xpath-expression id="testExpression" expression="/person/@age * 2"/>

View File

@@ -3,32 +3,46 @@
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<beans:prop key="booleanResult">BOOLEAN_RESULT</beans:prop>
<beans:prop key="stringResult">STRING_RESULT</beans:prop>
<beans:prop key="numberResult">NUMBER_RESULT</beans:prop>
<beans:prop key="nodeResult">NODE_RESULT</beans:prop>
<beans:prop key="nodeListResult">NODE_LIST_RESULT</beans:prop>
</util:properties>
<si:channel id="output">
<si:queue/>
</si:channel>
<xpath-transformer input-channel="defaultInput" xpath-expression="/person/@name" output-channel="output"/>
<xpath-transformer input-channel="numberInput" xpath-expression="/person/@age" evaluation-type="NUMBER_RESULT" output-channel="output"/>
<xpath-transformer input-channel="numberInput" xpath-expression="/person/@age" evaluation-type="${numberResult}" output-channel="output"/>
<xpath-transformer input-channel="booleanInput" xpath-expression="/person/@married = 'true'" evaluation-type="BOOLEAN_RESULT" output-channel="output"/>
<xpath-transformer input-channel="booleanInput" xpath-expression="/person/@married = 'true'" evaluation-type="${booleanResult}" output-channel="output"/>
<xpath-transformer input-channel="nodeInput" xpath-expression="/person/@age" evaluation-type="NODE_RESULT" output-channel="output"/>
<xpath-transformer input-channel="nodeInput" xpath-expression="/person/@age" evaluation-type="${nodeResult}" output-channel="output"/>
<xpath-transformer input-channel="nodeListInput" xpath-expression="/person/@*" evaluation-type="NODE_LIST_RESULT" output-channel="output"/>
<xpath-transformer input-channel="nodeListInput" xpath-expression="/person/@*" evaluation-type="${nodeListResult}" output-channel="output"/>
<xpath-transformer input-channel="nodeMapperInput" xpath-expression="/person/@age" node-mapper="testNodeMapper" output-channel="output"/>
<xpath-transformer input-channel="customConverterInput" xpath-expression="/test/@type" converter="testXmlPayloadConverter" output-channel="output"/>
<xpath-transformer input-channel="expressionRefInput" xpath-expression-ref="testExpression" evaluation-type="NUMBER_RESULT" output-channel="output"/>
<xpath-transformer input-channel="expressionRefInput" xpath-expression-ref="testExpression" evaluation-type="${numberResult}" output-channel="output"/>
<xpath-expression id="testExpression" expression="/person/@age * 2"/>

View File

@@ -3,11 +3,22 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<prop key="xmlSchema">xml-schema</prop>
</util:properties>
<int-xml:validating-filter id="filterA"
schema-type="${xmlSchema}"
input-channel="inputChannelA"
output-channel="validOutputChannel"
discard-channel="invalidOutputChannel"
@@ -38,4 +49,5 @@
<int:channel id="invalidOutputChannel">
<int:queue/>
</int:channel>
</beans>

View File

@@ -23,17 +23,20 @@ import static org.junit.Assert.fail;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.xml.AggregatedXmlMessageValidationException;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Jonas Partner
@@ -42,11 +45,15 @@ import org.springframework.test.context.ContextConfiguration;
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class XmlPayloadValidatingFilterParserTests {
@Autowired
private ApplicationContext ac;
@Test
public void testValidMessage() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
@@ -56,7 +63,6 @@ public class XmlPayloadValidatingFilterParserTests {
}
@Test
public void testInvalidMessageWithDiscardChannel() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
@@ -68,7 +74,6 @@ public class XmlPayloadValidatingFilterParserTests {
}
@Test
public void testInvalidMessageWithThrowException() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
Document doc = XmlTestUtil.getDocumentForString("<greeting ping=\"pong\"><other/></greeting>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
MessageChannel inputChannel = ac.getBean("inputChannelB", MessageChannel.class);
@@ -88,7 +93,6 @@ public class XmlPayloadValidatingFilterParserTests {
}
@Test
public void testValidMessageWithValidator() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
@@ -96,16 +100,15 @@ public class XmlPayloadValidatingFilterParserTests {
inputChannel.send(docMessage);
assertNotNull(validChannel.receive(100));
}
@SuppressWarnings("unused")
@Test
public void testInvalidMessageWithValidatorAndDiscardChannel() throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
PollableChannel invalidChannel = ac.getBean("invalidOutputChannel", PollableChannel.class);
MessageChannel inputChannel = ac.getBean("inputChannelC", MessageChannel.class);
inputChannel.send(docMessage);
assertNotNull(invalidChannel.receive(100));
}
}

View File

@@ -1,32 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<prop key="domResult">DOMResult</prop>
<prop key="stringResult">StringResult</prop>
</util:properties>
<si:channel id="output">
<si:queue capacity="1"/>
</si:channel>
<si:channel id="withResourceIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithResource"
input-channel="withResourceIn"
output-channel="output"
xsl-resource="org/springframework/integration/xml/config/test.xsl"/>
<si:channel id="withTemplatesIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplates"
input-channel="withTemplatesIn"
output-channel="output"
xsl-templates="templates"/>
<si:channel id="withTemplatesAndResultTransformerIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultTransformer"
input-channel="withTemplatesAndResultTransformerIn"
output-channel="output"
@@ -34,6 +48,7 @@
result-transformer="resultTransformer"/>
<si:channel id="withTemplatesAndResultFactoryIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultFactory"
input-channel="withTemplatesAndResultFactoryIn"
output-channel="output"
@@ -41,23 +56,24 @@
result-factory="stubResultFactory"/>
<si:channel id="withTemplatesAndStringResultTypeIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndStringResultType"
input-channel="withTemplatesAndStringResultTypeIn"
output-channel="output"
xsl-templates="templates"
result-type="StringResult"/>
result-type="${stringResult}"/>
<si-xml:xslt-transformer id="docInStringResultOutTransformer"
input-channel="docinStringResultOutTransformerChannel"
output-channel="output" result-type="StringResult"
output-channel="output" result-type="${stringResult}"
xsl-resource="classpath:org/springframework/integration/xml/transformer/transformer.xslt">
</si-xml:xslt-transformer>
<si-xml:xslt-transformer id="stringResultOutTransformer"
input-channel="stringResultOutTransformerChannel"
output-channel="output" result-type="DOMResult"
output-channel="output" result-type="${domResult}"
xsl-resource="classpath:org/springframework/integration/xml/transformer/transform.xsl">
</si-xml:xslt-transformer>
@@ -80,5 +96,4 @@
<bean id="stubResultFactory" class="org.springframework.integration.xml.config.StubResultFactory"/>
</beans>

View File

@@ -47,109 +47,104 @@ import org.springframework.xml.transform.StringResult;
*/
public class XsltPayloadTransformerParserTests {
private final String doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>";
private final String doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>";
private ApplicationContext applicationContext;
private ApplicationContext applicationContext;
private PollableChannel output;
private PollableChannel output;
@Before
public void setUp() {
applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
output = (PollableChannel) applicationContext.getBean("output");
}
@Before
public void setUp() {
applicationContext = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
output = (PollableChannel) applicationContext.getBean("output");
}
@Test
public void testWithResourceProvided() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withResourceIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
assertNotNull(TestUtils.getPropertyValue(applicationContext.getBean("xsltTransformerWithResource.handler"),
"transformer.evaluationContext.beanResolver"));
}
@Test
public void testWithResourceProvided() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withResourceIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
assertNotNull(TestUtils.getPropertyValue(applicationContext.getBean("xsltTransformerWithResource.handler"),
"transformer.evaluationContext.beanResolver"));
}
@Test
public void testWithTemplatesProvided() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
}
@Test
public void testWithTemplatesProvided() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a DOMResult", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
assertEquals("Wrong payload", "test", doc.getDocumentElement().getTextContent());
}
@Test
public void testWithTemplatesAndResultTransformer() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultTransformerIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertEquals("Wrong payload type", String.class, result.getPayload().getClass());
String strResult = (String) result.getPayload();
assertEquals("Wrong payload", "testReturn", strResult);
}
@Test
public void testWithTemplatesAndResultTransformer() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultTransformerIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertEquals("Wrong payload type", String.class, result.getPayload().getClass());
String strResult = (String) result.getPayload();
assertEquals("Wrong payload", "testReturn", strResult);
}
@Test
public void testWithResourceProvidedAndStubResultFactory() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultFactoryIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a StubStringResult", result.getPayload() instanceof StubStringResult);
}
@Test
public void testWithResourceProvidedAndStubResultFactory() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndResultFactoryIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a StubStringResult", result.getPayload() instanceof StubStringResult);
}
@Test
public void testWithResourceAndStringResultType() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndStringResultTypeIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a StringResult", result.getPayload() instanceof StringResult);
}
@Test
public void testWithResourceAndStringResultType() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndStringResultTypeIn");
GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Payload was not a StringResult", result.getPayload() instanceof StringResult);
}
@Test
public void docInStringResultOut() throws Exception {
MessageChannel input = applicationContext.getBean("docinStringResultOutTransformerChannel",
MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).build();
input.send(message);
Message<?> resultMessage = output.receive();
Assert.assertEquals("Wrong payload type", StringResult.class, resultMessage.getPayload().getClass());
String payload = resultMessage.getPayload().toString();
Assert.assertTrue(payload.contains("<bob>test</bob>"));
}
@Test
public void stringInDocResultOut() throws Exception {
MessageChannel input = applicationContext.getBean("stringResultOutTransformerChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(this.doc).build();
input.send(message);
Message<?> resultMessage = output.receive();
Assert.assertEquals("Wrong payload type", DOMResult.class, resultMessage.getPayload().getClass());
Document payload = (Document) ((DOMResult) resultMessage.getPayload()).getNode();
Assert.assertTrue(XmlTestUtil.docToString(payload).contains("<bob>test</bob>"));
}
@Test
public void docInStringResultOut() throws Exception {
MessageChannel input = applicationContext.getBean("docinStringResultOutTransformerChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).
build();
input.send(message);
Message<?> resultMessage = output.receive();
Assert.assertEquals("Wrong payload type", StringResult.class, resultMessage.getPayload().getClass());
String payload = resultMessage.getPayload().toString();
Assert.assertTrue(payload.contains("<bob>test</bob>"));
}
@Test
public void stringInDocResultOut() throws Exception {
MessageChannel input = applicationContext.getBean("stringResultOutTransformerChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(this.doc).
build();
input.send(message);
Message<?> resultMessage = output.receive();
Assert.assertEquals("Wrong payload type", DOMResult.class, resultMessage.getPayload().getClass());
Document payload = (Document) ((DOMResult) resultMessage.getPayload()).getNode();
Assert.assertTrue(XmlTestUtil.docToString(payload).contains("<bob>test</bob>"));
}
@Test
public void stringInAndCustomResultFactory() throws Exception {
MessageChannel input = applicationContext.getBean("stringInCustomResultFactoryChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).
build();
input.send(message);
Message<?> resultMessage = output.receive();
Assert.assertEquals("Wrong payload type", CustomTestResultFactory.FixedStringResult.class, resultMessage.getPayload().getClass());
String payload = resultMessage.getPayload().toString();
Assert.assertTrue(payload.contains("fixedStringForTesting"));
}
@Test
public void stringInAndCustomResultFactory() throws Exception {
MessageChannel input = applicationContext.getBean("stringInCustomResultFactoryChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(XmlTestUtil.getDocumentForString(this.doc)).build();
input.send(message);
Message<?> resultMessage = output.receive();
Assert.assertEquals("Wrong payload type", CustomTestResultFactory.FixedStringResult.class, resultMessage
.getPayload().getClass());
String payload = resultMessage.getPayload().toString();
Assert.assertTrue(payload.contains("fixedStringForTesting"));
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="xmlValidatingMessageSelector" class="org.springframework.integration.xml.selector.XmlValidatingMessageSelector">
<constructor-arg>
<bean class="org.springframework.core.io.ByteArrayResource">
<constructor-arg value="#{new byte[] { 0x03 } }"/>
</bean>
</constructor-arg>
<constructor-arg value="foo"/>
</bean>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
@@ -13,12 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.xml.selector;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.validation.XmlValidatorFactory;
import org.springframework.integration.xml.selector.XmlValidatingMessageSelector.SchemaType;
/**
* @author Oleg Zhurakousky
@@ -29,23 +35,34 @@ public class XmlValidatingMessageSelectorTests {
@Test
public void validateCreationWithSchemaAndDefaultSchemaType() throws Exception{
Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
new XmlValidatingMessageSelector(resource, null);
new XmlValidatingMessageSelector(resource, (SchemaType) null);
}
@Test
public void validateCreationWithSchemaAndProvidedSchemaType() throws Exception{
Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
new XmlValidatingMessageSelector(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
new XmlValidatingMessageSelector(resource, SchemaType.XML_SCHEMA);
}
@Test(expected=IllegalArgumentException.class)
@Test
public void validateFailureInvalidSchemaLanguage() throws Exception{
Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
new XmlValidatingMessageSelector(resource, "foo");
ConfigurableApplicationContext context = null;
try {
context = new ClassPathXmlApplicationContext("XmlValidatingMessageSelectorTests-context.xml", this.getClass());
}
catch (Exception e) {
assertTrue(e.getMessage().contains("java.lang.IllegalArgumentException: No enum constant"));
}
finally {
if(context != null) {
context.close();
}
}
}
@Test(expected=IllegalArgumentException.class)
public void validateFailureWhenNoSchemaResourceProvided() throws Exception{
new XmlValidatingMessageSelector(null, null);
new XmlValidatingMessageSelector(null, (SchemaType) null);
}
}

View File

@@ -4,22 +4,29 @@
xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<prop key="result">DOMResult</prop>
</util:properties>
<context:annotation-config/>
<si:channel id="marshallIn"/>
<si:channel id="unmarshallIn"/>
<si:channel id="unmarshallOut">
<si:queue capacity="10" />
</si:channel>
@@ -28,12 +35,10 @@
<si:queue capacity="10" />
</si:channel>
<si-xml:marshalling-transformer id="marshaller" input-channel="marshallIn" output-channel="marshallOut" marshaller="marshallerUnmarshaller" />
<si-xml:marshalling-transformer id="marshaller" input-channel="marshallIn" output-channel="marshallOut" marshaller="marshallerUnmarshaller" result-type="${result}" />
<si-xml:unmarshalling-transformer id="unmarshaller" input-channel="unmarshallIn" output-channel="unmarshallOut" unmarshaller="marshallerUnmarshaller" />
<bean id="marshallerUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller" >
<property name="classesToBeBound">
<list>
@@ -42,4 +47,4 @@
</property>
</bean>
</beans>
</beans>