diff options
author | Liam Fallon <liam.fallon@ericsson.com> | 2018-01-16 18:42:01 +0000 |
---|---|---|
committer | Liam Fallon <liam.fallon@ericsson.com> | 2018-01-16 18:47:17 +0000 |
commit | 59d71c593d295b2bd48a9971d89635f95759a0a2 (patch) | |
tree | 8cbdbd5180979b0c3aeb19739716462983bcb1cc /controlloop/common/actors/actor.appc | |
parent | 2b9b989f99700ebc11f77d8da2df4538fe7105d2 (diff) |
Fix Sonar Technical Debt, Unit Test for APPC POJOs
Mainly making fields private, fixing field and methods to follow Java guidelines, and adding getter and setter methods. Unit test added for all classes in org.onap.policy.appc
Change-Id: If3db740bc146a09f8f7387f02c12b048ad00b201
Signed-off-by: Liam Fallon <liam.fallon@ericsson.com>
Issue-ID: POLICY-455
Signed-off-by: Liam Fallon <liam.fallon@ericsson.com>
Diffstat (limited to 'controlloop/common/actors/actor.appc')
2 files changed, 38 insertions, 38 deletions
diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java index d525c4c85..41a99496c 100644 --- a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java +++ b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java @@ -41,15 +41,15 @@ public class APPCActorServiceProvider implements Actor { private static final ImmutableList<String> recipes = ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig"); private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>() - .put("Restart", ImmutableList.of("VM")) - .put("Rebuild", ImmutableList.of("VM")) - .put("Migrate", ImmutableList.of("VM")) - .put("ModifyConfig", ImmutableList.of("VNF")) - .build(); + .put("Restart", ImmutableList.of("VM")) + .put("Rebuild", ImmutableList.of("VM")) + .put("Migrate", ImmutableList.of("VM")) + .put("ModifyConfig", ImmutableList.of("VNF")) + .build(); private static final ImmutableMap<String, List<String>> payloads = new ImmutableMap.Builder<String, List<String>>() - .put("ModifyConfig", ImmutableList.of("generic-vnf.vnf-id")) - .build(); - + .put("ModifyConfig", ImmutableList.of("generic-vnf.vnf-id")) + .build(); + @Override public String actor() { return "APPC"; @@ -77,52 +77,52 @@ public class APPCActorServiceProvider implements Actor { * * @param onset * the event that is reporting the alert for policy - * to perform an action + * to perform an action * @param operation * the control loop operation specifying the actor, - * operation, target, etc. + * operation, target, etc. * @param policy * the policy the was specified from the yaml generated - * by CLAMP or through the Policy GUI/API + * by CLAMP or through the Policy GUI/API * @return an APPC request conforming to the legacy API * @throws AAIException */ public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy, String targetVnf) { + Policy policy, String targetVnf) { /* * Construct an APPC request */ Request request = new Request(); - request.CommonHeader = new CommonHeader(); - request.CommonHeader.RequestID = onset.requestID; - request.CommonHeader.SubRequestID = operation.subRequestId; - request.Action = policy.getRecipe().substring(0, 1).toUpperCase() - + policy.getRecipe().substring(1); - + request.setCommonHeader(new CommonHeader()); + request.getCommonHeader().setRequestID(onset.requestID); + request.getCommonHeader().setSubRequestID(operation.subRequestId); + request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() + + policy.getRecipe().substring(1)); + /* * For now Policy generates the PG Streams as a demo, in the * future the payload can be provided by CLAMP */ - request.Payload.put("generic-vnf.vnf-id", targetVnf); - + request.getPayload().put("generic-vnf.vnf-id", targetVnf); + PGRequest pgRequest = new PGRequest(); pgRequest.pgStreams = new PGStreams(); - + PGStream pgStream; for (int i = 0; i < 5; i++) { - pgStream = new PGStream(); - pgStream.streamId = "fw_udp"+(i+1); - pgStream.isEnabled = "true"; - pgRequest.pgStreams.pgStream.add(pgStream); + pgStream = new PGStream(); + pgStream.streamId = "fw_udp"+(i+1); + pgStream.isEnabled = "true"; + pgRequest.pgStreams.pgStream.add(pgStream); } - request.Payload.put("pg-streams", pgRequest.pgStreams); - + request.getPayload().put("pg-streams", pgRequest.pgStreams); + /* * Return the request */ - + return request; } - - + + } diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index 31a041d4b..e07589081 100644 --- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -123,11 +123,11 @@ public class AppcServiceProviderTest { /* A common header is required and cannot be null */ assertNotNull(appcRequest.getCommonHeader()); - assertEquals(appcRequest.getCommonHeader().RequestID, onsetEvent.requestID); + assertEquals(appcRequest.getCommonHeader().getRequestID(), onsetEvent.requestID); /* An action is required and cannot be null */ - assertNotNull(appcRequest.Action); - assertEquals(appcRequest.Action, "ModifyConfig"); + assertNotNull(appcRequest.getAction()); + assertEquals(appcRequest.getAction(), "ModifyConfig"); /* A payload is required and cannot be null */ assertNotNull(appcRequest.getPayload()); @@ -142,16 +142,16 @@ public class AppcServiceProviderTest { logger.debug("JSON Output: \n" + jsonRequest); /* The JSON string must contain the following fields */ - assertTrue(jsonRequest.contains("CommonHeader")); - assertTrue(jsonRequest.contains("Action")); + assertTrue(jsonRequest.contains("commonHeader")); + assertTrue(jsonRequest.contains("action")); assertTrue(jsonRequest.contains("ModifyConfig")); - assertTrue(jsonRequest.contains("Payload")); + assertTrue(jsonRequest.contains("payload")); assertTrue(jsonRequest.contains("generic-vnf.vnf-id")); assertTrue(jsonRequest.contains("pg-streams")); Response appcResponse = new Response(appcRequest); - appcResponse.getStatus().Code = ResponseCode.SUCCESS.getValue(); - appcResponse.getStatus().Description = "AppC success"; + appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue()); + appcResponse.getStatus().setDescription("AppC success"); /* Print out request as json to make sure serialization works */ String jsonResponse = Serialization.gsonPretty.toJson(appcResponse); logger.debug("JSON Output: \n" + jsonResponse); |