streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [4/5] incubator-streams git commit: factored out creation of a decent scanner to new test utility class
Date Sat, 06 Dec 2014 18:47:56 GMT
factored out creation of a decent scanner to new test utility class


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

Branch: refs/heads/master
Commit: 3f2078784308ba48d8b4a61f7f926d8c55fa3071
Parents: f7c7508
Author: sblackmon <sblackmon@w2odigital.com>
Authored: Fri Dec 5 17:55:35 2014 -0600
Committer: sblackmon <sblackmon@w2odigital.com>
Committed: Fri Dec 5 17:55:35 2014 -0600

----------------------------------------------------------------------
 pom.xml                                         |  5 ++---
 .../streams-provider-datasift/pom.xml           |  8 +++++++-
 .../DatasiftActivitySerializerTest.java         |  6 ++----
 .../serializer/DatasiftEventClassifierTest.java |  9 +++------
 ...DatasiftInstagramActivitySerializerTest.java |  4 ++--
 ...tasiftInteractionActivitySerializerTest.java |  4 ++--
 .../DatasiftTwitterActivitySerializerTest.java  |  4 ++--
 streams-util/pom.xml                            | 15 ++++++++++++++
 .../streams/util/files/StreamsScannerUtil.java  | 21 ++++++++++++++++++++
 9 files changed, 56 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9f0b291..de24ebf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,7 +127,7 @@
                 <configuration>
                     <source>${java.version}</source>
                     <target>${java.version}</target>
-                    <encoding>UTF-8</encoding>
+                    <encoding>${project.build.sourceEncoding}</encoding>
                 </configuration>
             </plugin>
             <plugin>
@@ -177,7 +177,7 @@
                 <artifactId>maven-resources-plugin</artifactId>
                 <version>2.7</version>
                 <configuration>
-                    <encoding>UTF-8</encoding>
+                    <encoding>${project.build.sourceEncoding}</encoding>
                 </configuration>
             </plugin>
         </plugins>
@@ -278,7 +278,6 @@
                 <artifactId>config</artifactId>
                 <version>${typesafe.config.version}</version>
             </dependency>
-
             <dependency>
                 <groupId>junit</groupId>
                 <artifactId>junit</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-contrib/streams-provider-datasift/pom.xml
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-datasift/pom.xml b/streams-contrib/streams-provider-datasift/pom.xml
index fe7257d..77c3e8a 100644
--- a/streams-contrib/streams-provider-datasift/pom.xml
+++ b/streams-contrib/streams-provider-datasift/pom.xml
@@ -90,7 +90,13 @@
             <version>1.9.5</version>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.streams</groupId>
+            <artifactId>streams-util</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftActivitySerializerTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftActivitySerializerTest.java
b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftActivitySerializerTest.java
index dcc7ba9..12bf918 100644
--- a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftActivitySerializerTest.java
+++ b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftActivitySerializerTest.java
@@ -10,6 +10,7 @@ import org.apache.streams.datasift.util.StreamsDatasiftMapper;
 import org.apache.streams.jackson.StreamsJacksonMapper;
 import org.apache.streams.pojo.json.Activity;
 import org.apache.streams.pojo.json.Actor;
