aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-03-21 13:20:54 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-21 13:20:54 +0000
commite53bd66cc71fcc3f7dff762054790c382d7dd499 (patch)
treee457e55abfb060d978508e2480a368ea294dc929 /ONAP-PDP-REST/src
parent6e00f46e0c2ee4dbbdb0e222e6f361210d1a0da1 (diff)
parenteef3c224cb6cad4b82a96938ade1e42ca881eea2 (diff)
Merge "Fix all bugs reported by Sonar in policy/engine"
Diffstat (limited to 'ONAP-PDP-REST/src')
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java2
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java11
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java2
3 files changed, 12 insertions, 3 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
index d3628f3c1..9b86204e0 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
@@ -247,7 +247,7 @@ public class GetDictionaryService {
jsonString = jsonString.replace("microServiceDictionaryDatas", "DictionaryDatas");
break;
default:
- return null;
+ break;
}
return jsonString;
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
index 8258aba1a..af7112ebd 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java
@@ -341,12 +341,13 @@ public class PDPServices {
pdpConfigLocation = pdpConfigLocation.replace("/", File.separator);
}
InputStream inputStream = null;
+ JsonReader jsonReader = null;
try {
inputStream = new FileInputStream(new File(pdpConfigLocation));
try {
if (pdpConfigLocation.endsWith("json")) {
pdpResponse.setType(PolicyType.JSON);
- JsonReader jsonReader = Json.createReader(inputStream);
+ jsonReader = Json.createReader(inputStream);
pdpResponse.setConfig(jsonReader.readObject().toString());
jsonReader.close();
} else if (pdpConfigLocation.endsWith("xml")) {
@@ -400,6 +401,14 @@ public class PDPServices {
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
throw new PDPException(XACMLErrorConstants.ERROR_PROCESS_FLOW +
"Cannot open a connection to the configURL", e);
+ } finally {
+ if(jsonReader != null) {
+ try {
+ jsonReader.close();
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured while closing the JsonReader"+e);
+ }
+ }
}
} catch (FileNotFoundException e) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java
index e18f8bb03..38dafee35 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/getDictionaryTest.java
@@ -41,7 +41,7 @@ public class getDictionaryTest {
dp.setDictionary("test");
GetDictionaryService gds = new GetDictionaryService(dp, null);
String result = (String) formatDictionary.invoke(gds, input);
- assertNull(result);
+ assertNotNull(result);
//
dp.setDictionary("OnapName");
gds = new GetDictionaryService(dp, null);