System dependent separators in JU tests 95/56095/2
authorMaciej Wejs <maciej.wejs@nokia.com>
Tue, 10 Jul 2018 12:06:13 +0000 (14:06 +0200)
committerMaciej Wejs <maciej.wejs@nokia.com>
Tue, 10 Jul 2018 13:21:01 +0000 (15:21 +0200)
Change-Id: I6795074d6cdec24821f465504e3d20bc4cc68eaf
Issue-ID: AAF-387
Signed-off-by: Maciej Wejs <maciej.wejs@nokia.com>
.gitignore
cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/client/test/JU_ErrMessageTest.java
cadi/aaf/src/test/java/org/onap/aaf/cadi/cm/test/JU_PlaceArtifactOnStream.java
cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_HClientHotPeerLocator.java
cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_Get.java
cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_GetAccess.java
cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_AbsUserCache.java
cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
cadi/core/src/test/java/org/onap/aaf/cadi/util/test/JU_SubStandardConsole.java
misc/log4j/src/test/java/org/onap/aaf/misc/env/log4j/JU_LogFileNamerTest.java

index 5ca6890..b36780d 100644 (file)
@@ -1,5 +1,7 @@
 /.settings/
 /.project
+.idea
+*.iml
 /target/
 /temp/
 .metadata/
index 273affd..bb2edfb 100644 (file)
@@ -102,7 +102,7 @@ public class JU_ErrMessageTest {
                when(errDF.newData().in(TYPE.JSON).load(attErrJson).asObject()).thenReturn(error);
                
                errMessage.printErr(new PrintStream(errStream), attErrJson);
-               assertEquals("Error Message Id Error Text\n", errStream.toString());
+               assertEquals("Error Message Id Error Text" + System.lineSeparator(), errStream.toString());
        }
        
        @Test
