From: Jorge Hernandez Date: Thu, 21 Sep 2017 17:36:57 +0000 (+0000) Subject: Merge "Add New Junit For ONAP-XACML" X-Git-Tag: v1.1.0~59 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=5ab9c7f1179455f3ea048c1bbea02e8339474bdf;hp=629edba90bdec1792c359f2c9654052da49584cd;p=policy%2Fengine.git Merge "Add New Junit For ONAP-XACML" --- diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java index 43031861b..a11e8b4b7 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java @@ -95,7 +95,7 @@ public class BRMSHandler implements BackUpHandler{ } } } - Boolean failureFlag = false; + Boolean failureFlag; int i = 0; do{ failureFlag = false; @@ -118,6 +118,7 @@ public class BRMSHandler implements BackUpHandler{ * (non-Javadoc) * @see org.onap.policy.utils.BackUpHandler#runOnNotification(org.onap.policy.api.PDPNotification) */ + @Override public void runOnNotification(PDPNotification notification){ if(notification.getNotificationType().equals(NotificationType.REMOVE)){ removedPolicies(notification.getRemovedPolicies()); diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java index c923c3c34..6e8588acb 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java @@ -388,11 +388,11 @@ public class BRMSPush { selectedName = responseAttributes.get(key); } // kmodule configurations - else if (key.equals("kSessionName")) { + else if ("kSessionName".equals(key)) { kSessionName = responseAttributes.get(key); } // Check User Specific values. - if (key.equals("$controller:")) { + if ("$controller:".equals(key)) { try { PEDependency dependency = PolicyUtils.jsonStringToObject(responseAttributes.get(key), PEDependency.class); @@ -402,7 +402,7 @@ public class BRMSPush { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e); } - } else if (key.equals("$dependency$")) { + } else if ("$dependency$".equals(key)) { String value = responseAttributes.get(key); if (value.startsWith("[") && value.endsWith("]")) { value = value.substring(1, value.length() - 1).trim(); @@ -500,7 +500,7 @@ public class BRMSPush { List pList = query.getResultList(); boolean createFlag = false; BRMSPolicyInfo brmsPolicyInfo = new BRMSPolicyInfo(); - if (pList.size() > 0) { + if (!pList.isEmpty()) { // Already exists. brmsPolicyInfo = (BRMSPolicyInfo) pList.get(0); if (!brmsPolicyInfo.getControllerName().getControllerName().equals(controllerName)) { @@ -514,7 +514,7 @@ public class BRMSPush { query.setParameter("cn", controllerName); List bList = query.getResultList(); BRMSGroupInfo brmsGroupInfo = new BRMSGroupInfo(); - if (bList.size() > 0) { + if (!bList.isEmpty()) { brmsGroupInfo = (BRMSGroupInfo) bList.get(0); } brmsPolicyInfo.setPolicyName(policyName); @@ -528,7 +528,7 @@ public class BRMSPush { private void syncProject(String selectedName) { boolean projectExists = checkProject(selectedName); if (projectExists) { - String version = null; + String version; version = getVersion(selectedName); if (version == null) { LOGGER.error("Error getting local version for the given Controller Name:" + selectedName @@ -599,7 +599,6 @@ public class BRMSPush { } fos.close(); is.close(); - f = null; LOGGER.info(fileName + " Created.."); } } @@ -641,7 +640,7 @@ public class BRMSPush { private boolean checkRemoteSync(String selectedName, String version) { List artifacts = getArtifactFromNexus(selectedName, version); - return (artifacts.size() == 0) ? false : true; + return artifacts.isEmpty() ? false : true; } private List getArtifactFromNexus(String selectedName, String version) { @@ -690,7 +689,7 @@ public class BRMSPush { if (artifact != null) { newVersion = incrementVersion(artifact.getVersion()); } - if (newVersion.equals("0.1.0")) { + if ("0.1.0".equals(newVersion)) { createFlag = true; } setVersion(newVersion, selectedName); @@ -736,8 +735,9 @@ public class BRMSPush { } if (!modifiedGroups.isEmpty()) { Boolean flag = false; - for (String group : modifiedGroups.keySet()) { + for (Map.Entry entry : modifiedGroups.entrySet()) { InvocationResult result = null; + String group = entry.getKey(); try { InvocationRequest request = new DefaultInvocationRequest(); setVersion(group); @@ -761,7 +761,7 @@ public class BRMSPush { if (createFlag) { addNotification(group, "create"); } else { - addNotification(group, modifiedGroups.get(group)); + addNotification(group, entry.getValue()); } flag = true; } else { @@ -795,7 +795,7 @@ public class BRMSPush { return policyMap.get(name); } else { syncGroupInfo(); - return (policyMap.containsKey(name)) ? policyMap.get(name) : null; + return policyMap.containsKey(name) ? policyMap.get(name) : null; } } @@ -869,7 +869,7 @@ public class BRMSPush { pub.send("MyPartitionKey", message); final List stuck = pub.close(uebDelay, TimeUnit.SECONDS); - if (stuck.size() > 0) { + if (!stuck.isEmpty()) { LOGGER.error(stuck.size() + " messages unsent"); } else { LOGGER.debug("Clean exit; Message Published on UEB : " + uebList + "for Topic: " + pubTopic); @@ -1018,7 +1018,7 @@ public class BRMSPush { } private void readGroups(Properties config) throws PolicyException { - String[] groupNames = null; + String[] groupNames; if (!config.containsKey("groupNames") || config.getProperty("groupNames")==null){ throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "groupNames property is missing or empty from the property file "); @@ -1069,7 +1069,7 @@ public class BRMSPush { query.setParameter("cn", name); List groupList = query.getResultList(); BRMSGroupInfo brmsGroupInfo = null; - if (groupList.size() > 0) { + if (!groupList.isEmpty()) { LOGGER.info("Controller name already Existing in DB. Will be updating the DB Values" + name); brmsGroupInfo = (BRMSGroupInfo) groupList.get(0); } @@ -1122,8 +1122,8 @@ public class BRMSPush { Query query = em.createQuery("select b from BRMSPolicyInfo as b where b.policyName = :pn"); query.setParameter("pn", policyName); List pList = query.getResultList(); - BRMSPolicyInfo brmsPolicyInfo = new BRMSPolicyInfo(); - if (pList.size() > 0) { + BRMSPolicyInfo brmsPolicyInfo; + if (!pList.isEmpty()) { // Already exists. brmsPolicyInfo = (BRMSPolicyInfo) pList.get(0); if (brmsPolicyInfo.getControllerName().getControllerName().equals(controllerName)) { diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java index a0f1ba86d..7c60ecfdf 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java @@ -202,7 +202,7 @@ class HtmlProcessor extends SimpleCallback { combiningAlgo2human.put("only-one-applicable", "to honour the result of the first successfully evaluated $placeholder$ in order"); } - private Map attributeIdentifiersMap = new HashMap(); + private Map attributeIdentifiersMap = new HashMap<>(); private final StringWriter stringWriter = new StringWriter(); private final PrintWriter htmlOut = new PrintWriter(stringWriter); @@ -357,7 +357,7 @@ class HtmlProcessor extends SimpleCallback { else policySet(policySet, "li"); - if (policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) + if (!policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) htmlOut.println("
    "); return super.onPreVisitPolicySet(parent, policySet); @@ -377,7 +377,7 @@ class HtmlProcessor extends SimpleCallback { LOGGER.trace("PolicySet: " + policySet.getPolicySetId() + " Description: " + policySet.getDescription()); - if (policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) + if (!policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) htmlOut.println("
"); htmlOut.println("

"); @@ -421,7 +421,7 @@ class HtmlProcessor extends SimpleCallback { } if (policySet.getPolicySetOrPolicyOrPolicySetIdReference() != null && - policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) { + !policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) { String algoDesc = combiningAlgo2human.get(combiningAlgorithm); if (algoDesc != null) { algoDesc = algoDesc.replace("$placeholder$", "policy") + " (" + "" + combiningAlgorithm + ")"; @@ -449,7 +449,7 @@ class HtmlProcessor extends SimpleCallback { policy(policy); - if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) + if (!policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) htmlOut.println("
    "); return super.onPreVisitPolicy(parent, policy); @@ -464,7 +464,7 @@ class HtmlProcessor extends SimpleCallback { LOGGER.trace("PolicySet: " + policy.getPolicyId() + "Parent PolicySet: " + parent.getPolicySetId() + " Version: " + parent.getVersion()); - if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) + if (!policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) htmlOut.println("
"); htmlOut.println("

"); @@ -506,7 +506,7 @@ class HtmlProcessor extends SimpleCallback { } if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition() != null && - policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) { + !policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) { String algoDesc = combiningAlgo2human.get(combiningAlgorithm); if (algoDesc != null) { algoDesc = algoDesc.replace("$placeholder$", "rule") + " (" + combiningAlgorithm + ")"; @@ -710,7 +710,7 @@ class HtmlProcessor extends SimpleCallback { // StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); - String attributeDataType = null; + String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), @@ -822,11 +822,12 @@ class HtmlProcessor extends SimpleCallback { } private String removePrimitives(String in) { - in = in.replace("string-", ""); - in = in.replace("integer-", ""); - in = in.replace("double-", ""); - in = in.replace("boolean-", ""); - return in; + String newIn = in; + newIn = newIn.replace("string-", ""); + newIn = newIn.replace("integer-", ""); + newIn = newIn.replace("double-", ""); + newIn = newIn.replace("boolean-", ""); + return newIn; } private String stringifyCondition(ConditionType condition) { diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java index 353e08a44..32f40b9e7 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java @@ -64,4 +64,6 @@ public class HibernateSession{ logSessionFactory = logSessionFactory1; } + private HibernateSession(){ + } } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java index f10041e38..392adf039 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java @@ -98,24 +98,24 @@ public class CreateClosedLoopPMController{ String attributeId = designator.getAttributeId(); // First match in the target is OnapName, so set that value. - if (attributeId.equals("ONAPName")) { + if ("ONAPName".equals(attributeId)) { policyAdapter.setOnapName(value); } - if (attributeId.equals("RiskType")){ + if ("RiskType".equals(attributeId)){ policyAdapter.setRiskType(value); } - if (attributeId.equals("RiskLevel")){ + if ("RiskLevel".equals(attributeId)){ policyAdapter.setRiskLevel(value); } - if (attributeId.equals("guard")){ + if ("guard".equals(attributeId)){ policyAdapter.setGuard(value); } - if (attributeId.equals("TTLDate") && !value.contains("NA")){ + if ("TTLDate".equals(attributeId) && !value.contains("NA")){ PolicyController controller = new PolicyController(); String newDate = controller.convertDate(value); policyAdapter.setTtlDate(newDate); } - if (attributeId.equals("ServiceType")){ + if ("ServiceType".equals(attributeId)){ LinkedHashMap serviceTypePolicyName1 = new LinkedHashMap<>(); String key = "serviceTypePolicyName"; serviceTypePolicyName1.put(key, value); diff --git a/pom.xml b/pom.xml index 96cc5015d..c615114d3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.onap.oparent oparent - 1.0.0-SNAPSHOT + 0.1.1