diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-09-27 12:28:19 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2018-09-27 16:59:41 -0400 |
commit | 1253af9756e8a7027fade727da68b38dff2d5159 (patch) | |
tree | 39b785d0ddad197933e6e3df4b21376f1d57ef9e /controlloop/common/simulators | |
parent | 1c32e0c17febcbef90756f3eef4868542723cc81 (diff) |
Fix more sonar issues
Most of these are minor issues along with a few others.
They have been bugging me so I thought I would get them
done. Some also do not show up on sonarlint.
Issue-ID: POLICY-1129
Change-Id: I31f2765f6babdfa80b23f0589daacc98da8d2002
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'controlloop/common/simulators')
-rw-r--r-- | controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java | 21 | ||||
-rw-r--r-- | controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java | 35 |
2 files changed, 31 insertions, 25 deletions
diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java index 3bacead01..8fa4892fb 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java @@ -43,6 +43,9 @@ import org.onap.policy.aai.util.Serialization; public class AaiSimulatorJaxRs { private static final String VSERVER = "vserver"; + private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop"; + private static final String ERROR = "error"; + private static final String GETFAIL = "getFail"; /** * A&AI get query. @@ -77,7 +80,7 @@ public class AaiSimulatorJaxRs { if (request.getInstanceFilters().getInstanceFilter().get(0).containsKey(VSERVER)) { final String vserverName = request.getInstanceFilters().getInstanceFilter().get(0).get(VSERVER).get("vserver-name"); - if ("error".equals(vserverName)) { + if (ERROR.equals(vserverName)) { Map<String,String> params = new TreeMap<>(); params.put("type", VSERVER); return load("aai/AaiNqResponse-Error.json", params); @@ -89,7 +92,7 @@ public class AaiSimulatorJaxRs { } else { final String vnfId = request.getInstanceFilters().getInstanceFilter().get(0).get("generic-vnf").get("vnf-id"); - if ("error".equals(vnfId)) { + if (ERROR.equals(vnfId)) { Map<String,String> params = new TreeMap<>(); params.put("type", "generic-vnf"); return load("aai/AaiNqResponse-Error.json", params); @@ -120,14 +123,14 @@ public class AaiSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String getByVnfName(@QueryParam("vnf-name") final String vnfName) { - if ("getFail".equals(vnfName)) { + if (GETFAIL.equals(vnfName)) { return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs" + "/generic-vnf\",\"ERR.5.4.6114\"]}}}"; } - final boolean isDisabled = "disableClosedLoop".equals(vnfName); - if ("error".equals(vnfName)) { + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName); + if (ERROR.equals(vnfName)) { return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"" + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"" @@ -195,13 +198,13 @@ public class AaiSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String getByVnfId(@PathParam("vnfId") final String vnfId) { - if ("getFail".equals(vnfId)) { + if (GETFAIL.equals(vnfId)) { return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/" + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/" + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}"; } - final boolean isDisabled = "disableClosedLoop".equals(vnfId); + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId); final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01"); return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"" @@ -241,12 +244,12 @@ public class AaiSimulatorJaxRs { @Consumes(MediaType.APPLICATION_JSON) @Produces("application/json") public String getByVserverName(@QueryParam("vserver-name") final String vserverName) { - if ("getFail".equals(vserverName)) { + if (GETFAIL.equals(vserverName)) { return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found" + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not" + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}"; } - final boolean isDisabled = "disableClosedLoop".equals(vserverName); + final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName); final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8"); return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \"" + vserverName + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": " diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java index 58aae6267..16ae615af 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -26,10 +26,6 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.utils.network.NetworkUtil; public class Util { - private Util() { - // Prevent instantiation of thic class - } - public static final String AAISIM_SERVER_NAME = "aaiSim"; public static final String SOSIM_SERVER_NAME = "soSim"; public static final String VFCSIM_SERVER_NAME = "vfcSim"; @@ -39,6 +35,13 @@ public class Util { public static final int SOSIM_SERVER_PORT = 6667; public static final int VFCSIM_SERVER_PORT = 6668; public static final int GUARDSIM_SERVER_PORT = 6669; + + private static final String CANNOT_CONNECT = "cannot connect to port "; + private static final String LOCALHOST = "localhost"; + + private Util() { + // Prevent instantiation of thic class + } /** * Build an A&AI simulator. @@ -49,11 +52,11 @@ public class Util { */ public static HttpServletServer buildAaiSim() throws InterruptedException, IOException { final HttpServletServer testServer = - HttpServletServer.factory.build(AAISIM_SERVER_NAME, "localhost", AAISIM_SERVER_PORT, "/", false, true); + HttpServletServer.factory.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)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } @@ -67,11 +70,11 @@ public class Util { */ public static HttpServletServer buildSoSim() throws InterruptedException, IOException { final HttpServletServer testServer = - HttpServletServer.factory.build(SOSIM_SERVER_NAME, "localhost", SOSIM_SERVER_PORT, "/", false, true); + HttpServletServer.factory.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)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } @@ -85,11 +88,11 @@ public class Util { */ public static HttpServletServer buildVfcSim() throws InterruptedException, IOException { final HttpServletServer testServer = - HttpServletServer.factory.build(VFCSIM_SERVER_NAME, "localhost", VFCSIM_SERVER_PORT, "/", false, true); + HttpServletServer.factory.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)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } @@ -102,12 +105,12 @@ public class Util { * @throws IOException if an IO errror occurs */ public static HttpServletServer buildGuardSim() throws InterruptedException, IOException { - HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, "localhost", + HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException("cannot connect to port " + testServer.getPort()); + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { + throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); } return testServer; } |