aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main
diff options
context:
space:
mode:
authorbobbymander <bobby.mander@att.com>2019-11-13 10:30:56 -0500
committerbobbymander <bobby.mander@att.com>2019-11-13 14:30:07 -0500
commit577b34e9bdad94d0b1559a9917af3283124aeeda (patch)
tree8e6defb4c95f2abe4873400b3a8c7698b1bf3b08 /ONAP-PAP-REST/src/main
parent0c20d1c294fe146e1018f14b07a8d861c29fe527 (diff)
Few JUnit additions for PAP-REST
Issue-ID: POLICY-2130 Change-Id: Ie9972bc0014def93acf04c4a2386585fb4accdef Signed-off-by: bobbymander <bobby.mander@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/Heartbeat.java35
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java31
2 files changed, 34 insertions, 32 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/Heartbeat.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/Heartbeat.java
index 81e7c6778..920c3dd87 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/Heartbeat.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/Heartbeat.java
@@ -23,7 +23,7 @@ package org.onap.policy.pap.xacml.rest;
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.api.pap.PDPStatus;
import com.att.research.xacml.util.XACMLProperties;
-
+import com.google.common.annotations.VisibleForTesting;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
@@ -33,7 +33,6 @@ import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
-
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -88,9 +87,9 @@ public class Heartbeat implements Runnable {
public Heartbeat(PAPPolicyEngine papEngine2) {
papEngine = papEngine2;
this.heartbeatInterval =
- Integer.parseInt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_HEARTBEAT_INTERVAL, "10000"));
+ Integer.parseInt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_HEARTBEAT_INTERVAL, "10000"));
this.heartbeatTimeout =
- Integer.parseInt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_HEARTBEAT_TIMEOUT, "10000"));
+ Integer.parseInt(XACMLProperties.getProperty(XacmlRestProperties.PROP_PAP_HEARTBEAT_TIMEOUT, "10000"));
}
@Override
@@ -127,7 +126,8 @@ public class Heartbeat implements Runnable {
}
}
- private void getPdpsFromGroup() {
+ @VisibleForTesting
+ protected void getPdpsFromGroup() {
try {
for (OnapPDPGroup g : papEngine.getOnapPDPGroups()) {
for (OnapPDP p : g.getOnapPdps()) {
@@ -136,11 +136,12 @@ public class Heartbeat implements Runnable {
}
} catch (PAPException e) {
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET,
- "Heartbeat unable to read PDPs from PAPEngine");
+ "Heartbeat unable to read PDPs from PAPEngine");
}
}
- private void notifyEachPdp() {
+ @VisibleForTesting
+ protected void notifyEachPdp() {
HashMap<String, URL> idToUrlMap = new HashMap<>();
for (OnapPDP pdp : pdps) {
// Check for shutdown
@@ -163,14 +164,15 @@ public class Heartbeat implements Runnable {
}
} catch (MalformedURLException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, XACMLPAPSERVLET,
- " PDP id '" + fullUrlString + "' is not a valid URL");
+ " PDP id '" + fullUrlString + "' is not a valid URL");
}
}
updatePdpStatus(pdp, openPdpConnection(pdpUrl, pdp));
}
}
- private String openPdpConnection(URL pdpUrl, OnapPDP pdp) {
+ @VisibleForTesting
+ protected String openPdpConnection(URL pdpUrl, OnapPDP pdp) {
// Do a GET with type HeartBeat
String newStatus = "";
HttpURLConnection connection = null;
@@ -197,25 +199,25 @@ public class Heartbeat implements Runnable {
// anything else is an unexpected result
newStatus = PDPStatus.Status.UNKNOWN.toString();
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " Heartbeat connect response code "
- + connection.getResponseCode() + ": " + pdp.getId());
+ + connection.getResponseCode() + ": " + pdp.getId());
}
}
} catch (UnknownHostException e) {
newStatus = PDPStatus.Status.NO_SUCH_HOST.toString();
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET,
- HEARTBEATSTRING + pdp.getId() + "' NO_SUCH_HOST");
+ HEARTBEATSTRING + pdp.getId() + "' NO_SUCH_HOST");
} catch (SocketTimeoutException e) {
newStatus = PDPStatus.Status.CANNOT_CONNECT.toString();
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET,
- HEARTBEATSTRING + pdp.getId() + "' connection timeout");
+ HEARTBEATSTRING + pdp.getId() + "' connection timeout");
} catch (ConnectException e) {
newStatus = PDPStatus.Status.CANNOT_CONNECT.toString();
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET,
- HEARTBEATSTRING + pdp.getId() + "' cannot connect");
+ HEARTBEATSTRING + pdp.getId() + "' cannot connect");
} catch (Exception e) {
newStatus = PDPStatus.Status.UNKNOWN.toString();
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET,
- HEARTBEATSTRING + pdp.getId() + "' connect exception");
+ HEARTBEATSTRING + pdp.getId() + "' connect exception");
} finally {
// cleanup the connection
if (connection != null)
@@ -224,7 +226,8 @@ public class Heartbeat implements Runnable {
return newStatus;
}
- private void updatePdpStatus(OnapPDP pdp, String newStatus) {
+ @VisibleForTesting
+ protected void updatePdpStatus(OnapPDP pdp, String newStatus) {
if (!pdp.getStatus().getStatus().toString().equals(newStatus)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("previous status='" + pdp.getStatus().getStatus() + "' new Status='" + newStatus + "'");
@@ -233,7 +236,7 @@ public class Heartbeat implements Runnable {
getPAPInstance().setPDPSummaryStatus(pdp, newStatus);
} catch (PAPException e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET,
- "Unable to set state for PDP '" + pdp.getId());
+ "Unable to set state for PDP '" + pdp.getId());
}
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
index c728f3bff..ffb902bc4 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
@@ -22,7 +22,7 @@ package org.onap.policy.pap.xacml.rest.components;
import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.std.IdentifierImpl;
-
+import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@@ -41,9 +41,7 @@ import java.util.Map.Entry;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import javax.script.SimpleBindings;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
@@ -57,7 +55,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
-
import org.apache.commons.io.FilenameUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
@@ -131,7 +128,7 @@ public class CreateBrmsParamPolicy extends Policy {
out.close();
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy",
- "Exception saving configuration file");
+ "Exception saving configuration file");
}
}
@@ -148,6 +145,7 @@ public class CreateBrmsParamPolicy extends Policy {
}
// Validations for Config form
+ @Override
public boolean validateConfigForm() {
// Validating mandatory Fields.
@@ -252,7 +250,7 @@ public class CreateBrmsParamPolicy extends Policy {
}
}
String param =
- params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", "");
+ params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", "");
String[] components = param.split(":");
String caption = "";
for (int i = 0; i < components.length; i++) {
@@ -283,7 +281,7 @@ public class CreateBrmsParamPolicy extends Policy {
}
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy",
- "Exception parsing file in findType");
+ "Exception parsing file in findType");
}
}
return mapFieldType;
@@ -327,7 +325,7 @@ public class CreateBrmsParamPolicy extends Policy {
try {
body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI "
- + "purpose. \n\t " + "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
+ + "purpose. \n\t " + "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
body.append("<%$Values=");
for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
String uiKey = entry.getKey();
@@ -339,7 +337,7 @@ public class CreateBrmsParamPolicy extends Policy {
body.append(valueFromDictionary + "\n");
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy",
- "Exception saving policy");
+ "Exception saving policy");
}
saveConfigurations(policyName, body.toString());
@@ -407,7 +405,7 @@ public class CreateBrmsParamPolicy extends Policy {
accessURI = new URI(ACTION_ID);
} catch (URISyntaxException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy",
- "Exception creating ACCESS URI");
+ "Exception creating ACCESS URI");
}
accessAttributeDesignator.setCategory(CATEGORY_ACTION);
accessAttributeDesignator.setDataType(STRING_DATATYPE);
@@ -429,7 +427,7 @@ public class CreateBrmsParamPolicy extends Policy {
configURI = new URI(RESOURCE_ID);
} catch (URISyntaxException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy",
- "Exception creating Config URI");
+ "Exception creating Config URI");
}
configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
@@ -461,7 +459,8 @@ public class CreateBrmsParamPolicy extends Policy {
}
// Data required for Advice part is setting here.
- private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+ @VisibleForTesting
+ protected AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
// Policy Config ID Assignment
AdviceExpressionsType advices = new AdviceExpressionsType();
@@ -546,8 +545,8 @@ public class CreateBrmsParamPolicy extends Policy {
// Adding Controller Information.
if (policyAdapter.getBrmsController() != null) {
BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
- advice.getAttributeAssignmentExpression().add(createResponseAttributes(
- "controller:" + policyAdapter.getBrmsController(),
+ advice.getAttributeAssignmentExpression()
+ .add(createResponseAttributes("controller:" + policyAdapter.getBrmsController(),
brmsDicitonaryController.getControllerDataByID(policyAdapter.getBrmsController()).getController()));
}
@@ -561,14 +560,14 @@ public class CreateBrmsParamPolicy extends Policy {
key.append(dependencyName + ",");
}
advice.getAttributeAssignmentExpression()
- .add(createResponseAttributes("dependencies:" + key.toString(), dependencies.toString()));
+ .add(createResponseAttributes("dependencies:" + key.toString(), dependencies.toString()));
}
// Dynamic Field Config Attributes.
Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
for (Entry<String, String> map : dynamicFieldConfigAttributes.entrySet()) {
advice.getAttributeAssignmentExpression()
- .add(createResponseAttributes("key:" + map.getKey(), map.getValue()));
+ .add(createResponseAttributes("key:" + map.getKey(), map.getValue()));
}
// Risk Attributes