Also test for detection / conversion of custom types
JavaDocs
Code Comments


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/d082e01a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/d082e01a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/d082e01a

Branch: refs/heads/master
Commit: d082e01a02d6d9d737da8ad9571fd577fdfb5e6e
Parents: 4d41eac
Author: sblackmon <[email protected]>
Authored: Tue Dec 2 11:43:50 2014 -0600
Committer: sblackmon <[email protected]>
Committed: Tue Dec 2 11:43:50 2014 -0600

----------------------------------------------------------------------
 .../converter/ActivityConverterProcessor.java   |  50 ++++++---
 .../converter/BaseDocumentClassifier.java       |  19 ++++
 .../BaseObjectNodeActivityConverter.java        |  19 ++++
 .../converter/BaseStringActivityConverter.java  |  19 ++++
 .../test/ActivityConverterProcessorTest.java    |  90 ----------------
 .../BaseActivityConverterProcessorTest.java     |  92 +++++++++++++++++
 .../converter/test/CustomActivityConverter.java |  72 +++++++++++++
 .../CustomActivityConverterProcessorTest.java   | 103 +++++++++++++++++++
 .../test/CustomDocumentClassifier.java          |  74 +++++++++++++
 .../streams/converter/test/CustomType.java      |  37 +++++++
 10 files changed, 469 insertions(+), 106 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
index ff09a86..68c8fd9 100644
--- 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
+++ 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
@@ -16,6 +16,7 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
+
 package org.apache.streams.converter;
 
 import com.google.common.base.Preconditions;
@@ -95,7 +96,7 @@ public class ActivityConverterProcessor implements 
StreamsProcessor {
             }
 
             // for each of these classes:
-            //   use TypeUtil to switch the document to
+            //   use TypeUtil to switch the document to that type
             Map<Class, Object> typedDocs = 
