From 1d5ac0923d96f9e181ce8786f5cbd911cfb80a45 Mon Sep 17 00:00:00 2001 From: Bhavik Patel Date: Wed, 20 Apr 2022 17:59:47 +0530 Subject: [PATCH] RANGER-3722: Fix Test-case failure --- .../org/apache/ranger/rest/TestServiceREST.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java index 6c5addbc95..d049f9949b 100644 --- a/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java +++ b/security-admin/src/test/java/org/apache/ranger/rest/TestServiceREST.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; @@ -1762,7 +1763,7 @@ public void test49importPoliciesFromFileAllowingOverride() throws Exception { SearchFilter filter = new SearchFilter(); filter.setParam("serviceType", "value"); - File jsonPolicyFile = new File(importPoliceTestFilePath); + File jsonPolicyFile = getFile(importPoliceTestFilePath); InputStream uploadedInputStream = new FileInputStream(jsonPolicyFile); FormDataContentDisposition fileDetail = FormDataContentDisposition.name("file") .fileName(jsonPolicyFile.getName()).size(uploadedInputStream.toString().length()).build(); @@ -1827,7 +1828,7 @@ public void test50importPoliciesFromFileNotAllowingOverride() throws Exception { SearchFilter filter = new SearchFilter(); filter.setParam("serviceType", "value"); - File jsonPolicyFile = new File(importPoliceTestFilePath); + File jsonPolicyFile = getFile(importPoliceTestFilePath); InputStream uploadedInputStream = new FileInputStream(jsonPolicyFile); FormDataContentDisposition fileDetail = FormDataContentDisposition.name("file") .fileName(jsonPolicyFile.getName()).size(uploadedInputStream.toString().length()).build(); @@ -1860,6 +1861,14 @@ public void test50importPoliciesFromFileNotAllowingOverride() throws Exception { } + private File getFile(String testFilePath) throws IOException { + File jsonPolicyFile = new File(testFilePath); + if (jsonPolicyFile.getCanonicalPath().contains("/target/jstest")) { + jsonPolicyFile = new File(jsonPolicyFile.getCanonicalPath().replace("/target/jstest", "")); + } + return jsonPolicyFile; + } + @Test public void test51getMetricByType() throws Exception { String type = "usergroup";