diff options
author | Jim Hahn <jrh3@att.com> | 2018-09-21 16:55:04 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-09-21 17:30:59 -0400 |
commit | 3c52de0725c942fe1f2fdeb05c8960645bc66f01 (patch) | |
tree | 929243eef3e87f0397b02d211262eff31492a35f /controlloop | |
parent | d85e766c5538de762820132ac723d928f5a9bf89 (diff) |
more sonar issues in drools-applications
Modified SO code to not return null lists for various buildXxxParam
methods.
Fixed commit message.
Added additional junit coverage to SO code.
Added additional junit coverage to SO code - cover more error cases.
Extracted another constant.
Change-Id: I65a27f2a1af1cfd8dd98bddab9ca1e862a3fa6fb
Issue-ID: POLICY-1129
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop')
2 files changed, 65 insertions, 18 deletions
diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java index 8775e68a6..7c0214bfb 100644 --- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java +++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java @@ -272,10 +272,10 @@ public class SOActorServiceProvider implements Actor { request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2); // Request Parameters - request.getRequestDetails().setRequestParameters(buildRequestParameters(policy)); + buildRequestParameters(policy, request.getRequestDetails()); // Configuration Parameters - request.getRequestDetails().setConfigurationParameters(buildConfigurationParameters(policy)); + buildConfigurationParameters(policy, request.getRequestDetails()); // Save the instance IDs for the VNF and service to static fields // vfModuleId is not required for the create vf-module preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance() @@ -400,39 +400,44 @@ public class SOActorServiceProvider implements Actor { * Builds the request parameters from the policy payload. * * @param policy the policy - * @return the request parameters, or {@code null} if the payload is {@code null} + * @param request request into which to stick the request parameters */ - private SORequestParameters buildRequestParameters(Policy policy) { + private void buildRequestParameters(Policy policy, SORequestDetails request) { + // assume null until proven otherwise + request.setRequestParameters(null); + if (policy.getPayload() == null) { - return null; + return; } String json = policy.getPayload().get(REQ_PARAM_NM); if (json == null) { - return null; + return; } - return Serialization.gsonPretty.fromJson(json, SORequestParameters.class); + request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SORequestParameters.class)); } /** * Builds the configuration parameters from the policy payload. * * @param policy the policy - * @return the configuration parameters, or {@code null} if the payload is - * {@code null} + * @param request request into which to stick the configuration parameters */ - private List<Map<String, String>> buildConfigurationParameters(Policy policy) { + private void buildConfigurationParameters(Policy policy, SORequestDetails request) { + // assume null until proven otherwise + request.setConfigurationParameters(null); + if (policy.getPayload() == null) { - return null; + return; } String json = policy.getPayload().get(CONFIG_PARAM_NM); if (json == null) { - return null; + return; } - return Serialization.gsonPretty.fromJson(json, CONFIG_TYPE); + request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE)); } /** diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java index 6de451d0c..9c1d87888 100644 --- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java +++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java @@ -47,6 +47,9 @@ import org.onap.policy.so.util.Serialization; public class SoActorServiceProviderTest { + private static final String VF_MODULE_CREATE = "VF Module Create"; + private static final String VF_MODULE_DELETE = "VF Module Delete"; + @Test public void testConstructRequest() throws Exception { VirtualControlLoopEvent onset = new VirtualControlLoopEvent(); @@ -59,12 +62,13 @@ public class SoActorServiceProviderTest { Policy policy = new Policy(); policy.setActor("Dorothy"); policy.setRecipe("GoToOz"); + assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); policy.setActor("SO"); assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); - policy.setRecipe("VF Module Create"); + policy.setRecipe(VF_MODULE_CREATE); // empty policy payload SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); @@ -82,6 +86,22 @@ public class SoActorServiceProviderTest { assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey")); assertEquals(1, request.getRequestDetails().getConfigurationParameters().size()); assertEquals("cvalue", request.getRequestDetails().getConfigurationParameters().get(0).get("ckey")); + + // payload with config, but no request params + policy.setPayload(makePayload()); + policy.getPayload().remove(SOActorServiceProvider.REQ_PARAM_NM); + request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + assertNotNull(request); + assertNull(request.getRequestDetails().getRequestParameters()); + assertNotNull(request.getRequestDetails().getConfigurationParameters()); + + // payload with request, but no config params + policy.setPayload(makePayload()); + policy.getPayload().remove(SOActorServiceProvider.CONFIG_PARAM_NM); + request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + assertNotNull(request); + assertNotNull(request.getRequestDetails().getRequestParameters()); + assertNull(request.getRequestDetails().getConfigurationParameters()); // null response assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, null)); @@ -94,10 +114,30 @@ public class SoActorServiceProviderTest { assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json"))); - policy.setRecipe("VF Module Delete"); + policy.setRecipe(VF_MODULE_DELETE); SORequest deleteRequest = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); assertNotNull(deleteRequest); assertEquals(SoOperationType.DELETE_VF_MODULE, deleteRequest.getOperationType()); + + /* + * NOTE: The remaining tests must be done in order + */ + + policy.setRecipe(VF_MODULE_CREATE); + + // null tenant + aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems() + .remove(1); + assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + + // null service item + aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0) + .setItems(null); + assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + + // null response + aaiNqResp.setAaiNqResponse(null); + assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); } @Test @@ -115,9 +155,11 @@ public class SoActorServiceProviderTest { assertEquals("SO", sp.actor()); assertEquals(2, sp.recipes().size()); - assertEquals("VF Module Create", sp.recipes().get(0)); - assertEquals("VF Module Delete", sp.recipes().get(1)); - assertEquals(0, sp.recipePayloads("VF Module Create").size()); + assertEquals(VF_MODULE_CREATE, sp.recipes().get(0)); + assertEquals(VF_MODULE_DELETE, sp.recipes().get(1)); + assertEquals(0, sp.recipePayloads(VF_MODULE_CREATE).size()); + assertEquals(0, sp.recipeTargets("unknown recipe").size()); + assertEquals(1, sp.recipeTargets(VF_MODULE_CREATE).size()); } /** |