Few JUnit additions for PAP-REST
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / CreateBrmsParamPolicy.java
index c728f3b..ffb902b 100644 (file)
@@ -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