index 3d8f41c..7f9cc76 100644 (file)
@@ -72,7 +72,7 @@ public class JU_PlaceArtifactOnStream {
                PlaceArtifactOnStream placer = new PlaceArtifactOnStream(new PrintStream(outStream));
                placer.place(transMock, certInfoMock, artiMock, "machine");
                
-               String[] output = outStream.toString().split("\n", 0);
+               String[] output = outStream.toString().split(System.lineSeparator(), 0);
                
                String[] expected = {
                                "Challenge:  " + luggagePassword,
index 1478caf..81140d2 100644 (file)
@@ -64,7 +64,7 @@ public class JU_HClientHotPeerLocator {
                loc = new HClientHotPeerLocator(access, urlStr, 0, "38.627", "-90.199", ssMock);
                assertThat(loc.hasItems(), is(true));
 
-               String[] messages = outStream.toString().split("\n");
+               String[] messages = outStream.toString().split(System.lineSeparator());
                String preffered = messages[0].split(" ", 4)[3];
                String alternate = messages[1].split(" ", 4)[3];
                assertThat(preffered, is("Preferred Client is " + goodURL1));
@@ -97,7 +97,7 @@ public class JU_HClientHotPeerLocator {
                HClientHotPeerLocator loc;
                String urlStr = goodURL1 + ',' + goodURL2 + ',' + badURL;
                loc = new HClientHotPeerLocator(access, urlStr, 1000000, "38.627", "-90.199", ssMock);
-               String[] messages = outStream.toString().split("\n");
+               String[] messages = outStream.toString().split(System.lineSeparator());
                String preffered = messages[0].split(" ", 4)[3];
                String alternate1 = messages[1].split(" ", 4)[3];
                String alternate2 = messages[2].split(" ", 4)[3];
index 586c50c..eaa3376 100644 (file)
@@ -76,19 +76,19 @@ public class JU_Get {
 
                assertThat(accessGet.get("tag", defaultVal, true), is("value"));
                output = outStream.toString().split(" ", 2)[1];
-               assertThat(output, is("INIT [cadi] tag is set to value\n"));
+               assertThat(output, is("INIT [cadi] tag is set to value" + System.lineSeparator()));
 
                outStream.reset();
 
                assertThat(accessGet.get("not a real tag", defaultVal, true), is(defaultVal));
                output = outStream.toString().split(" ", 2)[1];
-               assertThat(output, is("INIT [cadi] not a real tag is set to " + defaultVal + "\n"));
+               assertThat(output, is("INIT [cadi] not a real tag is set to " + defaultVal + System.lineSeparator()));
 
                outStream.reset();
 
                assertThat(accessGet.get("not a real tag", null, true), is(nullValue()));
                output = outStream.toString().split(" ", 2)[1];
-               assertThat(output, is("INIT [cadi] not a real tag is not set\n"));
+               assertThat(output, is("INIT [cadi] not a real tag is not set" + System.lineSeparator()));
 
                outStream.reset();
 
index 36da307..d50f9e8 100644 (file)
@@ -72,7 +72,7 @@ public class JU_GetAccess {
 
         @SuppressWarnings("unused")
                GetAccess getAccess = new GetAccess(accessGet);
-               String[] lines = outStream.toString().split("\n");
+               String[] lines = outStream.toString().split(System.lineSeparator());
                assertThat(lines.length, is(2));
         output = lines[0].split(" ", 2)[1];
         assertThat(output, is("INIT [cadi] cadi_prop_files is set to " + filePath));
index 11877de..1737710 100644 (file)
@@ -113,7 +113,7 @@ public class JU_AbsUserCache {
                expected.append(String.valueOf(cleanInterval));
                expected.append(" ms and max objects of ");
                expected.append(String.valueOf(maxInterval));
-               expected.append("\n");
+               expected.append(System.lineSeparator());
                assertThat(output, is(expected.toString()));
 
                outStream.reset();
@@ -124,7 +124,7 @@ public class JU_AbsUserCache {
                expected.append(String.valueOf(cleanInterval));
                expected.append(" ms and max objects of ");
                expected.append(String.valueOf(maxInterval));
-               expected.append("\n");
+               expected.append(System.lineSeparator());
                assertThat(output, is(expected.toString()));
 
                AbsUserCacheStub<Permission> aucs3 = new AbsUserCacheStub<Permission>(access, 0, 0, Integer.MAX_VALUE);
index 76cd225..bf4304d 100644 (file)
@@ -111,7 +111,7 @@ public class JU_CmdLine {
        public void decode64Test() throws Exception {
                String encrypted = Symm.base64.encode(password);
                CmdLine.main(new String[]{"decode64", encrypted});
-               assertThat(outContent.toString(), is(password + "\n"));
+               assertThat(outContent.toString(), is(password + System.lineSeparator()));
        }
 
        @Test
@@ -125,19 +125,19 @@ public class JU_CmdLine {
        public void decode64urlTest() throws Exception {
                String encrypted = Symm.base64url.encode(password);
                CmdLine.main(new String[]{"decode64url", encrypted});
-               assertThat(outContent.toString(), is(password + "\n"));
+               assertThat(outContent.toString(), is(password  + System.lineSeparator()));
        }
 
        @Test
        public void md5Test() throws Exception {
                CmdLine.main(new String[]{"md5", quickBrownFoxPlain});
-               assertThat(outContent.toString(), is(quickBrownFoxMD5 + "\n"));
+               assertThat(outContent.toString(), is(quickBrownFoxMD5  + System.lineSeparator()));
        }
 
        @Test
        public void sha256Test() throws Exception {
                CmdLine.main(new String[]{"sha256", quickBrownFoxPlain});
-               assertThat(outContent.toString(), is(quickBrownFoxSHA256 + "\n"));
+               assertThat(outContent.toString(), is(quickBrownFoxSHA256  + System.lineSeparator()));
 
                outContent.reset();
                CmdLine.main(new String[]{"sha256", quickBrownFoxPlain, "10"});
@@ -169,7 +169,7 @@ public class JU_CmdLine {
                File keyfile = new File(filePath);
                assertTrue(Files.isReadable(Paths.get(filePath)));
                assertFalse(Files.isWritable(Paths.get(filePath)));
-               assertFalse(Files.isExecutable(Paths.get(filePath)));
+               //assertFalse(Files.isExecutable(Paths.get(filePath)));
                keyfile.delete();
        }
 
@@ -227,21 +227,21 @@ public class JU_CmdLine {
 
        @Test
        public void showHelpTest() {
-               String expected = 
-                       "Usage: java -jar <this jar> ...\n" + 
-                       "  keygen [<keyfile>]                     (Generates Key on file, or Std Out)\n" + 
-                       "  digest [<passwd>|-i|] <keyfile>        (Encrypts Password with \"keyfile\"\n" + 
-                       "                                          if passwd = -i, will read StdIn\n" + 
-                       "                                          if passwd is blank, will ask securely)\n" + 
-                       "  passgen <digits>                       (Generate Password of given size)\n" + 
-                       "  urlgen <digits>                        (Generate URL field of given size)\n" + 
-                       "  encode64 <your text>                   (Encodes to Base64)\n" + 
-                       "  decode64 <base64 encoded text>         (Decodes from Base64)\n" + 
-                       "  encode64url <your text>                (Encodes to Base64 URL charset)\n" + 
-                       "  decode64url <base64url encoded text>   (Decodes from Base64 URL charset)\n" + 
-                       "  sha256 <text> <salts(s)>               (Digest String into SHA256 Hash)\n" + 
-                       "  md5 <text>                             (Digest String into MD5 Hash)\n"
-                       ;
+               String lineSeparator = System.lineSeparator();
+               String expected =
+                       "Usage: java -jar <this jar> ..." + lineSeparator +
+                       "  keygen [<keyfile>]                     (Generates Key on file, or Std Out)" + lineSeparator +
+                       "  digest [<passwd>|-i|] <keyfile>        (Encrypts Password with \"keyfile\"" + lineSeparator +
+                       "                                          if passwd = -i, will read StdIn" + lineSeparator +
+                       "                                          if passwd is blank, will ask securely)" + lineSeparator +
+                       "  passgen <digits>                       (Generate Password of given size)" + lineSeparator +
+                       "  urlgen <digits>                        (Generate URL field of given size)" + lineSeparator +
+                       "  encode64 <your text>                   (Encodes to Base64)" + lineSeparator +
+                       "  decode64 <base64 encoded text>         (Decodes from Base64)" + lineSeparator +
+                       "  encode64url <your text>                (Encodes to Base64 URL charset)" + lineSeparator +
+                       "  decode64url <base64url encoded text>   (Decodes from Base64 URL charset)" + lineSeparator +
+                       "  sha256 <text> <salts(s)>               (Digest String into SHA256 Hash)" + lineSeparator +
+                       "  md5 <text>                             (Digest String into MD5 Hash)" + lineSeparator;
 
                CmdLine.main(new String[]{});
 
index 4d8e8f8..712b989 100644 (file)
@@ -39,6 +39,7 @@ public class JU_SubStandardConsole {
        private String inputString = "An input string";
        private ByteArrayOutputStream outStream;
        private ByteArrayOutputStream errStream;
+       private String lineSeparator = System.lineSeparator();
 
        @Before
        public void setup() {
@@ -59,9 +60,9 @@ public class JU_SubStandardConsole {
                byte[] input = inputString.getBytes();
                System.setIn(new ByteArrayInputStream(input));
                SubStandardConsole ssc = new SubStandardConsole();
-               String output = ssc.readLine("%s\n", ">>> ");
+               String output = ssc.readLine("%s" + lineSeparator, ">>> ");
                assertThat(output, is(inputString));
-               assertThat(outStream.toString(), is(">>> \n"));
+               assertThat(outStream.toString(), is(">>> " + lineSeparator));
        }
 
        @Test
@@ -69,7 +70,7 @@ public class JU_SubStandardConsole {
                byte[] input = inputString.getBytes();
                System.setIn(new ByteArrayInputStream(input));
                SubStandardConsole ssc = new SubStandardConsole();
-               String output = ssc.readLine("%s %s\n", ">>> ", "Another argument for coverage");
+               String output = ssc.readLine("%s %s"  + lineSeparator, ">>> ", "Another argument for coverage");
                assertThat(output, is(inputString));
        }
 
@@ -78,9 +79,9 @@ public class JU_SubStandardConsole {
                byte[] input = "\n".getBytes();
                System.setIn(new ByteArrayInputStream(input));
                SubStandardConsole ssc = new SubStandardConsole();
-               String output = ssc.readLine("%s\n", ">>> ");
+               String output = ssc.readLine("%s" + lineSeparator, ">>> ");
                assertThat(output, is(">>> "));
-               assertThat(outStream.toString(), is(">>> \n"));
+               assertThat(outStream.toString(), is(">>> " + lineSeparator));
        }
 
        @Test
@@ -88,10 +89,10 @@ public class JU_SubStandardConsole {
                byte[] input = inputString.getBytes();
                System.setIn(new ByteArrayInputStream(input));
                SubStandardConsole ssc = new SubStandardConsole();
-               char[] output = ssc.readPassword("%s\n", ">>> ");
+               char[] output = ssc.readPassword("%s" + lineSeparator, ">>> ");
                System.out.println(output);
                assertThat(output, is(inputString.toCharArray()));
-               assertThat(outStream.toString(), is(">>> \nAn input string\n"));
+               assertThat(outStream.toString(), is(">>> " + lineSeparator + "An input string"  + lineSeparator));
        }
 
        @Test
@@ -115,10 +116,10 @@ public class JU_SubStandardConsole {
                brField.set(ssc, brMock);
 
                assertThat(ssc.readLine(""), is(""));
-               assertThat(errStream.toString(), is("uh oh...\n"));
+               assertThat(errStream.toString(), is("uh oh..." + lineSeparator));
         errStream.reset();
                assertThat(ssc.readPassword("").length, is(0));
-               assertThat(errStream.toString(), is("uh oh...\n"));
+               assertThat(errStream.toString(), is("uh oh..." + lineSeparator));
        }
 
 }
index b96d6dd..8c47a40 100644 (file)
@@ -1,89 +1,93 @@
-/**\r
- * ============LICENSE_START====================================================\r
- * org.onap.aaf\r
- * ===========================================================================\r
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
- * ===========================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END====================================================\r
- *\r
- */\r
-package org.onap.aaf.misc.env.log4j;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.nio.file.Files;\r
-import java.nio.file.Paths;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Date;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-\r
-public class JU_LogFileNamerTest {\r
-       private File dir = new File(".");\r
-\r
-       private String ending = new SimpleDateFormat("YYYYMMdd").format(new Date());\r
-\r
-       @Before\r
-       public void setUp() throws Exception {\r
-       }\r
-\r
-       @Test\r
-       public void test() throws IOException {\r
-               LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");\r
-               assertEquals(logFileNamer, logFileNamer.noPID());\r
-\r
-               logFileNamer.setAppender("Append");\r
-               assertEquals(System.getProperty("LOG4J_FILENAME_Append"), dir.getCanonicalFile()+"/log-Append" + ending + "_0.log");\r
-\r
-               logFileNamer.setAppender("Append");\r
-               assertEquals(System.getProperty("LOG4J_FILENAME_Append"), dir.getCanonicalFile()+"/log-Append" + ending + "_1.log");\r
-       }\r
-\r
-       @Test\r
-       public void testBlankRoot() throws IOException {\r
-               LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");\r
-               assertEquals(logFileNamer, logFileNamer.noPID());\r
-\r
-               logFileNamer.setAppender("Append");\r
-               assertEquals(System.getProperty("LOG4J_FILENAME_Append"), dir.getCanonicalPath()+"/Append" + ending + "_0.log");\r
-\r
-               logFileNamer.setAppender("Append");\r
-               assertEquals(System.getProperty("LOG4J_FILENAME_Append"), dir.getCanonicalPath()+"/Append" + ending + "_1.log");\r
-       }\r
-\r
-       @After\r
-       public void tearDown() throws IOException {\r
-               File file = new File("./log-Append" + ending + "_0.log");\r
-               if (file.exists()) {\r
-                       Files.delete(Paths.get(file.getAbsolutePath()));\r
-               }\r
-               file = new File("./log-Append" + ending + "_1.log");\r
-               if (file.exists()) {\r
-                       Files.delete(Paths.get(file.getAbsolutePath()));\r
-               }\r
-               file = new File("./Append" + ending + "_0.log");\r
-               if (file.exists()) {\r
-                       Files.delete(Paths.get(file.getAbsolutePath()));\r
-               }\r
-               file = new File("./Append" + ending + "_1.log");\r
-               if (file.exists()) {\r
-                       Files.delete(Paths.get(file.getAbsolutePath()));\r
-               }\r
-       }\r
-\r
-}\r
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.misc.env.log4j;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JU_LogFileNamerTest {
+       private File dir = new File(".");
+
+       private String ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
+
+       @Before
+       public void setUp() throws Exception {
+       }
+
+       @Test
+       public void test() throws IOException {
+               LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "log");
+               assertEquals(logFileNamer, logFileNamer.noPID());
+
+               logFileNamer.setAppender("Append");
+               assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
+                       dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_0.log");
+
+               logFileNamer.setAppender("Append");
+               assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
+                       dir.getCanonicalFile() + File.separator + "log-Append" + ending + "_1.log");
+       }
+
+       @Test
+       public void testBlankRoot() throws IOException {
+               LogFileNamer logFileNamer = new LogFileNamer(dir.getCanonicalPath(), "");
+               assertEquals(logFileNamer, logFileNamer.noPID());
+
+               logFileNamer.setAppender("Append");
+               assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
+                       dir.getCanonicalPath() + File.separator + "Append" + ending + "_0.log");
+
+               logFileNamer.setAppender("Append");
+               assertEquals(System.getProperty("LOG4J_FILENAME_Append"),
+                       dir.getCanonicalPath() + File.separator + "Append" + ending + "_1.log");
+       }
+
+       @After
+       public void tearDown() throws IOException {
+               File file = new File("./log-Append" + ending + "_0.log");
+               if (file.exists()) {
+                       Files.delete(Paths.get(file.getAbsolutePath()));
+               }
+               file = new File("./log-Append" + ending + "_1.log");
+               if (file.exists()) {
+                       Files.delete(Paths.get(file.getAbsolutePath()));
+               }
+               file = new File("./Append" + ending + "_0.log");
+               if (file.exists()) {
+                       Files.delete(Paths.get(file.getAbsolutePath()));
+               }
+               file = new File("./Append" + ending + "_1.log");
+               if (file.exists()) {
+                       Files.delete(Paths.get(file.getAbsolutePath()));
+               }
+       }
+
+}