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 2014/11/17 21:45:55 UTC

[1/4] incubator-streams git commit: refresh streams-config support detection of StreamsConfiguration support detection of any component configuration test using base ComponentConfiguration

Repository: incubator-streams
Updated Branches:
  refs/heads/master 9b89c0898 -> d0b5a0a6b


refresh streams-config
support detection of StreamsConfiguration
support detection of any component configuration
test using base ComponentConfiguration


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

Branch: refs/heads/master
Commit: 13024d00309b9576ff5cb6fe49beccbd33062228
Parents: bfa9466
Author: sblackmon <sb...@apache.org>
Authored: Tue Nov 11 17:44:59 2014 -0600
Committer: sblackmon <sb...@apache.org>
Committed: Tue Nov 11 17:44:59 2014 -0600

----------------------------------------------------------------------
 streams-config/pom.xml                          |  2 +-
 .../streams/config/ComponentConfigurator.java   | 47 +++++++++++++++++++
 .../streams/config/StreamsConfigurator.java     | 28 ++++++++++++
 .../main/jsonschema/ComponentConfiguration.json | 23 ++++++++++
 .../main/jsonschema/StreamsConfiguration.json   |  5 +-
 .../config/test/ComponentConfiguratorTest.java  | 37 +++++++++++++++
 .../config/test/StreamsConfiguratorTest.java    | 48 ++++++++++++++++++++
 .../src/test/resources/componentTest.conf       | 11 +++++
 8 files changed, 198 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/pom.xml
----------------------------------------------------------------------
diff --git a/streams-config/pom.xml b/streams-config/pom.xml
index aa8d59b..63a6857 100644
--- a/streams-config/pom.xml
+++ b/streams-config/pom.xml
@@ -104,7 +104,7 @@
                     <addCompileSourceRoot>true</addCompileSourceRoot>
                     <generateBuilders>true</generateBuilders>
                     <sourcePaths>
