diff options
author | Jim Hahn <jrh3@att.com> | 2020-03-23 11:36:09 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-03-23 12:19:00 -0400 |
commit | ef5768de060c6cbf10b06569e00617b052dc7e61 (patch) | |
tree | 8eb12ea7f269243c99997fc520f9c09c4e9e1da1 /models-interactions/model-actors/actor.sdnr/src/test | |
parent | 09ca398afe3ecebcbf9ed53a03919372831986b3 (diff) |
Update new SDNR actor with v2.0 structures
SDNR v2.0 introduced an extra "input" and "output" layer within
the body of the messages. Added POJOs to match that, and updated
the actor to use the new POJOs so that no extra steps are needed
during serialization or deserialization.
Also modified the SDNR and APPC-LCM simulators to discard request messages
when looking for the response, if the sink and source topics happen to
be the same.
Added the SDNR simulator.
Added more coverage to the SDNR actor.
Fixed a sonar issue in the SDNR junit code:
- use a constant instead of a literal (i.e., for "ModifyConfig")
Issue-ID: POLICY-2434
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I70914a299dd5e9ee8eaccb5d42a2596cab814091
Diffstat (limited to 'models-interactions/model-actors/actor.sdnr/src/test')
3 files changed, 50 insertions, 25 deletions
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java index 0aea35f37..27d7d435c 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java @@ -38,15 +38,16 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.impl.OperationMaker; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.policy.PolicyResult; +import org.onap.policy.sdnr.PciBody; +import org.onap.policy.sdnr.PciMessage; import org.onap.policy.sdnr.PciResponse; -import org.onap.policy.sdnr.PciResponseWrapper; import org.onap.policy.sdnr.Status; import org.onap.policy.sdnr.util.StatusCodeEnum; import org.powermock.reflect.Whitebox; public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation { - protected PciResponseWrapper response; + protected PciMessage response; /** * Constructs the object using a default actor and operation name. @@ -71,14 +72,18 @@ public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperatio public void setUp() throws Exception { super.setUpBasic(); - response = new PciResponseWrapper(); + response = new PciMessage(); + + PciBody body = new PciBody(); + response.setBody(body); + + PciResponse output = new PciResponse(); + body.setOutput(output); - PciResponse body = new PciResponse(); Status status = new Status(); + output.setStatus(status); status.setCode(100); status.setValue(StatusCodeEnum.SUCCESS.toString()); - body.setStatus(status); - response.setBody(body); } /** diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java index 19b2063da..3165d5814 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java @@ -36,7 +36,7 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.policy.PolicyResult; -import org.onap.policy.sdnr.PciRequestWrapper; +import org.onap.policy.sdnr.PciMessage; public class ModifyConfigOperationTest extends BasicSdnrOperation { @@ -89,7 +89,7 @@ public class ModifyConfigOperationTest extends BasicSdnrOperation { @Test public void testMakeRequest() throws CoderException { - Pair<String, PciRequestWrapper> result = oper.makeRequest(1); + Pair<String, PciMessage> result = oper.makeRequest(1); assertNotNull(result.getLeft()); assertNotNull(result.getRight()); } diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java index a7bfa3322..5f6a5df3b 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java @@ -32,7 +32,7 @@ import org.junit.Test; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdnr.PciCommonHeader; -import org.onap.policy.sdnr.PciRequestWrapper; +import org.onap.policy.sdnr.PciMessage; import org.onap.policy.sdnr.util.StatusCodeEnum; public class SdnrOperationTest extends BasicSdnrOperation { @@ -57,37 +57,41 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testMakeRequest() { - Pair<String, PciRequestWrapper> result = operation.makeRequest(1); + Pair<String, PciMessage> result = operation.makeRequest(1); assertNotNull(result.getLeft()); - PciRequestWrapper request = result.getRight(); + PciMessage request = result.getRight(); assertNotNull(request.getBody()); assertEquals("1.0", request.getVersion()); assertEquals("request", request.getType()); - PciCommonHeader header = request.getBody().getCommonHeader(); + PciCommonHeader header = request.getBody().getInput().getCommonHeader(); assertNotNull(header); assertEquals(params.getRequestId(), header.getRequestId()); } @Test public void testGetExpectedKeyValues() { - PciRequestWrapper request = operation.makeRequest(1).getRight(); - assertEquals(Arrays.asList(request.getBody().getCommonHeader().getSubRequestId()), - operation.getExpectedKeyValues(50, request)); + PciMessage request = operation.makeRequest(1).getRight(); + assertEquals(Arrays.asList(request.getBody().getInput().getCommonHeader().getSubRequestId()), + operation.getExpectedKeyValues(50, request)); + } + @Test + public void testStartPreprocessorAsync() { + assertNotNull(operation.startPreprocessorAsync()); } @Test public void testDetmStatusStringResponse() { - final org.onap.policy.sdnr.Status status = response.getBody().getStatus(); + final org.onap.policy.sdnr.Status status = response.getBody().getOutput().getStatus(); // null status - response.getBody().setStatus(null); + response.getBody().getOutput().setStatus(null); assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response)) .withMessage("SDNR response is missing the response status"); - response.getBody().setStatus(status); + response.getBody().getOutput().setStatus(status); // invalid code status.setCode(-45); @@ -106,17 +110,17 @@ public class SdnrOperationTest extends BasicSdnrOperation { status.setValue(StatusCodeEnum.REJECT.toString()); status.setCode(StatusCodeEnum.toValue(StatusCodeEnum.REJECT)); assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response)) - .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString()); + .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString()); status.setValue(StatusCodeEnum.REJECT.toString()); status.setCode(313); assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response)) - .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString()); + .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString()); status.setValue(StatusCodeEnum.ERROR.toString()); status.setCode(StatusCodeEnum.toValue(StatusCodeEnum.ERROR)); assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response)) - .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.ERROR.toString()); + .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.ERROR.toString()); status.setValue(StatusCodeEnum.FAILURE.toString()); status.setCode(450); @@ -125,14 +129,30 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testSetOutcome() { - final org.onap.policy.sdnr.Status status = response.getBody().getStatus(); + // with a status value + checkOutcome(); + assertEquals(StatusCodeEnum.SUCCESS.toString(), outcome.getMessage()); + + // null status value + response.getBody().getOutput().getStatus().setValue(null); + checkOutcome(); // null status - response.getBody().setStatus(null); + response.getBody().getOutput().setStatus(null); + checkOutcome(); + + // null output + response.getBody().setOutput(null); + checkOutcome(); + + // null body + response.setBody(null); + checkOutcome(); + } + + protected void checkOutcome() { assertSame(outcome, operation.setOutcome(outcome, PolicyResult.SUCCESS, response)); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertNotNull(outcome.getMessage()); - response.getBody().setStatus(status); - } } |