NIFI-663: Updating tests to provide valid options for assertions when in a Windows environment. Preferring regex to contains/endsWith

This commit is contained in:
Aldrin Piri 2015-06-06 11:16:52 -04:00
parent 245fef4ee2
commit c9ddf21ad6
1 changed files with 18 additions and 18 deletions

View File

@ -16,24 +16,24 @@
*/ */
package org.apache.nifi.processors.standard; package org.apache.nifi.processors.standard;
import static org.junit.Assert.assertEquals; import org.apache.nifi.util.MockFlowFile;
import static org.junit.Assert.assertTrue; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import org.apache.nifi.util.MockFlowFile; import static org.junit.Assert.assertEquals;
import org.apache.nifi.util.TestRunner; import static org.junit.Assert.assertTrue;
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;
/** /**
* *
@ -70,7 +70,7 @@ public class TestExecuteStreamCommand {
MockFlowFile outputFlowFile = flowFiles.get(0); MockFlowFile outputFlowFile = flowFiles.get(0);
byte[] byteArray = outputFlowFile.toByteArray(); byte[] byteArray = outputFlowFile.toByteArray();
String result = new String(byteArray); 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("0", outputFlowFile.getAttribute("execution.status"));
assertEquals("java", outputFlowFile.getAttribute("execution.command")); assertEquals("java", outputFlowFile.getAttribute("execution.command"));
assertEquals("-jar;", outputFlowFile.getAttribute("execution.command.args").substring(0, 5)); assertEquals("-jar;", outputFlowFile.getAttribute("execution.command.args").substring(0, 5));
@ -131,8 +131,7 @@ public class TestExecuteStreamCommand {
byte[] byteArray = flowFiles.get(0).toByteArray(); byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray); String result = new String(byteArray);
assertTrue(result.contains(File.separator + "nifi-standard-processors:ModifiedResult\r\n") assertTrue(Pattern.compile("nifi-standard-processors:ModifiedResult\r?\n").matcher(result).find());
|| result.contains(File.separator + "nifi-standard-processors:ModifiedResult\n"));
} }
@Test @Test
@ -153,8 +152,9 @@ public class TestExecuteStreamCommand {
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
byte[] byteArray = flowFiles.get(0).toByteArray(); byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray); 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 @Test
@ -177,7 +177,7 @@ public class TestExecuteStreamCommand {
byte[] byteArray = flowFiles.get(0).toByteArray(); byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray); String result = new String(byteArray);
assertTrue("TestIngestAndUpdate.jar should not have received anything to modify", 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 // this is dependent on window with cygwin...so it's not enabled
@ -226,7 +226,7 @@ public class TestExecuteStreamCommand {
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP); List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
byte[] byteArray = flowFiles.get(0).toByteArray(); byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray); 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("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_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]); assertEquals("NIFI_TEST_1 environment variable is missing", "NIFI_TEST_1=testvalue1", dynamicEnvironment[1]);