From 81bd67a59dfe34d976c504e5ba330ce99f175220 Mon Sep 17 00:00:00 2001 From: eeimmis Date: Tue, 6 Feb 2018 09:43:40 +0000 Subject: Fix technical debt/JUnit on MSB Unit tests added and technical debt removed Issue-ID: POLICY-455 Change-Id: Ib10613ff7cac64bb576046e038b2acbd66152648 Signed-off-by: mmis --- .../org/onap/policy/msb/client/MSBServiceFactory.java | 16 +++++++--------- .../org/onap/policy/msb/client/MSBServiceManager.java | 3 --- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'controlloop/common/msb/src/main/java') diff --git a/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceFactory.java b/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceFactory.java index 5332c0df2..7ebb5d6dc 100644 --- a/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceFactory.java +++ b/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceFactory.java @@ -20,7 +20,6 @@ import java.io.Serializable; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Iterator; import java.util.Properties; import org.onap.msb.sdk.discovery.common.RouteException; @@ -34,7 +33,7 @@ import org.slf4j.LoggerFactory; public class MSBServiceFactory implements Serializable { private static final long serialVersionUID = 4638414146278012425L; private static final Logger logger = LoggerFactory.getLogger(MSBServiceFactory.class); - private static final String msbPropertyFile = "msb.policy.properties"; + private static final String MSB_PROPERTY_FILE = "msb.policy.properties"; private static final String MSB_IP = "msb.ip"; private static final String MSB_PORT = "msb.port"; private transient MSBServiceClient msbClient; @@ -50,15 +49,16 @@ public class MSBServiceFactory implements Serializable { private void init() throws MSBServiceException,IOException { properties = new Properties(); - Path file = Paths.get(System.getProperty(msbPropertyFile)); - if (file == null) { + String propertyFilePath = System.getProperty(MSB_PROPERTY_FILE); + if (propertyFilePath == null) { throw new MSBServiceException("No msb.policy.properties specified."); } - if (Files.notExists(file)) { + Path file = Paths.get(propertyFilePath); + if (!file.toFile().exists()) { throw new MSBServiceException("No msb.policy.properties specified."); } - if (Files.isReadable(file) == false) { + if (!Files.isReadable(file)) { throw new MSBServiceException ("Repository is NOT readable: " + file.toAbsolutePath()); } try(InputStream is = new FileInputStream(file.toFile())){ @@ -94,9 +94,7 @@ public class MSBServiceFactory implements Serializable { node.setName(serviceName); try { MicroServiceFullInfo serviceInfo = msbClient.queryMicroServiceInfo(serviceName,version); - Iterator iterator = serviceInfo.getNodes().iterator(); - while(iterator.hasNext()) { - NodeInfo nodeInfo = (NodeInfo)iterator.next(); + for (NodeInfo nodeInfo: serviceInfo.getNodes()){ node.setIp(nodeInfo.getIp()); node.setPort(nodeInfo.getPort()); } diff --git a/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceManager.java b/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceManager.java index cbff8d88a..ccb13ece4 100644 --- a/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceManager.java +++ b/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceManager.java @@ -14,14 +14,11 @@ package org.onap.policy.msb.client; import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.Serializable; public class MSBServiceManager implements Serializable { - private static final Logger logger = LoggerFactory.getLogger(MSBServiceManager.class); private static final long serialVersionUID = -2517971308551895215L; private MSBServiceFactory factory; -- cgit 1.2.3-korg