From 06f456d8d06840a21f48531b0bd35b1a429b10f9 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 1 Feb 2018 12:22:30 -0500 Subject: 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 --- .../java/org/onap/policy/std/AutoClientUEB.java | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java') 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) { -- cgit 1.2.3-korg