You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2015/07/16 16:47:25 UTC

[32/50] [abbrv] incubator-nifi git commit: NIFI-749: Ignore line endings in unit test

NIFI-749: Ignore line endings in unit test


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

Branch: refs/heads/master
Commit: 74b48009376e950bfa455be31e15f13cde7d27b9
Parents: 136974a
Author: Mark Payne <ma...@hotmail.com>
Authored: Fri Jul 3 10:07:19 2015 -0400
Committer: Mark Payne <ma...@hotmail.com>
Committed: Fri Jul 3 12:45:33 2015 -0400

----------------------------------------------------------------------
 .../processors/standard/TestInvokeHTTP.java     | 44 ++++++++++----------
 1 file changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/74b48009/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 cb8fe63..acff14b 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
@@ -45,7 +45,9 @@ import org.junit.Assert;
 
 import static org.apache.commons.codec.binary.Base64.encodeBase64;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -103,7 +105,7 @@ public class TestInvokeHTTP {
 
     @Test
     public void testDateGeneration() throws Exception {
-        DateHandler dh = new DateHandler();
+        final DateHandler dh = new DateHandler();
         addHandler(dh);
 
         runner.setProperty(Config.PROP_URL, url);
@@ -112,8 +114,8 @@ public class TestInvokeHTTP {
 
         // extract the date string sent to the server
         // and store it as a java.util.Date
-        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
-        Date date = sdf.parse(dh.dateString);
+        final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
+        final Date date = sdf.parse(dh.dateString);
 
         // calculate the difference between the date string sent by the client and
         // the current system time -- these should be within a second or two
@@ -121,8 +123,8 @@ public class TestInvokeHTTP {
         //
         // If the difference is more like in hours, it's likely that a timezone
         // conversion caused a problem.
-        long diff = Math.abs(System.currentTimeMillis() - date.getTime());
-        long threshold = 15000; // 15 seconds
+        final long diff = Math.abs(System.currentTimeMillis() - date.getTime());
+        final long threshold = 15000; // 15 seconds
         if (diff > threshold) {
             fail("Difference (" + diff + ") was greater than threshold (" + threshold + ")");
         }
@@ -175,14 +177,14 @@ public class TestInvokeHTTP {
     public void test200auth() throws Exception {
         addHandler(new BasicAuthHandler());
 
-        String username = "basic_user";
-        String password = "basic_password";
+        final String username = "basic_user";
+        final String password = "basic_password";
 
         runner.setProperty(Config.PROP_URL, url + "/status/200");
         runner.setProperty(Config.PROP_BASIC_AUTH_USERNAME, username);
         runner.setProperty(Config.PROP_BASIC_AUTH_PASSWORD, password);
-        byte[] creds = String.format("%s:%s", username, password).getBytes(StandardCharsets.UTF_8);
-        final String expAuth = String.format("Basic %s\n", new String(encodeBase64(creds)));
+        final byte[] creds = String.format("%s:%s", username, password).getBytes(StandardCharsets.UTF_8);
+        final String expAuth = String.format("Basic %s", new String(encodeBase64(creds)));
 
         createFlowFiles(runner);
 
@@ -209,22 +211,20 @@ public class TestInvokeHTTP {
         //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);
-        bundle1.assertContentEquals(expAuth.getBytes("UTF-8"));
+        final String bundle1Content = new String(bundle1.toByteArray(), StandardCharsets.UTF_8);
+        assertTrue(bundle1Content.startsWith(expAuth)); // use startsWith instead of equals so we can ignore line endings
         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");
-        final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8);
-        Assert.assertEquals(expAuth, actual1);
-
     }
 
     @Test
     public void test401notauth() throws Exception {
         addHandler(new BasicAuthHandler());
 
-        String username = "basic_user";
-        String password = "basic_password";
+        final String username = "basic_user";
+        final String password = "basic_password";
 
         runner.setProperty(Config.PROP_URL, url + "/status/401");
         runner.setProperty(Config.PROP_BASIC_AUTH_USERNAME, username);
@@ -250,7 +250,7 @@ public class TestInvokeHTTP {
         final String expected = "Hello";
         Assert.assertEquals(expected, actual);
 
-        String response = bundle.getAttribute(Config.RESPONSE_BODY);
+        final String response = bundle.getAttribute(Config.RESPONSE_BODY);
         assertEquals(response, "Get off my lawn!");
     }
 
@@ -505,7 +505,7 @@ public class TestInvokeHTTP {
         addHandler(new GetOrHeadHandler());
 
         // this is the bad urls
-        String badurlport = "https://localhost:" + 445;
+        final String badurlport = "https://localhost:" + 445;
 
         runner.setProperty(Config.PROP_URL, badurlport + "/doesnotExist");
         createFlowFiles(runner);
@@ -529,7 +529,7 @@ public class TestInvokeHTTP {
     public void testConnectFailBadHost() throws Exception {
         addHandler(new GetOrHeadHandler());
 
-        String badurlhost = "https://localhOOst:" + 445;
+        final String badurlhost = "https://localhOOst:" + 445;
 
         runner.setProperty(Config.PROP_URL, badurlhost + "/doesnotExist");
         createFlowFiles(runner);
@@ -550,7 +550,7 @@ public class TestInvokeHTTP {
     }
 
     private static Map<String, String> createSslProperties() {
-        Map<String, String> map = new HashMap<>();
+        final 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");
@@ -583,7 +583,7 @@ public class TestInvokeHTTP {
 
             assertEquals("/post", target);
 
-            String body = request.getReader().readLine();
+            final String body = request.getReader().readLine();
             assertEquals("Hello", body);
 
         }
@@ -595,7 +595,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));
+            final int status = Integer.valueOf(target.substring("/status".length() + 1));
             response.setStatus(status);
 
             response.setContentType("text/plain");
@@ -638,7 +638,7 @@ public class TestInvokeHTTP {
 
             authString = request.getHeader("Authorization");
 
-            int status = Integer.valueOf(target.substring("/status".length() + 1));
+            final int status = Integer.valueOf(target.substring("/status".length() + 1));
 
             if (status == 200) {
                 response.setStatus(status);