You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2015/02/10 23:11:36 UTC

incubator-streams git commit: resolves STREAMS-275

Repository: incubator-streams
Updated Branches:
  refs/heads/asf-master [created] 2595ee327


resolves STREAMS-275


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

Branch: refs/heads/asf-master
Commit: 2595ee3278452bb13bd919394f541fae4cef834f
Parents: e13617d
Author: sblackmon <sb...@w2odigital.com>
Authored: Mon Feb 9 16:59:15 2015 -0600
Committer: sblackmon <sb...@w2odigital.com>
Committed: Mon Feb 9 16:59:15 2015 -0600

----------------------------------------------------------------------
 .../converter/ActivityConverterProcessor.java   |  8 +-
 .../NoConfigActivityConverterProcessorTest.java | 92 ++++++++++++++++++++
 2 files changed, 98 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/2595ee32/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 4ce6111..a8d79f2 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
@@ -214,7 +214,9 @@ public class ActivityConverterProcessor implements StreamsProcessor {
         Reflections reflections = new Reflections(new ConfigurationBuilder()
                 .setUrls(ClasspathHelper.forPackage("org.apache.streams"))
                 .setScanners(new SubTypesScanner()));
-        if (configuration.getClassifiers().size() > 0) {
+        if ( configuration != null &&
+                configuration.getClassifiers() != null &&
+                configuration.getClassifiers().size() > 0) {
             for( DocumentClassifier classifier : configuration.getClassifiers()) {
                 try {
                     this.classifiers.add(classifier);
@@ -233,7 +235,9 @@ public class ActivityConverterProcessor implements StreamsProcessor {
             }
         }
         Preconditions.checkArgument(this.classifiers.size() > 0);
-        if (configuration.getConverters().size() > 0) {
+        if (configuration != null &&
+                configuration.getConverters() != null &&
+                configuration.getConverters().size() > 0) {
             for( ActivityConverter converter : configuration.getConverters()) {
                 try {
                     this.converters.add(converter);

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/2595ee32/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/NoConfigActivityConverterProcessorTest.java
----------------------------------------------------------------------
diff --git a/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/NoConfigActivityConverterProcessorTest.java b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/NoConfigActivityConverterProcessorTest.java
new file mode 100644
index 0000000..9c5b128
--- /dev/null
+++ b/streams-components/streams-converters/src/test/java/org/apache/streams/converter/test/NoConfigActivityConverterProcessorTest.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 NoConfigActivityConverterProcessorTest {
+
+    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();
+        processor.prepare(null);
+    }
+
+    @Test
+    public void testNoConfigActivitySerializerProcessorInvalid() {
+        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 testNoConfigActivityConverterProcessorString() {
+        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 testNoConfigActivitySerializerProcessorObject() 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"));
+    }
+
+}