Repository: nifi
Updated Branches:
  refs/heads/master bb738f978 -> 3921ab827


NIFI-1651 unit tests work on windows. removed contributor name/package from 
data and schema

Reviewed by Aldrin Piri ([email protected]) and Mike Moser 
([email protected]). This closes #291


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/3921ab82
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/3921ab82
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/3921ab82

Branch: refs/heads/master
Commit: 3921ab827b650da9142e0b6986c6986d69fdb42d
Parents: bb738f9
Author: trkurc <[email protected]>
Authored: Sat Mar 19 14:48:44 2016 -0400
Committer: Tony Kurc <[email protected]>
Committed: Sun Mar 20 15:01:57 2016 -0400

----------------------------------------------------------------------
 .../processors/kite/TestInferAvroSchema.java    | 52 ++++++++++++++------
 .../src/test/resources/Shapes.json.avro         |  2 +-
 .../src/test/resources/Shapes_header.csv.avro   |  2 +-
 3 files changed, 39 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/3921ab82/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
index 510eaf9..125a631 100644
--- 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
+++ 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
@@ -18,24 +18,29 @@
  */
 package org.apache.nifi.processors.kite;
 
-import org.junit.Assert;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.nifi.flowfile.attributes.CoreAttributes;
 import org.apache.nifi.util.MockFlowFile;
 import org.apache.nifi.util.TestRunner;
 import org.apache.nifi.util.TestRunners;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.File;
-import java.io.StringWriter;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.HashMap;
-import java.util.Map;
-
 public class TestInferAvroSchema {
 
     private TestRunner runner = null;
@@ -53,7 +58,7 @@ public class TestInferAvroSchema {
         runner.setProperty(InferAvroSchema.HEADER_LINE_SKIP_COUNT, "0");
         runner.setProperty(InferAvroSchema.ESCAPE_STRING, "\\");
         runner.setProperty(InferAvroSchema.QUOTE_STRING, "'");
-        runner.setProperty(InferAvroSchema.RECORD_NAME, 
"com.jeremydyer.contact");
+        runner.setProperty(InferAvroSchema.RECORD_NAME, 
"org.apache.nifi.contact");
         runner.setProperty(InferAvroSchema.CHARSET, "UTF-8");
         runner.setProperty(InferAvroSchema.PRETTY_AVRO_OUTPUT, "true");
     }
@@ -74,7 +79,7 @@ public class TestInferAvroSchema {
         runner.assertTransferCount(InferAvroSchema.REL_SUCCESS, 1);
 
         MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(InferAvroSchema.REL_SUCCESS).get(0);
-        flowFile.assertContentEquals(new 
File("src/test/resources/Shapes_header.csv.avro").toPath());
+        flowFile.assertContentEquals(unix2PlatformSpecificLineEndings(new 
File("src/test/resources/Shapes_header.csv.avro")));
         flowFile.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), 
"application/avro-binary");
     }
 
@@ -101,7 +106,9 @@ public class TestInferAvroSchema {
 
         MockFlowFile data = 
runner.getFlowFilesForRelationship(InferAvroSchema.REL_SUCCESS).get(0);
         String avroSchema = 
data.getAttribute(InferAvroSchema.AVRO_SCHEMA_ATTRIBUTE_NAME);
-        String knownSchema = FileUtils.readFileToString(new 
File("src/test/resources/Shapes.json.avro"));
+        String knownSchema = new String(unix2PlatformSpecificLineEndings(
+                    new File("src/test/resources/Shapes.json.avro")),
+                    StandardCharsets.UTF_8);
         Assert.assertEquals(avroSchema, knownSchema);
 
         //Since that avro schema is written to an attribute this should be teh 
same as the original
@@ -130,7 +137,7 @@ public class TestInferAvroSchema {
         runner.assertTransferCount(InferAvroSchema.REL_SUCCESS, 1);
 
         MockFlowFile data = 
runner.getFlowFilesForRelationship(InferAvroSchema.REL_SUCCESS).get(0);
-        
data.assertContentEquals(Paths.get("src/test/resources/Shapes_header.csv.avro"));
+        data.assertContentEquals(unix2PlatformSpecificLineEndings(new 
File("src/test/resources/Shapes_header.csv.avro")));
         data.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), 
"application/avro-binary");
     }
 
@@ -149,7 +156,7 @@ public class TestInferAvroSchema {
 
         Map<String, String> attributes = new HashMap<>();
         attributes.put(CoreAttributes.MIME_TYPE.key(), "text/csv");
-        runner.enqueue((CSV_HEADER_LINE + 
"\nJeremy,Dyer,29,55555").getBytes(), attributes);
+        runner.enqueue((CSV_HEADER_LINE + "\nJane,Doe,29,55555").getBytes(), 
attributes);
 
         runner.run();
         runner.assertTransferCount(InferAvroSchema.REL_FAILURE, 0);
@@ -191,7 +198,7 @@ public class TestInferAvroSchema {
         runner.assertTransferCount(InferAvroSchema.REL_SUCCESS, 1);
 
         MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(InferAvroSchema.REL_SUCCESS).get(0);
-        flowFile.assertContentEquals(new 
File("src/test/resources/Shapes_header.csv.avro").toPath());
+        flowFile.assertContentEquals(unix2PlatformSpecificLineEndings(new 
File("src/test/resources/Shapes_header.csv.avro")));
         flowFile.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), 
"application/avro-binary");
     }
 
@@ -216,4 +223,19 @@ public class TestInferAvroSchema {
         flowFile.assertContentEquals(new 
File("src/test/resources/Shapes_Header_TabDelimited.csv").toPath());
         flowFile.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), 
"text/csv");
     }
+    static byte [] unix2PlatformSpecificLineEndings(final File file) throws 
IOException {
+        try ( final BufferedInputStream in = new BufferedInputStream(new 
FileInputStream(file));
+                final ByteArrayOutputStream out = new ByteArrayOutputStream()) 
{
+            byte eol[] = 
System.lineSeparator().getBytes(StandardCharsets.UTF_8);
+            int justRead;
+            while ((justRead = in.read()) != -1) {
+                if (justRead == '\n'){
+                    out.write(eol);
+                } else {
+                    out.write(justRead);
+                }
+            }
+            return out.toByteArray();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/3921ab82/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes.json.avro
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes.json.avro
 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes.json.avro
index e5f91e4..cdbf048 100644
--- 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes.json.avro
+++ 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes.json.avro
@@ -1,7 +1,7 @@
 {
   "type" : "record",
   "name" : "contact",
-  "namespace" : "com.jeremydyer",
+  "namespace" : "org.apache.nifi",
   "fields" : [ {
     "name" : "shapes",
     "type" : {

http://git-wip-us.apache.org/repos/asf/nifi/blob/3921ab82/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes_header.csv.avro
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes_header.csv.avro
 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes_header.csv.avro
index 2c35ea3..300b069 100644
--- 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes_header.csv.avro
+++ 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/resources/Shapes_header.csv.avro
@@ -1,7 +1,7 @@
 {
   "type" : "record",
   "name" : "contact",
-  "namespace" : "com.jeremydyer",
+  "namespace" : "org.apache.nifi",
   "doc" : "Schema generated by Kite",
   "fields" : [ {
     "name" : "shape",

Reply via email to