summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java2
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java5
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java29
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java37
4 files changed, 48 insertions, 25 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
index 650713c1e..84cd72fe6 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -1176,7 +1176,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
PolicyLogger.audit("Transaction Ended Successfully");
im.endTransaction();
return;
- } else if (apiflag != null && apiflag.equalsIgnoreCase("api")) {
+ } else if (apiflag != null && "api".equalsIgnoreCase(apiflag)) {
// this request is from the Policy Creation API
if(authorizeRequest(request)){
APIRequestHandler apiRequestHandler = new APIRequestHandler();
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
index 91530c7af..43eb4348e 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
@@ -256,15 +256,12 @@ public class ActionPolicy extends Policy {
// Saving the json Configurations file if exists at server location for action policy.
private void saveActionBody(String policyName, String actionBodyData) {
- try {
if(policyName.endsWith(".xml")){
policyName = policyName.replace(".xml", "");
}
File file = new File(ACTION_HOME+ File.separator + policyName + ".json");
- FileWriter fw = new FileWriter(file.getAbsoluteFile());
- BufferedWriter bw = new BufferedWriter(fw);
+ try(BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()))) {
bw.write(actionBodyData);
- bw.close();
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Action Body is succesfully saved at " + file.getAbsolutePath());
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
index d95b36709..6e46ab1c0 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
@@ -98,32 +98,21 @@ public class FirewallConfigPolicy extends Policy {
// Saving the Configurations file at server location for config policy.
protected void saveConfigurations(String policyName, String jsonBody) {
String configurationName = policyName;
- FileWriter fw = null;
- try{
- if(configurationName.endsWith(".xml")){
- configurationName = configurationName.replace(".xml", "");
- }
- fw = new FileWriter(CONFIG_HOME + File.separator + configurationName + ".json");
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(jsonBody);
- bw.close();
+ if(configurationName.endsWith(".xml")){
+ configurationName = configurationName.replace(".xml", "");
+ }
+ String fileName = CONFIG_HOME + File.separator + configurationName + ".json";
+ try(BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))){
+ bw.write(jsonBody);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Configuration is succesfully saved");
}
} catch (IOException e) {
- LOGGER.error("Exception Occured"+e);
- }finally{
- try{
- if(fw != null){
- fw.close();
- }
- }catch(Exception e){
- LOGGER.error("Exception Occured"+e);
- }
+ LOGGER.error("Save of configuration to file" +fileName+ "failed",e);
}
}
-
- //Utility to read json data from the existing file to a string
+
+ //Utility to read json data from the existing file to a string
static String readFile(String path, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
new file mode 100644
index 000000000..15bdf8962
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * 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.policy.pap.xacml.rest;
+
+import static org.junit.Assert.fail;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class WebConfigTest {
+ @Test(expected=NullPointerException.class)
+ public void testNegativeStartup() throws ServletException {
+ WebConfig init = new WebConfig();
+ ServletContext container = Mockito.mock(ServletContext.class);
+ init.onStartup(container);
+ fail("Expecting an exception.");
+ }
+}