diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-02-01 12:22:30 -0500 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2018-02-01 12:37:59 -0500 |
commit | 06f456d8d06840a21f48531b0bd35b1a429b10f9 (patch) | |
tree | a72db2dbec1a520589e98809d03424cf81c6aab1 /PolicyEngineAPI | |
parent | 066fc4529f36d210a4a4700e8dbfd2cb42f4dc66 (diff) |
Reduce technical debt and add JUnit
* Addressed some very simple cyclic complexity
* Added simple JUnit tests and finished others
* Removed useless assignments
Issue-ID: POLICY-477
Change-Id: Ic919bbf78ad2732a430c32f1feb3c88678be710d
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'PolicyEngineAPI')
39 files changed, 921 insertions, 439 deletions
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java index 5cf9d641d..2163bf555 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java @@ -38,6 +38,7 @@ public class DecisionRequestParameters { * Constructor with no Parameters */ public DecisionRequestParameters(){ + // Empty constructor } /** diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java index 6e4bbbd51..c3aa50378 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java @@ -37,6 +37,7 @@ public class EventRequestParameters { * Constructor with no Parameters */ public EventRequestParameters(){ + // Empty constructor } /** diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java index b42d8b280..5d370da08 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java @@ -29,6 +29,7 @@ public class PolicyConfigException extends Exception{ private static final long serialVersionUID = -188355220060684215L; public PolicyConfigException() { + // Empty constructor } public PolicyConfigException(String message) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java index 38081de7e..c705566ad 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java @@ -30,6 +30,7 @@ public class PolicyDecisionException extends Exception { private static final long serialVersionUID = -2080072039363261175L; public PolicyDecisionException() { + // Empty constructor } public PolicyDecisionException(String message) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java index 335c4905b..e9d9852d1 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java @@ -29,6 +29,7 @@ public class PolicyEventException extends Exception { private static final long serialVersionUID = -1477625011320634608L; public PolicyEventException() { + // Empty constructor } public PolicyEventException(String message) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java index 5d8555d38..cee1342ff 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java @@ -29,6 +29,7 @@ public class PolicyException extends Exception { private static final long serialVersionUID = -5006203722296799708L; public PolicyException() { + // Empty constructor } public PolicyException(String message) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java index ae9ba8a88..cb51e481d 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java @@ -53,7 +53,7 @@ public class PolicyParameters { private String priority; private RuleProvider ruleProvider; private String controllerName; - private ArrayList<String> dependencyNames; + private List<String> dependencyNames; private Date ttlDate; private boolean guard = false; private String riskLevel = "5"; @@ -548,7 +548,7 @@ public class PolicyParameters { * * @return ArrayList of String(s) format of dependency names. */ - public ArrayList<String> getDependencyNames() { + public List<String> getDependencyNames() { return dependencyNames; } @@ -557,7 +557,7 @@ public class PolicyParameters { * * @param dependencyNames ArrayList of String(s). */ - public void setDependencyNames(ArrayList<String> dependencyNames) { + public void setDependencyNames(List<String> dependencyNames) { this.dependencyNames = dependencyNames; } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java index 211be7e65..a55cd6ed3 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java @@ -38,6 +38,7 @@ public class PushPolicyParameters { * Constructor with no Parameters. */ public PushPolicyParameters(){ + // Empty constructor } /** diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java index be363c24f..e65413f50 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java @@ -36,48 +36,57 @@ public class APIPolicyConfigResponse implements APIConfigResponse { private Map<String, String> matchingConditions; private Map<String, String> responseAttributes; private Map<String, String> property; + + @Override public String getConfig() { return config; } public void setConfig(String config) { this.config = config; } + @Override public PolicyType getType() { return type; } public void setType(PolicyType type) { this.type = type; } + @Override public PolicyConfigStatus getPolicyConfigStatus() { return policyConfigStatus; } public void setPolicyConfigStatus(PolicyConfigStatus policyConfigStatus) { this.policyConfigStatus = policyConfigStatus; } + @Override public String getPolicyConfigMessage() { return policyConfigMessage; } public void setPolicyConfigMessage(String policyConfigMessage) { this.policyConfigMessage = policyConfigMessage; } + @Override public Map<String, String> getProperty() { return property; } public void setProperty(Map<String, String> property) { this.property = property; } + @Override public String getPolicyName(){ return policyName; } public void setPolicyName(String policyName){ this.policyName = policyName; } + @Override public String getPolicyVersion(){ return policyVersion; } public void setPolicyVersion(String policyVersion){ this.policyVersion = policyVersion; } + @Override public Map<String, String> getMatchingConditions(){ return matchingConditions; } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java index 97f60b0dc..2fa408810 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java @@ -90,36 +90,36 @@ public class AutoClientDMAAP implements Runnable { } String group = UUID.randomUUID().toString(); String id = "0"; + + if (scheme == null || handler == null || + ! (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || + scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) ) { + logger.info("no stop/start required"); + return; + } - // Stop and Start needs to be done. - if (scheme != null && handler != null) { - if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) - || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { - - // create a loop to listen for messages from DMaaP server - try { - setDmaapCosumer(new BusConsumer.DmaapConsumerWrapper(dmaapList, topic, aafLogin, aafPassword, group, - id, 15 * 1000, 1000)); - } catch (Exception e) { - logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Consumer: ", e); - } - - while (this.isRunning()) { - try { - for (String msg : dmaapConsumer.fetch()) { - logger.debug("Auto Notification Recieved Message " + msg + " from DMAAP server : " - + dmaapList.toString()); - setNotification(NotificationUnMarshal.notificationJSON(msg)); - callHandler(); - } - } catch (Exception e) { - logger.debug("Error in processing DMAAP message", e); - } + // create a loop to listen for messages from DMaaP server + try { + setDmaapCosumer(new BusConsumer.DmaapConsumerWrapper(dmaapList, topic, aafLogin, aafPassword, group, + id, 15 * 1000, 1000)); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Consumer: ", e); + } + while (this.isRunning()) { + try { + for (String msg : dmaapConsumer.fetch()) { + logger.debug("Auto Notification Recieved Message " + msg + " from DMAAP server : " + + dmaapList.toString()); + setNotification(NotificationUnMarshal.notificationJSON(msg)); + callHandler(); } - logger.debug("Stopping DMAAP Consumer loop will no longer fetch messages from the servers"); + } catch (Exception e) { + logger.debug("Error in processing DMAAP message", e); } + } + logger.debug("Stopping DMAAP Consumer loop will no longer fetch messages from the servers"); } private static void setNotification(StdPDPNotification notificationJSON) { @@ -131,30 +131,34 @@ public class AutoClientDMAAP implements Runnable { } private static void callHandler() { - if (handler != null && scheme != null) { - if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) { - boolean removed = false, updated = false; - if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { - removed = true; - } - if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { - updated = true; - } - if (removed && updated) { - notification.setNotificationType(NotificationType.BOTH); - } else if (removed) { - notification.setNotificationType(NotificationType.REMOVE); - } else if (updated) { - notification.setNotificationType(NotificationType.UPDATE); - } - handler.notificationReceived(notification); - } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { - PDPNotification newNotification = MatchStore.checkMatch(notification); - if (newNotification.getNotificationType() != null) { - handler.notificationReceived(newNotification); - } - } - } + + if (handler == null || scheme == null) { + logger.info("handler does not need to do anything"); + return; + } + if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) { + boolean removed = false; + boolean updated = false; + if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { + removed = true; + } + if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { + updated = true; + } + if (removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + } else if (removed) { + notification.setNotificationType(NotificationType.REMOVE); + } else if (updated) { + notification.setNotificationType(NotificationType.UPDATE); + } + handler.notificationReceived(notification); + } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + PDPNotification newNotification = MatchStore.checkMatch(notification); + if (newNotification.getNotificationType() != null) { + handler.notificationReceived(newNotification); + } + } } } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java index f0d99d09e..ec021a43e 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java @@ -56,6 +56,10 @@ public class AutoClientEnd { private static boolean error = false; private static Logger logger = FlexLogger.getLogger(AutoClientEnd.class.getName()); + private AutoClientEnd() { + // Empty constructor + } + public static void setAuto(NotificationScheme scheme, NotificationHandler handler) { AutoClientEnd.scheme = scheme; @@ -76,40 +80,42 @@ public class AutoClientEnd { public static void start(String url) { AutoClientEnd.url = url; + + if (scheme == null || handler == null || + ! (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) && + scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS) ) || + AutoClientEnd.client == null) { + return; + } + // Stop and Start needs to be done. - if (scheme != null && handler!=null) { - if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { - if (AutoClientEnd.client == null) { - client = ClientManager.createClient(); - if(url.contains("https")){ - url = url.replaceAll("https", "wss"); - }else { - url = url.replaceAll("http", "ws"); - } - try { - logger.info("Starting Auto Notification with the PDP server : " + url); - client.connectToServer(AutoClientEnd.class, new URI(url + "notifications")); - status = true; - if(error){ - // The URL's will be in Sync according to design Spec. - ManualClientEnd.start(AutoClientEnd.url); - StdPDPNotification notification = NotificationStore.getDeltaNotification((StdPDPNotification)ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)); - if(notification.getNotificationType()!=null&&oldNotification!=notification){ - oldNotification= notification; - AutoClientEnd.notification = notification; - callHandler(); - } - error = false; - } - // - } catch (DeploymentException | IOException | URISyntaxException e) { - logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); - client = null; - status = false; - changeURL(); - } + client = ClientManager.createClient(); + if(url.contains("https")){ + url = url.replaceAll("https", "wss"); + }else { + url = url.replaceAll("http", "ws"); + } + try { + logger.info("Starting Auto Notification with the PDP server : " + url); + client.connectToServer(AutoClientEnd.class, new URI(url + "notifications")); + status = true; + if(error){ + // The URL's will be in Sync according to design Spec. + ManualClientEnd.start(AutoClientEnd.url); + StdPDPNotification notification = NotificationStore.getDeltaNotification((StdPDPNotification)ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)); + if(notification.getNotificationType()!=null&&oldNotification!=notification){ + oldNotification= notification; + AutoClientEnd.notification = notification; + callHandler(); } + error = false; } + // + } catch (DeploymentException | IOException | URISyntaxException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + client = null; + status = false; + changeURL(); } } @@ -120,56 +126,58 @@ public class AutoClientEnd { } public static void stop() { - if (client != null) { - client.shutdown(); - if(session!=null){ - try { - stop = true; - logger.info("\n Closing Auto Notification WebSocket Connection.. "); - session.close(); - session = null; - } catch (IOException e) { - logger.error("Error closing websocket connection", e); - } + if (client == null) { + return; + } + client.shutdown(); + if(session!=null){ + try { + stop = true; + logger.info("\n Closing Auto Notification WebSocket Connection.. "); + session.close(); + session = null; + } catch (IOException e) { + logger.error("Error closing websocket connection", e); } - client = null; - status = false; - stop = false; } + client = null; + status = false; + stop = false; } private static void callHandler() { - if (handler != null && scheme != null) { - if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) { - boolean removed = false; - boolean updated = false; - if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { - removed = true; - } - if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { - updated = true; - } - if (removed && updated) { - notification.setNotificationType(NotificationType.BOTH); - } else if (removed) { - notification.setNotificationType(NotificationType.REMOVE); - } else if (updated) { - notification.setNotificationType(NotificationType.UPDATE); - } + if (handler == null || scheme == null) { + return; + } + if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) { + boolean removed = false; + boolean updated = false; + if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { + removed = true; + } + if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { + updated = true; + } + if (removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + } else if (removed) { + notification.setNotificationType(NotificationType.REMOVE); + } else if (updated) { + notification.setNotificationType(NotificationType.UPDATE); + } + try{ + handler.notificationReceived(notification); + }catch (Exception e){ + logger.error("Error in Clients Handler Object : ", e); + } + } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + PDPNotification newNotification = MatchStore.checkMatch(notification); + if (newNotification.getNotificationType() != null) { try{ - handler.notificationReceived(notification); + handler.notificationReceived(newNotification); }catch (Exception e){ logger.error("Error in Clients Handler Object : ", e); } - } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { - PDPNotification newNotification = MatchStore.checkMatch(notification); - if (newNotification.getNotificationType() != null) { - try{ - handler.notificationReceived(newNotification); - }catch (Exception e){ - logger.error("Error in Clients Handler Object : ", e); - } - } } } } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java index f84568aba..6bfcd2c7a 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java @@ -103,44 +103,44 @@ public class AutoClientUEB implements Runnable { String group = UUID.randomUUID ().toString (); String id = "0"; // Stop and Start needs to be done. - if (scheme != null && handler!=null) { - if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { - URL aURL; - try { - aURL = new URL(AutoClientUEB.topic); - setTopic(aURL.getHost() + aURL.getPort()); - } catch (MalformedURLException e) { - setTopic(AutoClientUEB.url.replace("[:/]", "")); - } - try { - ConsumerBuilder builder = new CambriaClientBuilders.ConsumerBuilder(); - builder.knownAs(group, id) - .usingHosts(uebURLList) - .onTopic(topic) - .waitAtServer(15*1000) - .receivingAtMost(1000) - .authenticatedBy(apiKey, apiSecret); - setConsumer(builder.build()); - } catch (Exception e1) { - logger.error("Exception Occured" + e1); - } - while (this.isRunning()) { - try { - for (String msg : cConsumer.fetch()) { - logger.debug("Auto Notification Recieved Message " + msg + " from UEB cluster : " - + uebURLList.toString()); - setNotification(NotificationUnMarshal.notificationJSON(msg)); - callHandler(); - } - } catch (Exception e) { - logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Error in processing UEB message" - + e.getMessage(), e); - } - - } - logger.debug("Stopping UEB Consumer loop will not logger fetch messages from the cluster"); - } + if (scheme == null || handler == null || + ! (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) ) { + return; } + URL aURL; + try { + aURL = new URL(AutoClientUEB.topic); + setTopic(aURL.getHost() + aURL.getPort()); + } catch (MalformedURLException e) { + setTopic(AutoClientUEB.url.replace("[:/]", "")); + } + try { + ConsumerBuilder builder = new CambriaClientBuilders.ConsumerBuilder(); + builder.knownAs(group, id) + .usingHosts(uebURLList) + .onTopic(topic) + .waitAtServer(15*1000) + .receivingAtMost(1000) + .authenticatedBy(apiKey, apiSecret); + setConsumer(builder.build()); + } catch (Exception e1) { + logger.error("Exception Occured" + e1); + } + while (this.isRunning()) { + try { + for (String msg : cConsumer.fetch()) { + logger.debug("Auto Notification Recieved Message " + msg + " from UEB cluster : " + + uebURLList.toString()); + setNotification(NotificationUnMarshal.notificationJSON(msg)); + callHandler(); + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Error in processing UEB message" + + e.getMessage(), e); + } + + } + logger.debug("Stopping UEB Consumer loop will not logger fetch messages from the cluster"); } private static void setNotification(StdPDPNotification notificationJSON) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java index 025bd2128..0281f6010 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java @@ -40,34 +40,37 @@ public class ManualClientEndDMAAP { private static String uniquID = null; private static String topic = null; + private ManualClientEndDMAAP() { + // Empty constructor + } + public static PDPNotification result(NotificationScheme scheme) { if (resultJson == null || notification == null) { logger.debug("No Result" ); return null; - } else { - if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { - boolean removed = false, updated = false; - if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ - removed = true; - } - if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ - updated = true; - } - if(removed && updated) { - notification.setNotificationType(NotificationType.BOTH); - }else if(removed){ - notification.setNotificationType(NotificationType.REMOVE); - }else if(updated){ - notification.setNotificationType(NotificationType.UPDATE); - } - return notification; - }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { - return MatchStore.checkMatch(notification); - }else { - return null; + } + if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { + boolean removed = false; + boolean updated = false; + if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ + removed = true; + } + if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ + updated = true; + } + if(removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + }else if(removed){ + notification.setNotificationType(NotificationType.REMOVE); + }else if(updated){ + notification.setNotificationType(NotificationType.UPDATE); } + return notification; + }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { + return MatchStore.checkMatch(notification); } + return null; } private static void publishMessage(String pubTopic, String uniqueID, List<String> dmaapList, String aafLogin, String aafPassword) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java index 29c85a2ad..8590f6a5b 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java @@ -51,35 +51,36 @@ public class ManualClientEndUEB { private static String url = null; private static String uniquID = null; private static String topic = null; - + + private ManualClientEndUEB() { + // Empty constructor + } public static PDPNotification result(NotificationScheme scheme) { if (resultJson == null || notification == null) { logger.debug("No Result" ); return null; - } else { - if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { - boolean removed = false, updated = false; - if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ - removed = true; - } - if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ - updated = true; - } - if(removed && updated) { - notification.setNotificationType(NotificationType.BOTH); - }else if(removed){ - notification.setNotificationType(NotificationType.REMOVE); - }else if(updated){ - notification.setNotificationType(NotificationType.UPDATE); - } - return notification; - }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { - return MatchStore.checkMatch(notification); - }else { - return null; + } + if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { + boolean removed = false, updated = false; + if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ + removed = true; + } + if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ + updated = true; + } + if(removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + }else if(removed){ + notification.setNotificationType(NotificationType.REMOVE); + }else if(updated){ + notification.setNotificationType(NotificationType.UPDATE); } + return notification; + }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { + return MatchStore.checkMatch(notification); } + return null; } private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) { diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java index a243c1fc1..ecdafe43c 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java @@ -37,6 +37,10 @@ public class MatchStore { private static HashSet<Matches> matchStore = new HashSet<>(); private static Logger logger = FlexLogger.getLogger(MatchStore.class.getName()); + private MatchStore() { + // Empty Constructor + } + public static HashSet<Matches> getMatchStore() { return matchStore; } @@ -103,14 +107,14 @@ public class MatchStore { //Logic changes for Requested Policies notifications.. public static PDPNotification checkMatch(PDPNotification oldNotification) { - boolean removed = false, updated = false; + boolean removed = false; + boolean updated = false; if(oldNotification==null){ return null; } StdPDPNotification newNotification = new StdPDPNotification(); if(matchStore.isEmpty()) { logger.debug("No Success Config Calls made yet.. "); - System.out.println("No success Config calls made yet. "); return null; } if(oldNotification.getRemovedPolicies()!=null && !oldNotification.getRemovedPolicies().isEmpty()){ @@ -132,7 +136,7 @@ public class MatchStore { for(LoadedPolicy updatedPolicy: oldNotification.getLoadedPolicies()){ // if it is config policies check their matches.. if(updatedPolicy.getMatches()!=null && !updatedPolicy.getMatches().isEmpty()){ - boolean matched = false; + boolean matched; for(Matches match : matchStore){ matched = false; // Again Better way would be comparing sizes first. @@ -144,14 +148,14 @@ public class MatchStore { // Comparing both the values.. boolean matchAttributes = false; for(String newKey: updatedPolicy.getMatches().keySet()){ - if(newKey.equals("ONAPName")){ + if("ONAPName".equals(newKey)){ if(updatedPolicy.getMatches().get(newKey).equals(match.getOnapName())){ matchAttributes = true; }else { matchAttributes = false; break; } - }else if(newKey.equals("ConfigName")) { + }else if("ConfigName".equals(newKey)) { if(updatedPolicy.getMatches().get(newKey).equals(match.getConfigName())){ matchAttributes = true; }else{ diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java index 447e7cb26..6772f5a9b 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java @@ -32,34 +32,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class NotificationUnMarshal { + private NotificationUnMarshal() { + // Empty constructor + } + public static StdPDPNotification notificationJSON(String json) throws IOException{ ObjectMapper mapper = new ObjectMapper(); StdPDPNotification notification = mapper.readValue(json, StdPDPNotification.class); - if(notification!=null&¬ification.getLoadedPolicies()!=null){ - Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>(); - for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){ - StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy; - if(notification.getRemovedPolicies()!=null){ - Boolean updated = false; - for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ - String regex = ".(\\d)*.xml"; - if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){ - updated = true; - break; - } - } - if(updated){ - stdLoadedPolicy.setUpdateType(UpdateType.UPDATE); - }else{ - stdLoadedPolicy.setUpdateType(UpdateType.NEW); - } - }else{ - stdLoadedPolicy.setUpdateType(UpdateType.NEW); - } - stdLoadedPolicies.add(stdLoadedPolicy); - } - notification.setLoadedPolicies(stdLoadedPolicies); + if(notification == null || notification.getLoadedPolicies() == null){ + return notification; } + Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>(); + for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){ + StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy; + if(notification.getRemovedPolicies()!=null){ + Boolean updated = false; + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + String regex = ".(\\d)*.xml"; + if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){ + updated = true; + break; + } + } + if(updated){ + stdLoadedPolicy.setUpdateType(UpdateType.UPDATE); + }else{ + stdLoadedPolicy.setUpdateType(UpdateType.NEW); + } + }else{ + stdLoadedPolicy.setUpdateType(UpdateType.NEW); + } + stdLoadedPolicies.add(stdLoadedPolicy); + } + notification.setLoadedPolicies(stdLoadedPolicies); return notification; } } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java index 62db64491..b5c1a4c8f 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java @@ -91,7 +91,7 @@ public class StdPolicyConfig implements PolicyConfig{ @Override public String getPolicyName() { if(policyName!=null && policyName.contains(".xml")){ - return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.'))); + return policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.')); } return policyName; } diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java index 6c74dde89..d08ea29f9 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java @@ -537,7 +537,7 @@ public class StdPolicyEngine { public DecisionResponse getDecisionImpl(String onapName, Map<String, String> decisionAttributes, UUID requestID) throws PolicyDecisionException { String resource = "getDecision"; - StdDecisionResponse response = new StdDecisionResponse(); + StdDecisionResponse response; String body = null; // Create Request. try { @@ -579,7 +579,7 @@ public class StdPolicyEngine { public Collection<PolicyConfig> getConfigImpl(ConfigRequestParameters configRequestParameters) throws PolicyConfigException { String resource = "getConfig"; - ArrayList<PolicyConfig> response = null; + ArrayList<PolicyConfig> response; String body = null; // Create Request. try { @@ -671,9 +671,9 @@ public class StdPolicyEngine { HashMap<String, String> configAttributes = new HashMap<>(); try { for (Map.Entry<String,String> entry : matchingConditions.entrySet()) { - if (entry.getKey().equalsIgnoreCase("ONAPName")) { + if ("ONAPName".equalsIgnoreCase(entry.getKey())) { match.setOnapName(entry.getValue()); - } else if (entry.getKey().equalsIgnoreCase("ConfigName")) { + } else if ("ConfigName".equalsIgnoreCase(entry.getKey())) { match.setConfigName(entry.getValue()); } else { configAttributes.put(entry.getKey(), entry.getValue()); @@ -716,31 +716,31 @@ public class StdPolicyEngine { break; } } - if (exception != null && exception.getStatusCode() != null) { - if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) { - String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":" - + ERROR_AUTH_GET_PERM + resource; - LOGGER.error(message); - throw new PolicyException(message, exception); - } - if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) { - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":" - + exception.getResponseBodyAsString(); - LOGGER.error(message); - throw new PolicyException(message, exception); - } - if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) { - String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps - + exception; - LOGGER.error(message); - throw new PolicyException(message, exception); - } - String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":" + if (exception == null || exception.getStatusCode() == null) { + return result; + } + if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) { + String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":" + + ERROR_AUTH_GET_PERM + resource; + LOGGER.error(message); + throw new PolicyException(message, exception); + } + if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":" + exception.getResponseBodyAsString(); LOGGER.error(message); throw new PolicyException(message, exception); } - return result; + if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) { + String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps + + exception; + LOGGER.error(message); + throw new PolicyException(message, exception); + } + String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":" + + exception.getResponseBodyAsString(); + LOGGER.error(message); + throw new PolicyException(message, exception); } private HttpHeaders getHeaders() { @@ -782,7 +782,7 @@ public class StdPolicyEngine { public Collection<PolicyResponse> sendEventImpl(Map<String, String> eventAttributes, UUID requestID) throws PolicyEventException { String resource = "sendEvent"; - ArrayList<PolicyResponse> response = null; + ArrayList<PolicyResponse> response; String body = null; // Create Request. try { @@ -835,140 +835,140 @@ public class StdPolicyEngine { if (propertyFilePath == null) { throw new PolicyEngineException( XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided"); + } + + // Adding logic for remote Properties file. + Properties prop = new Properties(); + if (propertyFilePath.startsWith("http")) { + URL configURL; + try { + configURL = new URL(propertyFilePath); + URLConnection connection; + connection = configURL.openConnection(); + prop.load(connection.getInputStream()); + } catch (IOException e) { + LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyEngineException( + XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage()); + } } else { - // Adding logic for remote Properties file. - Properties prop = new Properties(); - if (propertyFilePath.startsWith("http")) { - URL configURL; + Path file = Paths.get(propertyFilePath); + if (!file.toFile().exists()) { + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + + "File doesn't exist in the specified Path " + file.toString()); + } + if (file.toString().endsWith(".properties")) { + InputStream in; + prop = new Properties(); try { - configURL = new URL(propertyFilePath); - URLConnection connection = null; - connection = configURL.openConnection(); - prop.load(connection.getInputStream()); + in = new FileInputStream(file.toFile()); + prop.load(in); } catch (IOException e) { - LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); throw new PolicyEngineException( - XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage()); + XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e); } } else { - Path file = Paths.get(propertyFilePath); - if (!file.toFile().exists()) { - throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE - + "File doesn't exist in the specified Path " + file.toString()); - } - if (file.toString().endsWith(".properties")) { - InputStream in; - prop = new Properties(); - try { - in = new FileInputStream(file.toFile()); - prop.load(in); - } catch (IOException e) { - LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); - throw new PolicyEngineException( - XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e); - } - } else { - LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath); - throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file"); - } + LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file"); } - // UEB and DMAAP Settings - String checkType = prop.getProperty("NOTIFICATION_TYPE"); - String serverList = prop.getProperty("NOTIFICATION_SERVERS"); - topic = prop.getProperty("NOTIFICATION_TOPIC"); - apiKey = prop.getProperty("UEB_API_KEY"); - apiSecret = prop.getProperty("UEB_API_SECRET"); - - if (checkType == null) { - notificationType.add(DEFAULT_NOTIFICATION); - LOGGER.info( - "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets"); + } + // UEB and DMAAP Settings + String checkType = prop.getProperty("NOTIFICATION_TYPE"); + String serverList = prop.getProperty("NOTIFICATION_SERVERS"); + topic = prop.getProperty("NOTIFICATION_TOPIC"); + apiKey = prop.getProperty("UEB_API_KEY"); + apiSecret = prop.getProperty("UEB_API_SECRET"); + + if (checkType == null) { + notificationType.add(DEFAULT_NOTIFICATION); + LOGGER.info( + "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets"); + } else { + checkType = checkType.trim(); + if (checkType.contains(",")) { + notificationType = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(","))); } else { - checkType = checkType.trim(); - if (checkType.contains(",")) { - notificationType = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(","))); - } else { - notificationType = new ArrayList<>(); - notificationType.add(checkType); - } + notificationType = new ArrayList<>(); + notificationType.add(checkType); } - if (serverList == null) { - notificationType.clear(); - notificationType.add(DEFAULT_NOTIFICATION); - LOGGER.info( - "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets"); + } + if (serverList == null) { + notificationType.clear(); + notificationType.add(DEFAULT_NOTIFICATION); + LOGGER.info( + "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets"); + } else { + serverList = serverList.trim(); + if (serverList.contains(",")) { + notificationURLList = new ArrayList<>(Arrays.asList(serverList.split(","))); } else { - serverList = serverList.trim(); - if (serverList.contains(",")) { - notificationURLList = new ArrayList<>(Arrays.asList(serverList.split(","))); - } else { - notificationURLList = new ArrayList<>(); - notificationURLList.add(serverList); - } + notificationURLList = new ArrayList<>(); + notificationURLList.add(serverList); } + } - if (topic != null) { - topic = topic.trim(); - } else { - LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter."); - } + if (topic != null) { + topic = topic.trim(); + } else { + LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter."); + } - // Client ID Authorization Settings. - String clientID = prop.getProperty("CLIENT_ID"); - if (clientKey == null) { - clientKey = prop.getProperty("CLIENT_KEY"); - try { - clientKey = PolicyUtils.decode(clientKey); - } catch (UnsupportedEncodingException | IllegalArgumentException e) { - LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS - + " Cannot Decode the given Password Proceeding with given Password!!", e); - } - } - if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) { + // Client ID Authorization Settings. + String clientID = prop.getProperty("CLIENT_ID"); + if (clientKey == null) { + clientKey = prop.getProperty("CLIENT_KEY"); + try { + clientKey = PolicyUtils.decode(clientKey); + } catch (UnsupportedEncodingException | IllegalArgumentException e) { LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS - + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!"); - throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS - + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!"); - } else { - setClientId(clientID.trim()); - setClientKey(clientKey.trim()); + + " Cannot Decode the given Password Proceeding with given Password!!", e); } - setEnvironment(prop); - // Initializing the values. - init(); - // Check the Keys for PDP_URLs - Collection<Object> unsorted = prop.keySet(); - @SuppressWarnings({ "rawtypes", "unchecked" }) - List<String> sorted = new ArrayList(unsorted); - Collections.sort(sorted); - for (String propKey : sorted) { - if (propKey.startsWith("PDP_URL")) { - String checkVal = prop.getProperty(propKey); - if (checkVal == null) { - throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE - + "Properties file doesn't have the PDP_URL parameter"); - } - if (checkVal.contains(";")) { - List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*"))); - int pdpCount = 0; - while (pdpCount < pdpDefault.size()) { - String pdpVal = pdpDefault.get(pdpCount); - readPDPParam(pdpVal); - pdpCount++; - } - } else { - readPDPParam(checkVal); + } + if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) { + LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS + + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!"); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS + + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!"); + } else { + setClientId(clientID.trim()); + setClientKey(clientKey.trim()); + } + setEnvironment(prop); + // Initializing the values. + init(); + // Check the Keys for PDP_URLs + Collection<Object> unsorted = prop.keySet(); + @SuppressWarnings({ "rawtypes", "unchecked" }) + List<String> sorted = new ArrayList(unsorted); + Collections.sort(sorted); + for (String propKey : sorted) { + if (propKey.startsWith("PDP_URL")) { + String checkVal = prop.getProperty(propKey); + if (checkVal == null) { + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Properties file doesn't have the PDP_URL parameter"); + } + if (checkVal.contains(";")) { + List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*"))); + int pdpCount = 0; + while (pdpCount < pdpDefault.size()) { + String pdpVal = pdpDefault.get(pdpCount); + readPDPParam(pdpVal); + pdpCount++; } + } else { + readPDPParam(checkVal); } } - if (pdps == null || pdps.isEmpty()) { - LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs"); - throw new PolicyEngineException( - XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs"); - } - // Get JUNIT property from properties file when running tests - checkJunit(prop); } + if (pdps == null || pdps.isEmpty()) { + LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs"); + throw new PolicyEngineException( + XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs"); + } + // Get JUNIT property from properties file when running tests + checkJunit(prop); } private static void checkJunit(Properties prop) { @@ -976,7 +976,7 @@ public class StdPolicyEngine { if (junitFlag == null || junitFlag.isEmpty()) { LOGGER.info("No JUNIT property provided, this will not be executed as a test."); } else { - if (junitFlag.equalsIgnoreCase("test")) { + if ("test".equalsIgnoreCase(junitFlag)) { StdPolicyEngine.junit = true; } else { StdPolicyEngine.junit = false; @@ -1040,7 +1040,7 @@ public class StdPolicyEngine { LOGGER.debug("Scheme is : " + scheme.toString()); LOGGER.debug("Handler is : " + handler.getClass().getName()); - if (notificationType.get(0).equals("ueb")) { + if ("ueb".equals(notificationType.get(0))) { if (this.uebThread) { AutoClientUEB.setAuto(scheme, handler); this.uebThread = registerUEBThread.isAlive(); @@ -1059,7 +1059,7 @@ public class StdPolicyEngine { } if (pdps != null) { - if (notificationType.get(0).equals("ueb") && !this.uebThread) { + if ("ueb".equals(notificationType.get(0)) && !this.uebThread) { this.uebClientThread = new AutoClientUEB(pdps.get(0), notificationURLList, apiKey, apiSecret); AutoClientUEB.setAuto(scheme, handler); this.registerUEBThread = new Thread(this.uebClientThread); @@ -1089,7 +1089,7 @@ public class StdPolicyEngine { */ public PDPNotification getNotification() { // Check if there is proper scheme.. - PDPNotification notification = null; + PDPNotification notification; if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS) || this.scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { if (notificationType.get(0).equals("ueb")) { @@ -1106,12 +1106,10 @@ public class StdPolicyEngine { if (notification == null) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Notification yet.."); return null; - } else { - return notification; } - } else { - return null; + return notification; } + return null; } /* @@ -1119,7 +1117,7 @@ public class StdPolicyEngine { */ public void setScheme(NotificationScheme scheme) { this.scheme = scheme; - if (notificationType.get(0).equals("ueb")) { + if ("ueb".equals(notificationType.get(0))) { AutoClientUEB.setScheme(this.scheme); if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { ManualClientEndUEB.createTopic(pdps.get(0), UNIQUEID, notificationURLList); @@ -1155,7 +1153,7 @@ public class StdPolicyEngine { if (this.scheme != null && this.handler != null && (this.scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || this.scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS))) { LOGGER.info("Clear Notification called.. "); - if (notificationType.get(0).equals("ueb")) { + if ("ueb".equals(notificationType.get(0))) { this.uebClientThread.terminate(); this.uebThread = false; } else if (notificationType.get(0).equals(DMAAP)) { @@ -1222,7 +1220,7 @@ public class StdPolicyEngine { policyParameters.setPolicyDescription(policyDescription); policyParameters.setOnapName(onapName); policyParameters.setConfigName(configName); - Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>(); + Map<AttributeType, Map<String, String>> attributes = new HashMap<>(); attributes.put(AttributeType.MATCHING, configAttributes); policyParameters.setAttributes(attributes); policyParameters.setConfigBodyType(PolicyType.valueOf(configType)); diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java index fc854b077..b1b60dbd8 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java @@ -88,26 +88,32 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy return policyResponseMessage; } + @Override public void setPolicyResponseStatus(PolicyResponseStatus policyResponseStatus) { this.policyResponseStatus = policyResponseStatus; } + @Override public void setActionAdvised(Map<String, String> actionAdvised) { this.actionAdvised = actionAdvised; } + @Override public void setActionTaken(Map<String, String> actionTaken) { this.actionTaken = actionTaken; } + @Override public void setRequestAttributes(Map<String, String> requestAttributes) { this.requestAttributes = requestAttributes; } + @Override public void setPolicyResponseMessage(String policyResponseMessage) { this.policyResponseMessage = policyResponseMessage; } + @Override public void setPolicyResponseStatus(String policyResponseMessage, PolicyResponseStatus policyResponseStatus) { this.policyResponseMessage = policyResponseMessage; this.policyResponseStatus = policyResponseStatus; @@ -146,7 +152,7 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy @Override public String getPolicyName() { if(policyName!=null && policyName.contains(".xml")){ - return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf(".")).lastIndexOf("."))); + return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.'))); } return policyName; } diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java index 203b9f54f..664dcc808 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java @@ -37,18 +37,6 @@ import org.onap.policy.std.StdPolicyEngine; * @version $Revision: 1.0 $ */ public class AutoClientEndTest { - /** - * Run the AutoClientEnd() constructor test. - * - * @generatedBy CodePro at 6/1/16 1:40 PM - */ - @Test - public void testAutoClientEnd_1() - throws Exception { - AutoClientEnd result = new AutoClientEnd(); - assertNotNull(result); - // add additional test code here - } /** * Run the boolean getStatus() method test. diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java index 77b0c6f49..d81ba3f98 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java @@ -62,18 +62,6 @@ public class ManualClientEndUEBTest { uebURLList.add(url); } - /** - * Run the ManualClientEndUEB() constructor test. - * - * @generatedBy CodePro at 6/1/16 1:40 PM - */ - @Test - public void testManualClientEndUEB_1() - throws Exception { - ManualClientEndUEB result = new ManualClientEndUEB(); - assertNotNull(result); - // add additional test code here - } /** * Run the PDPNotification result(NotificationScheme) method test. diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java index 856474dd8..e4116db1d 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java @@ -41,18 +41,6 @@ import org.onap.policy.std.StdPDPNotification; * @version $Revision: 1.0 $ */ public class MatchStoreTest { - /** - * Run the MatchStore() constructor test. - * - * @generatedBy CodePro at 6/1/16 1:41 PM - */ - @Test - public void testMatchStore_1() - throws Exception { - MatchStore result = new MatchStore(); - assertNotNull(result); - // add additional test code here - } /** * Run the PDPNotification checkMatch(PDPNotification) method test. diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java index 62c447fae..d817deff3 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java @@ -48,6 +48,15 @@ public class AttributeTypeTest { // add additional test code here assertEquals("matching", result); + + AttributeType type = AttributeType.create("dictionary"); + assertEquals(AttributeType.DICTIONARY, type); + + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + AttributeType.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java index 2513816bb..d59a14658 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java @@ -48,8 +48,15 @@ public class DeletePolicyConditionTest { // add additional test code here assertEquals("All Versions", result); + + assertEquals(DeletePolicyCondition.ALL, DeletePolicyCondition.create(DeletePolicyCondition.ALL.name())); } + @Test(expected = IllegalArgumentException.class) + public void testException() { + DeletePolicyCondition.create("foobar"); + } + /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java new file mode 100644 index 000000000..63e1d7c5a --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.api.DictionaryParameters; +import org.onap.policy.api.DictionaryType; + +public class DictionaryParametersTest { + + @Test + public void test() { + DictionaryParameters params = new DictionaryParameters(); + + params.setDictionary("dictionary"); + assertEquals("dictionary", params.getDictionary()); + + UUID uuid = UUID.randomUUID(); + params.setRequestID(uuid); + assertEquals(uuid, params.getRequestID()); + + params.setDictionaryJson("{}"); + assertEquals("{}", params.getDictionaryJson()); + + params.setDictionaryType(DictionaryType.BRMS); + assertEquals(DictionaryType.BRMS, params.getDictionaryType()); + + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java new file mode 100644 index 000000000..bbab6d318 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.api.DictionaryType; + +public class DictionaryTypeTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test(expected = IllegalArgumentException.class) + public void test() { + assertEquals(DictionaryType.Action, DictionaryType.create(DictionaryType.Action.toString())); + DictionaryType.create("foobar"); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java new file mode 100644 index 000000000..19d7933fc --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.api.MetricsRequestParameters; + +public class MetricsRequestParametersTest { + + @Test + public void test() { + MetricsRequestParameters p = new MetricsRequestParameters(); + + p.setRequestID(UUID.randomUUID()); + assertNotNull(p.getRequestID()); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java index 24eafc1ad..b4aaa64d8 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java @@ -40,16 +40,22 @@ public class PolicyClassTest { * @generatedBy CodePro at 6/1/16 1:40 PM */ @Test - public void testToString_1() - throws Exception { + public void testToString_1() { PolicyClass fixture = PolicyClass.Action; String result = fixture.toString(); // add additional test code here assertEquals("Action", result); + + assertEquals(PolicyClass.Decision, PolicyClass.create(PolicyClass.Decision.toString())); } + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyClass.create("foobar"); + } + /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java index 7a93f0505..49691724a 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java @@ -51,6 +51,8 @@ public class PolicyConfigStatusTest { assertEquals("not_found", result.toString()); assertEquals("CONFIG_NOT_FOUND", result.name()); assertEquals(1, result.ordinal()); + + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED, PolicyConfigStatus.create("retrieved")); } /** @@ -63,15 +65,15 @@ public class PolicyConfigStatusTest { @Test public void testGetStatus_2() throws Exception { - String configStatus = ""; + String configStatus = "retrieved"; PolicyConfigStatus result = PolicyConfigStatus.getStatus(configStatus); // add additional test code here assertNotNull(result); - assertEquals("not_found", result.toString()); - assertEquals("CONFIG_NOT_FOUND", result.name()); - assertEquals(1, result.ordinal()); + assertEquals("retrieved", result.toString()); + assertEquals("CONFIG_RETRIEVED", result.name()); + assertEquals(0, result.ordinal()); } /** @@ -92,6 +94,10 @@ public class PolicyConfigStatusTest { assertEquals("not_found", result); } + @Test(expected = IllegalArgumentException.class) + public void testException () { + PolicyConfigStatus.create("foobar"); + } /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java index e5e0b5494..2d838aa08 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java @@ -48,8 +48,14 @@ public class PolicyConfigTypeTest { // add additional test code here assertEquals("BRMS_Param", result); + + assertEquals(PolicyConfigType.MicroService, PolicyConfigType.create(PolicyConfigType.MicroService.name())); } + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyConfigType.create("foobar"); + } /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java index 4d9523859..a6391700f 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java @@ -48,6 +48,13 @@ public class PolicyDecisionTest { // add additional test code here assertEquals("deny", result); + + assertEquals(PolicyDecision.PERMIT, PolicyDecision.create(PolicyDecision.PERMIT.name())); + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyDecision.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java new file mode 100644 index 000000000..f925edbfa --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.api.PolicyException; + +public class PolicyExceptionTest { + + @Test + public void test1() { + PolicyException result = new PolicyException(); + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.onap.policy.api.PolicyException", result.toString()); + assertEquals(null, result.getLocalizedMessage()); + assertEquals(null, result.getMessage()); + } + + @Test + public void test2() { + String message = "message"; + PolicyException result = new PolicyException(message); + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.onap.policy.api.PolicyException: " + message, result.toString()); + assertEquals(message, result.getLocalizedMessage()); + assertEquals(message, result.getMessage()); + + } + + @Test + public void test3() { + Throwable cause = new Throwable(); + PolicyException result = new PolicyException(cause); + assertNotNull(result); + assertEquals("org.onap.policy.api.PolicyException: java.lang.Throwable", result.toString()); + assertEquals("java.lang.Throwable", result.getLocalizedMessage()); + assertEquals("java.lang.Throwable", result.getMessage()); + } + + @Test + public void test4() { + String message = ""; + Throwable cause = new Throwable(); + PolicyException result = new PolicyException(message, cause); + assertNotNull(result); + assertEquals("org.onap.policy.api.PolicyException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + @Test + public void test5() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + boolean enableSuppression = true; + boolean writableStackTrace = true; + + PolicyException result = new PolicyException(message, cause, enableSuppression, writableStackTrace); + + // add additional test code here + assertNotNull(result); + assertEquals("org.onap.policy.api.PolicyException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java index ff192dcab..c0bc0e84f 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java @@ -20,9 +20,10 @@ package org.onap.policy.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; +import java.util.Collections; +import java.util.Date; import java.util.Hashtable; import java.util.LinkedList; import java.util.List; @@ -45,6 +46,30 @@ import org.onap.policy.api.PolicyType; * @version $Revision: 1.0 $ */ public class PolicyParametersTest { + + @Test + public void testEverythingElse() { + PolicyParameters params = new PolicyParameters(); + params.setRuleProvider(null); + assertNull(params.getRuleProvider()); + params.setGuard(false); + assertFalse(params.getGuard()); + params.setRiskLevel("level"); + assertEquals("level", params.getRiskLevel()); + params.setRiskType("type"); + assertEquals("type", params.getRiskType()); + params.setTtlDate(new Date()); + assertNotNull(params.getTtlDate()); + params.setControllerName(null); + assertNull(params.getControllerName()); + params.setDependencyNames(Collections.emptyList()); + params.setExtendedOption(null); + assertNull(params.getExtendedOption()); + params.setTreatments(Collections.emptyMap()); + assertTrue(params.getTreatments().size() == 0); + assertNotNull(params.toString()); + } + /** * Run the String getActionAttribute() method test. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java index 294f0929d..4803a8ece 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java @@ -63,15 +63,15 @@ public class PolicyResponseStatusTest { @Test public void testGetStatus_2() throws Exception { - String responseStatus = ""; + String responseStatus = "action_advised"; PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); // add additional test code here assertNotNull(result); - assertEquals("no_action", result.toString()); - assertEquals("NO_ACTION_REQUIRED", result.name()); - assertEquals(0, result.ordinal()); + assertEquals("action_advised", result.toString()); + assertEquals("ACTION_ADVISED", result.name()); + assertEquals(1, result.ordinal()); } /** @@ -84,15 +84,15 @@ public class PolicyResponseStatusTest { @Test public void testGetStatus_3() throws Exception { - String responseStatus = ""; + String responseStatus = "action_taken"; PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); // add additional test code here assertNotNull(result); - assertEquals("no_action", result.toString()); - assertEquals("NO_ACTION_REQUIRED", result.name()); - assertEquals(0, result.ordinal()); + assertEquals("action_taken", result.toString()); + assertEquals("ACTION_TAKEN", result.name()); + assertEquals(2, result.ordinal()); } /** @@ -111,6 +111,13 @@ public class PolicyResponseStatusTest { // add additional test code here assertEquals("action_advised", result); + + assertEquals(PolicyResponseStatus.ACTION_ADVISED, PolicyResponseStatus.create("ACTION_ADVISED")); + } + + @Test(expected = IllegalArgumentException.class) + public void testTheRest() { + PolicyResponseStatus.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java index 9f1a608da..267dd9771 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java @@ -48,6 +48,13 @@ public class PolicyTypeTest { // add additional test code here assertEquals("json", result); + + assertEquals(PolicyType.JSON, PolicyType.create("json")); + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyType.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java new file mode 100644 index 000000000..23353232e --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.policy.api.RuleProvider; + +public class RuleProviderTest { + + @Test + public void test() { + assertEquals(RuleProvider.RAINY_DAY, RuleProvider.create(RuleProvider.RAINY_DAY.name())); + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + RuleProvider.create("foobar"); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java new file mode 100644 index 000000000..0808c6b3a --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.policy.api.PolicyDecision; +import org.onap.policy.std.StdDecisionResponse; + +public class StdDecisionResponseTest { + + @Test + public void test() { + StdDecisionResponse r = new StdDecisionResponse(); + r.setDecision(PolicyDecision.DENY); + assertEquals(PolicyDecision.DENY, r.getDecision()); + r.setDetails("details"); + assertEquals("details", r.getDetails()); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java new file mode 100644 index 000000000..fc0b9f97c --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import java.util.Collections; + +import org.junit.Test; +import org.onap.policy.std.StdDictionaryResponse; + +public class StdDictionaryResponseTest { + + @Test + public void test() { + StdDictionaryResponse r = new StdDictionaryResponse(); + r.setResponseCode(0); + assertEquals(0, r.getResponseCode()); + r.setResponseMessage("msg"); + assertEquals("msg", r.getResponseMessage()); + r.setDictionaryData(Collections.emptyMap()); + assertEquals(0, r.getDictionaryData().size()); + r.setDictionaryJson(null); + assertNull(r.getDictionaryJson()); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java new file mode 100644 index 000000000..a17fb06c2 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.policy.std.StdMetricsResponse; + +public class StdMetricsResponseTest { + + @Test + public void test() { + StdMetricsResponse r = new StdMetricsResponse(); + r.setMetricsTotal(0); + assertEquals(0, r.getMetricsTotal()); + r.setPapMetrics(0); + assertEquals(0, r.getPapMetrics()); + r.setPdpMetrics(0); + assertEquals(0, r.getPdpMetrics()); + r.setResponseCode(0); + assertEquals(0, r.getResponseCode()); + r.setResponseMessage("msg"); + assertEquals("msg", r.getResponseMessage()); + } + +} |