summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java2
-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.java (renamed from ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopPerformanceMetrics.java)35
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ClosedLoopPolicyAdaptersTest.java11
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java15
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java2
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/utils/XACMLPolicyWriterWithPapNotify.java483
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java3
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyValidationControllerTest.java41
11 files changed, 79 insertions, 549 deletions
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java b/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java
index 07d21f45b..5ca2b309c 100644
--- a/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java
+++ b/BRMSGateway/src/test/java/org/onap/policy/brmsInterface/BRMSPushTest.java
@@ -22,7 +22,6 @@ package org.onap.policy.brmsInterface;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import java.util.HashMap;
@@ -32,7 +31,6 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
-
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
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-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopPerformanceMetrics.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
index 97546460a..15bdf8962 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopPerformanceMetrics.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
@@ -1,8 +1,8 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Engine
+ * ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -18,23 +18,20 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.rest.adapter;
+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 ClosedLoopPerformanceMetrics {
- public static final String CLPM_UIFIELD_ONSET_MESSAGE = "Onset Message";
- public static final String CLPM_UIJSON_ONSET_MESSAGE = "attributes.OnsetMessage";
-
- public static final String CLPM_UIFIELD_POLICY_NAME = "PolicyName";
- public static final String CLPM_UIJSON_POLICY_NAME = "attributes.PolicyName";
-
- public static final String CLPM_UIFIELD_ABATEMENT_MESSAGE = "Abatement Message";
- public static final String CLPM_UIJSON_ABATEMENT_MESSAGE = "attributes.AbatementMessage";
-
- public static final String CLPM_UIFIELD_GEOLINK = "Geo Link";
- public static final String CLPM_UIJSON_GEOLINK = "geoLink";
-
- private ClosedLoopPerformanceMetrics() {
- // Empty constructor
- }
+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.");
+ }
}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ClosedLoopPolicyAdaptersTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ClosedLoopPolicyAdaptersTest.java
index 320c30213..085dde1b6 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ClosedLoopPolicyAdaptersTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ClosedLoopPolicyAdaptersTest.java
@@ -22,9 +22,6 @@ package org.onap.policy.rest.adapter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -168,12 +165,4 @@ public class ClosedLoopPolicyAdaptersTest {
assertEquals(ClosedLoopPolicyStatus.ACTIVE.toString(), "active");
assertEquals(ClosedLoopPolicyStatus.INACTIVE.toString(), "inactive");
}
-
- @Test
- public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
- Constructor<ClosedLoopPerformanceMetrics> constructor = ClosedLoopPerformanceMetrics.class.getDeclaredConstructor();
- assertTrue(Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- }
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
index 4d549fea2..b28850dd7 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
@@ -530,16 +530,15 @@ public class PolicyManagerServlet extends HttpServlet {
}
try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))) {
bw.write(entity.getPolicyData());
- object = HumanPolicyComponent.DescribePolicy(temp);
} catch (IOException e) {
LOGGER.error("Exception Occured while Describing the Policy"+e);
- }finally{
- if(temp != null){
- try {
- Files.delete(temp.toPath());
- } catch (IOException e) {
- LOGGER.warn("Failed to delete " + temp.getName() + e);
- }
+ }
+ object = HumanPolicyComponent.DescribePolicy(temp);
+ if(temp != null){
+ try {
+ Files.delete(temp.toPath());
+ } catch (IOException e) {
+ LOGGER.warn("Failed to delete " + temp.getName() + e);
}
}
return object;
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
index 6f8eea8e7..5ff20b6fc 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
@@ -205,7 +205,7 @@ public class DecisionPolicyController extends RestrictedBaseController {
ApplyType decisionApply = (ApplyType) condition.getExpression().getValue();
decisionApply = (ApplyType) decisionApply.getExpression().get(0).getValue();
ruleAlgoirthmTracker = new LinkedList<>();
- if(policyAdapter.getRuleProvider()!=null && ("GUARD_YAML".equals(policyAdapter.getRuleProvider())||(policyAdapter.getRuleProvider().equals("GUARD_BL_YAML")))){
+ if(policyAdapter.getRuleProvider()!=null && ("GUARD_YAML".equals(policyAdapter.getRuleProvider())||("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())))){
YAMLParams yamlParams = new YAMLParams();
for(int i=0; i<attributeList.size() ; i++){
Map<String, String> map = (Map<String,String>)attributeList.get(i);
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/XACMLPolicyWriterWithPapNotify.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/XACMLPolicyWriterWithPapNotify.java
deleted file mode 100644
index 1cf2b7648..000000000
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/utils/XACMLPolicyWriterWithPapNotify.java
+++ /dev/null
@@ -1,483 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine
- * ================================================================================
- * Copyright (C) 2017-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.utils;
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.ProtocolException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.DirectoryNotEmptyException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Base64;
-import java.util.UUID;
-
-import org.onap.policy.rest.XACMLRestProperties;
-
-import org.onap.policy.xacml.api.XACMLErrorConstants;
-import org.onap.policy.xacml.util.XACMLPolicyWriter;
-import com.att.research.xacml.util.XACMLProperties;
-
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-
-import org.onap.policy.common.logging.flexlogger.FlexLogger;
-import org.onap.policy.common.logging.flexlogger.Logger;
-
-/**
- * Helper static class that wraps XACMLPolicyWriter
- *
- *
- */
-public class XACMLPolicyWriterWithPapNotify{
- private static final Logger LOGGER = FlexLogger.getLogger(XACMLPolicyWriterWithPapNotify.class);
-
- private XACMLPolicyWriterWithPapNotify() {
- // Add private constructor to hide the implicit public one
- }
-
- /**
- * Helper static class that does the work to write a policy set to a file on disk and notify PAP
- *
- *
- */
- public static Path writePolicyFile(Path filename, PolicySetType policySet) {
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet)"
- + "\nfilename = " + filename
- + "\npolicySet = " + policySet);
- }
- //write to file
- Path path = XACMLPolicyWriter.writePolicyFile(filename, policySet);
-
- if(path!=null){
- //write to DB
- if(notifyPapOfCreateUpdate(filename.toAbsolutePath().toString())){
- return path;
- }else{
- //write to DB failed. So, delete the file
- try{
- Files.deleteIfExists(path);
- }catch(DirectoryNotEmptyException e){
- //We are trying to delete a directory and it is not empty
- LOGGER.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)"
- + "\nDirectoryNotEmptyException for path = " + path
- + "\nException message = " + e);
- }catch(IOException e) {
- // File permission problems are caught here.
- LOGGER.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)"
- + "\nIOException for path = " + path
- + "\nException message = " + e);
- }catch(Exception e){
- LOGGER.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)"
- + "\nException for path = " + path
- + "\nException message = " + e);
- }
- return null;
- }
-
- }else{
- return null;
- }
- }
-
- /**
- * Helper static class that does the work to write a policy set to an output stream and notify PAP
- *
- *
- */
- public static void writePolicyFile(OutputStream os, PolicySetType policySet) {
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(OutputStream os, PolicySetType policySet)"
- + "\nos = " + os
- + "\npolicySet = " + policySet);
- }
- //Only used for writing a byte array output stream for a message. No file is written
- XACMLPolicyWriter.writePolicyFile(os, policySet);
- }
-
- /**
- * Helper static class that does the work to write a policy to a file on disk.
- *
- *
- */
- public static Path writePolicyFile(Path filename, PolicyType policy) {
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicyType policy)"
- + "\nfilename = " + filename
- + "\npolicy = " + policy);
- }
-
- //write to file
- Path path = XACMLPolicyWriter.writePolicyFile(filename, policy);
-
- if(path!=null){
- //write to DB
- if(notifyPapOfCreateUpdate(filename.toAbsolutePath().toString())){
- return path;
- }else{
- //write to DB failed so delete the file
- try{
- Files.deleteIfExists(path);
- }catch(DirectoryNotEmptyException e){
- //We are trying to delete a directory and it is not empty
- LOGGER.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet)Files.deleteIfExists(path) :"
- + "\nDirectoryNotEmptyException for path = " + path
- + "\nException message = " + e);
- }catch(IOException e) {
- // File permission problems are caught here.
- LOGGER.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)"
- + "\nIOException for path = " + path
- + "\nException message = " + e);
- }catch(Exception e){
- LOGGER.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)"
- + "\nException for path = " + path
- + "\nException message = " + e);
- }
- return null;
- }
-
- }else{
- return null;
- }
- }
-
-
- /**
- * Helper static class that does the work to write a policy to a file on disk.
- *
- *
- */
- public static InputStream getXmlAsInputStream(PolicyType policy) {
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.getXmlAsInputStream(PolicyType policy)"
- + "\npolicy = " + policy);
- }
- return XACMLPolicyWriter.getXmlAsInputStream(policy);
- }
- /**
- * Helper static class that does the work to write a policy set to an output stream.
- *
- *
- */
- public static void writePolicyFile(OutputStream os, PolicyType policy) {
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(OutputStream os, PolicyType policy)"
- + "\nos = " + os
- + "\npolicy = " + policy);
- }
- //There are no references to this and if there were, it would most likely be used in an http message
- XACMLPolicyWriter.writePolicyFile(os, policy);
- }
-
- public static String changeFileNameInXmlWhenRenamePolicy(Path filename) {
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.changeFileNameInXmlWhenRenamePolicy(Path filename)"
- + "\nfilename = " + filename);
- }
- return XACMLPolicyWriter.changeFileNameInXmlWhenRenamePolicy(filename);
- }
-
- public static boolean notifyPapOfPolicyRename(String oldPolicyName, String newPolicyName){
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.notifyPapOfCreateUpdate(String policyToCreateUpdate) "
- + "\npolicyToCreateUpdate = " + " ");
- }
- Base64.Encoder encoder = Base64.getEncoder();
- String encoding = encoder.encodeToString((XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID)+":"+CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS))).getBytes(StandardCharsets.UTF_8));
- HttpURLConnection connection;
- UUID requestID = UUID.randomUUID();
- URL url;
- try {
- url = new URL(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL)+"?oldPolicyName="+ URLEncoder.encode(oldPolicyName, "UTF-8")+"&newPolicyName="+URLEncoder.encode(newPolicyName,"UTF-8"));
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nnotifyPapOfCreateUpdate: URL = " + url);
- }
- } catch (MalformedURLException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nMalformedURLException message = " + e);
-
- return false;
- } catch (UnsupportedEncodingException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nUnsupportedEncodingException message = " + e);
-
- return false;
- }
- //
- // Open up the connection
- //
- try {
- connection = (HttpURLConnection)url.openConnection();
- } catch (IOException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nurl.openConnection() IOException message = " + e);
- return false;
- }
- //
- // Setup our method and headers
- //
- try {
- connection.setRequestMethod("PUT");
- } catch (ProtocolException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.setRequestMethod(PUT) ProtocolException message = " + e);
- connection.disconnect();
- return false;
- }
- connection.setRequestProperty("Authorization", "Basic " + encoding);
- connection.setRequestProperty("Accept", "text/x-java-properties");
- connection.setRequestProperty("Content-Type", "text/x-java-properties");
- connection.setRequestProperty("requestID", requestID.toString());
- connection.setUseCaches(false);
- //
- // Adding this in. It seems the HttpUrlConnection class does NOT
- // properly forward our headers for POST re-direction. It does so
- // for a GET re-direction.
- //
- // So we need to handle this ourselves.
- //
- connection.setInstanceFollowRedirects(false);
- connection.setDoOutput(true);
- connection.setDoInput(true);
- try {
- connection.connect();
- } catch (IOException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.connect() IOException message = " + e);
- connection.disconnect();
- return false;
- }
- try {
- int responseCode = connection.getResponseCode();
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.getResponseCode() = " + responseCode);
- }
- if (responseCode == 200) {
- connection.disconnect();
- return true;
- } else {
- connection.disconnect();
- return false;
- }
- } catch (IOException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.getResponseCode() IOException message = " + e);
- connection.disconnect();
- return false;
- }
- }
-
- public static boolean notifyPapOfDelete(String policyToDelete){
- Base64.Encoder encoder = Base64.getEncoder();
- String encoding = encoder.encodeToString((XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID)+":"+CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS))).getBytes(StandardCharsets.UTF_8));
- HttpURLConnection connection;
- UUID requestID = UUID.randomUUID();
- String papUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
- if(papUrl == null){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE +
- "PAP url property does not exist");
- return false;
- }
- String urlString = "";
- try{
- urlString = papUrl+"?groupId=0&isDeleteNotify=1&policyToDelete="+ URLEncoder.encode(policyToDelete, "UTF-8");
- } catch(UnsupportedEncodingException e){
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE +
- "Invalid encoding: UTF-8", e);
- return false;
- }
- URL url;
- try {
- url = new URL(urlString);
- } catch (MalformedURLException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +
- "Error parsing PAP url: "
- + urlString
- , e);
- return false;
- }
- //
- // Open up the connection
- //
- try {
- connection = (HttpURLConnection)url.openConnection();
- } catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +
- "Error opening HttpURLConnection to: "
- + url.toString()
- , e);
- return false;
- }
- //
- // Setup our method and headers
- //
- try {
- connection.setRequestMethod("DELETE");
- } catch (ProtocolException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE +
- "Invalid request method: DELETE", e);
- connection.disconnect();
- return false;
- }
- connection.setRequestProperty("Authorization", "Basic " + encoding);
- connection.setRequestProperty("Accept", "text/x-java-properties");
- connection.setRequestProperty("Content-Type", "text/x-java-properties");
- connection.setRequestProperty("requestID", requestID.toString());
- connection.setUseCaches(false);
- //
- // Adding this in. It seems the HttpUrlConnection class does NOT
- // properly forward our headers for POST re-direction. It does so
- // for a GET re-direction.
- //
- // So we need to handle this ourselves.
- //
- connection.setInstanceFollowRedirects(false);
- connection.setDoOutput(true);
- connection.setDoInput(true);
- try {
- connection.connect();
- } catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +
- "Error connecting HttpURLConnection to: "
- + connection.getURL().toString()
- , e);
- connection.disconnect();
- return false;
- }
- try {
- if (connection.getResponseCode() == 200) {
- connection.disconnect();
- //worked
- return true;
- } else {
- connection.disconnect();
- return false;
- }
- } catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +
- "Error getting HttpUrlConnection response code for: "
- + connection.getURL().toString()
- , e);
- connection.disconnect();
- return false;
- }
- }
-
- public static boolean notifyPapOfCreateUpdate(String policyToCreateUpdate){
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPolicyWriterWithPapNotify.notifyPapOfCreateUpdate(String policyToCreateUpdate) "
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- }
- Base64.Encoder encoder = Base64.getEncoder();
- String encoding = encoder.encodeToString((XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID)+":"+CryptoUtils.decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS))).getBytes(StandardCharsets.UTF_8));
- HttpURLConnection connection;
- UUID requestID = UUID.randomUUID();
- URL url;
- try {
- url = new URL(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL)+"?policyToCreateUpdate="+ URLEncoder.encode(policyToCreateUpdate, "UTF-8"));
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nnotifyPapOfCreateUpdate: URL = " + url);
- }
- } catch (MalformedURLException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nMalformedURLException message = " + e);
-
- return false;
- } catch (UnsupportedEncodingException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nUnsupportedEncodingException message = " + e);
-
- return false;
- }
- //
- // Open up the connection
- //
- try {
- connection = (HttpURLConnection)url.openConnection();
- } catch (IOException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nurl.openConnection() IOException message = " + e);
- return false;
- }
- //
- // Setup our method and headers
- //
- try {
- connection.setRequestMethod("PUT");
- } catch (ProtocolException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.setRequestMethod(PUT) ProtocolException message = " + e);
- connection.disconnect();
- return false;
- }
- connection.setRequestProperty("Authorization", "Basic " + encoding);
- connection.setRequestProperty("Accept", "text/x-java-properties");
- connection.setRequestProperty("Content-Type", "text/x-java-properties");
- connection.setRequestProperty("requestID", requestID.toString());
- connection.setUseCaches(false);
- //
- // Adding this in. It seems the HttpUrlConnection class does NOT
- // properly forward our headers for POST re-direction. It does so
- // for a GET re-direction.
- //
- // So we need to handle this ourselves.
- //
- connection.setInstanceFollowRedirects(false);
- connection.setDoOutput(true);
- connection.setDoInput(true);
- try {
- connection.connect();
- } catch (IOException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.connect() IOException message = " + e);
- connection.disconnect();
- return false;
- }
- try {
- int responseCode = connection.getResponseCode();
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.getResponseCode() = " + responseCode);
- }
- if (responseCode == 200) {
- connection.disconnect();
- return true;
- } else {
- connection.disconnect();
- return false;
- }
- } catch (IOException e) {
- LOGGER.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)"
- + "\nconnection.getResponseCode() IOException message = " + e);
- connection.disconnect();
- return false;
- }
- }
-}
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
index 06a2bb98e..bda2de1d0 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
@@ -85,6 +85,9 @@ public class PolicyManagerServletTest extends Mockito{
roles.setLoginId("Test");
roles.setRole("super-admin");
Roles roles1 = new Roles();
+ roles1.setId(1);
+ roles1.setName("Test");
+ assertTrue("Test".equals(roles1.getName()));
roles1.setLoginId("Test");
roles1.setRole("admin");
roles1.setScope("['com','Test']");
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyValidationControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyValidationControllerTest.java
new file mode 100644
index 000000000..580fc30f9
--- /dev/null
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyValidationControllerTest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Engine
+ * ================================================================================
+ * 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.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import org.junit.Test;
+import org.springframework.web.servlet.ModelAndView;
+import com.mockrunner.mock.web.MockHttpServletRequest;
+import com.mockrunner.mock.web.MockHttpServletResponse;
+
+public class PolicyValidationControllerTest {
+ @Test
+ public void testValidate() throws IOException {
+ PolicyValidationController controller = new PolicyValidationController();
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ ModelAndView model = controller.validatePolicy(request, response);
+ assertNull(model);
+ assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
+ }
+}