diff options
Diffstat (limited to 'ONAP-PAP-REST')
32 files changed, 418 insertions, 221 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/DictionaryNames.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/DictionaryNames.java index 2bb2e95bb..0e1cc521a 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/DictionaryNames.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/DictionaryNames.java @@ -36,7 +36,7 @@ public enum DictionaryNames { VSCLAction, ClosedLoopService, ClosedLoopSite, - PEPOptions, + PepOptions, VarbindDictionary, BRMSParamDictionary, BRMSControllerDictionary, 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/UpdateOthersPAPS.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/UpdateOthersPAPS.java index 2bb4229a6..1b25c3b9f 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/UpdateOthersPAPS.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/UpdateOthersPAPS.java @@ -48,7 +48,7 @@ import org.onap.policy.rest.XacmlRestProperties; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionBodyEntity; import org.onap.policy.rest.jpa.ConfigurationDataEntity; -import org.onap.policy.rest.jpa.PolicyDBDaoEntity; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.onap.policy.utils.PeCryptoUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; @@ -103,11 +103,11 @@ public class UpdateOthersPAPS { body.setOldPolicyName(request.getParameter("oldPolicyName")); String currentPap = XacmlRestProperties.getProperty("xacml.rest.pap.url"); - List<Object> getPAPUrls = commonClassDao.getData(PolicyDBDaoEntity.class); + List<Object> getPAPUrls = commonClassDao.getData(PolicyDbDaoEntity.class); if (getPAPUrls != null && !getPAPUrls.isEmpty()) { for (int i = 0; i < getPAPUrls.size(); i++) { - PolicyDBDaoEntity papId = (PolicyDBDaoEntity) getPAPUrls.get(i); - String papUrl = papId.getPolicyDBDaoUrl(); + PolicyDbDaoEntity papId = (PolicyDbDaoEntity) getPAPUrls.get(i); + String papUrl = papId.getPolicyDbDaoUrl(); if (!papUrl.equals(currentPap)) { String userName = papId.getUsername(); String password = papId.getPassword(); 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 36ab893fe..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. @@ -184,7 +182,7 @@ public class CreateBrmsParamPolicy extends Policy { private String getValueFromDictionary(String templateName) { String ruleTemplate = null; CommonClassDaoImpl dbConnection = new CommonClassDaoImpl(); - String queryString = "from BRMSParamTemplate where param_template_name= :templateName"; + String queryString = "from BrmsParamTemplate where param_template_name= :templateName"; SimpleBindings params = new SimpleBindings(); params.put("templateName", templateName); List<Object> result = dbConnection.getDataByQuery(queryString, params); @@ -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 diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java index 573f274f2..ea5e8aa43 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java @@ -275,7 +275,7 @@ public class CreateNewMicroServiceModel { newModel.setDependency("[]"); if (mainClass.getSubClass() != null) { String value = new Gson().toJson(mainClass.getSubClass()); - newModel.setSub_attributes(value); + newModel.setSubAttributes(value); } if (mainClass.getAttribute() != null) { @@ -289,7 +289,7 @@ public class CreateNewMicroServiceModel { String refAttributes = mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""); int equalsIndex = refAttributes.indexOf("="); String refAttributesAfterFirstEquals = refAttributes.substring(equalsIndex + 1); - this.newModel.setRef_attributes(refAttributesAfterFirstEquals); + this.newModel.setRefAttributes(refAttributesAfterFirstEquals); } if (mainClass.getEnumType() != null) { @@ -328,14 +328,14 @@ public class CreateNewMicroServiceModel { } subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName()); - this.newModel.setSub_attributes(subAttribute); + this.newModel.setSubAttributes(subAttribute); if (mainClass.getAttribute() != null && !mainClass.getAttribute().isEmpty()) { this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", "")); } if (mainClass.getRefAttribute() != null && !mainClass.getRefAttribute().isEmpty()) { this.newModel - .setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); + .setRefAttributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); } if (mainClass.getEnumType() != null && !mainClass.getEnumType().isEmpty()) { @@ -368,8 +368,8 @@ public class CreateNewMicroServiceModel { model.setDependency(this.newModel.getDependency()); model.setDescription(this.newModel.getDescription()); model.setEnumValues(this.newModel.getEnumValues()); - model.setRef_attributes(this.newModel.getRef_attributes()); - model.setSub_attributes(this.newModel.getSub_attributes()); + model.setRefAttributes(this.newModel.getRefAttributes()); + model.setSubAttributes(this.newModel.getSubAttributes()); model.setDataOrderInfo(this.newModel.getDataOrderInfo()); model.setDecisionModel(this.newModel.isDecisionModel()); model.setRuleFormation(this.newModel.getRuleFormation()); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotifications.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotifications.java index 4e4c02672..72e6f488a 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotifications.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotifications.java @@ -250,12 +250,12 @@ public class HandleIncomingNotifications { } else if (localGroup == null) { // creating a new group try { - PolicyDbDao.getPolicyDbDaoInstance().getPapEngine().newGroup(groupRecord.getgroupName(), + PolicyDbDao.getPolicyDbDaoInstance().getPapEngine().newGroup(groupRecord.getGroupName(), groupRecord.getDescription()); } catch (NullPointerException | PAPException e) { PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, PolicyDbDao.POLICYDBDAO_VAR, "Caught PAPException trying to create pdp group with " - + "papEngine.newGroup(groupRecord.getgroupName(), groupRecord.getDescription());"); + + "papEngine.newGroup(groupRecord.getGroupName(), groupRecord.getDescription());"); throw new PAPException("Could not create group " + groupRecord); } try { @@ -311,11 +311,11 @@ public class HandleIncomingNotifications { needToUpdate = true; } if (!PolicyDbDao.stringEquals(localGroupClone.getId(), groupRecord.getGroupId()) - || !PolicyDbDao.stringEquals(localGroupClone.getName(), groupRecord.getgroupName())) { + || !PolicyDbDao.stringEquals(localGroupClone.getName(), groupRecord.getGroupName())) { // changing ids // we do not want to change the id, the papEngine will do this // for us, it needs to know the old id - localGroupClone.setName(groupRecord.getgroupName()); + localGroupClone.setName(groupRecord.getGroupName()); needToUpdate = true; } if (!PolicyDbDao.stringEquals(localGroupClone.getDescription(), groupRecord.getDescription())) { diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPaps.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPaps.java index cd290c66c..e9db043bf 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPaps.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPaps.java @@ -35,13 +35,13 @@ import java.util.UUID; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.XacmlRestProperties; -import org.onap.policy.rest.jpa.PolicyDBDaoEntity; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.onap.policy.utils.PeCryptoUtils; public class NotifyOtherPaps { private static final Logger LOGGER = FlexLogger.getLogger(NotifyOtherPaps.class); - private List<PolicyDBDaoEntity> failedPaps = null; + private List<PolicyDbDaoEntity> failedPaps = null; public void notifyOthers(long entityId, String entityType) { notifyOthers(entityId, entityType, null); @@ -104,8 +104,8 @@ public class NotifyOtherPaps { @Override public void run() { PolicyDbDao dao = new PolicyDbDao(); - PolicyDBDaoEntity dbdEntity = (PolicyDBDaoEntity) obj; - String otherPap = dbdEntity.getPolicyDBDaoUrl(); + PolicyDbDaoEntity dbdEntity = (PolicyDbDaoEntity) obj; + String otherPap = dbdEntity.getPolicyDbDaoUrl(); String txt; try { txt = PeCryptoUtils.decrypt(dbdEntity.getPassword()); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDao.java index e0db53e8b..9af380b05 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDao.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDao.java @@ -59,7 +59,7 @@ import org.onap.policy.rest.jpa.ConfigurationDataEntity; import org.onap.policy.rest.jpa.DatabaseLockEntity; import org.onap.policy.rest.jpa.GroupEntity; import org.onap.policy.rest.jpa.PdpEntity; -import org.onap.policy.rest.jpa.PolicyDBDaoEntity; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.utils.PeCryptoUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; @@ -212,14 +212,14 @@ public class PolicyDbDao { /** * Gets the list of other registered PolicyDBDaos from the database. * - * @return List (type PolicyDBDaoEntity) of other PolicyDBDaos + * @return List (type PolicyDbDaoEntity) of other PolicyDBDaos */ private List<?> getRemotePolicyDbDaoList() { logger.debug("getRemotePolicyDBDaoList() as getRemotePolicyDBDaoList() called"); List<?> policyDbDaoEntityList = new LinkedList<>(); Session session = sessionfactory.openSession(); try { - Criteria cr = session.createCriteria(PolicyDBDaoEntity.class); + Criteria cr = session.createCriteria(PolicyDbDaoEntity.class); policyDbDaoEntityList = cr.list(); } catch (Exception e) { PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, POLICYDBDAO_VAR, @@ -328,7 +328,7 @@ public class PolicyDbDao { } /** - * Register the PolicyDBDao instance in the PolicyDBDaoEntity table. + * Register the PolicyDBDao instance in the PolicyDbDaoEntity table. * * @return Boolean, were we able to register? */ @@ -370,19 +370,19 @@ public class PolicyDbDao { } } logger.debug("\nPolicyDBDao.register. Database locking and concurrency control is initialized\n"); - PolicyDBDaoEntity foundPolicyDbDaoEntity = null; - Criteria cr = session.createCriteria(PolicyDBDaoEntity.class); - cr.add(Restrictions.eq("policyDBDaoUrl", url[0])); + PolicyDbDaoEntity foundPolicyDbDaoEntity = null; + Criteria cr = session.createCriteria(PolicyDbDaoEntity.class); + cr.add(Restrictions.eq("policyDbDaoUrl", url[0])); List<?> data = cr.list(); if (!data.isEmpty()) { - foundPolicyDbDaoEntity = (PolicyDBDaoEntity) data.get(0); + foundPolicyDbDaoEntity = (PolicyDbDaoEntity) data.get(0); } // encrypt the password String txt = PeCryptoUtils.encrypt(url[2]); if (foundPolicyDbDaoEntity == null) { - PolicyDBDaoEntity newPolicyDbDaoEntity = new PolicyDBDaoEntity(); - newPolicyDbDaoEntity.setPolicyDBDaoUrl(url[0]); + PolicyDbDaoEntity newPolicyDbDaoEntity = new PolicyDbDaoEntity(); + newPolicyDbDaoEntity.setPolicyDbDaoUrl(url[0]); newPolicyDbDaoEntity.setDescription("PAP server at " + url[0]); newPolicyDbDaoEntity.setUsername(url[1]); newPolicyDbDaoEntity.setPassword(txt); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java index 882169a34..67214acf2 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDbDaoTransactionInstance.java @@ -1008,7 +1008,7 @@ public class PolicyDbDaoTransactionInstance implements PolicyDbDaoTransaction { } if (group.getName() != null - && !PolicyDbDao.stringEquals(group.getName(), groupToUpdateInDb.getgroupName())) { + && !PolicyDbDao.stringEquals(group.getName(), groupToUpdateInDb.getGroupName())) { // we need to check if the new id exists in the database String newGrpId = PolicyDbDao.createNewPdpGroupId(group.getName()); Query checkGroupQuery = session.createQuery(PolicyDbDao.GROUPENTITY_SELECT); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java index 0b94b40bc..16e8e2e2c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java @@ -38,7 +38,7 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ClosedLoopD2Services; import org.onap.policy.rest.jpa.ClosedLoopSite; import org.onap.policy.rest.jpa.OnapName; -import org.onap.policy.rest.jpa.PEPOptions; +import org.onap.policy.rest.jpa.PepOptions; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.rest.jpa.VNFType; import org.onap.policy.rest.jpa.VSCLAction; @@ -134,7 +134,7 @@ public class ClosedLoopDictionaryController { produces = MediaType.APPLICATION_JSON_VALUE) public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getDataByEntity(response, pepOptionDatas, pepName, PEPOptions.class); + utils.getDataByEntity(response, pepOptionDatas, pepName, PepOptions.class); } @RequestMapping( @@ -143,7 +143,7 @@ public class ClosedLoopDictionaryController { produces = MediaType.APPLICATION_JSON_VALUE) public void getPEPOptionsDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getData(response, pepOptionDatas, PEPOptions.class); + utils.getData(response, pepOptionDatas, PepOptions.class); } @RequestMapping( @@ -336,15 +336,15 @@ public class ClosedLoopDictionaryController { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - PEPOptions pEPOptions; + PepOptions pEPOptions; GridData gridData; String userId = null; if (fromAPI) { - pEPOptions = mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class); + pEPOptions = mapper.readValue(root.get(dictionaryFields).toString(), PepOptions.class); gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); userId = "API"; } else { - pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class); + pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PepOptions.class); gridData = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class); userId = root.get(userid).textValue(); } @@ -355,10 +355,10 @@ public class ClosedLoopDictionaryController { } List<Object> duplicateData = - commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class); + commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PepOptions.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { - PEPOptions data = (PEPOptions) duplicateData.get(0); + PepOptions data = (PepOptions) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { pEPOptions.setId(data.getId()); } else if ((request.getParameter(operation) != null @@ -377,7 +377,7 @@ public class ClosedLoopDictionaryController { pEPOptions.setModifiedDate(new Date()); commonClassDao.update(pEPOptions); } - responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)); + responseString = mapper.writeValueAsString(commonClassDao.getData(PepOptions.class)); } else { responseString = duplicateResponseString; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java index 5de2dfbc2..e2e2e3872 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java @@ -211,7 +211,7 @@ public class DictionaryController { UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = - commonClassDao.checkDuplicateEntry(onapData.getOnapName(), onapName, OnapName.class); + commonClassDao.checkDuplicateEntry(onapData.getName(), onapName, OnapName.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { OnapName data = (OnapName) duplicateData.get(0); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java index 7400eb0c8..ef475039d 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java @@ -56,7 +56,7 @@ import org.onap.policy.rest.jpa.DescriptiveScope; import org.onap.policy.rest.jpa.GroupServiceList; import org.onap.policy.rest.jpa.MicroServiceModels; import org.onap.policy.rest.jpa.OnapName; -import org.onap.policy.rest.jpa.PEPOptions; +import org.onap.policy.rest.jpa.PepOptions; import org.onap.policy.rest.jpa.PrefixList; import org.onap.policy.rest.jpa.ProtocolList; import org.onap.policy.rest.jpa.SecurityZone; @@ -213,7 +213,7 @@ public class DictionaryImportController { for (int j = 0; j < rows.length; j++) { if ("onap_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Onap Name".equalsIgnoreCase(dictSheet.get(0)[j])) { - attribute.setOnapName(rows[j]); + attribute.setName(rows[j]); } if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setDescription(rows[j]); @@ -252,10 +252,10 @@ public class DictionaryImportController { attribute.setEnumValues(rows[j]); } if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { - attribute.setRef_attributes(rows[j]); + attribute.setRefAttributes(rows[j]); } if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { - attribute.setSub_attributes(rows[j]); + attribute.setSubAttributes(rows[j]); } if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAnnotation(rows[j]); @@ -295,10 +295,10 @@ public class DictionaryImportController { attribute.setEnumValues(rows[j]); } if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { - attribute.setRef_attributes(rows[j]); + attribute.setRefAttributes(rows[j]); } if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) { - attribute.setSub_attributes(rows[j]); + attribute.setSubAttributes(rows[j]); } if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) { attribute.setAnnotation(rows[j]); @@ -389,9 +389,9 @@ public class DictionaryImportController { commonClassDao.save(attribute); } } - if (dictionaryName.startsWith("PEPOptions")) { + if (dictionaryName.startsWith("PepOptions")) { for (int i = 1; i < dictSheet.size(); i++) { - PEPOptions attribute = new PEPOptions(); + PepOptions attribute = new PepOptions(); UserInfo userinfo = new UserInfo(); userinfo.setUserLoginId(userId); attribute.setUserCreatedBy(userinfo); @@ -801,7 +801,7 @@ public class DictionaryImportController { case VSCLAction: case ClosedLoopService: case ClosedLoopSite: - case PEPOptions: + case PepOptions: case VarbindDictionary: case BRMSParamDictionary: case BRMSControllerDictionary: diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java index 8dda4ddc7..39a12c81a 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java @@ -42,8 +42,8 @@ import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionList; import org.onap.policy.rest.jpa.AddressGroup; -import org.onap.policy.rest.jpa.FWTag; -import org.onap.policy.rest.jpa.FWTagPicker; +import org.onap.policy.rest.jpa.FwTag; +import org.onap.policy.rest.jpa.FwTagPicker; import org.onap.policy.rest.jpa.FirewallDictionaryList; import org.onap.policy.rest.jpa.GroupServiceList; import org.onap.policy.rest.jpa.PortList; @@ -1013,7 +1013,7 @@ public class FirewallDictionaryController { produces = MediaType.APPLICATION_JSON_VALUE) public void getTagPickerNameEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getDataByEntity(response, fwTagPickerDatas, tagPickerName, FWTagPicker.class); + utils.getDataByEntity(response, fwTagPickerDatas, tagPickerName, FwTagPicker.class); } @RequestMapping( @@ -1022,7 +1022,7 @@ public class FirewallDictionaryController { produces = MediaType.APPLICATION_JSON_VALUE) public void getTagPickerDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getData(response, fwTagPickerDatas, FWTagPicker.class); + utils.getData(response, fwTagPickerDatas, FwTagPicker.class); } @RequestMapping(value = {"/fw_dictionary/save_fwTagPicker"}, method = {RequestMethod.POST}) @@ -1034,15 +1034,15 @@ public class FirewallDictionaryController { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - FWTagPicker fwTagPicker; + FwTagPicker fwTagPicker; TagGridValues data; String userId = ""; if (fromAPI) { - fwTagPicker = mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class); + fwTagPicker = mapper.readValue(root.get(dictionaryFields).toString(), FwTagPicker.class); data = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class); userId = "API"; } else { - fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); + fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FwTagPicker.class); data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); userId = root.get(userid).textValue(); } @@ -1051,10 +1051,10 @@ public class FirewallDictionaryController { UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), - tagPickerName, FWTagPicker.class); + tagPickerName, FwTagPicker.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { - FWTagPicker data1 = (FWTagPicker) duplicateData.get(0); + FwTagPicker data1 = (FwTagPicker) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { fwTagPicker.setId(data1.getId()); } else if ((request.getParameter(operation) != null @@ -1073,7 +1073,7 @@ public class FirewallDictionaryController { fwTagPicker.setModifiedDate(new Date()); commonClassDao.update(fwTagPicker); } - responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); + responseString = mapper.writeValueAsString(commonClassDao.getData(FwTagPicker.class)); } else { responseString = duplicateResponseString; } @@ -1092,7 +1092,7 @@ public class FirewallDictionaryController { public void removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.removeData(request, response, fwTagPickerDatas, FWTagPicker.class); + utils.removeData(request, response, fwTagPickerDatas, FwTagPicker.class); } @RequestMapping( @@ -1101,7 +1101,7 @@ public class FirewallDictionaryController { produces = MediaType.APPLICATION_JSON_VALUE) public void getTagDictionaryEntityData(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getData(response, fwTagDatas, FWTag.class); + utils.getData(response, fwTagDatas, FwTag.class); } @RequestMapping( @@ -1110,7 +1110,7 @@ public class FirewallDictionaryController { produces = MediaType.APPLICATION_JSON_VALUE) public void getTagNameEntityDataByName(HttpServletResponse response) { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.getDataByEntity(response, fwTagDatas, "fwTagName", FWTag.class); + utils.getDataByEntity(response, fwTagDatas, "fwTagName", FwTag.class); } @RequestMapping(value = {"/fw_dictionary/save_fwTag"}, method = {RequestMethod.POST}) @@ -1122,15 +1122,15 @@ public class FirewallDictionaryController { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - FWTag fwTag; + FwTag fwTag; TagGridValues tagGridValues; String userId = ""; if (fromAPI) { - fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FWTag.class); + fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FwTag.class); tagGridValues = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class); userId = "API"; } else { - fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class); + fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FwTag.class); tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class); userId = root.get(userid).textValue(); } @@ -1138,10 +1138,10 @@ public class FirewallDictionaryController { UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = - commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class); + commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FwTag.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { - FWTag data = (FWTag) duplicateData.get(0); + FwTag data = (FwTag) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { fwTag.setId(data.getId()); } else if ((request.getParameter(operation) != null @@ -1160,7 +1160,7 @@ public class FirewallDictionaryController { fwTag.setModifiedDate(new Date()); commonClassDao.update(fwTag); } - responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); + responseString = mapper.writeValueAsString(commonClassDao.getData(FwTag.class)); } else { responseString = duplicateResponseString; } @@ -1179,7 +1179,7 @@ public class FirewallDictionaryController { public void removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); - utils.removeData(request, response, fwTagDatas, FWTag.class); + utils.removeData(request, response, fwTagDatas, FwTag.class); } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java index dfd7af48d..b9e1ce1ce 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java @@ -658,7 +658,7 @@ public class MicroServiceDictionaryController { MSAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); - this.newModel.setSub_attributes(value); + this.newModel.setSubAttributes(value); String attributes = mainClass.getAttribute().toString().replace("{", "").replace("}", ""); int equalsIndexForAttributes = attributes.indexOf('='); String atttributesAfterFirstEquals = attributes.substring(equalsIndexForAttributes + 1); @@ -666,7 +666,7 @@ public class MicroServiceDictionaryController { String refAttributes = mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""); int equalsIndex = refAttributes.indexOf("="); String refAttributesAfterFirstEquals = refAttributes.substring(equalsIndex + 1); - this.newModel.setRef_attributes(refAttributesAfterFirstEquals); + this.newModel.setRefAttributes(refAttributesAfterFirstEquals); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel .setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); @@ -713,10 +713,10 @@ public class MicroServiceDictionaryController { } } microServiceModels.setAttributes(this.newModel.getAttributes()); - microServiceModels.setRef_attributes(this.newModel.getRef_attributes()); + microServiceModels.setRefAttributes(this.newModel.getRefAttributes()); microServiceModels.setDependency(this.newModel.getDependency()); microServiceModels.setModelName(this.newModel.getModelName()); - microServiceModels.setSub_attributes(this.newModel.getSub_attributes()); + microServiceModels.setSubAttributes(this.newModel.getSubAttributes()); microServiceModels.setVersion(this.newModel.getVersion()); microServiceModels.setEnumValues(this.newModel.getEnumValues()); microServiceModels.setAnnotation(this.newModel.getAnnotation()); @@ -798,9 +798,9 @@ public class MicroServiceDictionaryController { } if (mainClass != null) { this.newModel.setDependency(mainClass.getDependency()); - this.newModel.setSub_attributes(subAttribute); + this.newModel.setSubAttributes(subAttribute); this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", "")); - this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); + this.newModel.setRefAttributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java index ad6b9cf8e..f21ac60c8 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java @@ -58,7 +58,7 @@ import org.onap.policy.rest.jpa.GroupPolicyScopeList; import org.onap.policy.rest.jpa.MicroServiceLocation; import org.onap.policy.rest.jpa.MicroServiceModels; import org.onap.policy.rest.jpa.OnapName; -import org.onap.policy.rest.jpa.PEPOptions; +import org.onap.policy.rest.jpa.PepOptions; import org.onap.policy.rest.jpa.RiskType; import org.onap.policy.rest.jpa.SafePolicyWarning; import org.onap.policy.rest.jpa.TermList; @@ -340,7 +340,7 @@ public class PolicyElasticSearchController { break; case onapName: OnapName onapName = mapper.readValue(root.get("data").toString(), OnapName.class); - value = onapName.getOnapName(); + value = onapName.getName(); policyList = searchElkDatabase(all, "onapName", value); break; case actionPolicy: @@ -356,7 +356,7 @@ public class PolicyElasticSearchController { policyList = searchElkDatabase(config, "ruleName", value); break; case pepOptions: - PEPOptions pEPOptions = mapper.readValue(root.get("data").toString(), PEPOptions.class); + PepOptions pEPOptions = mapper.readValue(root.get("data").toString(), PepOptions.class); value = pEPOptions.getPepName(); policyList = searchElkDatabase(closedloop, "jsonBodyData.pepName", value); break; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java index 65c50b1c0..f16c2031c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java @@ -56,7 +56,7 @@ public class DictionaryHandlerImpl implements DictionaryHandler { case "VNFType": dictionary.getVnfType(response); break; - case "PEPOptions": + case "PepOptions": dictionary.getPEPOptions(response); break; case "Varbind": @@ -206,7 +206,7 @@ public class DictionaryHandlerImpl implements DictionaryHandler { case "VNFType": result = dictionary.saveVnfType(request, response); break; - case "PEPOptions": + case "PepOptions": result = dictionary.savePEPOptions(request, response); break; case "Varbind": diff --git a/ONAP-PAP-REST/src/main/resources/META-INF/drop.ddl b/ONAP-PAP-REST/src/main/resources/META-INF/drop.ddl index 062169345..d28a00dde 100644 --- a/ONAP-PAP-REST/src/main/resources/META-INF/drop.ddl +++ b/ONAP-PAP-REST/src/main/resources/META-INF/drop.ddl @@ -20,7 +20,7 @@ DROP TABLE IF EXISTS ConfigurationDataEntity DROP TABLE IF EXISTS PolicyEntity -DROP TABLE IF EXISTS PolicyDBDaoEntity +DROP TABLE IF EXISTS PolicyDbDaoEntity DROP TABLE IF EXISTS ActionBodyEntity DROP SEQUENCE IF EXISTS seqPolicy DROP SEQUENCE IF EXISTS seqConfig diff --git a/ONAP-PAP-REST/src/main/resources/META-INF/persistence.xml b/ONAP-PAP-REST/src/main/resources/META-INF/persistence.xml index 7be95014d..0280219a7 100644 --- a/ONAP-PAP-REST/src/main/resources/META-INF/persistence.xml +++ b/ONAP-PAP-REST/src/main/resources/META-INF/persistence.xml @@ -22,7 +22,7 @@ <persistence-unit name="XACML-PAP-REST"> <class>org.onap.policy.rest.jpa.PolicyEntity</class> <class>org.onap.policy.rest.jpa.ConfigurationDataEntity</class> - <class>org.onap.policy.rest.jpa.PolicyDBDaoEntity</class> + <class>org.onap.policy.rest.jpa.PolicyDbDaoEntity</class> <class>org.onap.policy.rest.jpa.GroupEntity</class> <class>org.onap.policy.rest.jpa.PdpEntity</class> <class>org.onap.policy.rest.jpa.ActionBodyEntity</class> @@ -40,7 +40,7 @@ <class>org.onap.policy.rest.jpa.ActionPolicyDict</class> <class>org.onap.policy.rest.jpa.DecisionSettings</class> <class>org.onap.policy.rest.jpa.MicroServiceModels</class> - <class>org.onap.policy.rest.jpa.BRMSParamTemplate</class> + <class>org.onap.policy.rest.jpa.BrmsParamTemplate</class> <class>org.onap.policy.rest.jpa.PolicyEditorScopes</class> <!-- unique to PolicyEngineUtils - will be audited from PAP --> <class>org.onap.policy.jpa.BackUpMonitorEntity</class> @@ -109,7 +109,7 @@ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>org.onap.policy.rest.jpa.PolicyEntity</class> <class>org.onap.policy.rest.jpa.ConfigurationDataEntity</class> - <class>org.onap.policy.rest.jpa.PolicyDBDaoEntity</class> + <class>org.onap.policy.rest.jpa.PolicyDbDaoEntity</class> <class>org.onap.policy.rest.jpa.GroupEntity</class> <class>org.onap.policy.rest.jpa.PdpEntity</class> <class>org.onap.policy.rest.jpa.ActionBodyEntity</class> @@ -131,11 +131,11 @@ <class>org.onap.policy.rest.jpa.ActionList</class> <class>org.onap.policy.rest.jpa.AddressGroup</class> <class>org.onap.policy.rest.jpa.AttributeAssignment</class> - <class>org.onap.policy.rest.jpa.BRMSParamTemplate</class> + <class>org.onap.policy.rest.jpa.BrmsParamTemplate</class> <class>org.onap.policy.rest.jpa.ClosedLoopD2Services</class> <class>org.onap.policy.rest.jpa.ClosedLoopSite</class> - <class>org.onap.policy.rest.jpa.DCAEUsers</class> - <class>org.onap.policy.rest.jpa.DCAEuuid</class> + <class>org.onap.policy.rest.jpa.DcaeUsers</class> + <class>org.onap.policy.rest.jpa.Dcaeuuid</class> <class>org.onap.policy.rest.jpa.DescriptiveScope</class> <class>org.onap.policy.rest.jpa.OnapName</class> <class>org.onap.policy.rest.jpa.EnforcingType</class> @@ -146,12 +146,12 @@ <class>org.onap.policy.rest.jpa.MicroServiceLocation</class> <class>org.onap.policy.rest.jpa.Obadvice</class> <class>org.onap.policy.rest.jpa.ObadviceExpression</class> - <class>org.onap.policy.rest.jpa.PEPOptions</class> - <class>org.onap.policy.rest.jpa.PIPConfigParam</class> - <class>org.onap.policy.rest.jpa.PIPConfiguration</class> - <class>org.onap.policy.rest.jpa.PIPResolver</class> - <class>org.onap.policy.rest.jpa.PIPResolverParam</class> - <class>org.onap.policy.rest.jpa.PIPType</class> + <class>org.onap.policy.rest.jpa.PepOptions</class> + <class>org.onap.policy.rest.jpa.PipConfigParam</class> + <class>org.onap.policy.rest.jpa.PipConfiguration</class> + <class>org.onap.policy.rest.jpa.PipResolver</class> + <class>org.onap.policy.rest.jpa.PipResolverParam</class> + <class>org.onap.policy.rest.jpa.PipType</class> <class>org.onap.policy.rest.jpa.PolicyAlgorithms</class> <class>org.onap.policy.rest.jpa.PolicyManagement</class> <class>org.onap.policy.rest.jpa.PolicyScopeService</class> diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java index 99902012b..ffac655a6 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java @@ -43,7 +43,7 @@ import org.onap.policy.pap.xacml.rest.UpdateOthersPAPS; import org.onap.policy.pap.xacml.rest.adapters.UpdateObjectData; import org.onap.policy.pap.xacml.rest.components.Policy; import org.onap.policy.rest.dao.CommonClassDao; -import org.onap.policy.rest.jpa.PolicyDBDaoEntity; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -65,20 +65,20 @@ public class UpdateOthersPAPSTest { request = mock(HttpServletRequest.class); response = new MockHttpServletResponse(); List<Object> data = new ArrayList<>(); - PolicyDBDaoEntity entity = new PolicyDBDaoEntity(); - entity.setPolicyDBDaoUrl("http://localhost:8070/pap"); + PolicyDbDaoEntity entity = new PolicyDbDaoEntity(); + entity.setPolicyDbDaoUrl("http://localhost:8070/pap"); entity.setUsername("test"); entity.setPassword("test"); - PolicyDBDaoEntity entity1 = new PolicyDBDaoEntity(); - entity1.setPolicyDBDaoUrl("http://localhost:8071/pap"); + PolicyDbDaoEntity entity1 = new PolicyDbDaoEntity(); + entity1.setPolicyDbDaoUrl("http://localhost:8071/pap"); entity1.setUsername("test"); entity1.setPassword("test"); data.add(entity); data.add(entity1); System.setProperty("xacml.rest.pap.url", "http://localhost:8070/pap"); - when(commonClassDao.getData(PolicyDBDaoEntity.class)).thenReturn(data); + when(commonClassDao.getData(PolicyDbDaoEntity.class)).thenReturn(data); } @Test diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java index 10fcd300d..f978d7464 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java @@ -499,14 +499,14 @@ public class XACMLPAPTest { // Verify Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); // - // Check PEPOptions + // Check PepOptions // httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); json = "{\"dictionaryFields\":{\"pepName\":\"testRestAPI\",\"description\":\"testing create\"," + "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," + "\"number\":\"test\"}]}}"; - dictionaryTestSetup(false, "PEPOptions", json); + dictionaryTestSetup(false, "PepOptions", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); // Verify @@ -886,7 +886,7 @@ public class XACMLPAPTest { @Test public void getDictionary() throws ServletException, IOException { String[] dictionarys = new String[] {"Attribute", "OnapName", "Action", "BRMSParamTemplate", "VSCLAction", - "VNFType", "PEPOptions", "Varbind", "Service", "Site", "Settings", "RainyDayTreatments", + "VNFType", "PepOptions", "Varbind", "Service", "Site", "Settings", "RainyDayTreatments", "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone", "PrefixList", "AddressGroup", "ServiceGroup", "ServiceList", "TermList", "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID", "MicroServiceModels", "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType", diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java index 13fb81d17..33b7f8be6 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java @@ -20,13 +20,24 @@ package org.onap.policy.pap.xacml.rest; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import com.att.research.xacml.api.pap.PAPException; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashSet; +import java.util.Set; import org.junit.Test; +import org.mockito.Mockito; +import org.onap.policy.xacml.api.pap.OnapPDP; +import org.onap.policy.xacml.api.pap.OnapPDPGroup; +import org.onap.policy.xacml.api.pap.PAPPolicyEngine; +import org.onap.policy.xacml.std.pap.StdPDP; +import org.onap.policy.xacml.std.pap.StdPDPGroup; public class HeartbeatTest { @Test @@ -38,4 +49,43 @@ public class HeartbeatTest { hb.terminate(); assertFalse(hb.isHeartBeatRunning()); } + + @Test + public void testGetPdps() throws PAPException, IOException { + Set<OnapPDPGroup> pdpGroups = new HashSet<OnapPDPGroup>(); + StdPDPGroup pdpGroup = new StdPDPGroup(); + OnapPDP pdp = new StdPDP(); + pdpGroup.addPDP(pdp); + pdpGroups.add(pdpGroup); + PAPPolicyEngine pap = Mockito.mock(PAPPolicyEngine.class); + Mockito.when(pap.getOnapPDPGroups()).thenReturn(pdpGroups); + Heartbeat hb = new Heartbeat(pap); + hb.getPdpsFromGroup(); + assertFalse(hb.isHeartBeatRunning()); + + assertThatCode(hb::notifyEachPdp).doesNotThrowAnyException(); + assertThatThrownBy(hb::run).isInstanceOf(Exception.class); + assertThatThrownBy(hb::notifyEachPdp).isInstanceOf(Exception.class); + } + + @Test + public void testOpen() throws MalformedURLException { + Heartbeat hb = new Heartbeat(null); + OnapPDP pdp = new StdPDP(); + + assertThatCode(() -> { + URL url = new URL("http://onap.org"); + hb.openPdpConnection(url, pdp); + }).doesNotThrowAnyException(); + + assertThatCode(() -> { + URL url = new URL("http://1.2.3.4"); + hb.openPdpConnection(url, pdp); + }).doesNotThrowAnyException(); + + assertThatCode(() -> { + URL url = new URL("http://fakesite.fakenews"); + hb.openPdpConnection(url, pdp); + }).doesNotThrowAnyException(); + } } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java index 333d878ca..5c1d3dd76 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/BRMSPolicyTest.java @@ -22,15 +22,22 @@ package org.onap.policy.pap.xacml.rest.components; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import com.att.research.xacml.api.pap.PAPException; import java.io.IOException; - +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; +import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.CommonClassDao; public class BRMSPolicyTest { @@ -68,4 +75,42 @@ public class BRMSPolicyTest { String userID = "testID"; assertEquals(1, template.addRule(rule, ruleName, description, userID).size()); } + + @Test + public void testCreateBrmsParamPolicyAdapter() throws PAPException { + Map<String, String> brmsParamBody = new HashMap<String, String>(); + brmsParamBody.put("key", "value"); + + PolicyRestAdapter adapter = new PolicyRestAdapter(); + adapter.setHighestVersion(1); + adapter.setPolicyType("Config"); + adapter.setBrmsParamBody(brmsParamBody); + adapter.setNewFileName("policyName.1.xml"); + Map<String, String> dynamicFieldConfigAttributes = new HashMap<String, String>(); + dynamicFieldConfigAttributes.put("key", "value"); + adapter.setDynamicFieldConfigAttributes(dynamicFieldConfigAttributes); + CreateBrmsParamPolicy policy = new CreateBrmsParamPolicy(adapter); + String ruleContents = "contents"; + + assertThatCode(() -> policy.saveConfigurations("name.xml", "rules")).doesNotThrowAnyException(); + try { + policy.prepareToSave(); + policy.savePolicies(); + } catch (Exception ex) { + // Ignore + } + + assertThatThrownBy(() -> policy.expandConfigBody(ruleContents, brmsParamBody)) + .isInstanceOf(NullPointerException.class); + assertTrue(policy.validateConfigForm()); + policy.getAdviceExpressions(1, "name.1.xml"); + assertNotNull(policy.getCorrectPolicyDataObject()); + } + + @Test + public void testRead() { + Charset encoding = Charset.defaultCharset(); + assertThatCode(() -> CreateBrmsParamPolicy.readFile("xacml.pap.properties", encoding)) + .doesNotThrowAnyException(); + } } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java index 50c166aed..7156ec788 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java @@ -28,7 +28,7 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.onap.policy.rest.jpa.PolicyDBDaoEntity; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; public class NotifyOtherPapsTest { private static final String systemKey = XACMLProperties.XACML_PROPERTIES_NAME; @@ -43,9 +43,9 @@ public class NotifyOtherPapsTest { @Test public void negTestNotify() { NotifyOtherPaps notify = new NotifyOtherPaps(); - List<PolicyDBDaoEntity> otherServers = new ArrayList<PolicyDBDaoEntity>(); - PolicyDBDaoEntity dbdaoEntity = new PolicyDBDaoEntity(); - dbdaoEntity.setPolicyDBDaoUrl("http://test"); + List<PolicyDbDaoEntity> otherServers = new ArrayList<PolicyDbDaoEntity>(); + PolicyDbDaoEntity dbdaoEntity = new PolicyDbDaoEntity(); + dbdaoEntity.setPolicyDbDaoUrl("http://test"); otherServers.add(dbdaoEntity); long entityId = 0; String entityType = "entityType"; diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java index 05f633099..99cc47c23 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java @@ -312,7 +312,7 @@ public class PolicyDBDaoTest { getGroup.setParameter("deleted", false); List<?> groups = getGroup.list(); GroupEntity groupEntity = (GroupEntity) groups.get(0); - Assert.assertEquals(groupName, groupEntity.getgroupName()); + Assert.assertEquals(groupName, groupEntity.getGroupName()); Assert.assertEquals("this is a test group", groupEntity.getDescription()); session.getTransaction().commit(); session.close(); @@ -375,7 +375,7 @@ public class PolicyDBDaoTest { Assert.fail(); } PdpEntity pdp = (PdpEntity) pdps.get(0); - Assert.assertEquals(groupName, pdp.getGroup().getgroupName()); + Assert.assertEquals(groupName, pdp.getGroup().getGroupName()); Assert.assertEquals(pdp.getPdpName(), "primary"); session3.getTransaction().commit(); session3.close(); @@ -451,7 +451,7 @@ public class PolicyDBDaoTest { getPdp3.setParameter("deleted", false); List<?> pdps3 = getPdp3.list(); for (Object obj : pdps3) { - Assert.assertEquals("testgroup1", ((PdpEntity) obj).getGroup().getgroupName()); + Assert.assertEquals("testgroup1", ((PdpEntity) obj).getGroup().getGroupName()); } session5.getTransaction().commit(); @@ -490,7 +490,7 @@ public class PolicyDBDaoTest { getPdp4.setParameter("deleted", false); List<?> pdps4 = getPdp4.list(); for (Object obj : pdps4) { - Assert.assertEquals("testgroup2", ((PdpEntity) obj).getGroup().getgroupName()); + Assert.assertEquals("testgroup2", ((PdpEntity) obj).getGroup().getGroupName()); } session7.getTransaction().commit(); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java index 3472b0df5..fab361118 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java @@ -42,7 +42,7 @@ import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ClosedLoopD2Services; import org.onap.policy.rest.jpa.ClosedLoopSite; -import org.onap.policy.rest.jpa.PEPOptions; +import org.onap.policy.rest.jpa.PepOptions; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.rest.jpa.VNFType; import org.onap.policy.rest.jpa.VSCLAction; @@ -140,7 +140,7 @@ public class ClosedLoopDictionaryControllerTest { @Test public void testGetPEPOptionsDictionaryByNameEntityData() { - when(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")).thenReturn(data); + when(commonClassDao.getDataByColumn(PepOptions.class, "pepName")).thenReturn(data); controller.getPEPOptionsDictionaryByNameEntityData(response); try { assertTrue(response.getContentAsString() != null @@ -153,7 +153,7 @@ public class ClosedLoopDictionaryControllerTest { @Test public void testGetPEPOptionsDictionaryEntityData() { - when(commonClassDao.getData(PEPOptions.class)).thenReturn(new ArrayList<>()); + when(commonClassDao.getData(PepOptions.class)).thenReturn(new ArrayList<>()); controller.getPEPOptionsDictionaryEntityData(response); try { assertTrue(response.getContentAsString() != null diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java index ef723a3fd..ee4dff803 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java @@ -96,7 +96,7 @@ public class DictionaryImportControllerTest extends Mockito { fileNames.add("SearchCriteria.csv"); fileNames.add("VNFType.csv"); fileNames.add("VSCLAction.csv"); - fileNames.add("PEPOptions.csv"); + fileNames.add("PepOptions.csv"); fileNames.add("Settings.csv"); fileNames.add("Zone.csv"); fileNames.add("ActionList.csv"); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java index b94e8d338..3359a7aed 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java @@ -47,8 +47,8 @@ import org.onap.policy.rest.adapter.Term; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionList; import org.onap.policy.rest.jpa.AddressGroup; -import org.onap.policy.rest.jpa.FWTag; -import org.onap.policy.rest.jpa.FWTagPicker; +import org.onap.policy.rest.jpa.FwTag; +import org.onap.policy.rest.jpa.FwTagPicker; import org.onap.policy.rest.jpa.FirewallDictionaryList; import org.onap.policy.rest.jpa.GroupServiceList; import org.onap.policy.rest.jpa.PortList; @@ -228,25 +228,25 @@ public class FirewallDictionaryControllerTest { @Test public void testGetTagPickerNameEntityDataByName() { - test_WithGetDataByColumn(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", + test_WithGetDataByColumn(FwTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", () -> controller.getTagPickerNameEntityDataByName(response)); } @Test public void testGetTagPickerDictionaryEntityData() { - test_WithGetData(FWTagPicker.class, "fwTagPickerDictionaryDatas", + test_WithGetData(FwTagPicker.class, "fwTagPickerDictionaryDatas", () -> controller.getTagPickerDictionaryEntityData(response)); } @Test public void testGetTagNameEntityDataByName() { - test_WithGetDataByColumn(FWTag.class, "fwTagDictionaryDatas", "fwTagName", + test_WithGetDataByColumn(FwTag.class, "fwTagDictionaryDatas", "fwTagName", () -> controller.getTagNameEntityDataByName(response)); } @Test public void testGetTagDictionaryEntityData() { - test_WithGetData(FWTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response)); + test_WithGetData(FwTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response)); } @Test @@ -563,7 +563,7 @@ public class FirewallDictionaryControllerTest { "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":" + "\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":" + "\"Test\"}]},\"userid\":\"demo\"}"; - testSave(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", + testSave(FwTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", () -> controller.saveFirewallTagPickerDictionary(request, response)); } @@ -573,14 +573,14 @@ public class FirewallDictionaryControllerTest { "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":" + "\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":" + "\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; - testUpdate(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", + testUpdate(FwTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", () -> controller.saveFirewallTagPickerDictionary(request, response)); } @Test public void testRemoveFirewallTagPickerDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"tagPickerName\":\"Test\"}}"; - testRemove(FWTagPicker.class, "fwTagPickerDictionaryDatas", + testRemove(FwTagPicker.class, "fwTagPickerDictionaryDatas", () -> controller.removeFirewallTagPickerDictionary(request, response)); } @@ -589,7 +589,7 @@ public class FirewallDictionaryControllerTest { jsonString = "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":" + "\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}"; - testSave(FWTag.class, "fwTagDictionaryDatas", "fwTagName", + testSave(FwTag.class, "fwTagDictionaryDatas", "fwTagName", () -> controller.saveFirewallTagDictionary(request, response)); } @@ -598,14 +598,14 @@ public class FirewallDictionaryControllerTest { jsonString = "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":" + "[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}"; - testUpdate(FWTag.class, "fwTagDictionaryDatas", "fwTagName", + testUpdate(FwTag.class, "fwTagDictionaryDatas", "fwTagName", () -> controller.saveFirewallTagDictionary(request, response)); } @Test public void testRemoveFirewallTagDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\"}}"; - testRemove(FWTag.class, "fwTagDictionaryDatas", + testRemove(FwTag.class, "fwTagDictionaryDatas", () -> controller.removeFirewallTagDictionary(request, response)); } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java index 451989c1f..d990b9002 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java @@ -22,16 +22,20 @@ package org.onap.policy.pap.xacml.rest.controller; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.mockrunner.mock.web.MockHttpServletRequest; import java.io.BufferedReader; import java.io.StringReader; import javax.servlet.http.HttpServletRequest; - +import javax.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -72,16 +76,16 @@ public class OptimizationDictionaryControllerTest { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); jsonString = "{\"optimizationModelsDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false,\"model\":" - + " {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],\"type\": \"dir\"," - + "\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", \"version\": \"\"," - + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\"," + "\"recursive\": false}," - + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"}," - + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\"," - + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\"," - + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\"," - + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\"," - + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}}," - + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}"; + + " {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": [],\"type\": \"dir\"," + + "\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", \"version\": \"\"," + + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\"," + "\"recursive\": false}," + + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"}," + + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\"," + + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\"," + + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\"," + + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\"," + + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}}," + + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}"; br = new BufferedReader(new StringReader(jsonString)); // --- mock the getReader() call @@ -108,7 +112,7 @@ public class OptimizationDictionaryControllerTest { controller.getOptimizationModelsDictionaryEntityData(response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null - && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); + && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -130,7 +134,7 @@ public class OptimizationDictionaryControllerTest { controller.saveOptimizationModelsDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null - && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); + && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -149,28 +153,59 @@ public class OptimizationDictionaryControllerTest { try { // mock the getReader() call jsonString = - "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\"," - + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0," - + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\"," - + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false}," - + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"}," - + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\"," - + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\"," - + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\"," - + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\"," - + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}}," - + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}"; + "{\"data\": {\"modelName\": \"test\",\"inprocess\": false,\"model\": {\"name\": \"testingdata\"," + + "\"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0," + + "\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\",\"createdBy\": \"someone\"," + + "\"modifiedBy\": \"someone\",\"content\": \"\",\"recursive\": false}," + + "\"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\"}," + + "\"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\"," + + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\"," + + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\"," + + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\"," + + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}}," + + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.removeOptimizationModelsDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null - && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); + && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testRemoveOptimizationModelsDictionary: exit"); } + + @Test + public void testGet() { + OptimizationDictionaryController controller = new OptimizationDictionaryController(commonClassDao); + MockHttpServletResponse response = new MockHttpServletResponse(); + controller.getOptimizationModelsDictionaryByNameEntityData(response); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + } + + @Test + public void testSave() { + OptimizationDictionaryController controller = new OptimizationDictionaryController(commonClassDao); + MockHttpServletRequest req = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + req.setBodyContent("{\n\"modelType\": \"type.yml\", \"dataOrderInfo\": \"info\", \"userid\": \"id\", " + + "\"optimizationModelsDictionaryData\": {\"description\": \"desc\", \"modelName\": \"name\", \"version\": \"1.0\"}, " + + "\"classMap\": \"{\\\"dep\\\":\\\"{\\\"dependency\\\":\\\"depval\\\"}\\\"}\" }\n"); + // + "\"classMap\": \"{\\\"dep\\\":\\\"dependency\\\"}\" }\n"); + assertThatThrownBy(() -> controller.saveOptimizationModelsDictionary(req, response)) + .isInstanceOf(NullPointerException.class); + + req.setBodyContent("{\n\"modelType\": \"type.xml\", \"dataOrderInfo\": \"info\", \"userid\": \"id\", " + + "\"optimizationModelsDictionaryData\": {\"description\": \"desc\", \"modelName\": \"name\", \"version\": \"1.0\"}, " + + "\"classMap\": \"{\\\"dep\\\": {\\\"dependency\\\":\\\"depval\\\"} }\" }\n"); + assertThatCode(() -> controller.saveOptimizationModelsDictionary(req, response)).doesNotThrowAnyException(); + + req.setupAddParameter("apiflag", "api"); + assertThatThrownBy(() -> controller.saveOptimizationModelsDictionary(req, response)) + .isInstanceOf(NullPointerException.class); + } + } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java index a9da00d5a..d0e4416f9 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java @@ -25,11 +25,13 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpServletResponse; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.hibernate.Session; @@ -45,6 +47,7 @@ import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyEntity; +import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.xacml.api.pap.PAPPolicyEngine; import org.onap.policy.xacml.std.pap.StdEngine; import org.powermock.api.mockito.PowerMockito; @@ -120,12 +123,74 @@ public class DeleteHandlerTest { CommonClassDao dao = Mockito.mock(CommonClassDao.class); DeleteHandler handler = new DeleteHandler(dao); - // Mock request + // Request #1 MockHttpServletRequest request = new MockHttpServletRequest(); request.setBodyContent( "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n"); MockHttpServletResponse response = new MockHttpServletResponse(); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Request #2 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Action_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Request #3 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Request #4 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Bar_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Request #5 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Request #6 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Action_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Request #7 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + + // Mock dao + List<PolicyVersion> pePVs = new ArrayList<PolicyVersion>(); + PolicyVersion pv = new PolicyVersion(); + pePVs.add(pv); + List<Object> peObjs = new ArrayList<Object>(pePVs); + List<PolicyEntity> peEnts = new ArrayList<PolicyEntity>(); + PolicyEntity peEnt = new PolicyEntity(); + peEnts.add(peEnt); + List<Object> peEntObjs = new ArrayList<Object>(peEnts); + Mockito.when(dao.getDataByQuery(eq("Select p from PolicyVersion p where p.policyName=:pname"), any())) + .thenReturn(peObjs); + Mockito.when( + dao.getDataByQuery(eq("SELECT p FROM PolicyEntity p WHERE p.policyName=:pName and p.scope=:pScope"), any())) + .thenReturn(peEntObjs); + + // Request #8 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"Current Version\"\n}\n"); + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + // Request #9 + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Decision_name.1.xml\", \"deleteCondition\": \"Current Version\"\n, \"deleteCondition\": \"All Versions\"}\n"); handler.doApiDeleteFromPap(request, response); assertTrue(response.containsHeader("error")); } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java index 9da3f8b5c..d7fbda259 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java @@ -38,7 +38,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.XacmlRestProperties; import org.onap.policy.rest.jpa.ActionBodyEntity; import org.onap.policy.rest.jpa.ConfigurationDataEntity; -import org.onap.policy.rest.jpa.PolicyDBDaoEntity; +import org.onap.policy.rest.jpa.PolicyDbDaoEntity; import org.onap.policy.rest.jpa.PolicyEntity; public class PolicyEntityTest { @@ -59,7 +59,7 @@ public class PolicyEntityTest { et.begin(); // Make sure the DB is clean - em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyDbDaoEntity").executeUpdate(); em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); @@ -605,7 +605,7 @@ public class PolicyEntityTest { + "\n with exception: " + e); } - // ****************Test the PolicyDBDaoEntity************************ + // ****************Test the PolicyDbDaoEntity************************ // Create a transaction EntityTransaction et3 = em.getTransaction(); @@ -613,29 +613,29 @@ public class PolicyEntityTest { et3.begin(); // create one - PolicyDBDaoEntity pe1 = new PolicyDBDaoEntity(); + PolicyDbDaoEntity pe1 = new PolicyDbDaoEntity(); em.persist(pe1); pe1.setDescription("This is pe1"); - pe1.setPolicyDBDaoUrl("http://123.45.2.456:2345"); + pe1.setPolicyDbDaoUrl("http://123.45.2.456:2345"); // push it to the DB em.flush(); // create another - PolicyDBDaoEntity pe2 = new PolicyDBDaoEntity(); + PolicyDbDaoEntity pe2 = new PolicyDbDaoEntity(); em.persist(pe2); pe2.setDescription("This is pe2"); - pe2.setPolicyDBDaoUrl("http://789.01.2.345:2345"); + pe2.setPolicyDbDaoUrl("http://789.01.2.345:2345"); // Print them to the log before flushing - logger.debug("\n\n***********PolicyEntityTest: PolicyDBDaoEntity objects before flush********" - + "\n policyDBDaoUrl-1 = " + pe1.getPolicyDBDaoUrl() + "\n description-1 = " + pe1.getDescription() + logger.debug("\n\n***********PolicyEntityTest: PolicyDbDaoEntity objects before flush********" + + "\n policyDbDaoUrl-1 = " + pe1.getPolicyDbDaoUrl() + "\n description-1 = " + pe1.getDescription() + "\n createdDate-1 = " + pe1.getCreatedDate() + "\n modifiedDate-1 " + pe1.getModifiedDate() - + "\n*****************************************" + "\n policyDBDaoUrl-2 = " + pe2.getPolicyDBDaoUrl() + + "\n*****************************************" + "\n policyDbDaoUrl-2 = " + pe2.getPolicyDbDaoUrl() + "\n description-2 = " + pe2.getDescription() + "\n createdDate-2 = " + pe2.getCreatedDate() + "\n modifiedDate-2 " + pe2.getModifiedDate()); @@ -644,36 +644,36 @@ public class PolicyEntityTest { // Now let's retrieve them from the DB using the named query - resultList = em.createNamedQuery("PolicyDBDaoEntity.findAll").getResultList(); + resultList = em.createNamedQuery("PolicyDbDaoEntity.findAll").getResultList(); - PolicyDBDaoEntity pex = null; - PolicyDBDaoEntity pey = null; + PolicyDbDaoEntity pex = null; + PolicyDbDaoEntity pey = null; if (!resultList.isEmpty()) { if (resultList.size() != 2) { - fail("\nPolicyEntityTest: Number of PolicyDBDaoEntity entries = " + resultList.size() + fail("\nPolicyEntityTest: Number of PolicyDbDaoEntity entries = " + resultList.size() + " instead of 2"); } for (Object policyDBDaoEntity : resultList) { - PolicyDBDaoEntity pdbdao = (PolicyDBDaoEntity) policyDBDaoEntity; - if (pdbdao.getPolicyDBDaoUrl().equals("http://123.45.2.456:2345")) { + PolicyDbDaoEntity pdbdao = (PolicyDbDaoEntity) policyDBDaoEntity; + if (pdbdao.getPolicyDbDaoUrl().equals("http://123.45.2.456:2345")) { pex = pdbdao; - } else if (pdbdao.getPolicyDBDaoUrl().equals("http://789.01.2.345:2345")) { + } else if (pdbdao.getPolicyDbDaoUrl().equals("http://789.01.2.345:2345")) { pey = pdbdao; } } // Print them to the log before flushing - logger.debug("\n\n***********PolicyEntityTest: PolicyDBDaoEntity objects retrieved from DB********" - + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl() + "\n description-x = " + logger.debug("\n\n***********PolicyEntityTest: PolicyDbDaoEntity objects retrieved from DB********" + + "\n policyDbDaoUrl-x = " + pex.getPolicyDbDaoUrl() + "\n description-x = " + pex.getDescription() + "\n createdDate-x = " + pex.getCreatedDate() + "\n modifiedDate-x " + pex.getModifiedDate() + "\n*****************************************" - + "\n policyDBDaoUrl-y = " - + pey.getPolicyDBDaoUrl() + "\n description-y = " + pey.getDescription() + + "\n policyDbDaoUrl-y = " + + pey.getPolicyDbDaoUrl() + "\n description-y = " + pey.getDescription() + "\n createdDate-y = " + pey.getCreatedDate() + "\n modifiedDate-y " + pey.getModifiedDate()); // Verify the retrieved objects are the same as the ones we stored in the DB - if (pex.getPolicyDBDaoUrl().equals("http://123.45.2.456:2345")) { + if (pex.getPolicyDbDaoUrl().equals("http://123.45.2.456:2345")) { assertSame(pe1, pex); assertSame(pe2, pey); } else { @@ -682,46 +682,46 @@ public class PolicyEntityTest { } } else { - fail("\nPolicyEntityTest: No PolicyDBDaoEntity DB entry found"); + fail("\nPolicyEntityTest: No PolicyDbDaoEntity DB entry found"); } - // Now let's see if we can do an update on the PolicyDBDaoEntity which we retrieved. + // Now let's see if we can do an update on the PolicyDbDaoEntity which we retrieved. // em.persist(pex); pex.setDescription("This is pex"); em.flush(); // retrieve it - Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyDBDaoEntity p WHERE p.description=:desc"); + Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyDbDaoEntity p WHERE p.description=:desc"); resultList = createPolicyQuery.setParameter("desc", "This is pex").getResultList(); - PolicyDBDaoEntity pez = null; + PolicyDbDaoEntity pez = null; if (!resultList.isEmpty()) { if (resultList.size() != 1) { - fail("\nPolicyEntityTest: Update Test - Number of PolicyDBDaoEntity entries = " + resultList.size() + fail("\nPolicyEntityTest: Update Test - Number of PolicyDbDaoEntity entries = " + resultList.size() + " instead of 1"); } - pez = (PolicyDBDaoEntity) resultList.get(0); + pez = (PolicyDbDaoEntity) resultList.get(0); // Print them to the log before flushing logger.debug( - "\n\n***********PolicyEntityTest: Update Test - PolicyDBDaoEntity objects retrieved from " + "\n\n***********PolicyEntityTest: Update Test - PolicyDbDaoEntity objects retrieved from " + "DB********" - + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl() + "\n description-x = " + + "\n policyDbDaoUrl-x = " + pex.getPolicyDbDaoUrl() + "\n description-x = " + pex.getDescription() + "\n createdDate-x = " + pex.getCreatedDate() + "\n modifiedDate-x " + pex.getModifiedDate() - + "\n*****************************************" + "\n policyDBDaoUrl-z = " - + pez.getPolicyDBDaoUrl() + "\n description-z = " + pez.getDescription() + + "\n*****************************************" + "\n policyDbDaoUrl-z = " + + pez.getPolicyDbDaoUrl() + "\n description-z = " + pez.getDescription() + "\n createdDate-z = " + pez.getCreatedDate() + "\n modifiedDate-z " + pez.getModifiedDate()); // Verify the retrieved objects are the same as the ones we stored in the DB assertSame(pex, pez); } else { - fail("\nPolicyEntityTest: Update Test - No PolicyDBDaoEntity DB updated entry found"); + fail("\nPolicyEntityTest: Update Test - No PolicyDbDaoEntity DB updated entry found"); } // Clean up the DB - em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyDbDaoEntity").executeUpdate(); em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java index 3b826f694..b7d6bacbd 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java @@ -37,7 +37,7 @@ public class ImportServiceTest { HttpServletRequest request = new MockHttpServletRequest(); HttpServletResponse response = new MockHttpServletResponse(); service.doImportMicroServicePut(request, response); - assertEquals(response.getHeader("error"), "missing"); + assertEquals("missing", response.getHeader("error")); } @Test diff --git a/ONAP-PAP-REST/src/test/resources/dictionaryImport/PEPOptions.csv b/ONAP-PAP-REST/src/test/resources/dictionaryImport/PepOptions.csv index 61adca140..61adca140 100644 --- a/ONAP-PAP-REST/src/test/resources/dictionaryImport/PEPOptions.csv +++ b/ONAP-PAP-REST/src/test/resources/dictionaryImport/PepOptions.csv |