From 0a4dcfbe5612b64be111dee34e7c9e335eba8827 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 15 Oct 2019 12:26:48 +0100 Subject: Fix remaining fixable Sonar issues on policy models This patch fixes the remaining easy to fix Sonar issues on policy models. The remaining issues are - methods that do not follow Java naming conventions and fixing those will probably break policies that use those methods - TODO statements to do with functionality we didn't get done in Dublin and will address in Frankfurt Issue-ID: POLICY-2165 Change-Id: I7f604bc2335388bdc0dd9286ae17a5ab76517665 Signed-off-by: liamfallon --- .../main/java/org/onap/policy/simulators/Util.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'models-interactions/model-simulators/src') diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java index 11efd973d..f21fb6f38 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -21,12 +21,12 @@ package org.onap.policy.simulators; -import java.io.IOException; import java.util.Properties; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.common.gson.GsonMessageBodyHandler; +import org.onap.policy.common.parameters.ParameterRuntimeException; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.network.NetworkUtil; @@ -49,11 +49,12 @@ public class Util { public static final int SDNCSIM_SERVER_PORT = 6670; public static final int DMAAPSIM_SERVER_PORT = 3904; + private static final String CANNOT_PROCESS_PARAMETERS = "cannot parse parameters "; private static final String CANNOT_CONNECT = "cannot connect to port "; private static final String LOCALHOST = "localhost"; private Util() { - // Prevent instantiation of thic class + // Prevent instantiation of this class } /** @@ -61,11 +62,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ public static HttpServletServer buildAaiSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); + .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -79,11 +79,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ public static HttpServletServer buildSdncSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true); + .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -98,11 +97,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ public static HttpServletServer buildSoSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); + .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -116,11 +114,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ public static HttpServletServer buildVfcSim() throws InterruptedException { final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory() - .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); + .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { @@ -134,11 +131,10 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs */ public static HttpServletServer buildGuardSim() throws InterruptedException { HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(GUARDSIM_SERVER_NAME, - LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); + LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); testServer.setSerializationProvider(GsonMessageBodyHandler.class.getName()); testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); @@ -153,21 +149,25 @@ public class Util { * * @return the simulator * @throws InterruptedException if a thread is interrupted - * @throws IOException if an IO errror occurs - * @throws CoderException if the server parameters cannot be loaded */ - public static HttpServletServer buildDmaapSim() throws InterruptedException, CoderException { + public static HttpServletServer buildDmaapSim() throws InterruptedException { String json = ResourceUtils.getResourceAsString("org/onap/policy/simulators/dmaap/DmaapParameters.json"); - DmaapSimParameterGroup params = new StandardCoder().decode(json, DmaapSimParameterGroup.class); + DmaapSimParameterGroup params = null; + try { + params = new StandardCoder().decode(json, DmaapSimParameterGroup.class); + } catch (CoderException ce) { + throw new ParameterRuntimeException( + CANNOT_PROCESS_PARAMETERS + "org/onap/policy/simulators/dmaap/DmaapParameters.json", ce); + } DmaapSimProvider.setInstance(new DmaapSimProvider(params)); Properties props = DmaapSimRestServer.getServerProperties(params.getRestServerParameters()); final String svcpfx = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." - + params.getRestServerParameters().getName(); + + params.getRestServerParameters().getName(); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, - Integer.toString(DMAAPSIM_SERVER_PORT)); + Integer.toString(DMAAPSIM_SERVER_PORT)); props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(props).get(0); -- cgit 1.2.3-korg