convertToDetectedClasses(detectedClasses, document);
 
             if( typedDocs.size() == 0 ) {
@@ -106,41 +107,58 @@ public class ActivityConverterProcessor implements 
StreamsProcessor {
                 LOGGER.debug("Document has " + typedDocs.size() + " 
representations: " + typedDocs.toString());
             }
 
+            // for each specified / discovered converter
             for( ActivityConverter converter : converters ) {
 
                 Object typedDoc = typedDocs.get(converter.requiredClass());
 
+                // if the document can be typed as the required class
                 if( typedDoc != null ) {
 
                     StreamsDatum datum = DatumUtils.cloneDatum(entry);
 
-                    List<Activity> activities = convertToActivity(converter, 
document);
+                    // let the converter create activities if it can
+                    List<Activity> activities;
+                    try {
+                        activities = convertToActivity(converter, typedDoc);
 
-                    for( Activity activity : activities ) {
+                        if( activities != null && activities.size() > 0) {
 
-                        if (activity != null) {
+                            for (Activity activity : activities) {
 
-                            if( ActivityUtil.isValid(activity)) {
-                                datum.setDocument(activity);
-                                datum.setId(activity.getId());
-                                result.add(datum);
-                            } else {
-                                
LOGGER.debug(converter.getClass().getCanonicalName() + " produced invalid 
Activity converting " + 
converter.requiredClass().getClass().getCanonicalName());
-                            }
+                                if (activity != null) {
 
-                        } else {
-                            
LOGGER.debug(converter.getClass().getCanonicalName() + " returned null 
converting " + converter.requiredClass().getClass().getCanonicalName() + " to 
Activity");
-                        }
+                                    // only accept valid activities
+                                    //   this primitive validity check should 
be replaced with
+                                    //   one that applies javax.validation to 
JSR303 annotations
+                                    //   on the Activity json schema once a 
suitable implementation
+                                    //   is found.
+                                    if (ActivityUtil.isValid(activity)) {
+                                        datum.setDocument(activity);
+                                        datum.setId(activity.getId());
+                                        result.add(datum);
+                                    } else {
+                                        
LOGGER.debug(converter.getClass().getCanonicalName() + " produced invalid 
Activity converting " + 
converter.requiredClass().getClass().getCanonicalName());
+                                    }
+
+                                } else {
+                                    
LOGGER.debug(converter.getClass().getCanonicalName() + " returned null 
converting " + converter.requiredClass().getClass().getCanonicalName() + " to 
Activity");
+                                }
 
+                            }
+                        }
+                    } catch( Exception e ) {
+                        LOGGER.debug("convertToActivity caught exception " + 
e.getMessage());
                     }
 
+
+
                 }
 
             }
 
         } catch( Exception e ) {
-            LOGGER.warn("Unable to fromActivity!  " + e.getMessage());
-            e.printStackTrace();
+            LOGGER.warn("General exception in process! " + e.getMessage());
         } finally {
             return result;
         }

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseDocumentClassifier.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseDocumentClassifier.java
 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseDocumentClassifier.java
index ca22cd4..6451aba 100644
--- 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseDocumentClassifier.java
+++ 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseDocumentClassifier.java
@@ -1,3 +1,22 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.apache.streams.converter;
 
 import com.fasterxml.jackson.databind.ObjectMapper;

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseObjectNodeActivityConverter.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseObjectNodeActivityConverter.java
 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseObjectNodeActivityConverter.java
index 3bedb98..a6d2bd5 100644
--- 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseObjectNodeActivityConverter.java
+++ 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseObjectNodeActivityConverter.java
@@ -1,3 +1,22 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.apache.streams.converter;
 
 import com.fasterxml.jackson.databind.ObjectMapper;

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseStringActivityConverter.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseStringActivityConverter.java
 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseStringActivityConverter.java
index 55f7cc1..ced1c7a 100644
--- 
a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseStringActivityConverter.java
+++ 
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/BaseStringActivityConverter.java
@@ -1,3 +1,22 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.apache.streams.converter;
 
 import com.fasterxml.jackson.core.JsonProcessingException;

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/ActivityConverterProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/ActivityConverterProcessorTest.java
 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/ActivityConverterProcessorTest.java
deleted file mode 100644
index e15ba29..0000000
--- 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/ActivityConverterProcessorTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- *
- *   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.apache.streams.converter.test;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.apache.streams.converter.ActivityConverterProcessor;
-import org.apache.streams.converter.ActivityConverterProcessorConfiguration;
-import org.apache.streams.core.StreamsDatum;
-import org.apache.streams.jackson.StreamsJacksonMapper;
-import org.apache.streams.pojo.json.Activity;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.util.List;
-
-import static junit.framework.Assert.*;
-
-/**
- * Test for
- * @see {@link org.apache.streams.converter.ActivityConverterProcessor}
- */
-public class ActivityConverterProcessorTest {
-
-    private static final ObjectMapper mapper = new StreamsJacksonMapper();
-
-    private static final String ACTIVITY_JSON = 
"{\"id\":\"id\",\"published\":\"Tue Jan 17 21:21:46 Z 
2012\",\"verb\":\"post\",\"provider\":{\"id\":\"providerid\"}}";
-
-    ActivityConverterProcessor processor;
-
-    @Before
-    public void setup() {
-        processor = new ActivityConverterProcessor(new 
ActivityConverterProcessorConfiguration());
-        processor.prepare(new ActivityConverterProcessorConfiguration());
-    }
-
-    @Test
-    public void testBaseActivitySerializerProcessorInvalid() {
-        String INVALID_DOCUMENT = " 38Xs}";
-        StreamsDatum datum = new StreamsDatum(INVALID_DOCUMENT);
-        List<StreamsDatum> result = processor.process(datum);
-        assertNotNull(result);
-        assertEquals(0, result.size());
-    }
-
-    @Test
-    public void testActivityConverterProcessorString() {
-        StreamsDatum datum = new StreamsDatum(ACTIVITY_JSON);
-        List<StreamsDatum> result = processor.process(datum);
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        StreamsDatum resultDatum = result.get(0);
-        assertNotNull(resultDatum);
-        assertNotNull(resultDatum.getDocument());
-        assertTrue(resultDatum.getDocument() instanceof Activity);
-        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("post"));
-    }
-
-    @Test
-    public void testBaseActivitySerializerProcessorObject() throws IOException 
{
-        ObjectNode OBJECT_DOCUMENT = mapper.readValue(ACTIVITY_JSON, 
ObjectNode.class);
-        StreamsDatum datum = new StreamsDatum(OBJECT_DOCUMENT);
-        List<StreamsDatum> result = processor.process(datum);
-        assertNotNull(result);
-        assertEquals(1, result.size());
-        StreamsDatum resultDatum = result.get(0);
-        assertNotNull(resultDatum);
-        assertNotNull(resultDatum.getDocument());
-        assertTrue(resultDatum.getDocument() instanceof Activity);
-        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("post"));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/BaseActivityConverterProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/BaseActivityConverterProcessorTest.java
 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/BaseActivityConverterProcessorTest.java
new file mode 100644
index 0000000..97a52a4
--- /dev/null
+++ 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/BaseActivityConverterProcessorTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ *   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.apache.streams.converter.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.streams.converter.ActivityConverterProcessor;
+import org.apache.streams.converter.ActivityConverterProcessorConfiguration;
+import org.apache.streams.core.StreamsDatum;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Activity;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.List;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Test for
+ * @see {@link org.apache.streams.converter.ActivityConverterProcessor}
+ *
+ * Test that default String & ObjectNode conversion works.
+ */
+public class BaseActivityConverterProcessorTest {
+
+    private static final ObjectMapper mapper = new StreamsJacksonMapper();
+
+    private static final String ACTIVITY_JSON = 
"{\"id\":\"id\",\"published\":\"Tue Jan 17 21:21:46 Z 
2012\",\"verb\":\"post\",\"provider\":{\"id\":\"providerid\"}}";
+
+    ActivityConverterProcessor processor;
+
+    @Before
+    public void setup() {
+        processor = new ActivityConverterProcessor(new 
ActivityConverterProcessorConfiguration());
+        processor.prepare(new ActivityConverterProcessorConfiguration());
+    }
+
+    @Test
+    public void testBaseActivitySerializerProcessorInvalid() {
+        String INVALID_DOCUMENT = " 38Xs}";
+        StreamsDatum datum = new StreamsDatum(INVALID_DOCUMENT);
+        List<StreamsDatum> result = processor.process(datum);
+        assertNotNull(result);
+        assertEquals(0, result.size());
+    }
+
+    @Test
+    public void testActivityConverterProcessorString() {
+        StreamsDatum datum = new StreamsDatum(ACTIVITY_JSON);
+        List<StreamsDatum> result = processor.process(datum);
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        StreamsDatum resultDatum = result.get(0);
+        assertNotNull(resultDatum);
+        assertNotNull(resultDatum.getDocument());
+        assertTrue(resultDatum.getDocument() instanceof Activity);
+        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("post"));
+    }
+
+    @Test
+    public void testBaseActivitySerializerProcessorObject() throws IOException 
{
+        ObjectNode OBJECT_DOCUMENT = mapper.readValue(ACTIVITY_JSON, 
ObjectNode.class);
+        StreamsDatum datum = new StreamsDatum(OBJECT_DOCUMENT);
+        List<StreamsDatum> result = processor.process(datum);
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        StreamsDatum resultDatum = result.get(0);
+        assertNotNull(resultDatum);
+        assertNotNull(resultDatum.getDocument());
+        assertTrue(resultDatum.getDocument() instanceof Activity);
+        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("post"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverter.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverter.java
 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverter.java
new file mode 100644
index 0000000..8421273
--- /dev/null
+++ 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverter.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ *   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.apache.streams.converter.test;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.streams.converter.ActivityConverterProcessor;
+import org.apache.streams.converter.ActivityConverterProcessorConfiguration;
+import org.apache.streams.data.ActivityConverter;
+import org.apache.streams.exceptions.ActivityConversionException;
+import org.apache.streams.pojo.json.Activity;
+import org.apache.streams.pojo.json.Provider;
+
+import java.util.List;
+
+/**
+ * Support class for
+ * @see {@link 
org.apache.streams.converter.test.CustomActivityConverterProcessorTest}
+ */
+public class CustomActivityConverter implements ActivityConverter<CustomType> {
+
+
+    @Override
+    public Class requiredClass() {
+        return CustomType.class;
+    }
+
+    @Override
+    public String serializationFormat() {
+        return null;
+    }
+
+    @Override
+    public CustomType fromActivity(Activity deserialized) throws 
ActivityConversionException {
+        return null;
+    }
+
+    @Override
+    public List<Activity> toActivityList(CustomType document) throws 
ActivityConversionException {
+        Activity customActivity = new Activity();
+        customActivity.setId(document.getTest());
+        customActivity.setVerb(document.getTest());
+        customActivity.setProvider((Provider)new 
Provider().withId(document.getTest()));
+        return Lists.newArrayList(customActivity);
+    }
+
+    @Override
+    public List<Activity> toActivityList(List<CustomType> list) throws 
ActivityConversionException {
+        return null;
+    }
+
+    @Override
+    public List<CustomType> fromActivityList(List<Activity> list) throws 
ActivityConversionException {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverterProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverterProcessorTest.java
 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverterProcessorTest.java
new file mode 100644
index 0000000..c9333c7
--- /dev/null
+++ 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomActivityConverterProcessorTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *
+ *   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.apache.streams.converter.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.streams.converter.ActivityConverterProcessor;
+import org.apache.streams.converter.ActivityConverterProcessorConfiguration;
+import org.apache.streams.core.StreamsDatum;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Activity;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.List;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Test for
+ * @see {@link org.apache.streams.converter.ActivityConverterProcessor}
+ *
+ * Test that arbitrary POJO conversion works, including when POJO represented 
as String & ObjectNode.
+ */
+public class CustomActivityConverterProcessorTest {
+
+    private static final ObjectMapper mapper = new StreamsJacksonMapper();
+
+    ActivityConverterProcessor processor;
+
+    ActivityConverterProcessorConfiguration configuration;
+
+    CustomType testDocument;
+
+    @Before
+    public void setup() {
+        configuration = new ActivityConverterProcessorConfiguration();
+        configuration.getClassifiers().add(new CustomDocumentClassifier());
+        configuration.getConverters().add(new CustomActivityConverter());
+        processor = new ActivityConverterProcessor(configuration);
+        processor.prepare(configuration);
+        testDocument = new CustomType();
+        testDocument.setTest("testValue");
+    }
+
+    @Test
+    public void testCustomActivityConverterProcessorString() throws 
IOException  {
+        StreamsDatum datum = new 
StreamsDatum(mapper.writeValueAsString(testDocument));
+        List<StreamsDatum> result = processor.process(datum);
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        StreamsDatum resultDatum = result.get(0);
+        assertNotNull(resultDatum);
+        assertNotNull(resultDatum.getDocument());
+        assertTrue(resultDatum.getDocument() instanceof Activity);
+        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("testValue"));
+    }
+
+    @Test
+    public void testCustomActivitySerializerProcessorObjectNode() throws 
IOException {
+        ObjectNode OBJECT_DOCUMENT = mapper.convertValue(testDocument, 
ObjectNode.class);
+        StreamsDatum datum = new StreamsDatum(OBJECT_DOCUMENT);
+        List<StreamsDatum> result = processor.process(datum);
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        StreamsDatum resultDatum = result.get(0);
+        assertNotNull(resultDatum);
+        assertNotNull(resultDatum.getDocument());
+        assertTrue(resultDatum.getDocument() instanceof Activity);
+        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("testValue"));
+    }
+
+    @Test
+    public void testCustomActivitySerializerProcessorPOJO() throws IOException 
{
+        StreamsDatum datum = new StreamsDatum(testDocument);
+        List<StreamsDatum> result = processor.process(datum);
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        StreamsDatum resultDatum = result.get(0);
+        assertNotNull(resultDatum);
+        assertNotNull(resultDatum.getDocument());
+        assertTrue(resultDatum.getDocument() instanceof Activity);
+        
assertTrue(((Activity)resultDatum.getDocument()).getVerb().equals("testValue"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomDocumentClassifier.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomDocumentClassifier.java
 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomDocumentClassifier.java
new file mode 100644
index 0000000..102c8ba
--- /dev/null
+++ 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomDocumentClassifier.java
@@ -0,0 +1,74 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.apache.streams.converter.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.streams.converter.ActivityConverterProcessorConfiguration;
+import org.apache.streams.data.DocumentClassifier;
+import org.apache.streams.data.util.ActivityUtil;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Activity;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Support class for
+ * @see {@link 
org.apache.streams.converter.test.CustomActivityConverterProcessorTest}
+ */
+public class CustomDocumentClassifier implements DocumentClassifier {
+
+    private ObjectMapper mapper = StreamsJacksonMapper.getInstance();
+
+    @Override
+    public List<Class> detectClasses(Object document) {
+
+        CustomType possibleMatchDocument = null;
+        ObjectNode node = null;
+
+        List<Class> classes = Lists.newArrayList();
+
+        if( document instanceof String ) {
+            classes.add(String.class);
+            try {
+                possibleMatchDocument = 
this.mapper.readValue((String)document, CustomType.class);
+                if(possibleMatchDocument != null && 
possibleMatchDocument.getTest() != null)
+                    classes.add(CustomType.class);
+            } catch (IOException e1) {
+                try {
+                    node = this.mapper.readValue((String)document, 
ObjectNode.class);
+                    classes.add(ObjectNode.class);
+                } catch (IOException e2) { }
+            }
+        } else if( document instanceof ObjectNode ){
+            classes.add(ObjectNode.class);
+            possibleMatchDocument = 
this.mapper.convertValue((ObjectNode)document, CustomType.class);
+            if(possibleMatchDocument != null && 
possibleMatchDocument.getTest() != null)
+                classes.add(CustomType.class);
+        } else {
+            classes.add(document.getClass());
+        }
+
+        return classes;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d082e01a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomType.java
----------------------------------------------------------------------
diff --git 
a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomType.java
 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomType.java
new file mode 100644
index 0000000..ddcec4b
--- /dev/null
+++ 
b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/CustomType.java
@@ -0,0 +1,37 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.apache.streams.converter.test;
+
+/**
+ * Support class for
+ * @see {@link 
org.apache.streams.converter.test.CustomActivityConverterProcessorTest}
+ */
+public class CustomType {
+
+    private String test;
+
+    public String getTest() {
+        return test;
+    }
+
+    public void setTest(String test) {
+        this.test = test;
+    }
+}

Reply via email to