From 93623538e85fae3e0513568916f0f9b28dd8e731 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Mon, 26 Jul 2010 19:12:20 +0000 Subject: [PATCH] INT-1120 Generalize serialization strategy to enable serialization implementations to be usable from transformers and when streaming is required. --- .../DeserializationFailureException.java | 45 +++++++++++ .../serializer/InputStreamingConverter.java | 40 ++++++++++ .../JavaDeserializingConverter.java | 51 +++++++++++++ .../JavaSerializationConverter.java | 58 ++++++++++++++ .../serializer/JavaSerializingConverter.java | 49 ++++++++++++ .../serializer/OutputStreamingConverter.java | 39 ++++++++++ .../serializer/SerializationException.java | 47 ++++++++++++ .../SerializationFailureException.java | 45 +++++++++++ .../commons/serializer/package-info.java | 8 ++ .../PayloadDeserializingTransformer.java | 46 +++++------ .../PayloadSerializingTransformer.java | 35 +++++---- .../PayloadTypeConvertingTransformer.java | 50 ++++++++++++ .../serializer/JavaSerializationTests.java | 76 +++++++++++++++++++ ...PayloadTypeConvertingTransformerTests.java | 49 ++++++++++++ 14 files changed, 598 insertions(+), 40 deletions(-) create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/DeserializationFailureException.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/InputStreamingConverter.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaDeserializingConverter.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializationConverter.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializingConverter.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/OutputStreamingConverter.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationException.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationFailureException.java create mode 100644 spring-integration-core/src/main/java/org/springframework/commons/serializer/package-info.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformer.java create mode 100644 spring-integration-core/src/test/java/org/springframework/commons/serializer/JavaSerializationTests.java create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformerTests.java diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/DeserializationFailureException.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/DeserializationFailureException.java new file mode 100644 index 0000000000..4938bfef0e --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/DeserializationFailureException.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +/** + * @author Gary Russell + * @since 2.0 + * + */ +@SuppressWarnings("serial") +public class DeserializationFailureException extends SerializationException { + + /** + * Construct a DeserializationException with the specified detail message. + * @param msg the detail message + */ + public DeserializationFailureException(String msg) { + super(msg); + } + + /** + * Construct a DeserializationFailureException with the specified detail message + * and nested exception. + * @param msg the detail message + * @param cause the nested exception + */ + public DeserializationFailureException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/InputStreamingConverter.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/InputStreamingConverter.java new file mode 100644 index 0000000000..4c9bbcf3af --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/InputStreamingConverter.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import java.io.IOException; +import java.io.InputStream; + +/** + * An standard interface to convert from data in an InputStream to + * an Object. + * + * @author Gary Russell + * @since 2.0 + * + */ +public interface InputStreamingConverter { + + /** + * Read (assemble an object of type T) from an InputStream. + * @param is The InputStream. + * @return The object. + * @throws IOException + */ + public T convert(InputStream inputStream) throws IOException; + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaDeserializingConverter.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaDeserializingConverter.java new file mode 100644 index 0000000000..9480df1745 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaDeserializingConverter.java @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.springframework.core.convert.converter.Converter; + +/** + * Delegates to a {@link JavaSerializationConverter} to deserialize data + * in a byte[] to an object. + * + * @author Gary Russell + * @since 2.0 + * + */ +public class JavaDeserializingConverter implements Converter { + + private JavaSerializationConverter converter = new JavaSerializationConverter(); + + public Object convert(byte[] source) { + ByteArrayInputStream byteStream = new ByteArrayInputStream(source); + try { + return converter.convert(byteStream); + } + catch (Exception e) { + try { + byteStream.close(); + } catch (IOException e1) { } + throw new DeserializationFailureException( + "Failed to deserialize payload. Is the byte array a result of Object serialization?", e); + } + } + + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializationConverter.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializationConverter.java new file mode 100644 index 0000000000..6c8c23771b --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializationConverter.java @@ -0,0 +1,58 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; + + +/** + * Converter that implements both input and output streaming using Java + * Serialization. + * + * @author Gary Russell + * @since 2.0 + * + */ +public class JavaSerializationConverter + implements InputStreamingConverter, + OutputStreamingConverter { + + public Object convert(InputStream inputStream) throws IOException { + ObjectInputStream objectInputStream = null; + try { + objectInputStream = new ObjectInputStream(inputStream); + return objectInputStream.readObject(); + } catch (ClassNotFoundException e) { + if (objectInputStream != null) { + objectInputStream.close(); + } + throw new IOException(e); + } + } + + public void convert(Object object, OutputStream outputStream) + throws IOException { + ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); + objectOutputStream.writeObject(object); + objectOutputStream.flush(); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializingConverter.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializingConverter.java new file mode 100644 index 0000000000..8b57f0d6cb --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/JavaSerializingConverter.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import java.io.ByteArrayOutputStream; +import java.io.Serializable; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.util.Assert; + +/** + * Delegates to a {@link JavaSerializationConverter} to serialize an object + * to a byte[]. Source object must implement {@link Serializable}. + * + * @author Gary Russell + * @since 2.0 + * + */ +public class JavaSerializingConverter implements Converter { + + private JavaSerializationConverter converter = new JavaSerializationConverter(); + + public byte[] convert(Object source) { + Assert.isTrue(source instanceof Serializable, this.getClass().getName() + + " requires a Serializable payload, but received [" + source.getClass().getName() + "]"); + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + try { + this.converter.convert(source, byteStream); + return byteStream.toByteArray(); + } catch (Exception e) { + throw new SerializationFailureException("Failed to serialize", e); + } + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/OutputStreamingConverter.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/OutputStreamingConverter.java new file mode 100644 index 0000000000..58a7afd927 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/OutputStreamingConverter.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * A standard interface to stream an object to an OutputStream. + * + * @author Gary Russell + * @since 2.0 + * + */ +public interface OutputStreamingConverter { + + /** + * Write an object of type T to the outputSream. + * @param object The object. + * @param outputStream The outputStream. + * @throws IOException + */ + public void convert(T object, OutputStream outputStream) throws IOException; + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationException.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationException.java new file mode 100644 index 0000000000..e1a398cb0b --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationException.java @@ -0,0 +1,47 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import org.springframework.core.NestedRuntimeException; + +/** + * @author Gary Russell + * @since 2.0 + * + */ +@SuppressWarnings("serial") +public abstract class SerializationException extends NestedRuntimeException { + + /** + * Construct a SerializationException with the specified detail message. + * @param msg the detail message + */ + public SerializationException(String msg) { + super(msg); + } + + /** + * Construct a SerializationException with the specified detail message + * and nested exception. + * @param msg the detail message + * @param cause the nested exception + */ + public SerializationException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationFailureException.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationFailureException.java new file mode 100644 index 0000000000..f89168508c --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/SerializationFailureException.java @@ -0,0 +1,45 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +/** + * @author Gary Russell + * @since 2.0 + * + */ +@SuppressWarnings("serial") +public class SerializationFailureException extends SerializationException { + + /** + * Construct a SerializationFailureException with the specified detail message. + * @param msg the detail message + */ + public SerializationFailureException(String msg) { + super(msg); + } + + /** + * Construct a SerializationFailureException with the specified detail message + * and nested exception. + * @param msg the detail message + * @param cause the nested exception + */ + public SerializationFailureException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/commons/serializer/package-info.java b/spring-integration-core/src/main/java/org/springframework/commons/serializer/package-info.java new file mode 100644 index 0000000000..31640cb021 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/commons/serializer/package-info.java @@ -0,0 +1,8 @@ +/** + * + * Root package for Spring commons' serializer interfaces and implementations. + * Provides an abstraction over various serialization techniques. + * Includes exceptions for serialization and deserialization failures. + */ +package org.springframework.commons.serializer; + diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadDeserializingTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadDeserializingTransformer.java index cc429644ae..f9fc495f34 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadDeserializingTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadDeserializingTransformer.java @@ -16,39 +16,35 @@ package org.springframework.integration.transformer; -import java.io.ByteArrayInputStream; -import java.io.ObjectInputStream; -import java.io.ObjectStreamException; +import org.springframework.commons.serializer.JavaDeserializingConverter; +import org.springframework.core.convert.converter.Converter; +import org.springframework.util.Assert; /** - * Transformer that deserializes the inbound byte array payload to an object. - *

The byte array payload must be a result of serialization. + * Transformer that deserializes the inbound byte array payload to an object by delegating to a + * Converter<byte[], Object>. Default delegate is a {@link JavaDeserializingConverter}. + *

The byte array payload must be a result of equivalent serialization. * * @author Mark Fisher + * @author Gary Russell * @since 1.0.1 */ -public class PayloadDeserializingTransformer extends AbstractPayloadTransformer { - +public class PayloadDeserializingTransformer extends PayloadTypeConvertingTransformer { + + public PayloadDeserializingTransformer() { + this.converter = new JavaDeserializingConverter(); + } + @Override protected Object transformPayload(byte[] payload) throws Exception { - ByteArrayInputStream byteStream = new ByteArrayInputStream(payload); - ObjectInputStream objectStream = null; - try { - objectStream = new ObjectInputStream(byteStream); - return objectStream.readObject(); - } - catch (ObjectStreamException e) { - throw new IllegalArgumentException( - "Failed to deserialize payload. Is the byte array a result of Object serialization?", e); - } - finally { - try { - objectStream.close(); - } - catch (Exception e) { - // ignore - } - } + Assert.notNull(this.converter, this.getClass().getName() + " needs a Converter"); + return converter.convert(payload); } + @Override + public void setConverter(Converter converter) { + this.converter = converter; + } + + } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadSerializingTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadSerializingTransformer.java index 3c8a02ecec..dce0ac8378 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadSerializingTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadSerializingTransformer.java @@ -16,31 +16,36 @@ package org.springframework.integration.transformer; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - +import org.springframework.commons.serializer.JavaSerializingConverter; +import org.springframework.core.convert.converter.Converter; import org.springframework.util.Assert; /** - * Transformer that serializes the inbound payload into a byte array. - *

The payload instance must be Serializable. + * Transformer that serializes the inbound payload into a byte array by delegating to a + * Converter<Object, byte[]>. Default delegate is a {@link JavaSerializingConverter}. + * + *

The payload instance must be Serializable if the default converter is used. * * @author Mark Fisher + * @author Gary Russell * @since 1.0.1 */ -public class PayloadSerializingTransformer extends AbstractPayloadTransformer { +public class PayloadSerializingTransformer extends PayloadTypeConvertingTransformer { + + + public PayloadSerializingTransformer() { + this.converter = new JavaSerializingConverter(); + } @Override protected byte[] transformPayload(Object payload) throws Exception { - Assert.isTrue(payload instanceof Serializable, this.getClass().getName() - + " requires a Serializable payload, but received [" + payload.getClass().getName() + "]"); - ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); - ObjectOutputStream objectStream = new ObjectOutputStream(byteStream); - objectStream.writeObject(payload); - objectStream.flush(); - objectStream.close(); - return byteStream.toByteArray(); + Assert.notNull(this.converter, this.getClass().getName() + " needs a Converter"); + return converter.convert(payload); } + @Override + public void setConverter(Converter converter) { + this.converter = converter; + } + } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformer.java new file mode 100644 index 0000000000..f93f41949a --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformer.java @@ -0,0 +1,50 @@ +/* + * 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. + */ + +package org.springframework.integration.transformer; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.util.Assert; + +/** + * Transformer that converts the inbound payload to an object by delegating to a + * Converter<Object, Object>. A reference to the delegate must be provided. + * + * @author Gary Russell + * @since 2.0 + * + */ +public class PayloadTypeConvertingTransformer extends AbstractPayloadTransformer { + + protected Converter converter; + + @Override + protected U transformPayload(T payload) throws Exception { + Assert.notNull(this.converter, this.getClass().getName() + " needs a Converter"); + return converter.convert(payload); + } + + /** + * Sets the converter to be used for Serialization. + * + * @param converter The Converter. + */ + public void setConverter(Converter converter) { + this.converter = converter; + } + + +} diff --git a/spring-integration-core/src/test/java/org/springframework/commons/serializer/JavaSerializationTests.java b/spring-integration-core/src/test/java/org/springframework/commons/serializer/JavaSerializationTests.java new file mode 100644 index 0000000000..d5bf70ca2f --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/commons/serializer/JavaSerializationTests.java @@ -0,0 +1,76 @@ +/* + * 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. + */ + +package org.springframework.commons.serializer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.Serializable; + +import org.junit.Test; + + +/** + * @author Gary Russell + * @since 2.0 + * + */ +public class JavaSerializationTests { + + @Test + public void testGood() { + JavaSerializingConverter toBytes = new JavaSerializingConverter(); + byte[] bytes = toBytes.convert("Testing"); + JavaDeserializingConverter fromBytes = new JavaDeserializingConverter(); + assertEquals("Testing", fromBytes.convert(bytes)); + } + + @Test + public void testBadSerializeNotSerializable() { + JavaSerializingConverter toBytes = new JavaSerializingConverter(); + try { + toBytes.convert(new Object()); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { } + + } + + @Test + public void testBadSerializeNotSerializableField() { + JavaSerializingConverter toBytes = new JavaSerializingConverter(); + try { + toBytes.convert(new UnSerializable()); + fail("Expected SerializationFailureException"); + } catch (SerializationFailureException e) { } + + } + + @Test + public void testBadDeserialize() { + JavaDeserializingConverter fromBytes = new JavaDeserializingConverter(); + try { + fromBytes.convert("Junk".getBytes()); + fail("Expected DeserializationFailureException"); + } catch (DeserializationFailureException e) { } + } + + class UnSerializable implements Serializable { + private static final long serialVersionUID = 1L; + @SuppressWarnings("unused") + private Object object; + } +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformerTests.java new file mode 100644 index 0000000000..284d85d5ad --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/PayloadTypeConvertingTransformerTests.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.springframework.integration.transformer; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.springframework.core.convert.converter.Converter; + +/** + * @author Gary Russell + * @since 2.0 + * + */ +public class PayloadTypeConvertingTransformerTests { + + /** + * Test method for {@link org.springframework.integration.transformer.PayloadTypeConvertingTransformer#transformPayload(java.lang.Object)}. + */ + @Test + public void testTransformPayloadObject() throws Exception { + PayloadTypeConvertingTransformer tx = new PayloadTypeConvertingTransformer(); + tx.setConverter(new Converter () { + public String convert(String source) { + return source.toUpperCase(); + }} + ); + String in = "abcd"; + String out = tx.transformPayload(in); + assertEquals("ABCD", out); + } + +} + +