From c9ddf21ad63c032ec936adc25e2886b7632be098 Mon Sep 17 00:00:00 2001 From: Aldrin Piri Date: Sat, 6 Jun 2015 11:16:52 -0400 Subject: [PATCH] NIFI-663: Updating tests to provide valid options for assertions when in a Windows environment. Preferring regex to contains/endsWith --- .../standard/TestExecuteStreamCommand.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java index 90fb28f287..d565bca3aa 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java @@ -16,24 +16,24 @@ */ package org.apache.nifi.processors.standard; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; +import java.util.regex.Pattern; -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @@ -70,7 +70,7 @@ public class TestExecuteStreamCommand { MockFlowFile outputFlowFile = flowFiles.get(0); byte[] byteArray = outputFlowFile.toByteArray(); String result = new String(byteArray); - assertTrue("Test was a success\r\n".equals(result) || "Test was a success\n".equals(result)); + assertTrue(Pattern.compile("Test was a success\r?\n").matcher(result).find()); assertEquals("0", outputFlowFile.getAttribute("execution.status")); assertEquals("java", outputFlowFile.getAttribute("execution.command")); assertEquals("-jar;", outputFlowFile.getAttribute("execution.command.args").substring(0, 5)); @@ -131,8 +131,7 @@ public class TestExecuteStreamCommand { byte[] byteArray = flowFiles.get(0).toByteArray(); String result = new String(byteArray); - assertTrue(result.contains(File.separator + "nifi-standard-processors:ModifiedResult\r\n") - || result.contains(File.separator + "nifi-standard-processors:ModifiedResult\n")); + assertTrue(Pattern.compile("nifi-standard-processors:ModifiedResult\r?\n").matcher(result).find()); } @Test @@ -153,8 +152,9 @@ public class TestExecuteStreamCommand { List flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); byte[] byteArray = flowFiles.get(0).toByteArray(); String result = new String(byteArray); - assertTrue(result.contains(File.separator + "nifi-standard-processors" + File.separator + "target:ModifiedResult\r\n") - || result.contains(File.separator + "nifi-standard-processors" + File.separator + "target:ModifiedResult\n")); + + final String quotedSeparator = Pattern.quote(File.separator); + assertTrue(Pattern.compile(quotedSeparator + "nifi-standard-processors" + quotedSeparator + "target:ModifiedResult\r?\n").matcher(result).find()); } @Test @@ -177,7 +177,7 @@ public class TestExecuteStreamCommand { byte[] byteArray = flowFiles.get(0).toByteArray(); String result = new String(byteArray); assertTrue("TestIngestAndUpdate.jar should not have received anything to modify", - result.endsWith("target:ModifiedResult\n")); + Pattern.compile("target:ModifiedResult\r?\n$").matcher(result).find()); } // this is dependent on window with cygwin...so it's not enabled @@ -226,7 +226,7 @@ public class TestExecuteStreamCommand { List flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); byte[] byteArray = flowFiles.get(0).toByteArray(); String result = new String(byteArray); - String[] dynamicEnvironment = result.split("\n"); + String[] dynamicEnvironment = result.split("\r?\n"); assertEquals("Should contain two environment variables starting with NIFI", 2, dynamicEnvironment.length); assertEquals("NIFI_TEST_2 environment variable is missing", "NIFI_TEST_2=testvalue2", dynamicEnvironment[0]); assertEquals("NIFI_TEST_1 environment variable is missing", "NIFI_TEST_1=testvalue1", dynamicEnvironment[1]);