From e2855d181e760721a4024ee02f7116487242ebd3 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Thu, 15 Feb 2018 20:40:33 +0100 Subject: SdcConfig sonar fixes Change-Id: Ia947837f00401b1c9da900dc2db3b6931fb682fb Issue-ID: APPC-639 Signed-off-by: Jakub Dudycz --- .../java/org/onap/appc/sdc/listener/SdcConfig.java | 65 ++++++++++++---------- .../org/onap/appc/sdc/listener/SdcConfigTest.java | 4 +- 2 files changed, 39 insertions(+), 30 deletions(-) (limited to 'appc-sdc-listener/appc-sdc-listener-bundle') diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcConfig.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcConfig.java index 2acb2e625..4f16bc5c9 100644 --- a/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcConfig.java +++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/main/java/org/onap/appc/sdc/listener/SdcConfig.java @@ -26,15 +26,17 @@ package org.onap.appc.sdc.listener; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.openecomp.sdc.api.consumer.IConfiguration; - +import com.google.common.collect.Lists; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import org.apache.commons.lang.StringUtils; +import org.openecomp.sdc.api.consumer.IConfiguration; public class SdcConfig implements IConfiguration { @@ -44,9 +46,13 @@ public class SdcConfig implements IConfiguration { private String env; private String keystorePath; private String keystorePass; - /** Polling internal is time between listening sessions */ + /** + * Polling internal is time between listening sessions + */ private int pollingInterval; - /** Polling timeout is the time to listen for (dmaap timeout url param)/1000 */ + /** + * Polling timeout is the time to listen for (dmaap timeout url param)/1000 + */ private int pollingTimeout; private List types = new ArrayList<>(); private String user; @@ -55,12 +61,12 @@ public class SdcConfig implements IConfiguration { private Properties props; private final EELFLogger logger = EELFManager.getInstance().getLogger(SdcConfig.class); - SdcConfig(Properties props) throws Exception { + SdcConfig(Properties props) throws URISyntaxException { this.props = props; init(); } - private void init() throws Exception { + private void init() throws URISyntaxException { if (props == null) { logger.error("SdcConfig init is skipped due to properties is null"); return; @@ -92,8 +98,8 @@ public class SdcConfig implements IConfiguration { if (pollingInterval > pollingTimeout) { logger.warn(String.format( - "Message acknowledgement may be delayed by %ds in the ADSC listener. [Listening Time: %s, Poll Period: %s]", - pollingInterval - pollingTimeout, pollingTimeout, pollingInterval)); + "Message acknowledgement may be delayed by %ds in the ADSC listener. [Listening Time: %s, Poll Period: %s]", + pollingInterval - pollingTimeout, pollingTimeout, pollingInterval)); } logParams(); @@ -104,7 +110,7 @@ public class SdcConfig implements IConfiguration { */ types.add("APPC_CONFIG"); types.add("VF_LICENSE"); - // types.add("TOSCA_CSAR"); commenting it out as we are not listening to TOSCA_CSAR + // types.add("TOSCA_CSAR"); commenting it out as we are not listening to TOSCA_CSAR storeOp = new URI(props.getProperty("appc.sdc.provider.url")); } @@ -114,6 +120,7 @@ public class SdcConfig implements IConfiguration { return false; } + @Override public boolean isFilterInEmptyResources() { return false; } @@ -174,32 +181,32 @@ public class SdcConfig implements IConfiguration { } @Override - public Boolean isUseHttpsWithDmaap(){ - return true; + public Boolean isUseHttpsWithDmaap() { + return true; } @Override - public List getMsgBusAddress() { - return (getMsgBusProperties()); + public List getMsgBusAddress() { + return getMsgBusProperties(); } public List getMsgBusProperties() { - List uebAddresses = new ArrayList(); - String uebAddressesList=null; - if (null != this.props) + List uebAddresses; + String uebAddressesList; + if (null != this.props) { uebAddressesList = this.props.getProperty("appc.ClosedLoop.poolMembers"); - else { + } else { logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::props is null for SdcConfig"); - return null; + return Collections.emptyList(); } if (null == uebAddressesList) { logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is null for SdcConfig"); - return null; + return Collections.emptyList(); } - logger.debug("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is="+ uebAddressesList); + logger.debug("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is=" + uebAddressesList); String[] sList = uebAddressesList.split(","); - uebAddresses= formatAddresses(sList); - logger.debug("SdcConfig:getMsgBusProperties:::Returning addresses as "+uebAddresses.toString()); + uebAddresses = formatAddresses(sList); + logger.debug("SdcConfig:getMsgBusProperties:::Returning addresses as " + uebAddresses.toString()); return uebAddresses; } @@ -222,16 +229,16 @@ public class SdcConfig implements IConfiguration { logger.info(String.format("SDC Params: %s", params)); } - protected List formatAddresses(String[] sList) { - List uebAddresses = new ArrayList(); - for (String fqdnPort:sList) { + private List formatAddresses(String[] sList) { + List uebAddresses = new ArrayList<>(); + for (String fqdnPort : sList) { if (fqdnPort.startsWith("http")) { - fqdnPort=StringUtils.substringAfter(fqdnPort, "://"); + fqdnPort = StringUtils.substringAfter(fqdnPort, "://"); } - if (null != fqdnPort && fqdnPort.contains(":")) { - fqdnPort=StringUtils.substringBefore(fqdnPort,":"); + if (fqdnPort.contains(":")) { + fqdnPort = StringUtils.substringBefore(fqdnPort, ":"); } - logger.debug("SdcConfig:formatAddresses:: "+fqdnPort); + logger.debug("SdcConfig:formatAddresses:: " + fqdnPort); uebAddresses.add(fqdnPort); } return uebAddresses; diff --git a/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcConfigTest.java b/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcConfigTest.java index 5d88fe7ea..5ba17c922 100644 --- a/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcConfigTest.java +++ b/appc-sdc-listener/appc-sdc-listener-bundle/src/test/java/org/onap/appc/sdc/listener/SdcConfigTest.java @@ -24,7 +24,9 @@ package org.onap.appc.sdc.listener; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.List; import java.util.Properties; @@ -41,6 +43,6 @@ public class SdcConfigTest { properties.setProperty("appc.ClosedLoop.poolMembers","localhost:3905"); SdcConfig sdc = new SdcConfig(properties); List uebAddresses = sdc.getMsgBusProperties(); - assertNotNull(uebAddresses); + assertFalse(uebAddresses.isEmpty()); } } -- cgit 1.2.3-korg