Fix junit for "native" on Windows 31/118131/1
authorJim Hahn <jrh3@att.com>
Fri, 19 Feb 2021 20:41:24 +0000 (15:41 -0500)
committerJim Hahn <jrh3@att.com>
Fri, 19 Feb 2021 20:52:32 +0000 (15:52 -0500)
Windows doesn't like file names containing ":".  Added code to replace
":" with "_", but only when the JVM is run on a Windows OS.

Issue-ID: POLICY-3085
Change-Id: I1d3b6819bf564571eddda69e4c5fbd2bb807a3aa
Signed-off-by: Jim Hahn <jrh3@att.com>
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java

index 1babe30..a2ecf8c 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 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.
@@ -38,6 +38,7 @@ import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringJoiner;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
@@ -57,6 +58,15 @@ public class XacmlPolicyUtils {
     private static final String DOT_FILE_SUFFIX = ".file";
     private static final String NOT_FOUND_MESSAGE = "NOT FOUND";
 
+    /**
+     * Function that sanitizes a file name, if the OS is Windows, so that it's a valid
+     * file name. Does nothing for other OSs.
+     */
+    private static final Function<String, String> SANITIZE_FILE_NAME =
+                    System.getProperty("os.name").startsWith("Windows")
+                    ? filename -> filename.replace(':', '_')
+                    : filename -> filename;
+
     private XacmlPolicyUtils() {
         super();
     }
@@ -371,7 +381,7 @@ public class XacmlPolicyUtils {
         //
         // Construct the Path
         //
-        return Paths.get(path.toAbsolutePath().toString(), filename);
+        return Paths.get(path.toAbsolutePath().toString(), SANITIZE_FILE_NAME.apply(filename));
     }
 
     /**