-                        <sourcePath>src/main/jsonschema/StreamsConfiguration.json</sourcePath>
+                        <sourcePath>src/main/jsonschema</sourcePath>
                     </sourcePaths>
                     <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory>
                     <targetPackage>org.apache.streams.config</targetPackage>

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
new file mode 100644
index 0000000..0056a4a
--- /dev/null
+++ b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
@@ -0,0 +1,47 @@
+package org.apache.streams.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.reflect.TypeToken;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigRenderOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+
+/**
+ * Created by sblackmon on 11/11/14.
+ */
+public class ComponentConfigurator<T extends Serializable> {
+
+    private Class<T> configClass;
+    public ComponentConfigurator(Class<T> configClass) {
+        this.configClass = configClass;
+    }
+
+    private final static Logger LOGGER = LoggerFactory.getLogger(ComponentConfigurator.class);
+
+    private final static ObjectMapper mapper = new ObjectMapper();
+
+    public T detectConfiguration(Config typesafeConfig) {
+
+        T pojoConfig = null;
+
+        try {
+            pojoConfig = mapper.readValue(typesafeConfig.root().render(ConfigRenderOptions.concise()), configClass);
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOGGER.warn("Could not parse:", typesafeConfig);
+        }
+
+        return pojoConfig;
+    }
+
+    public T detectConfiguration(String subConfig) {
+        return detectConfiguration( StreamsConfigurator.config.getString(subConfig));
+    }
+
+    public T detectConfiguration(Config typesafeConfig, String subConfig) {
+        return detectConfiguration( typesafeConfig.getString(subConfig));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
index e35dd5d..34e3844 100644
--- a/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
+++ b/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
@@ -18,8 +18,15 @@
 
 package org.apache.streams.config;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.reflect.TypeToken;
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
+import com.typesafe.config.ConfigRenderOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
 
 /**
  * Created with IntelliJ IDEA.
@@ -30,9 +37,30 @@ import com.typesafe.config.ConfigFactory;
  */
 public class StreamsConfigurator {
 
+    private final static Logger LOGGER = LoggerFactory.getLogger(ComponentConfigurator.class);
+
+    private final static ObjectMapper mapper = new ObjectMapper();
+
     /*
         Pull all configuration files from the classpath, system properties, and environment variables
      */
     public static Config config = ConfigFactory.load();
 
+    public static StreamsConfiguration detectConfiguration() {
+        return detectConfiguration(config);
+    }
+
+    public static StreamsConfiguration detectConfiguration(Config typesafeConfig) {
+
+        StreamsConfiguration pojoConfig = null;
+
+        try {
+            pojoConfig = mapper.readValue(typesafeConfig.root().render(ConfigRenderOptions.concise()), StreamsConfiguration.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+            LOGGER.warn("Could not parse:", typesafeConfig);
+        }
+
+        return pojoConfig;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/main/jsonschema/ComponentConfiguration.json
----------------------------------------------------------------------
diff --git a/streams-config/src/main/jsonschema/ComponentConfiguration.json b/streams-config/src/main/jsonschema/ComponentConfiguration.json
new file mode 100644
index 0000000..dcb9cde
--- /dev/null
+++ b/streams-config/src/main/jsonschema/ComponentConfiguration.json
@@ -0,0 +1,23 @@
+{
+    "type": "object",
+    "$schema": "http://json-schema.org/draft-03/schema",
+    "id": "#",
+    "javaType" : "org.apache.streams.config.ComponentConfiguration",
+    "javaInterfaces": ["java.io.Serializable"],
+    "properties": {
+        "inClasses": {
+            "type" : "array",
+            "items" : {
+                "type" : "string"
+            },
+            "default": ["java.lang.String"]
+        },
+        "outClasses": {
+            "type" : "array",
+            "items" : {
+                "type" : "string"
+            },
+            "default": ["java.lang.String"]
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/main/jsonschema/StreamsConfiguration.json
----------------------------------------------------------------------
diff --git a/streams-config/src/main/jsonschema/StreamsConfiguration.json b/streams-config/src/main/jsonschema/StreamsConfiguration.json
index 9a23130..fabf378 100644
--- a/streams-config/src/main/jsonschema/StreamsConfiguration.json
+++ b/streams-config/src/main/jsonschema/StreamsConfiguration.json
@@ -2,11 +2,12 @@
     "type": "object",
     "$schema": "http://json-schema.org/draft-03/schema",
     "id": "#",
-    "javaType" : "org.apache.streams.StreamsConfiguration",
+    "javaType" : "org.apache.streams.config.StreamsConfiguration",
     "javaInterfaces": ["java.io.Serializable"],
     "properties": {
         "pipeline": {
-            "type" : "string"
+            "type" : "string",
+            "default": "No-name Stream"
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
new file mode 100644
index 0000000..e0acd6a
--- /dev/null
+++ b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
@@ -0,0 +1,37 @@
+package org.apache.streams.config.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import junit.framework.Assert;
+import org.apache.streams.config.ComponentConfiguration;
+import org.apache.streams.config.ComponentConfigurator;
+import org.apache.streams.config.StreamsConfigurator;
+import org.junit.Test;
+
+/**
+ * Created by sblackmon on 10/20/14.
+ */
+public class ComponentConfiguratorTest {
+
+    private final static ObjectMapper mapper = new ObjectMapper();
+
+    @Test
+    public void testDetectConfiguration() throws Exception {
+
+        Config config = ConfigFactory.load("componentTest");
+
+        ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);
+        
+        ComponentConfiguration defaultPojo = configurator.detectConfiguration(config.getConfig("defaultComponent"));
+
+        assert(defaultPojo != null);
+
+        ComponentConfiguration configuredPojo = configurator.detectConfiguration(config.getConfig("configuredComponent"));
+
+        assert(configuredPojo != null);
+
+        Assert.assertEquals(configuredPojo,defaultPojo);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java b/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
new file mode 100644
index 0000000..6f610c3
--- /dev/null
+++ b/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
@@ -0,0 +1,48 @@
+package org.apache.streams.config.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import org.apache.streams.config.ComponentConfiguration;
+import org.apache.streams.config.StreamsConfiguration;
+import org.apache.streams.config.StreamsConfigurator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Scanner;
+
+/**
+ * Created by sblackmon on 10/20/14.
+ */
+public class StreamsConfiguratorTest {
+
+    private final static ObjectMapper mapper = new ObjectMapper();
+
+    @Test
+    public void testDetectConfiguration() throws Exception {
+
+        Config config = ConfigFactory.load();
+
+        Config detected = StreamsConfigurator.config;
+
+        StreamsConfiguration defaultPojo = StreamsConfigurator.detectConfiguration();
+
+        assert(defaultPojo != null);
+
+        StreamsConfiguration configuredPojo = StreamsConfigurator.detectConfiguration(StreamsConfigurator.config);
+
+        assert(configuredPojo != null);
+
+        junit.framework.Assert.assertEquals(configuredPojo, defaultPojo);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/13024d00/streams-config/src/test/resources/componentTest.conf
----------------------------------------------------------------------
diff --git a/streams-config/src/test/resources/componentTest.conf b/streams-config/src/test/resources/componentTest.conf
new file mode 100644
index 0000000..52859b3
--- /dev/null
+++ b/streams-config/src/test/resources/componentTest.conf
@@ -0,0 +1,11 @@
+defaultComponent {
+
+}
+configuredComponent {
+  inClasses = [
+    java.lang.String
+  ]
+  outClasses = [
+    java.lang.String
+  ]
+}
\ No newline at end of file


[4/4] incubator-streams git commit: Merge branch 'STREAMS-215'

Posted by sb...@apache.org.
Merge branch 'STREAMS-215'

Conflicts:
	streams-config/src/main/jsonschema/StreamsConfiguration.json


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

Branch: refs/heads/master
Commit: d0b5a0a6be93eb41ba0cd6f9a1bd96894220dfe3
Parents: 9b89c08 991b170
Author: sblackmon <sb...@apache.org>
Authored: Mon Nov 17 14:45:33 2014 -0600
Committer: sblackmon <sb...@apache.org>
Committed: Mon Nov 17 14:45:33 2014 -0600

----------------------------------------------------------------------
 streams-config/pom.xml                          |  14 ++-
 .../streams/config/ComponentConfigurator.java   |  73 +++++++++++
 .../streams/config/StreamsConfigurator.java     |  41 +++++-
 .../main/jsonschema/ComponentConfiguration.json |  23 ++++
 .../main/jsonschema/StreamsConfiguration.json   |   7 +-
 .../config/test/ComponentConfiguratorTest.java  | 125 +++++++++++++++++++
 .../config/test/StreamsConfiguratorTest.java    |  69 ++++++++++
 .../src/test/resources/componentTest.conf       |  11 ++
 8 files changed, 354 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/d0b5a0a6/streams-config/src/main/jsonschema/StreamsConfiguration.json
----------------------------------------------------------------------
diff --cc streams-config/src/main/jsonschema/StreamsConfiguration.json
index 7341ecb,fabf378..b6f30b1
--- a/streams-config/src/main/jsonschema/StreamsConfiguration.json
+++ b/streams-config/src/main/jsonschema/StreamsConfiguration.json
@@@ -6,10 -6,8 +6,11 @@@
      "javaInterfaces": ["java.io.Serializable"],
      "properties": {
          "pipeline": {
-             "type" : "string"
+             "type" : "string",
+             "default": "No-name Stream"
 +        },
-         "broadcastURI": {
++		"broadcastURI": {
 +            "type": "string"
          }
      }
  }


[2/4] incubator-streams git commit: Additional tests

Posted by sb...@apache.org.
Additional tests


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

Branch: refs/heads/master
Commit: 265562af9942038d5bd29a6a1c5512161d1610ea
Parents: 13024d0
Author: sblackmon <sb...@apache.org>
Authored: Mon Nov 17 14:16:57 2014 -0600
Committer: sblackmon <sb...@apache.org>
Committed: Mon Nov 17 14:16:57 2014 -0600

----------------------------------------------------------------------
 streams-config/pom.xml                          | 12 ++++
 .../streams/config/ComponentConfigurator.java   | 32 ++++++++-
 .../streams/config/StreamsConfigurator.java     |  4 ++
 .../config/test/ComponentConfiguratorTest.java  | 68 +++++++++++++++++++-
 4 files changed, 111 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/265562af/streams-config/pom.xml
----------------------------------------------------------------------
diff --git a/streams-config/pom.xml b/streams-config/pom.xml
index 63a6857..bfc877a 100644
--- a/streams-config/pom.xml
+++ b/streams-config/pom.xml
@@ -63,6 +63,18 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-module-junit4</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/265562af/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
index 0056a4a..7e3451d 100644
--- a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
+++ b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
@@ -1,3 +1,21 @@
+/*
+ * 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.config;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -10,7 +28,14 @@ import org.slf4j.LoggerFactory;
 import java.io.Serializable;
 
 /**
- * Created by sblackmon on 11/11/14.
+ * ComponentConfigurator supplies serializable configuration beans derived from a specified typesafe path or object.
+ *
+ * Typically a component will select a 'default' typesafe path to be used if no other path or object is provided.
+ *
+ * For example, streams-persist-elasticsearch will use 'elasticsearch' by default, but an implementation
+ *   such as github.com/w2ogroup/elasticsearch-reindex can resolve a reader from elasticsearch.source
+ *   and a writer from elasticsearch.destination
+ *
  */
 public class ComponentConfigurator<T extends Serializable> {
 
@@ -38,10 +63,11 @@ public class ComponentConfigurator<T extends Serializable> {
     }
 
     public T detectConfiguration(String subConfig) {
-        return detectConfiguration( StreamsConfigurator.config.getString(subConfig));
+        Config streamsConfig = StreamsConfigurator.config;
+        return detectConfiguration( streamsConfig.getConfig(subConfig));
     }
 
     public T detectConfiguration(Config typesafeConfig, String subConfig) {
-        return detectConfiguration( typesafeConfig.getString(subConfig));
+        return detectConfiguration( typesafeConfig.getConfig(subConfig));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/265562af/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
index 34e3844..4a69456 100644
--- a/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
+++ b/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
@@ -46,6 +46,10 @@ public class StreamsConfigurator {
      */
     public static Config config = ConfigFactory.load();
 
+    public static Config getConfig() {
+        return config;
+    }
+
     public static StreamsConfiguration detectConfiguration() {
         return detectConfiguration(config);
     }

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/265562af/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
index e0acd6a..5b5c216 100644
--- a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
+++ b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
@@ -3,11 +3,14 @@ package org.apache.streams.config.test;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
+import com.typesafe.config.ConfigRenderOptions;
 import junit.framework.Assert;
 import org.apache.streams.config.ComponentConfiguration;
 import org.apache.streams.config.ComponentConfigurator;
 import org.apache.streams.config.StreamsConfigurator;
 import org.junit.Test;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
 
 /**
  * Created by sblackmon on 10/20/14.
@@ -17,7 +20,7 @@ public class ComponentConfiguratorTest {
     private final static ObjectMapper mapper = new ObjectMapper();
 
     @Test
-    public void testDetectConfiguration() throws Exception {
+    public void testDetectDefaults() throws Exception {
 
         Config config = ConfigFactory.load("componentTest");
 
@@ -34,4 +37,65 @@ public class ComponentConfiguratorTest {
         Assert.assertEquals(configuredPojo,defaultPojo);
 
     }
-}
+
+    @Test
+     public void testDetectConfigurationConfig() throws Exception {
+
+        Config config = ConfigFactory.load("componentTest").getConfig("configuredComponent");
+
+        ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);
+
+        ComponentConfiguration testPojo = mapper.readValue(config.root().render(ConfigRenderOptions.concise()), ComponentConfiguration.class);
+
+        assert(testPojo != null);
+
+        ComponentConfiguration configuredPojo = configurator.detectConfiguration(config);
+
+        assert(configuredPojo != null);
+
+        Assert.assertEquals(configuredPojo,testPojo);
+
+    }
+
+    @Test
+    public void testDetectConfigurationString() throws Exception {
+
+        Config config = ConfigFactory.load("componentTest");
+
+        StreamsConfigurator mockStreamsConfigurator = Mockito.mock(StreamsConfigurator.class);
+
+        PowerMockito.when(mockStreamsConfigurator.getConfig())
+                .thenReturn(config);
+
+        ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);
+
+        ComponentConfiguration testPojo = mapper.readValue(config.root().get("configuredComponent").render(ConfigRenderOptions.concise()), ComponentConfiguration.class);
+
+        assert(testPojo != null);
+
+        ComponentConfiguration configuredPojo = configurator.detectConfiguration("configuredComponent");
+
+        assert(configuredPojo != null);
+
+        Assert.assertEquals(configuredPojo,testPojo);
+    }
+
+    @Test
+    public void testDetectConfigurationConfigString() throws Exception {
+
+        Config config = ConfigFactory.load("componentTest");
+
+        ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);
+
+        ComponentConfiguration testPojo = mapper.readValue(config.root().get("configuredComponent").render(ConfigRenderOptions.concise()), ComponentConfiguration.class);
+
+
+        assert(testPojo != null);
+
+        ComponentConfiguration configuredPojo = configurator.detectConfiguration(config, "configuredComponent");
+
+        assert(configuredPojo != null);
+
+        Assert.assertEquals(configuredPojo,testPojo);
+    }
+}
\ No newline at end of file


[3/4] incubator-streams git commit: https://github.com/apache/incubator-streams/pull/126 feedback

Posted by sb...@apache.org.
https://github.com/apache/incubator-streams/pull/126 feedback


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

Branch: refs/heads/master
Commit: 991b17078be3a7fdb193f39786d829eeb6bfb586
Parents: 265562a
Author: sblackmon <sb...@apache.org>
Authored: Mon Nov 17 14:28:16 2014 -0600
Committer: sblackmon <sb...@apache.org>
Committed: Mon Nov 17 14:28:16 2014 -0600

----------------------------------------------------------------------
 .../streams/config/ComponentConfigurator.java   |  2 +-
 .../streams/config/StreamsConfigurator.java     |  9 +++---
 .../config/test/ComponentConfiguratorTest.java  | 32 +++++++++++++++++---
 .../config/test/StreamsConfiguratorTest.java    | 25 +++++++++++++--
 4 files changed, 56 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/991b1707/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
index 7e3451d..42b70a6 100644
--- a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
+++ b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
@@ -63,7 +63,7 @@ public class ComponentConfigurator<T extends Serializable> {
     }
 
     public T detectConfiguration(String subConfig) {
-        Config streamsConfig = StreamsConfigurator.config;
+        Config streamsConfig = StreamsConfigurator.getConfig();
         return detectConfiguration( streamsConfig.getConfig(subConfig));
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/991b1707/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
----------------------------------------------------------------------
diff --git a/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
index 4a69456..9da0260 100644
--- a/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
+++ b/streams-config/src/main/java/org/apache/streams/config/StreamsConfigurator.java
@@ -29,11 +29,10 @@ import org.slf4j.LoggerFactory;
 import java.io.Serializable;
 
 /**
- * Created with IntelliJ IDEA.
- * User: sblackmon
- * Date: 9/23/13
- * Time: 10:44 AM
- * To change this template use File | Settings | File Templates.
+ * StreamsConfigurator supplies the entire typesafe tree to runtimes and modules.
+ *
+ * StreamsConfigurator also supplies StreamsConfiguration POJO to runtimes and modules.
+ *
  */
 public class StreamsConfigurator {
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/991b1707/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
index 5b5c216..4acad9d 100644
--- a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
+++ b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.config.test;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -9,12 +27,18 @@ import org.apache.streams.config.ComponentConfiguration;
 import org.apache.streams.config.ComponentConfigurator;
 import org.apache.streams.config.StreamsConfigurator;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 /**
- * Created by sblackmon on 10/20/14.
- */
+* Test for
+* @see {@link org.apache.streams.config.ComponentConfigurator}
+*/
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(StreamsConfigurator.class)
 public class ComponentConfiguratorTest {
 
     private final static ObjectMapper mapper = new ObjectMapper();
@@ -62,9 +86,9 @@ public class ComponentConfiguratorTest {
 
         Config config = ConfigFactory.load("componentTest");
 
-        StreamsConfigurator mockStreamsConfigurator = Mockito.mock(StreamsConfigurator.class);
+        PowerMockito.mockStatic(StreamsConfigurator.class);
 
-        PowerMockito.when(mockStreamsConfigurator.getConfig())
+        PowerMockito.when(StreamsConfigurator.getConfig())
                 .thenReturn(config);
 
         ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator<>(ComponentConfiguration.class);

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/991b1707/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
----------------------------------------------------------------------
diff --git a/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java b/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
index 6f610c3..65dbd75 100644
--- a/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
+++ b/streams-config/src/test/java/org/apache/streams/config/test/StreamsConfiguratorTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.config.test;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -21,7 +39,8 @@ import java.util.Map;
 import java.util.Scanner;
 
 /**
- * Created by sblackmon on 10/20/14.
+ * Test for
+ * @see {@link org.apache.streams.config.StreamsConfigurator}
  */
 public class StreamsConfiguratorTest {
 
@@ -32,7 +51,9 @@ public class StreamsConfiguratorTest {
 
         Config config = ConfigFactory.load();
 
-        Config detected = StreamsConfigurator.config;
+        Config detected = StreamsConfigurator.getConfig();
+
+        junit.framework.Assert.assertEquals(config, detected);
 
         StreamsConfiguration defaultPojo = StreamsConfigurator.detectConfiguration();