http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java index 8b9b2ac..6012b04 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java @@ -44,15 +44,13 @@ public class TestHandleHttpRequest { @Test public void testRequestAddedToService() throws InitializationException, MalformedURLException, IOException { - final TestRunner runner = TestRunners. - newTestRunner(HandleHttpRequest.class); + final TestRunner runner = TestRunners.newTestRunner(HandleHttpRequest.class); runner.setProperty(HandleHttpRequest.PORT, "0"); final MockHttpContextMap contextMap = new MockHttpContextMap(); runner.addControllerService("http-context-map", contextMap); runner.enableControllerService(contextMap); - runner. - setProperty(HandleHttpRequest.HTTP_CONTEXT_MAP, "http-context-map"); + runner.setProperty(HandleHttpRequest.HTTP_CONTEXT_MAP, "http-context-map"); // trigger processor to stop but not shutdown. runner.run(1, false); @@ -61,8 +59,7 @@ public class TestHandleHttpRequest { @Override public void run() { try { - final int port = ((HandleHttpRequest) runner. - getProcessor()).getPort(); + final int port = ((HandleHttpRequest) runner.getProcessor()).getPort(); final HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:" + port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange"). openConnection(); connection.setDoOutput(false); @@ -73,8 +70,7 @@ public class TestHandleHttpRequest { connection.setConnectTimeout(3000); connection.setReadTimeout(3000); - StreamUtils. - copy(connection.getInputStream(), new NullOutputStream()); + StreamUtils.copy(connection.getInputStream(), new NullOutputStream()); } catch (final Throwable t) { t.printStackTrace(); Assert.fail(t.toString()); @@ -92,13 +88,10 @@ public class TestHandleHttpRequest { // process the request. runner.run(1, false); - runner. - assertAllFlowFilesTransferred(HandleHttpRequest.REL_SUCCESS, 1); + runner.assertAllFlowFilesTransferred(HandleHttpRequest.REL_SUCCESS, 1); assertEquals(1, contextMap.size()); - final MockFlowFile mff = runner. - getFlowFilesForRelationship(HandleHttpRequest.REL_SUCCESS). - get(0); + final MockFlowFile mff = runner.getFlowFilesForRelationship(HandleHttpRequest.REL_SUCCESS).get(0); mff.assertAttributeEquals("http.query.param.query", "true"); mff.assertAttributeEquals("http.query.param.value1", "value1"); mff.assertAttributeEquals("http.query.param.value2", "");
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java index 40683ae..2bceda6 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java @@ -51,14 +51,12 @@ public class TestHandleHttpResponse { @Test public void testEnsureCompleted() throws InitializationException { - final TestRunner runner = TestRunners. - newTestRunner(HandleHttpResponse.class); + final TestRunner runner = TestRunners.newTestRunner(HandleHttpResponse.class); final MockHttpContextMap contextMap = new MockHttpContextMap("my-id"); runner.addControllerService("http-context-map", contextMap); runner.enableControllerService(contextMap); - runner. - setProperty(HandleHttpResponse.HTTP_CONTEXT_MAP, "http-context-map"); + runner.setProperty(HandleHttpResponse.HTTP_CONTEXT_MAP, "http-context-map"); runner.setProperty(HandleHttpResponse.STATUS_CODE, "${status.code}"); runner.setProperty("my-attr", "${my-attr}"); runner.setProperty("no-valid-attr", "${no-valid-attr}"); @@ -104,47 +102,42 @@ public class TestHandleHttpResponse { @Override public HttpServletResponse getResponse(final String identifier) { if (!id.equals(identifier)) { - Assert. - fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier); + Assert.fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier); } try { - final HttpServletResponse response = Mockito. - mock(HttpServletResponse.class); - Mockito.when(response.getOutputStream()). - thenReturn(new ServletOutputStream() { - @Override - public boolean isReady() { - return true; - } - - @Override - public void setWriteListener(WriteListener writeListener) { - } - - @Override - public void write(int b) throws IOException { - baos.write(b); - } - - @Override - public void write(byte[] b) throws IOException { - baos.write(b); - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - baos.write(b, off, len); - } - }); + final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); + Mockito.when(response.getOutputStream()).thenReturn(new ServletOutputStream() { + @Override + public boolean isReady() { + return true; + } + + @Override + public void setWriteListener(WriteListener writeListener) { + } + + @Override + public void write(int b) throws IOException { + baos.write(b); + } + + @Override + public void write(byte[] b) throws IOException { + baos.write(b); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + baos.write(b, off, len); + } + }); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { - final String key = invocation. - getArgumentAt(0, String.class); - final String value = invocation. - getArgumentAt(1, String.class); + final String key = invocation.getArgumentAt(0, String.class); + final String value = invocation.getArgumentAt(1, String.class); if (value == null) { headersWithNoValue.add(key); } else { @@ -153,10 +146,7 @@ public class TestHandleHttpResponse { return null; } - }). - when(response). - setHeader(Mockito.any(String.class), Mockito. - any(String.class)); + }).when(response).setHeader(Mockito.any(String.class), Mockito.any(String.class)); Mockito.doAnswer(new Answer<Object>() { @Override @@ -164,9 +154,7 @@ public class TestHandleHttpResponse { statusCode = invocation.getArgumentAt(0, int.class); return null; } - }). - when(response). - setStatus(Mockito.anyInt()); + }).when(response).setStatus(Mockito.anyInt()); return response; } catch (final Exception e) { @@ -179,8 +167,7 @@ public class TestHandleHttpResponse { @Override public void complete(final String identifier) { if (!id.equals(identifier)) { - Assert. - fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier); + Assert.fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier); } completedCount.incrementAndGet(); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java index a57f6cf..7426e9e 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java @@ -36,8 +36,7 @@ public class TestHashAttribute { @Test public void test() { final TestRunner runner = TestRunners.newTestRunner(new HashAttribute()); - runner. - setProperty(HashAttribute.HASH_VALUE_ATTRIBUTE.getName(), "hashValue"); + runner.setProperty(HashAttribute.HASH_VALUE_ATTRIBUTE.getName(), "hashValue"); runner.setProperty("MDKey1", ".*"); runner.setProperty("MDKey2", "(.).*"); @@ -67,9 +66,8 @@ public class TestHashAttribute { runner.assertTransferCount(HashAttribute.REL_FAILURE, 1); runner.assertTransferCount(HashAttribute.REL_SUCCESS, 4); - final List<MockFlowFile> success = runner. - getFlowFilesForRelationship(HashAttribute.REL_SUCCESS); - final Map<String, Integer> correlationCount = new HashMap<String, Integer>(); + final List<MockFlowFile> success = runner.getFlowFilesForRelationship(HashAttribute.REL_SUCCESS); + final Map<String, Integer> correlationCount = new HashMap<>(); for (final MockFlowFile flowFile : success) { final String correlationId = flowFile.getAttribute("hashValue"); assertNotNull(correlationId); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java index 8f6f5f4..d14683c 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.processors.standard; -import org.apache.nifi.processors.standard.HashContent; import static org.junit.Assert.assertEquals; import java.io.IOException; @@ -59,9 +58,7 @@ public class TestHashContent { runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(HashContent.REL_SUCCESS, 1); - final MockFlowFile outFile = runner. - getFlowFilesForRelationship(HashContent.REL_SUCCESS). - get(0); + final MockFlowFile outFile = runner.getFlowFilesForRelationship(HashContent.REL_SUCCESS).get(0); final String hashValue = outFile.getAttribute("hash"); assertEquals(expectedHash, hashValue); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java index 9f49476..0094cb0 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.processors.standard; -import org.apache.nifi.processors.standard.IdentifyMimeType; import static org.junit.Assert.assertEquals; import java.io.File; @@ -36,8 +35,7 @@ public class TestIdentifyMimeType { @Test public void testFiles() throws IOException { - final TestRunner runner = TestRunners. - newTestRunner(new IdentifyMimeType()); + final TestRunner runner = TestRunners.newTestRunner(new IdentifyMimeType()); final File dir = new File("src/test/resources/TestIdentifyMimeType"); final File[] files = dir.listFiles(); @@ -54,8 +52,7 @@ public class TestIdentifyMimeType { runner.setThreadCount(1); runner.run(fileCount); - runner. - assertAllFlowFilesTransferred(IdentifyMimeType.REL_SUCCESS, fileCount); + runner.assertAllFlowFilesTransferred(IdentifyMimeType.REL_SUCCESS, fileCount); final Map<String, String> expectedMimeTypes = new HashMap<>(); expectedMimeTypes.put("1.7z", "application/x-7z-compressed"); @@ -93,13 +90,10 @@ public class TestIdentifyMimeType { expectedExtensions.put("flowfilev3", ""); expectedExtensions.put("flowfilev1.tar", ""); - final List<MockFlowFile> filesOut = runner. - getFlowFilesForRelationship(IdentifyMimeType.REL_SUCCESS); + final List<MockFlowFile> filesOut = runner.getFlowFilesForRelationship(IdentifyMimeType.REL_SUCCESS); for (final MockFlowFile file : filesOut) { - final String filename = file.getAttribute(CoreAttributes.FILENAME. - key()); - final String mimeType = file.getAttribute(CoreAttributes.MIME_TYPE. - key()); + final String filename = file.getAttribute(CoreAttributes.FILENAME.key()); + final String mimeType = file.getAttribute(CoreAttributes.MIME_TYPE.key()); final String expected = expectedMimeTypes.get(filename); final String extension = file.getAttribute("mime.extension"); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java index 03fd14b..2f8dea9 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java @@ -145,9 +145,7 @@ public class TestInvokeHTTP { //expected in request status.code and status.message //original flow file (+attributes)?????????? - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_REQ). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_REQ).get(0); bundle.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); @@ -159,15 +157,12 @@ public class TestInvokeHTTP { //status code, status message, all headers from server response --> ff attributes //server response message body into payload of ff //should not contain any original ff attributes - final MockFlowFile bundle1 = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_RESP). - get(0); + final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_RESP).get(0); bundle1.assertContentEquals("/status/200".getBytes("UTF-8")); bundle1.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle1.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); bundle1.assertAttributeEquals("Foo", "Bar"); - bundle1. - assertAttributeEquals("Content-Type", "text/plain; charset=ISO-8859-1"); + bundle1.assertAttributeEquals("Content-Type", "text/plain; charset=ISO-8859-1"); final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = "/status/200"; Assert.assertEquals(expected1, actual1); @@ -190,9 +185,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_FAILURE, 0); //expected in response - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_RETRY). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_RETRY).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); bundle.assertAttributeEquals(Config.STATUS_CODE, "500"); bundle.assertAttributeEquals(Config.STATUS_MESSAGE, "Server Error"); @@ -220,9 +213,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_FAILURE, 0); //getMyFlowFiles(); //expected in response - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_NO_RETRY). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_NO_RETRY).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); bundle.assertAttributeEquals(Config.STATUS_CODE, "302"); @@ -249,9 +240,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_FAILURE, 0); //getMyFlowFiles(); //expected in response - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_NO_RETRY). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_NO_RETRY).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); bundle.assertAttributeEquals(Config.STATUS_CODE, "304"); @@ -278,9 +267,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_FAILURE, 0); //getMyFlowFiles(); //expected in response - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_NO_RETRY). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_NO_RETRY).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); bundle.assertAttributeEquals(Config.STATUS_CODE, "400"); @@ -309,14 +296,11 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_FAILURE, 0); //expected in response - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_NO_RETRY). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_NO_RETRY).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); bundle.assertAttributeEquals(Config.STATUS_CODE, "412"); - bundle. - assertAttributeEquals(Config.STATUS_MESSAGE, "Precondition Failed"); + bundle.assertAttributeEquals(Config.STATUS_MESSAGE, "Precondition Failed"); bundle.assertAttributeEquals(Config.RESPONSE_BODY, "/status/412"); final String expected = "Hello"; Assert.assertEquals(expected, actual); @@ -340,9 +324,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_NO_RETRY, 0); runner.assertTransferCount(Config.REL_FAILURE, 0); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_REQ). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_REQ).get(0); bundle.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); @@ -350,9 +332,7 @@ public class TestInvokeHTTP { Assert.assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); - final MockFlowFile bundle1 = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_RESP). - get(0); + final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_RESP).get(0); bundle1.assertContentEquals("".getBytes("UTF-8")); bundle1.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle1.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); @@ -379,9 +359,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_NO_RETRY, 0); runner.assertTransferCount(Config.REL_FAILURE, 0); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_REQ). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_REQ).get(0); bundle.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); @@ -389,9 +367,7 @@ public class TestInvokeHTTP { Assert.assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); - final MockFlowFile bundle1 = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_RESP). - get(0); + final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_RESP).get(0); bundle1.assertContentEquals("".getBytes("UTF-8")); bundle1.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle1.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); @@ -419,9 +395,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_NO_RETRY, 0); runner.assertTransferCount(Config.REL_FAILURE, 0); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_REQ). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_REQ).get(0); bundle.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); @@ -429,9 +403,7 @@ public class TestInvokeHTTP { Assert.assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); - final MockFlowFile bundle1 = runner. - getFlowFilesForRelationship(Config.REL_SUCCESS_RESP). - get(0); + final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(Config.REL_SUCCESS_RESP).get(0); bundle1.assertContentEquals("".getBytes("UTF-8")); bundle1.assertAttributeEquals(Config.STATUS_CODE, "200"); bundle1.assertAttributeEquals(Config.STATUS_MESSAGE, "OK"); @@ -460,9 +432,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_NO_RETRY, 0); runner.assertTransferCount(Config.REL_FAILURE, 1); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_FAILURE). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_FAILURE).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); final String expected = "Hello"; @@ -470,54 +440,6 @@ public class TestInvokeHTTP { bundle.assertAttributeEquals("Foo", "Bar"); } - // @Test - // public void testGetFlowfileAttributes() throws IOException { - // Map<String, List<String>> input = new HashMap<>(); - // input.put("A", Arrays.asList("1")); - // input.put("B", Arrays.asList("1", "2", "3")); - // input.put("C", new ArrayList<String>()); - // input.put("D", null); - // - // Map<String, String> expected = new HashMap<>(); - // expected.put(Config.STATUS_CODE, "200"); - // expected.put(Config.STATUS_MESSAGE, "OK"); - // expected.put(Config.STATUS_LINE, "HTTP/1.1 200 OK"); - // expected.put("A", "1"); - // expected.put("B", "1, 2, 3"); - // - // URL url = new URL("file:/dev/null"); - // HttpURLConnection conn = new MockHttpURLConnection(url, 200, "OK", input); - // - // Map<String, String> actual = processor.getAttributesFromHeaders(conn); - // - // assertEquals(expected, actual); - // } - // @Test - // public void testCsv() { - // // null input should return an empty string - // assertEquals("", processor.csv(null)); - // - // // empty collection returns empty string - // assertEquals("", processor.csv(new ArrayList<String>())); - // - // // pretty normal checks - // assertEquals("1", processor.csv(Arrays.asList("1"))); - // assertEquals("1, 2", processor.csv(Arrays.asList("1", "2"))); - // assertEquals("1, 2, 3", processor.csv(Arrays.asList("1", "2", "3"))); - // - // // values should be trimmed - // assertEquals("1, 2, 3", processor.csv(Arrays.asList(" 1", " 2 ", "3 "))); - // - // // empty values should be skipped - // assertEquals("1, 3", processor.csv(Arrays.asList("1", "", "3"))); - // - // // whitespace values should be skipped - // assertEquals("1, 3", processor.csv(Arrays.asList("1", " ", "3"))); - // - // // this (mis)behavior is currently expected, embedded comma delimiters are not escaped - // // note the embedded unescaped comma in the "1, " value - // assertEquals("1,, 2, 3", processor.csv(Arrays.asList("1, ", "2", "3"))); - // } @Test public void testConnectFailBadHost() throws Exception { addHandler(new GetOrHeadHandler()); @@ -534,9 +456,7 @@ public class TestInvokeHTTP { runner.assertTransferCount(Config.REL_NO_RETRY, 0); runner.assertTransferCount(Config.REL_FAILURE, 1); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(Config.REL_FAILURE). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(Config.REL_FAILURE).get(0); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); final String expected = "Hello"; @@ -545,16 +465,12 @@ public class TestInvokeHTTP { } private static Map<String, String> createSslProperties() { - Map<String, String> map = new HashMap<String, String>(); - map. - put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks"); - map. - put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest"); + Map<String, String> map = new HashMap<>(); + map.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks"); + map.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest"); map.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS"); - map. - put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks"); - map. - put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest"); + map.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks"); + map.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest"); map.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS"); return map; } @@ -582,8 +498,7 @@ public class TestInvokeHTTP { assertEquals("/post", target); - String body = request.getReader(). - readLine(); + String body = request.getReader().readLine(); assertEquals("Hello", body); } @@ -595,8 +510,7 @@ public class TestInvokeHTTP { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); - int status = Integer.valueOf(target. - substring("/status".length() + 1)); + int status = Integer.valueOf(target.substring("/status".length() + 1)); response.setStatus(status); response.setContentType("text/plain"); @@ -625,8 +539,7 @@ public class TestInvokeHTTP { response.setStatus(200); response.setContentType("text/plain"); - response.getWriter(). - println("Way to go!"); + response.getWriter().println("Way to go!"); } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java index 8511b50..274333e 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java @@ -56,8 +56,7 @@ public class TestJmsConsumer { } /** - * Test method for - * {@link org.apache.nifi.processors.standard.JmsConsumer#createMapMessageAttrs(javax.jms.MapMessage)}. + * Test method for {@link org.apache.nifi.processors.standard.JmsConsumer#createMapMessageAttrs(javax.jms.MapMessage)}. * * @throws JMSException jms */ @@ -66,17 +65,12 @@ public class TestJmsConsumer { MapMessage mapMessage = createMapMessage(); - Map<String, String> mapMessageValues = JmsConsumer. - createMapMessageValues(mapMessage); + Map<String, String> mapMessageValues = JmsConsumer.createMapMessageValues(mapMessage); assertEquals("", 4, mapMessageValues.size()); - assertEquals("", "Arnold", mapMessageValues. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "name")); - assertEquals("", "97", mapMessageValues. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "age")); - assertEquals("", "89686.564", mapMessageValues. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz")); - assertEquals("", "true", mapMessageValues. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "good")); + assertEquals("", "Arnold", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "name")); + assertEquals("", "97", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "age")); + assertEquals("", "89686.564", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz")); + assertEquals("", "true", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "good")); } /** @@ -91,28 +85,18 @@ public class TestJmsConsumer { MapMessage mapMessage = createMapMessage(); ProcessContext context = runner.getProcessContext(); - ProcessSession session = runner.getProcessSessionFactory(). - createSession(); - ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner. - getProcessor(), - (MockProcessContext) runner.getProcessContext()); - - JmsProcessingSummary summary = JmsConsumer. - map2FlowFile(context, session, mapMessage, true, pic.getLogger()); - - assertEquals("MapMessage should not create FlowFile content", 0, summary. - getBytesReceived()); - - Map<String, String> attributes = summary.getLastFlowFile(). - getAttributes(); - assertEquals("", "Arnold", attributes. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "name")); - assertEquals("", "97", attributes. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "age")); - assertEquals("", "89686.564", attributes. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz")); - assertEquals("", "true", attributes. - get(JmsConsumer.MAP_MESSAGE_PREFIX + "good")); + ProcessSession session = runner.getProcessSessionFactory().createSession(); + ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext()); + + JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, mapMessage, true, pic.getLogger()); + + assertEquals("MapMessage should not create FlowFile content", 0, summary.getBytesReceived()); + + Map<String, String> attributes = summary.getLastFlowFile().getAttributes(); + assertEquals("", "Arnold", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "name")); + assertEquals("", "97", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "age")); + assertEquals("", "89686.564", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz")); + assertEquals("", "true", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "good")); } @Test @@ -125,19 +109,12 @@ public class TestJmsConsumer { textMessage.setText(payload); ProcessContext context = runner.getProcessContext(); - ProcessSession session = runner.getProcessSessionFactory(). - createSession(); - ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner. - getProcessor(), - (MockProcessContext) runner.getProcessContext()); + ProcessSession session = runner.getProcessSessionFactory().createSession(); + ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext()); - JmsProcessingSummary summary = JmsConsumer. - map2FlowFile(context, session, textMessage, true, pic. - getLogger()); + JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, textMessage, true, pic.getLogger()); - assertEquals("TextMessage content length should equal to FlowFile content size", payload. - length(), summary.getLastFlowFile(). - getSize()); + assertEquals("TextMessage content length should equal to FlowFile content size", payload.length(), summary.getLastFlowFile().getSize()); final byte[] buffer = new byte[payload.length()]; runner.clearTransferState(); @@ -155,6 +132,8 @@ public class TestJmsConsumer { /** * Test BytesMessage to FlowFile conversion + * + * @throws java.lang.Exception ex */ @Test public void testMap2FlowFileBytesMessage() throws Exception { @@ -168,19 +147,12 @@ public class TestJmsConsumer { bytesMessage.reset(); ProcessContext context = runner.getProcessContext(); - ProcessSession session = runner.getProcessSessionFactory(). - createSession(); - ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner. - getProcessor(), - (MockProcessContext) runner.getProcessContext()); - - JmsProcessingSummary summary = JmsConsumer. - map2FlowFile(context, session, bytesMessage, true, pic. - getLogger()); - - assertEquals("BytesMessage content length should equal to FlowFile content size", payload.length, summary. - getLastFlowFile(). - getSize()); + ProcessSession session = runner.getProcessSessionFactory().createSession(); + ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext()); + + JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, bytesMessage, true, pic.getLogger()); + + assertEquals("BytesMessage content length should equal to FlowFile content size", payload.length, summary.getLastFlowFile().getSize()); final byte[] buffer = new byte[payload.length]; runner.clearTransferState(); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java index d4d5524..864d7a7 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.processors.standard; -import org.apache.nifi.processors.standard.ListenUDP; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -51,10 +50,8 @@ public class TestListenUDP { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); System.setProperty("org.slf4j.simpleLogger.showDateTime", "true"); System.setProperty("org.slf4j.simpleLogger.log.nifi.io.nio", "debug"); - System. - setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ListenUDP", "debug"); - System. - setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestListenUDP", "debug"); + System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ListenUDP", "debug"); + System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestListenUDP", "debug"); LOGGER = LoggerFactory.getLogger(TestListenUDP.class); } @@ -88,8 +85,7 @@ public class TestListenUDP { ProcessContext context = runner.getProcessContext(); ListenUDP processor = (ListenUDP) runner.getProcessor(); - ProcessSessionFactory processSessionFactory = runner. - getProcessSessionFactory(); + ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); processor.initializeChannelListenerAndConsumerProcessing(context); udpSender.start(); boolean transferred = false; @@ -97,18 +93,14 @@ public class TestListenUDP { while (!transferred && System.currentTimeMillis() < timeOut) { Thread.sleep(200); processor.onTrigger(context, processSessionFactory); - transferred = runner. - getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS). - size() > 0; + transferred = runner.getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS).size() > 0; } assertTrue("Didn't process the datagrams", transferred); Thread.sleep(7000); processor.stopping(); processor.stopped(); socket.close(); - assertTrue(runner. - getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS). - size() >= 60); + assertTrue(runner.getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS).size() >= 60); } @Test @@ -129,8 +121,7 @@ public class TestListenUDP { ProcessContext context = runner.getProcessContext(); ListenUDP processor = (ListenUDP) runner.getProcessor(); - ProcessSessionFactory processSessionFactory = runner. - getProcessSessionFactory(); + ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); processor.initializeChannelListenerAndConsumerProcessing(context); udpSender.start(); boolean transferred = false; @@ -138,18 +129,14 @@ public class TestListenUDP { while (!transferred && System.currentTimeMillis() < timeOut) { Thread.sleep(1000); processor.onTrigger(context, processSessionFactory); - transferred = runner. - getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS). - size() > 0; + transferred = runner.getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS).size() > 0; } assertTrue("Didn't process the datagrams", transferred); Thread.sleep(7000); processor.stopping(); processor.stopped(); socket.close(); - assertTrue(runner. - getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS). - size() >= 2); + assertTrue(runner.getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS).size() >= 2); } @Test @@ -166,8 +153,7 @@ public class TestListenUDP { ProcessContext context = runner.getProcessContext(); ListenUDP processor = (ListenUDP) runner.getProcessor(); - ProcessSessionFactory processSessionFactory = runner. - getProcessSessionFactory(); + ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory(); processor.initializeChannelListenerAndConsumerProcessing(context); udpSender.start(); int numTransfered = 0; @@ -175,9 +161,7 @@ public class TestListenUDP { while (numTransfered <= 80 && System.currentTimeMillis() < timeout) { Thread.sleep(200); processor.onTrigger(context, processSessionFactory); - numTransfered = runner. - getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS). - size(); + numTransfered = runner.getFlowFilesForRelationship(ListenUDP.RELATIONSHIP_SUCCESS).size(); } assertFalse("Did not process all the datagrams", numTransfered < 80); processor.stopping(); @@ -215,8 +199,7 @@ public class TestListenUDP { } final long endTime = System.nanoTime(); final long durationMillis = (endTime - startTime) / 1000000; - LOGGER. - info("Sent all UDP packets without any obvious errors | duration ms= " + durationMillis); + LOGGER.info("Sent all UDP packets without any obvious errors | duration ms= " + durationMillis); } catch (IOException e) { LOGGER.error("", e); } finally { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java index 48ed8c6..a657453 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java @@ -47,16 +47,14 @@ public class TestMergeContent { @BeforeClass public static void setup() { - System. - setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard", "DEBUG"); + System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard", "DEBUG"); } @Test public void testSimpleBinaryConcat() throws IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); createFlowFiles(runner); runner.run(); @@ -66,20 +64,16 @@ public class TestMergeContent { runner.assertTransferCount(MergeContent.REL_FAILURE, 0); runner.assertTransferCount(MergeContent.REL_ORIGINAL, 3); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); bundle.assertContentEquals("Hello, World!".getBytes("UTF-8")); - bundle. - assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/plain-text"); + bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/plain-text"); } @Test public void testMimeTypeIsOctetStreamIfConflictingWithBinaryConcat() throws IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); createFlowFiles(runner); @@ -93,12 +87,9 @@ public class TestMergeContent { runner.assertTransferCount(MergeContent.REL_FAILURE, 0); runner.assertTransferCount(MergeContent.REL_ORIGINAL, 4); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); bundle.assertContentEquals("Hello, World!".getBytes("UTF-8")); - bundle. - assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/octet-stream"); + bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/octet-stream"); } @Test @@ -108,10 +99,8 @@ public class TestMergeContent { runner.setProperty(MergeContent.MAX_BIN_COUNT, "50"); runner.setProperty(MergeContent.MIN_ENTRIES, "10"); runner.setProperty(MergeContent.MAX_ENTRIES, "10"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); - runner. - setProperty(MergeContent.CORRELATION_ATTRIBUTE_NAME, "correlationId"); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + runner.setProperty(MergeContent.CORRELATION_ATTRIBUTE_NAME, "correlationId"); final Map<String, String> attrs = new HashMap<>(); for (int i = 0; i < 49; i++) { @@ -143,8 +132,7 @@ public class TestMergeContent { @Test public void testSimpleBinaryConcatWaitsForMin() throws IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); runner.setProperty(MergeContent.MIN_SIZE, "20 KB"); createFlowFiles(runner); @@ -159,8 +147,7 @@ public class TestMergeContent { public void testZip() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_ZIP); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_ZIP); createFlowFiles(runner); runner.run(); @@ -170,12 +157,8 @@ public class TestMergeContent { runner.assertTransferCount(MergeContent.REL_FAILURE, 0); runner.assertTransferCount(MergeContent.REL_ORIGINAL, 3); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - try (final InputStream rawIn = new ByteArrayInputStream(runner. - getContentAsByteArray(bundle)); - final ZipInputStream in = new ZipInputStream(rawIn)) { + final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + try (final InputStream rawIn = new ByteArrayInputStream(runner.getContentAsByteArray(bundle)); final ZipInputStream in = new ZipInputStream(rawIn)) { Assert.assertNotNull(in.getNextEntry()); final byte[] part1 = IOUtils.toByteArray(in); Assert.assertTrue(Arrays.equals("Hello".getBytes("UTF-8"), part1)); @@ -188,16 +171,14 @@ public class TestMergeContent { final byte[] part3 = IOUtils.toByteArray(in); Assert.assertTrue(Arrays.equals("World!".getBytes("UTF-8"), part3)); } - bundle. - assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/zip"); + bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/zip"); } @Test public void testTar() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_TAR); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_TAR); final Map<String, String> attributes = new HashMap<>(); attributes.put(CoreAttributes.MIME_TYPE.key(), "application/plain-text"); @@ -206,9 +187,7 @@ public class TestMergeContent { runner.enqueue("Hello".getBytes("UTF-8"), attributes); attributes.put(CoreAttributes.FILENAME.key(), "ALongerrrFileName"); runner.enqueue(", ".getBytes("UTF-8"), attributes); - attributes - .put(CoreAttributes.FILENAME.key(), - "AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName"); + attributes.put(CoreAttributes.FILENAME.key(), "AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName"); runner.enqueue("World!".getBytes("UTF-8"), attributes); runner.run(); @@ -217,12 +196,8 @@ public class TestMergeContent { runner.assertTransferCount(MergeContent.REL_FAILURE, 0); runner.assertTransferCount(MergeContent.REL_ORIGINAL, 3); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - try (final InputStream rawIn = new ByteArrayInputStream(runner. - getContentAsByteArray(bundle)); - final TarArchiveInputStream in = new TarArchiveInputStream(rawIn)) { + final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + try (final InputStream rawIn = new ByteArrayInputStream(runner.getContentAsByteArray(bundle)); final TarArchiveInputStream in = new TarArchiveInputStream(rawIn)) { ArchiveEntry entry = in.getNextEntry(); Assert.assertNotNull(entry); assertEquals("AShortFileName", entry.getName()); @@ -235,13 +210,11 @@ public class TestMergeContent { Assert.assertTrue(Arrays.equals(", ".getBytes("UTF-8"), part2)); entry = in.getNextEntry(); - assertEquals("AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName", entry. - getName()); + assertEquals("AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName", entry.getName()); final byte[] part3 = IOUtils.toByteArray(in); Assert.assertTrue(Arrays.equals("World!".getBytes("UTF-8"), part3)); } - bundle. - assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/tar"); + bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/tar"); } @Test @@ -250,33 +223,26 @@ public class TestMergeContent { runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); runner.setProperty(MergeContent.MIN_ENTRIES, "2"); runner.setProperty(MergeContent.MAX_ENTRIES, "2"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_FLOWFILE_STREAM_V3); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_FLOWFILE_STREAM_V3); final Map<String, String> attributes = new HashMap<>(); attributes.put("path", "folder"); - runner.enqueue(Paths. - get("src/test/resources/TestUnpackContent/folder/cal.txt"), attributes); - runner.enqueue(Paths. - get("src/test/resources/TestUnpackContent/folder/date.txt"), attributes); + runner.enqueue(Paths.get("src/test/resources/TestUnpackContent/folder/cal.txt"), attributes); + runner.enqueue(Paths.get("src/test/resources/TestUnpackContent/folder/date.txt"), attributes); runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); runner.assertTransferCount(MergeContent.REL_FAILURE, 0); runner.assertTransferCount(MergeContent.REL_ORIGINAL, 2); - final MockFlowFile merged = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - merged. - assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/flowfile-v3"); + final MockFlowFile merged = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + merged.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/flowfile-v3"); } @Test public void testDefragment() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 min"); final Map<String, String> attributes = new HashMap<>(); @@ -295,18 +261,14 @@ public class TestMergeContent { runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); - final MockFlowFile assembled = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - assembled.assertContentEquals("A Man A Plan A Canal Panama". - getBytes("UTF-8")); + final MockFlowFile assembled = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + assembled.assertContentEquals("A Man A Plan A Canal Panama".getBytes("UTF-8")); } @Test public void testDefragmentWithTooFewFragments() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); runner.setProperty(MergeContent.MAX_BIN_AGE, "2 secs"); final Map<String, String> attributes = new HashMap<>(); @@ -339,8 +301,7 @@ public class TestMergeContent { @Test public void testDefragmentOutOfOrder() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 min"); final Map<String, String> attributes = new HashMap<>(); @@ -359,19 +320,15 @@ public class TestMergeContent { runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); - final MockFlowFile assembled = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - assembled.assertContentEquals("A Man A Plan A Canal Panama". - getBytes("UTF-8")); + final MockFlowFile assembled = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + assembled.assertContentEquals("A Man A Plan A Canal Panama".getBytes("UTF-8")); } @Ignore("this test appears to be faulty") @Test public void testDefragmentMultipleMingledSegments() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 min"); final Map<String, String> attributes = new HashMap<>(); @@ -400,22 +357,16 @@ public class TestMergeContent { runner.run(2); runner.assertTransferCount(MergeContent.REL_MERGED, 2); - final MockFlowFile assembled = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - assembled.assertContentEquals("A Man A Plan A Canal Panama". - getBytes("UTF-8")); - final MockFlowFile assembledTwo = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(1); + final MockFlowFile assembled = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + assembled.assertContentEquals("A Man A Plan A Canal Panama".getBytes("UTF-8")); + final MockFlowFile assembledTwo = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(1); assembledTwo.assertContentEquals("No x in Nixon".getBytes("UTF-8")); } @Test public void testDefragmentOldStyleAttributes() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 min"); final Map<String, String> attributes = new HashMap<>(); @@ -435,20 +386,15 @@ public class TestMergeContent { runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); - final MockFlowFile assembled = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - assembled.assertContentEquals("A Man A Plan A Canal Panama". - getBytes("UTF-8")); - assembled. - assertAttributeEquals(CoreAttributes.FILENAME.key(), "originalfilename"); + final MockFlowFile assembled = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + assembled.assertContentEquals("A Man A Plan A Canal Panama".getBytes("UTF-8")); + assembled.assertAttributeEquals(CoreAttributes.FILENAME.key(), "originalfilename"); } @Test public void testDefragmentMultipleOnTriggers() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_DEFRAGMENT); final Map<String, String> attributes = new HashMap<>(); attributes.put(MergeContent.FRAGMENT_ID_ATTRIBUTE, "1"); @@ -470,19 +416,15 @@ public class TestMergeContent { runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); - final MockFlowFile assembled = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); - assembled.assertContentEquals("A Man A Plan A Canal Panama". - getBytes("UTF-8")); + final MockFlowFile assembled = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + assembled.assertContentEquals("A Man A Plan A Canal Panama".getBytes("UTF-8")); } @Ignore("This test appears to be a fail...is retuning 1 instead of 2...needs work") @Test public void testMergeBasedOnCorrelation() throws IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_BIN_PACK); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_BIN_PACK); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 min"); runner.setProperty(MergeContent.CORRELATION_ATTRIBUTE_NAME, "attr"); runner.setProperty(MergeContent.MAX_ENTRIES, "3"); @@ -503,8 +445,7 @@ public class TestMergeContent { runner.assertTransferCount(MergeContent.REL_MERGED, 2); - final List<MockFlowFile> mergedFiles = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED); + final List<MockFlowFile> mergedFiles = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED); final MockFlowFile merged1 = mergedFiles.get(0); final MockFlowFile merged2 = mergedFiles.get(1); @@ -526,8 +467,7 @@ public class TestMergeContent { @Test public void testMaxBinAge() throws InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_BIN_PACK); + runner.setProperty(MergeContent.MERGE_STRATEGY, MergeContent.MERGE_STRATEGY_BIN_PACK); runner.setProperty(MergeContent.MAX_BIN_AGE, "2 sec"); runner.setProperty(MergeContent.CORRELATION_ATTRIBUTE_NAME, "attr"); runner.setProperty(MergeContent.MAX_ENTRIES, "500"); @@ -552,8 +492,7 @@ public class TestMergeContent { @Test public void testUniqueAttributes() { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.ATTRIBUTE_STRATEGY, MergeContent.ATTRIBUTE_STRATEGY_ALL_UNIQUE); + runner.setProperty(MergeContent.ATTRIBUTE_STRATEGY, MergeContent.ATTRIBUTE_STRATEGY_ALL_UNIQUE); runner.setProperty(MergeContent.MAX_SIZE, "2 B"); runner.setProperty(MergeContent.MIN_SIZE, "2 B"); @@ -572,9 +511,7 @@ public class TestMergeContent { runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); - final MockFlowFile outFile = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); + final MockFlowFile outFile = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); outFile.assertAttributeEquals("abc", "xyz"); outFile.assertAttributeEquals("hello", "good-bye"); @@ -585,8 +522,7 @@ public class TestMergeContent { @Test public void testCommonAttributesOnly() { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); - runner. - setProperty(MergeContent.ATTRIBUTE_STRATEGY, MergeContent.ATTRIBUTE_STRATEGY_ALL_COMMON); + runner.setProperty(MergeContent.ATTRIBUTE_STRATEGY, MergeContent.ATTRIBUTE_STRATEGY_ALL_COMMON); runner.setProperty(MergeContent.MAX_SIZE, "2 B"); runner.setProperty(MergeContent.MIN_SIZE, "2 B"); @@ -605,9 +541,7 @@ public class TestMergeContent { runner.run(); runner.assertTransferCount(MergeContent.REL_MERGED, 1); - final MockFlowFile outFile = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); + final MockFlowFile outFile = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); outFile.assertAttributeEquals("abc", "xyz"); outFile.assertAttributeNotExists("hello"); @@ -615,8 +549,7 @@ public class TestMergeContent { outFile.assertAttributeNotExists("xyz"); final Set<String> uuids = new HashSet<>(); - for (final MockFlowFile mff : runner. - getFlowFilesForRelationship(MergeContent.REL_ORIGINAL)) { + for (final MockFlowFile mff : runner.getFlowFilesForRelationship(MergeContent.REL_ORIGINAL)) { uuids.add(mff.getAttribute(CoreAttributes.UUID.key())); } uuids.add(outFile.getAttribute(CoreAttributes.UUID.key())); @@ -628,8 +561,7 @@ public class TestMergeContent { public void testCountAttribute() throws IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); - runner. - setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); createFlowFiles(runner); runner.run(); @@ -639,9 +571,7 @@ public class TestMergeContent { runner.assertTransferCount(MergeContent.REL_FAILURE, 0); runner.assertTransferCount(MergeContent.REL_ORIGINAL, 3); - final MockFlowFile bundle = runner. - getFlowFilesForRelationship(MergeContent.REL_MERGED). - get(0); + final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); bundle.assertContentEquals("Hello, World!".getBytes("UTF-8")); bundle.assertAttributeEquals(MergeContent.MERGE_COUNT_ATTRIBUTE, "3"); bundle.assertAttributeExists(MergeContent.MERGE_BIN_AGE_ATTRIBUTE); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/d29a2d68/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java index 2c58b80..768a8d0 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java @@ -16,7 +16,6 @@ */ package org.apache.nifi.processors.standard; -import org.apache.nifi.processors.standard.ModifyBytes; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -41,14 +40,11 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "1 MB"); runner.setProperty(ModifyBytes.END_OFFSET, "1 MB"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); out.assertContentEquals("".getBytes("UTF-8")); } @@ -58,16 +54,12 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "0 MB"); runner.setProperty(ModifyBytes.END_OFFSET, "0 MB"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); - out. - assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/testFile.txt"))); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); + out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/testFile.txt"))); } @Test @@ -76,18 +68,14 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "12 B"); //REMOVE - '<<<HEADER>>>' runner.setProperty(ModifyBytes.END_OFFSET, "0 MB"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); System.out.println(outContent); - out. - assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noHeader.txt"))); + out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noHeader.txt"))); } @Test @@ -96,14 +84,11 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "181 B"); runner.setProperty(ModifyBytes.END_OFFSET, "0 B"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); System.out.println(outContent); out.assertContentEquals("<<<FOOTER>>>".getBytes("UTF-8")); @@ -115,14 +100,11 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "0 B"); runner.setProperty(ModifyBytes.END_OFFSET, "181 B"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); out.assertContentEquals("<<<HEADER>>>".getBytes("UTF-8")); } @@ -132,18 +114,14 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "0 B"); runner.setProperty(ModifyBytes.END_OFFSET, "12 B"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); System.out.println(outContent); - out. - assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter.txt"))); + out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter.txt"))); } @Test @@ -152,18 +130,14 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "12 B"); runner.setProperty(ModifyBytes.END_OFFSET, "12 B"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); System.out.println(outContent); - out. - assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter_noHeader.txt"))); + out.assertContentEquals(translateNewLines(new File("src/test/resources/TestModifyBytes/noFooter_noHeader.txt"))); } @Test @@ -172,14 +146,11 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "97 B"); runner.setProperty(ModifyBytes.END_OFFSET, "97 B"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); out.assertContentEquals("".getBytes("UTF-8")); } @@ -189,14 +160,11 @@ public class TestModifyBytes { runner.setProperty(ModifyBytes.START_OFFSET, "94 B"); runner.setProperty(ModifyBytes.END_OFFSET, "96 B"); - runner.enqueue(Paths. - get("src/test/resources/TestModifyBytes/testFile.txt")); + runner.enqueue(Paths.get("src/test/resources/TestModifyBytes/testFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); - final MockFlowFile out = runner. - getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS). - get(0); + final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); System.out.println(outContent); out.assertContentEquals("Dew".getBytes("UTF-8")); @@ -209,15 +177,13 @@ public class TestModifyBytes { private byte[] translateNewLines(final Path path) throws IOException { final byte[] data = Files.readAllBytes(path); final String text = new String(data, StandardCharsets.UTF_8); - return translateNewLines(text). - getBytes(StandardCharsets.UTF_8); + return translateNewLines(text).getBytes(StandardCharsets.UTF_8); } private String translateNewLines(final String text) { final String lineSeparator = System.getProperty("line.separator"); final Pattern pattern = Pattern.compile("\n", Pattern.MULTILINE); - final String translated = pattern.matcher(text). - replaceAll(lineSeparator); + final String translated = pattern.matcher(text).replaceAll(lineSeparator); return translated; } }