+import org.apache.streams.util.files.StreamsScannerUtil;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -26,8 +27,6 @@ public class DatasiftActivitySerializerTest {
 
     protected static ObjectMapper MAPPER = StreamsJacksonMapper.getInstance(Lists.newArrayList(StreamsDatasiftMapper.DATASIFT_FORMAT));
 
-    protected static Pattern newLinePattern = Pattern.compile("(\\r\\n?|\\n)", Pattern.MULTILINE);
-
     @Before
     public void initSerializer() {
         SERIALIZER = new DatasiftActivitySerializer();
@@ -36,8 +35,7 @@ public class DatasiftActivitySerializerTest {
     @Test
     public void testConversion() throws Exception {
 
-        InputStream testFileStream = DatasiftTwitterActivitySerializerTest.class.getResourceAsStream("/rand_sample_datasift_json.txt");
-        Scanner scanner = new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+        Scanner scanner = StreamsScannerUtil.getInstance("/rand_sample_datasift_json.txt");
 
         String line = null;
         while(scanner.hasNextLine()) {

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftEventClassifierTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftEventClassifierTest.java
b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftEventClassifierTest.java
index 6a880b8..a29d0f4 100644
--- a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftEventClassifierTest.java
+++ b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftEventClassifierTest.java
@@ -25,6 +25,7 @@ import org.apache.streams.datasift.instagram.Instagram;
 import org.apache.streams.datasift.twitter.Twitter;
 import org.apache.streams.datasift.util.StreamsDatasiftMapper;
 import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.util.files.StreamsScannerUtil;
 import org.junit.Test;
 
 import java.io.InputStream;
@@ -38,13 +39,10 @@ public class DatasiftEventClassifierTest {
 
     private static final ObjectMapper MAPPER = StreamsJacksonMapper.getInstance(Lists.newArrayList(StreamsDatasiftMapper.DATASIFT_FORMAT));
 
-    protected static Pattern newLinePattern = Pattern.compile("(\\r\\n?|\\n)", Pattern.MULTILINE);
-
     @Test
     public void testTwitterDetection() throws Exception {
 
-        InputStream testFileStream = DatasiftTwitterActivitySerializerTest.class.getResourceAsStream("/twitter_datasift_json.txt");
-        Scanner scanner = new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+        Scanner scanner = StreamsScannerUtil.getInstance("/twitter_datasift_json.txt");
 
         String line = null;
         while(scanner.hasNextLine()) {
@@ -58,8 +56,7 @@ public class DatasiftEventClassifierTest {
     @Test
     public void testInstagramDetection() throws Exception {
 
-        InputStream testFileStream = DatasiftTwitterActivitySerializerTest.class.getResourceAsStream("/instagram_datasift_json.txt");
-        Scanner scanner = new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+        Scanner scanner = StreamsScannerUtil.getInstance("/instagram_datasift_json.txt");
 
         String line = null;
         while(scanner.hasNextLine()) {

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInstagramActivitySerializerTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInstagramActivitySerializerTest.java
b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInstagramActivitySerializerTest.java
index c409642..e3d1207 100644
--- a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInstagramActivitySerializerTest.java
+++ b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInstagramActivitySerializerTest.java
@@ -9,6 +9,7 @@ import org.apache.streams.datasift.util.StreamsDatasiftMapper;
 import org.apache.streams.jackson.StreamsJacksonMapper;
 import org.apache.streams.pojo.json.Activity;
 import org.apache.streams.pojo.json.Actor;
+import org.apache.streams.util.files.StreamsScannerUtil;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -30,8 +31,7 @@ public class DatasiftInstagramActivitySerializerTest extends DatasiftActivitySer
     @Override
     public void testConversion() throws Exception {
 
-        InputStream testFileStream = DatasiftTwitterActivitySerializerTest.class.getResourceAsStream("/instagram_datasift_json.txt");
-        Scanner scanner = new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+        Scanner scanner = StreamsScannerUtil.getInstance("/instagram_datasift_json.txt");
 
         String line = null;
         while(scanner.hasNextLine()) {

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInteractionActivitySerializerTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInteractionActivitySerializerTest.java
b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInteractionActivitySerializerTest.java
index c9886eb..ce30303 100644
--- a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInteractionActivitySerializerTest.java
+++ b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftInteractionActivitySerializerTest.java
@@ -9,6 +9,7 @@ import org.apache.streams.datasift.util.StreamsDatasiftMapper;
 import org.apache.streams.jackson.StreamsJacksonMapper;
 import org.apache.streams.pojo.json.Activity;
 import org.apache.streams.pojo.json.Actor;
+import org.apache.streams.util.files.StreamsScannerUtil;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -30,8 +31,7 @@ public class DatasiftInteractionActivitySerializerTest extends DatasiftActivityS
     @Override
     public void testConversion() throws Exception {
 
-        InputStream testFileStream = DatasiftInteractionActivitySerializerTest.class.getResourceAsStream("/rand_sample_datasift_json.txt");
-        Scanner scanner = new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+        Scanner scanner = StreamsScannerUtil.getInstance("/rand_sample_datasift_json.txt");
 
         String line = null;
         while(scanner.hasNextLine()) {

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftTwitterActivitySerializerTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftTwitterActivitySerializerTest.java
b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftTwitterActivitySerializerTest.java
index f458e21..1b82cba 100644
--- a/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftTwitterActivitySerializerTest.java
+++ b/streams-contrib/streams-provider-datasift/src/test/java17/org/apache/streams/datasift/serializer/DatasiftTwitterActivitySerializerTest.java
@@ -9,6 +9,7 @@ import org.apache.streams.datasift.util.StreamsDatasiftMapper;
 import org.apache.streams.jackson.StreamsJacksonMapper;
 import org.apache.streams.pojo.json.Activity;
 import org.apache.streams.pojo.json.Actor;
+import org.apache.streams.util.files.StreamsScannerUtil;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -32,8 +33,7 @@ public class DatasiftTwitterActivitySerializerTest extends DatasiftActivitySeria
     @Override
     public void testConversion() throws Exception {
 
-        InputStream testFileStream = DatasiftTwitterActivitySerializerTest.class.getResourceAsStream("/twitter_datasift_json.txt");
-        Scanner scanner = new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+        Scanner scanner = StreamsScannerUtil.getInstance("/twitter_datasift_json.txt");
 
         String line = null;
         while(scanner.hasNextLine()) {

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-util/pom.xml
----------------------------------------------------------------------
diff --git a/streams-util/pom.xml b/streams-util/pom.xml
index 7a50201..88fdab1 100644
--- a/streams-util/pom.xml
+++ b/streams-util/pom.xml
@@ -49,4 +49,19 @@
             <version>2.1.2</version>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/3f207878/streams-util/src/test/java/org/apache/streams/util/files/StreamsScannerUtil.java
----------------------------------------------------------------------
diff --git a/streams-util/src/test/java/org/apache/streams/util/files/StreamsScannerUtil.java
b/streams-util/src/test/java/org/apache/streams/util/files/StreamsScannerUtil.java
new file mode 100644
index 0000000..d15edd3
--- /dev/null
+++ b/streams-util/src/test/java/org/apache/streams/util/files/StreamsScannerUtil.java
@@ -0,0 +1,21 @@
+package org.apache.streams.util.files;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Scanner;
+import java.util.regex.Pattern;
+
+/**
+ * Test Utility for acquiring a Scanner that won't choke on unicode or odd line-breaks.
+ */
+public class StreamsScannerUtil {
+
+    protected static Pattern newLinePattern = Pattern.compile("(\\r\\n?|\\n)", Pattern.MULTILINE);
+
+    public static Scanner getInstance(String resourcePath) {
+
+        InputStream testFileStream = StreamsScannerUtil.class.getResourceAsStream(resourcePath);
+        return new Scanner(testFileStream, "UTF-8").useDelimiter(newLinePattern);
+
+    };
+}


Mime
View raw message