summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-02-21 12:48:49 -0500
committerPamela Dragosh <pdragosh@research.att.com>2020-02-21 12:55:43 -0500
commit3710a41879717441884c75262015c536819a34c2 (patch)
tree67bbfc04a95f08c76036234c0d9c06ac7fc84395 /ONAP-PAP-REST/src/main/java/org
parent9a03ea31d42b8a73c3aa8f96bbad85093cb169a7 (diff)
Fix policycreation test
This test was only performing code coverage, it should have revealed that IllegalArgument exceptions were incorrect. Fixed bug in savePolicy when an exception being thrown has a null message. Added warning and error messages for debugging in the future. Issue-ID: POLICY-1590 Change-Id: Ie32a73adbaf944f96e411a2c612cd8293382911c Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java5
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java10
2 files changed, 12 insertions, 3 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java
index 67214acf2..e694f7e0b 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -549,6 +549,9 @@ public class PolicyDbDaoTransactionInstance implements PolicyDbDaoTransaction {
IOUtils.closeQuietly(policyXmlStream);
if (PolicyDbDao.isJunit()) {
+ if (policyDataString != null) {
+ logger.warn("isJUnit will overwrite policyDataString");
+ }
// Using parentPath object to set policy data.
policyDataString = policy.policyAdapter.getParentPath();
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
index 29b244046..f2f2e8dbc 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -618,7 +618,13 @@ public class PolicyCreation extends AbstractPolicyCreation {
} catch (Exception e) {
LOGGER.error("Exception Occured : " + e.getMessage(), e);
body = ERROR;
- response.addHeader(ERROR, e.getMessage());
+ //
+ // Because we are catching any old exception instead of a dedicated exception,
+ // its possible the e.getMessage() returns a null value. You cannot add a header
+ // to the response with a null value, it will throw an exception. This is something
+ // this is undesirable.
+ //
+ response.addHeader(ERROR, (e.getMessage() == null ? "missing exception message" : e.getMessage()));
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(body, status);