Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SPR-66

Capability for C24 model objects to be marshalled into JSON String objects through the C24 Spring Integration namespace.
  • Loading branch information...
commit 3905a7d3a8e515d3e6de6a6c59fc5f06e129f2bc 1 parent 0938cfe
Matt Vickery authored
View
4 .gitignore
@@ -1,4 +1,6 @@
.project
.classpath
.settings/
-target/
+target/
+.idea
+*.iml
View
16 c24-spring-core/src/main/java/biz/c24/io/spring/sink/JSonSinkFactory.java
@@ -0,0 +1,16 @@
+package biz.c24.io.spring.sink;
+
+import biz.c24.io.api.presentation.JsonSink;
+import biz.c24.io.api.presentation.Sink;
+
+/**
+ * User: mvickery
+ * Date: 23/04/2012
+ */
+public class JsonSinkFactory extends AbstractSinkFactory {
+
+ @Override
+ protected Sink createSink() {
+ return new JsonSink();
+ }
+}
View
66 c24-spring-integration/src/test/java/biz/c24/io/spring/integration/test/TestUtils.java
@@ -24,49 +24,61 @@
/**
* @author askogman
- *
*/
public class TestUtils {
- public static ComplexDataObject loadObject() throws Exception {
+ public static ComplexDataObject loadObject() throws Exception {
- ClassPathResource resource = new ClassPathResource("valid-1.txt");
+ ClassPathResource resource = new ClassPathResource("valid-1.txt");
- TextualSource textualSource = new TextualSource(
- resource.getInputStream());
+ TextualSource textualSource = new TextualSource(
+ resource.getInputStream());
- ComplexDataObject object = textualSource
- .readObject(InputDocumentRootElement.getInstance());
+ ComplexDataObject object = textualSource
+ .readObject(InputDocumentRootElement.getInstance());
- return object;
- }
+ return object;
+ }
- public static byte[] loadXmlBytes() throws Exception {
+ public static byte[] loadXmlBytes() throws Exception {
- ClassPathResource resource = new ClassPathResource("valid-XML-1.xml");
- byte[] valid1 = FileCopyUtils
- .copyToByteArray(resource.getInputStream());
+ ClassPathResource resource = new ClassPathResource("valid-XML-1.xml");
+ byte[] valid1 = FileCopyUtils
+ .copyToByteArray(resource.getInputStream());
- return valid1;
- }
+ return valid1;
+ }
- public static String loadXmlString() throws Exception {
+ public static String loadXmlString() throws Exception {
- return new String(loadXmlBytes(), "UTF-8");
- }
+ return new String(loadXmlBytes(), "UTF-8");
+ }
- public static byte[] loadCsvBytes() throws Exception {
+ public static byte[] loadCsvBytes() throws Exception {
- ClassPathResource resource = new ClassPathResource("valid-1.txt");
- byte[] valid1 = FileCopyUtils
- .copyToByteArray(resource.getInputStream());
+ ClassPathResource resource = new ClassPathResource("valid-1.txt");
+ byte[] valid1 = FileCopyUtils
+ .copyToByteArray(resource.getInputStream());
- return valid1;
- }
+ return valid1;
+ }
- public static String loadCsvString() throws Exception {
+ public static String loadCsvString() throws Exception {
- return new String(loadCsvBytes(), "UTF-8");
- }
+ return new String(loadCsvBytes(), "UTF-8");
+ }
+
+ public static byte[] loadJsonBytes() throws Exception {
+
+ ClassPathResource resource = new ClassPathResource("valid-1.json");
+ byte[] valid1 = FileCopyUtils
+ .copyToByteArray(resource.getInputStream());
+ return valid1;
+ }
+
+ public static String loadJsonString() throws Exception {
+
+ return new String(loadJsonBytes(), "UTF-8");
+ }
}
View
29 ...integration/src/test/java/biz/c24/io/spring/integration/transformer/IoMarshallingTransformerIUTests.java
@@ -15,19 +15,20 @@
*/
package biz.c24.io.spring.integration.transformer;
-import static biz.c24.io.spring.integration.test.TestUtils.*;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.springframework.integration.Message;
-import org.springframework.integration.support.MessageBuilder;
-
import biz.c24.io.examples.models.basic.InputDocumentRootElement;
import biz.c24.io.spring.core.C24Model;
+import biz.c24.io.spring.sink.JsonSinkFactory;
import biz.c24.io.spring.sink.OutputType;
import biz.c24.io.spring.sink.TextualSinkFactory;
import biz.c24.io.spring.sink.XmlSinkFactory;
+import org.junit.Test;
+import org.springframework.integration.Message;
+import org.springframework.integration.support.MessageBuilder;
+
+import static biz.c24.io.spring.integration.test.TestUtils.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
public class IoMarshallingTransformerIUTests {
@@ -103,5 +104,17 @@ public void canMarshalTextToByteArray() throws Exception {
}
+ @Test
+ public void canMarshalTextToJsonString() throws Exception {
+
+ C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
+ ioMarshallingTransformer.setOutputType(OutputType.STRING);
+ ioMarshallingTransformer.setSinkFactory(new JsonSinkFactory());
+
+ Message message = MessageBuilder.withPayload(loadObject()).build();
+ Message<?> outputMessage = ioMarshallingTransformer.transform(message);
+
+ assertThat((String) outputMessage.getPayload(), is(loadJsonString()));
+ }
}
View
27 c24-spring-integration/src/test/java/log4j.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jakarta.apache.org/log4j/ ">
+
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ISO8601} [%t] %p %c %x - %m%n"/>
+ </layout>
+ </appender>
+
+ <appender name="file" class="org.apache.log4j.FileAppender">
+ <param name="file" value="c24-spring-integration-test.log"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ISO8601} [%t] %p %c %x - %m%n"/>
+ </layout>
+ </appender>
+
+
+ <root>
+ <level value="info"/>
+ <appender-ref ref="console"/>
+ <appender-ref ref="file"/>
+ </root>
+
+</log4j:configuration>
View
1  c24-spring-integration/src/test/resources/valid-1.json
@@ -0,0 +1 @@
+{"DocumentRoot":{"Employees":{"Employee":[{"Salutation":"Mr","FirstName":"Andy","LastName":"Acheson","JobTitle":"Software Developer"},{"Salutation":"Mr","FirstName":"Joe","LastName":"Bloggs","JobTitle":"Security Guard"},{"Salutation":"Mr","FirstName":"Greg","LastName":"Gatsby","JobTitle":"Managing Director"}]}}}
Please sign in to comment.
Something went wrong with that request. Please try again.