From 5617d2e2d84c78e466b9a00d1daf979328b1b449 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 25 Sep 2013 17:43:33 -0400 Subject: [PATCH] INT-2768 Polishing - Docs, White Space Add what's new; fix white space in test case. --- .../XsltPayloadTransformerTests.java | 276 +++++++++--------- src/reference/docbook/whats-new.xml | 7 + src/reference/docbook/xml.xml | 9 + 3 files changed, 154 insertions(+), 138 deletions(-) diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java index 460db25ea7..7bee4335b5 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltPayloadTransformerTests.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -49,176 +49,176 @@ import org.springframework.xml.transform.StringSource; */ public class XsltPayloadTransformerTests { - private XsltPayloadTransformer transformer; + private XsltPayloadTransformer transformer; - private String docAsString = "test"; + private final String docAsString = "test"; - private String outputAsString = "test"; + private final String outputAsString = "test"; - @Before - public void setUp() throws Exception { - transformer = new XsltPayloadTransformer(getXslResource()); + @Before + public void setUp() throws Exception { + transformer = new XsltPayloadTransformer(getXslResource()); transformer.afterPropertiesSet(); - } + } - @Test - public void testDocumentAsPayload() throws Exception { - Object transformed = transformer.doTransform(buildMessage(XmlTestUtil - .getDocumentForString(docAsString))); - assertTrue("Wrong return type for document payload", Document.class - .isAssignableFrom(transformed.getClass())); - Document transformedDocument = (Document) transformed; - assertXMLEqual(outputAsString, XmlTestUtil - .docToString(transformedDocument)); - } + @Test + public void testDocumentAsPayload() throws Exception { + Object transformed = transformer.doTransform(buildMessage(XmlTestUtil + .getDocumentForString(docAsString))); + assertTrue("Wrong return type for document payload", Document.class + .isAssignableFrom(transformed.getClass())); + Document transformedDocument = (Document) transformed; + assertXMLEqual(outputAsString, XmlTestUtil + .docToString(transformedDocument)); + } - @Test - public void testSourceAsPayload() throws Exception { - Object transformed = transformer - .doTransform(buildMessage(new StringSource(docAsString))); - assertEquals("Wrong return type for source payload", DOMResult.class, - transformed.getClass()); - DOMResult result = (DOMResult) transformed; - assertXMLEqual("Document incorrect after transformation", XmlTestUtil - .getDocumentForString(outputAsString), (Document) result - .getNode()); - } + @Test + public void testSourceAsPayload() throws Exception { + Object transformed = transformer + .doTransform(buildMessage(new StringSource(docAsString))); + assertEquals("Wrong return type for source payload", DOMResult.class, + transformed.getClass()); + DOMResult result = (DOMResult) transformed; + assertXMLEqual("Document incorrect after transformation", XmlTestUtil + .getDocumentForString(outputAsString), (Document) result + .getNode()); + } - @Test - public void testStringAsPayload() throws Exception { - Object transformed = transformer.doTransform(buildMessage(docAsString)); - assertEquals("Wrong return type for string payload", String.class, - transformed.getClass()); - String transformedString = (String) transformed; - assertXMLEqual("String incorrect after transform", outputAsString, - transformedString); - } + @Test + public void testStringAsPayload() throws Exception { + Object transformed = transformer.doTransform(buildMessage(docAsString)); + assertEquals("Wrong return type for string payload", String.class, + transformed.getClass()); + String transformedString = (String) transformed; + assertXMLEqual("String incorrect after transform", outputAsString, + transformedString); + } - @Test - public void testStringAsPayloadUseResultFactoryTrue() throws Exception { - transformer.setAlwaysUseResultFactory(true); - Object transformed = transformer.doTransform(buildMessage(docAsString)); - assertEquals("Wrong return type for useFactories true", - DOMResult.class, transformed.getClass()); - DOMResult result = (DOMResult) transformed; - assertXMLEqual("Document incorrect after transformation", XmlTestUtil - .getDocumentForString(outputAsString), (Document) result - .getNode()); - } + @Test + public void testStringAsPayloadUseResultFactoryTrue() throws Exception { + transformer.setAlwaysUseResultFactory(true); + Object transformed = transformer.doTransform(buildMessage(docAsString)); + assertEquals("Wrong return type for useFactories true", + DOMResult.class, transformed.getClass()); + DOMResult result = (DOMResult) transformed; + assertXMLEqual("Document incorrect after transformation", XmlTestUtil + .getDocumentForString(outputAsString), (Document) result + .getNode()); + } - @Test - public void testSourceWithResultTransformer() throws Exception { - Integer returnValue = new Integer(13); - transformer = new XsltPayloadTransformer(getXslResource(), - new StubResultTransformer(returnValue)); + @Test + public void testSourceWithResultTransformer() throws Exception { + Integer returnValue = new Integer(13); + transformer = new XsltPayloadTransformer(getXslResource(), + new StubResultTransformer(returnValue)); transformer.afterPropertiesSet(); - Object transformed = transformer - .doTransform(buildMessage(new StringSource(docAsString))); - assertEquals("Wrong value from result conversion", returnValue, - transformed); - } + Object transformed = transformer + .doTransform(buildMessage(new StringSource(docAsString))); + assertEquals("Wrong value from result conversion", returnValue, + transformed); + } - @Test - public void testXsltPayloadWithTransformerFactoryClassname() throws Exception { - Integer returnValue = new Integer(13); - transformer = new XsltPayloadTransformer(getXslResource(), new StubResultTransformer(returnValue), - "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); + @Test + public void testXsltPayloadWithTransformerFactoryClassname() throws Exception { + Integer returnValue = new Integer(13); + transformer = new XsltPayloadTransformer(getXslResource(), new StubResultTransformer(returnValue), + "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); transformer.afterPropertiesSet(); - Object transformed = transformer - .doTransform(buildMessage(new StringSource(docAsString))); - assertEquals("Wrong value from result conversion", returnValue, - transformed); - } + Object transformed = transformer + .doTransform(buildMessage(new StringSource(docAsString))); + assertEquals("Wrong value from result conversion", returnValue, + transformed); + } - @Test(expected = TransformerFactoryConfigurationError.class) - public void testXsltPayloadWithBadTransformerFactoryClassname() throws Exception { - transformer = new XsltPayloadTransformer(getXslResource(), "foo.bar.Baz"); + @Test(expected = TransformerFactoryConfigurationError.class) + public void testXsltPayloadWithBadTransformerFactoryClassname() throws Exception { + transformer = new XsltPayloadTransformer(getXslResource(), "foo.bar.Baz"); transformer.afterPropertiesSet(); - transformer.doTransform(buildMessage(new StringSource(docAsString))); - } + transformer.doTransform(buildMessage(new StringSource(docAsString))); + } - @Test(expected = TransformerException.class) - public void testNonXmlString() throws Exception { - transformer.doTransform(buildMessage("test")); - } + @Test(expected = TransformerException.class) + public void testNonXmlString() throws Exception { + transformer.doTransform(buildMessage("test")); + } - @Test(expected = MessagingException.class) - public void testUnsupportedPayloadType() throws Exception { - transformer.doTransform(buildMessage(new Long(12))); - } + @Test(expected = MessagingException.class) + public void testUnsupportedPayloadType() throws Exception { + transformer.doTransform(buildMessage(new Long(12))); + } - @Test - public void testXsltWithImports() throws Exception { - Resource resource = new ClassPathResource("transform-with-import.xsl", - this.getClass()); - transformer = new XsltPayloadTransformer(resource); + @Test + public void testXsltWithImports() throws Exception { + Resource resource = new ClassPathResource("transform-with-import.xsl", + this.getClass()); + transformer = new XsltPayloadTransformer(resource); transformer.afterPropertiesSet(); - assertEquals(transformer.doTransform(buildMessage(docAsString)), + assertEquals(transformer.doTransform(buildMessage(docAsString)), outputAsString); - } + } - @Test - public void documentInStringResultOut() throws Exception { - Resource resource = new ClassPathResource("transform-with-import.xsl", - this.getClass()); - transformer = new XsltPayloadTransformer(resource); - transformer.setResultFactory(new StringResultFactory()); - transformer.setAlwaysUseResultFactory(true); + @Test + public void documentInStringResultOut() throws Exception { + Resource resource = new ClassPathResource("transform-with-import.xsl", + this.getClass()); + transformer = new XsltPayloadTransformer(resource); + transformer.setResultFactory(new StringResultFactory()); + transformer.setAlwaysUseResultFactory(true); transformer.afterPropertiesSet(); - Object returned = transformer.doTransform(buildMessage(XmlTestUtil.getDocumentForString(docAsString))); - assertEquals("Wrong type of return ", StringResult.class, returned.getClass()); - } + Object returned = transformer.doTransform(buildMessage(XmlTestUtil.getDocumentForString(docAsString))); + assertEquals("Wrong type of return ", StringResult.class, returned.getClass()); + } - @Test - public void stringInDomResultOut() throws Exception { - Resource resource = new ClassPathResource("transform-with-import.xsl", - this.getClass()); - transformer = new XsltPayloadTransformer(resource); - transformer.setResultFactory(new StringResultFactory()); - transformer.setAlwaysUseResultFactory(true); + @Test + public void stringInDomResultOut() throws Exception { + Resource resource = new ClassPathResource("transform-with-import.xsl", + this.getClass()); + transformer = new XsltPayloadTransformer(resource); + transformer.setResultFactory(new StringResultFactory()); + transformer.setAlwaysUseResultFactory(true); transformer.afterPropertiesSet(); - Object returned = transformer.doTransform(buildMessage(XmlTestUtil.getDocumentForString(docAsString))); - assertEquals("Wrong type of return ", StringResult.class, returned.getClass()); - } + Object returned = transformer.doTransform(buildMessage(XmlTestUtil.getDocumentForString(docAsString))); + assertEquals("Wrong type of return ", StringResult.class, returned.getClass()); + } - @Test - public void docInStringOut() throws Exception { - transformer = new XsltPayloadTransformer(getXslResourceThatOutputsText()); - transformer.setResultFactory(new StringResultFactory()); - transformer.setAlwaysUseResultFactory(true); + @Test + public void docInStringOut() throws Exception { + transformer = new XsltPayloadTransformer(getXslResourceThatOutputsText()); + transformer.setResultFactory(new StringResultFactory()); + transformer.setAlwaysUseResultFactory(true); transformer.afterPropertiesSet(); - Object returned = transformer.doTransform(buildMessage(XmlTestUtil.getDocumentForString(docAsString))); - assertEquals("Wrong type of return ", StringResult.class, returned.getClass()); - assertEquals("Wrong content in string", "hello world", returned.toString()); - } + Object returned = transformer.doTransform(buildMessage(XmlTestUtil.getDocumentForString(docAsString))); + assertEquals("Wrong type of return ", StringResult.class, returned.getClass()); + assertEquals("Wrong content in string", "hello world", returned.toString()); + } - protected Message buildMessage(Object payload) { - return MessageBuilder.withPayload(payload).build(); - } + protected Message buildMessage(Object payload) { + return MessageBuilder.withPayload(payload).build(); + } - private Resource getXslResource() throws Exception { - String xsl = "test"; - return new ByteArrayResource(xsl.getBytes("UTF-8")); - } + private Resource getXslResource() throws Exception { + String xsl = "test"; + return new ByteArrayResource(xsl.getBytes("UTF-8")); + } - private Resource getXslResourceThatOutputsText() throws Exception { - String xsl = "hello world"; - return new ByteArrayResource(xsl.getBytes("UTF-8")); - } + private Resource getXslResourceThatOutputsText() throws Exception { + String xsl = "hello world"; + return new ByteArrayResource(xsl.getBytes("UTF-8")); + } - public static class StubResultTransformer implements ResultTransformer { + public static class StubResultTransformer implements ResultTransformer { - private Object objectToReturn; + private final Object objectToReturn; - public StubResultTransformer(Object objectToReturn) { - this.objectToReturn = objectToReturn; - } + public StubResultTransformer(Object objectToReturn) { + this.objectToReturn = objectToReturn; + } - public Object transformResult(Result result) { - return objectToReturn; - } - } + public Object transformResult(Result result) { + return objectToReturn; + } + } } diff --git a/src/reference/docbook/whats-new.xml b/src/reference/docbook/whats-new.xml index 444a45bcde..c3e1a0eee4 100644 --- a/src/reference/docbook/whats-new.xml +++ b/src/reference/docbook/whats-new.xml @@ -372,6 +372,13 @@ For more information see . +
+ XsltPayloadTransformer + + You can now specify the transformer factory class name using the + transformer-factory-class attribute. See + +
Message Headers and TCP diff --git a/src/reference/docbook/xml.xml b/src/reference/docbook/xml.xml index 813e86ac18..427d4c0723 100644 --- a/src/reference/docbook/xml.xml +++ b/src/reference/docbook/xml.xml @@ -463,6 +463,11 @@ ]]> + + Starting with Spring Integration 3.0, you can now specify the transformer factory class name using + a constructor argument. This is configured using the transformer-factory-class + attribute when using the namespace. +
ResultTransformers @@ -640,6 +645,10 @@ Xslt parameters could now be mapped to any accessible part of the Message as well as any literal value. + + Starting with Spring Integration 3.0, you can now specify the transformer factory class name using + the transformer-factory-class attribute. +
Namespace Configuration and ResultTransformers