From 770e374bc2e4ba814bb0e59eadf0f9fe2d5291e5 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 27 May 2020 10:49:39 -0400 Subject: Include response in OperationOutcome Added the response field and modified the actors to populate it. Issue-ID: POLICY-2592 Change-Id: I24487b6fbc23b69bde4a95acd470864d8231c49d Signed-off-by: Jim Hahn --- .../actor/aai/AaiCustomQueryOperationTest.java | 4 ++++ .../controlloop/actor/aai/AaiGetPnfOperationTest.java | 1 + .../actor/aai/AaiGetTenantOperationTest.java | 1 + .../policy/controlloop/actor/appc/AppcOperation.java | 2 ++ .../controlloop/actor/appc/AppcOperationTest.java | 3 +++ .../actor/appc/ModifyConfigOperationTest.java | 2 ++ .../controlloop/actor/appclcm/AppcLcmOperation.java | 2 ++ .../actor/appclcm/AppcLcmOperationTest.java | 9 ++++++++- .../controlloop/actor/cds/CdsActorServiceManager.java | 2 ++ .../actor/cds/GrpcActorServiceManagerTest.java | 12 +++++++----- .../policy/controlloop/actor/guard/GuardOperation.java | 2 ++ .../controlloop/actor/guard/GuardOperationTest.java | 13 +++++++++++-- .../actor/sdnc/BandwidthOnDemandOperationTest.java | 3 +++ .../controlloop/actor/sdnc/BasicSdncOperation.java | 6 ++++-- .../controlloop/actor/sdnc/RerouteOperationTest.java | 3 +++ .../policy/controlloop/actor/sdnr/SdnrOperation.java | 12 +++++++----- .../controlloop/actor/sdnr/SdnrOperationTest.java | 2 ++ .../onap/policy/controlloop/actor/so/SoOperation.java | 2 ++ .../policy/controlloop/actor/so/SoOperationTest.java | 4 ++++ .../controlloop/actor/so/VfModuleCreateTest.java | 6 ++++++ .../controlloop/actor/so/VfModuleDeleteTest.java | 5 +++++ .../policy/controlloop/actor/vfc/VfcOperation.java | 2 ++ .../onap/policy/controlloop/actor/vfc/RestartTest.java | 3 +++ .../policy/controlloop/actor/vfc/VfcOperationTest.java | 18 +++++++++--------- .../actorserviceprovider/OperationOutcome.java | 7 +++++++ .../impl/BidirectionalTopicOperation.java | 1 + .../actorserviceprovider/impl/HttpOperation.java | 1 + .../actorserviceprovider/OperationOutcomeTest.java | 3 +++ .../impl/BidirectionalTopicOperationTest.java | 14 ++++++++++++-- .../actorserviceprovider/impl/HttpOperationTest.java | 8 ++++++++ .../impl/OperationPartialTest.java | 4 ++++ 31 files changed, 131 insertions(+), 26 deletions(-) (limited to 'models-interactions/model-actors') diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index 243a0c696..ca6cfb2f8 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -20,6 +20,7 @@ package org.onap.policy.controlloop.actor.aai; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; @@ -123,6 +124,9 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof StandardCoderObject); } /** diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java index 496d2ea68..1e9a1d987 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetTenantOperationTest.java @@ -92,6 +92,7 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof StandardCoderObject); } /** diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java index 75a4c9f58..14ab355bf 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java @@ -171,6 +171,8 @@ public abstract class AppcOperation extends BidirectionalTopicOperation { protected CompletableFuture postProcessResponse(OperationOutcome outcome, String url, Response rawResponse, DecisionResponse response) { + outcome.setResponse(response); + // determine the result String status = response.getStatus(); if (status == null) { diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java index 58d54a5ed..daf4dff6e 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java @@ -24,6 +24,8 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -119,6 +121,7 @@ public class GuardOperationTest extends BasicHttpOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof DecisionResponse); } /** @@ -135,6 +138,7 @@ public class GuardOperationTest extends BasicHttpOperation { outcome = oper.start().get(); assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof DecisionResponse); } @Test @@ -159,7 +163,9 @@ public class GuardOperationTest extends BasicHttpOperation { executor.runAll(100); assertTrue(future2.isDone()); - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + outcome = future2.get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(resp, outcome.getResponse()); assertNotNull(oper.getSubRequestId()); assertEquals(oper.getSubRequestId(), future2.get().getSubRequestId()); @@ -181,7 +187,9 @@ public class GuardOperationTest extends BasicHttpOperation { // should already be done assertTrue(future2.isDone()); - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + outcome = future2.get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertNull(outcome.getResponse()); // ensure callbacks were invoked verify(started).accept(any()); @@ -246,6 +254,7 @@ public class GuardOperationTest extends BasicHttpOperation { oper.postProcessResponse(outcome, BASE_URI, rawResponse, response); assertEquals(expectedResult, outcome.getResult()); assertEquals(expectedMessage, outcome.getMessage()); + assertSame(response, outcome.getResponse()); } @Override diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java index 2b856707e..95b4bd739 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java @@ -21,6 +21,7 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.Map; import org.junit.AfterClass; @@ -32,6 +33,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdnc.SdncRequest; +import org.onap.policy.sdnc.SdncResponse; public class BandwidthOnDemandOperationTest extends BasicSdncOperation { @@ -80,6 +82,7 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SdncResponse); } @Test diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java index bb1285ea3..921694269 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java @@ -126,9 +126,11 @@ public abstract class BasicSdncOperation extends BasicHttpOperation executor.runAll(100); assertTrue(future2.isDone()); - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + outcome = future2.get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SdncResponse); - assertNotNull(future2.get().getSubRequestId()); + assertNotNull(outcome.getSubRequestId()); return requestCaptor.getValue().getEntity(); } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java index 678648db3..142f10743 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java @@ -21,6 +21,7 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.Map; import org.junit.AfterClass; @@ -32,6 +33,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdnc.SdncRequest; +import org.onap.policy.sdnc.SdncResponse; public class RerouteOperationTest extends BasicSdncOperation { @@ -74,6 +76,7 @@ public class RerouteOperationTest extends BasicSdncOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SdncResponse); } @Test diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java index 40face7fa..d0bb38e43 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java @@ -118,20 +118,22 @@ public class SdnrOperation extends BidirectionalTopicOperation { if (getCount++ >= getMaxGets()) { logger.warn("{}: execeeded 'get' limit {} for {}", getFullName(), getMaxGets(), params.getRequestId()); setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT); + outcome.setResponse(response); outcome.setMessage(SO_RESPONSE_CODE + " " + outcome.getMessage()); return CompletableFuture.completedFuture(outcome); } @@ -316,6 +317,7 @@ public abstract class SoOperation extends HttpOperation { // set default result and message setOutcome(outcome, result); + outcome.setResponse(response); outcome.setMessage(rawResponse.getStatus() + " " + outcome.getMessage()); return outcome; } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index 644521869..9e72c8aaf 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -176,6 +176,7 @@ public class SoOperationTest extends BasicSoOperation { assertSame(outcome, future2.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertNotNull(oper.getSubRequestId()); + assertSame(response, outcome.getResponse()); // failed oper.generateSubRequestId(2); @@ -186,6 +187,7 @@ public class SoOperationTest extends BasicSoOperation { assertSame(outcome, future2.get()); assertEquals(PolicyResult.FAILURE, outcome.getResult()); assertNotNull(oper.getSubRequestId()); + assertSame(response, outcome.getResponse()); // no request id in the response oper.generateSubRequestId(2); @@ -291,6 +293,7 @@ public class SoOperationTest extends BasicSoOperation { assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertEquals("200 " + ControlLoopOperation.SUCCESS_MSG, outcome.getMessage()); + assertSame(response, outcome.getResponse()); // failure case when(rawResponse.getStatus()).thenReturn(500); @@ -298,6 +301,7 @@ public class SoOperationTest extends BasicSoOperation { assertEquals(PolicyResult.FAILURE, outcome.getResult()); assertEquals("500 " + ControlLoopOperation.FAILED_MSG, outcome.getMessage()); + assertSame(response, outcome.getResponse()); } @Test diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java index def107441..2b3e1163b 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java @@ -53,6 +53,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.so.SoRequest; +import org.onap.policy.so.SoResponse; public class VfModuleCreateTest extends BasicSoOperation { private static final String MODEL_NAME2 = "my-model-name-B"; @@ -96,6 +97,7 @@ public class VfModuleCreateTest extends BasicSoOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SoResponse); } @Test @@ -187,6 +189,10 @@ public class VfModuleCreateTest extends BasicSoOperation { outcome = future2.get(5, TimeUnit.SECONDS); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + SoResponse resp = outcome.getResponse(); + assertNotNull(resp); + assertEquals(REQ_ID.toString(), resp.getRequestReferences().getRequestId()); + assertEquals(origCount + 1, oper.getVfCount()); } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java index 0ec1a1df0..86242f042 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java @@ -130,6 +130,7 @@ public class VfModuleDeleteTest extends BasicSoOperation { outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof SoResponse); } @Test @@ -219,6 +220,10 @@ public class VfModuleDeleteTest extends BasicSoOperation { outcome = future2.get(5, TimeUnit.SECONDS); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + SoResponse resp = outcome.getResponse(); + assertNotNull(resp); + assertEquals(REQ_ID.toString(), resp.getRequestReferences().getRequestId()); + assertEquals(origCount - 1, oper.getVfCount()); } diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java index 827109d10..573ee2698 100644 --- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java +++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcOperation.java @@ -119,6 +119,7 @@ public abstract class VfcOperation extends HttpOperation { if (getCount++ >= getMaxGets()) { logger.warn("{}: execeeded 'get' limit {} for {}", getFullName(), getMaxGets(), params.getRequestId()); setOutcome(outcome, PolicyResult.FAILURE_TIMEOUT); + outcome.setResponse(response); outcome.setMessage(VFC_RESPONSE_CODE + " " + outcome.getMessage()); return CompletableFuture.completedFuture(outcome); } @@ -179,6 +180,7 @@ public abstract class VfcOperation extends HttpOperation { // set default result and message setOutcome(outcome, result); + outcome.setResponse(response); outcome.setMessage(rawResponse.getStatus() + " " + outcome.getMessage()); return outcome; } diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java index 5fe4973ce..d8ba7e4e8 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java +++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java @@ -22,6 +22,7 @@ package org.onap.policy.controlloop.actor.vfc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.concurrent.CompletableFuture; import org.apache.commons.lang3.tuple.Pair; @@ -33,6 +34,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.vfc.VfcRequest; +import org.onap.policy.vfc.VfcResponse; public class RestartTest extends BasicVfcOperation { private Restart restartOper; @@ -72,6 +74,7 @@ public class RestartTest extends BasicVfcOperation { outcome = restartOper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof VfcResponse); } @Test diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java index 4d98b97c9..0b58fd4a3 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java +++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java @@ -82,30 +82,30 @@ public class VfcOperationTest extends BasicVfcOperation { response.setResponseDescriptor(new VfcResponseDescriptor()); response.setJobId("sampleJobId"); + + // null status CompletableFuture future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertFalse(future2.isDone()); - // assertSame(outcome, future2.get()); TODO Hanging - assertEquals(PolicyResult.SUCCESS, outcome.getResult()); response.getResponseDescriptor().setStatus("FinisHeD"); future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertSame(response, outcome.getResponse()); + // failed response.getResponseDescriptor().setStatus("eRRor"); future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertSame(response, outcome.getResponse()); - // failed - /* - * response.getResponseDescriptor().setStatus("anything but finished"); future2 = - * oper.postProcessResponse(outcome, PATH, rawResponse, response); - * assertTrue(future2.isDone()); assertSame(outcome, future2.get()); - * assertEquals(PolicyResult.FAILURE, outcome.getResult()); - */ + // unfinished + response.getResponseDescriptor().setStatus("anything but finished"); + future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); + assertFalse(future2.isDone()); } @Test diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java index e2d94b3b3..0fd2c0bfd 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java @@ -43,6 +43,7 @@ public class OperationOutcome { private PolicyResult result = PolicyResult.SUCCESS; private String message; private boolean finalOutcome; + private Object response; private ControlLoopResponse controlLoopResponse; /** @@ -60,6 +61,7 @@ public class OperationOutcome { this.result = source.result; this.message = source.message; this.finalOutcome = source.finalOutcome; + this.response = source.response; this.controlLoopResponse = source.controlLoopResponse; } @@ -85,6 +87,11 @@ public class OperationOutcome { return clo; } + @SuppressWarnings("unchecked") + public T getResponse() { + return (T) response; + } + /** * Determines if this outcome is for the given actor and operation. * diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index 9decd8a61..8285a5635 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -250,6 +250,7 @@ public abstract class BidirectionalTopicOperation extends OperationPartial * @return the updated operation */ public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, S response) { + outcome.setResponse(response); return setOutcome(outcome, result); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java index e83fe8c94..1acc1ff65 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperation.java @@ -217,6 +217,7 @@ public abstract class HttpOperation extends OperationPartial { public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response rawResponse, T response) { + outcome.setResponse(response); return setOutcome(outcome, result); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java index 77d2253e1..c60a0f00c 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java @@ -42,6 +42,7 @@ public class OperationOutcomeTest { private static final String SUB_REQ_ID = "my-sub-request-id"; private static final PolicyResult RESULT = PolicyResult.FAILURE_GUARD; private static final String MESSAGE = "my-message"; + private static final String RESPONSE = "my-response"; private ControlLoopResponse response; private OperationOutcome outcome; @@ -70,6 +71,7 @@ public class OperationOutcomeTest { assertEquals(SUB_REQ_ID, outcome2.getSubRequestId()); assertEquals(RESULT, outcome2.getResult()); assertEquals(MESSAGE, outcome2.getMessage()); + assertSame(RESPONSE, outcome2.getResponse()); assertSame(response, outcome2.getControlLoopResponse()); } @@ -142,6 +144,7 @@ public class OperationOutcomeTest { outcome.setStart(START); outcome.setSubRequestId(SUB_REQ_ID); outcome.setTarget(TARGET); + outcome.setResponse(RESPONSE); outcome.setControlLoopResponse(response); } } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index 55782a34d..84a4d5d29 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import org.junit.Before; @@ -85,6 +86,7 @@ public class BidirectionalTopicOperationTest { private ControlLoopOperationParams params; private OperationOutcome outcome; private StandardCoderObject stdResponse; + private MyResponse response; private String responseText; private PseudoExecutor executor; private int ntimes; @@ -109,7 +111,9 @@ public class BidirectionalTopicOperationTest { params = ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION).executor(executor).build(); outcome = params.makeOutcome(); - responseText = coder.encode(new MyResponse()); + response = new MyResponse(); + response.setRequestId(REQ_ID); + responseText = coder.encode(response); stdResponse = coder.decode(responseText, StandardCoderObject.class); ntimes = 1; @@ -159,6 +163,7 @@ public class BidirectionalTopicOperationTest { assertSame(outcome, future.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(response, outcome.getResponse()); verify(forwarder).unregister(eq(Arrays.asList(REQ_ID)), eq(listenerCaptor.getValue())); } @@ -258,6 +263,7 @@ public class BidirectionalTopicOperationTest { assertSame(outcome, oper2.processResponse(outcome, TEXT, null)); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(TEXT, outcome.getResponse()); } /** @@ -270,6 +276,7 @@ public class BidirectionalTopicOperationTest { assertSame(outcome, oper2.processResponse(outcome, responseText, stdResponse)); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(stdResponse, outcome.getResponse()); } /** @@ -286,6 +293,7 @@ public class BidirectionalTopicOperationTest { assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse)); assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertEquals(resp, outcome.getResponse()); } /** @@ -295,6 +303,7 @@ public class BidirectionalTopicOperationTest { public void testProcessResponseDecodeOk() throws CoderException { assertSame(outcome, oper.processResponse(outcome, responseText, stdResponse)); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(response, outcome.getResponse()); } /** @@ -344,8 +353,9 @@ public class BidirectionalTopicOperationTest { @Getter @Setter + @EqualsAndHashCode public static class MyResponse { - private String requestId = REQ_ID; + private String requestId; private String output; } diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java index 81238defa..eb1aa880f 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpOperationTest.java @@ -256,6 +256,7 @@ public class HttpOperationTest { callback.get().completed(response); assertSame(outcome, future2.get(5, TimeUnit.SECONDS)); + assertSame(TEXT, outcome.getResponse()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); } @@ -290,6 +291,7 @@ public class HttpOperationTest { assertTrue(result.isDone()); assertSame(outcome, result.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertSame(TEXT, outcome.getResponse()); } /** @@ -302,6 +304,7 @@ public class HttpOperationTest { assertTrue(result.isDone()); assertSame(outcome, result.get()); assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertSame(TEXT, outcome.getResponse()); } /** @@ -317,6 +320,7 @@ public class HttpOperationTest { assertTrue(result.isDone()); assertSame(outcome, result.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertEquals(Integer.valueOf(10), outcome.getResponse()); } /** @@ -357,6 +361,7 @@ public class HttpOperationTest { assertNotNull(outcome); assertEquals(1, nget); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof MyResponse); } /** @@ -373,6 +378,7 @@ public class HttpOperationTest { assertNotNull(outcome); assertEquals(1, ndelete); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof String); } /** @@ -388,6 +394,7 @@ public class HttpOperationTest { assertNotNull(outcome); assertEquals(1, npost); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof MyResponse); } /** @@ -404,6 +411,7 @@ public class HttpOperationTest { assertNotNull(outcome); assertEquals(1, nput); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertTrue(outcome.getResponse() instanceof MyResponse); } @Test diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index 75463b9d7..f5fd9fb75 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -1027,6 +1027,10 @@ public class OperationPartialTest { assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + oper.setOutcome(outcome, PolicyResult.SUCCESS); + assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage()); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + for (PolicyResult result : FAILURE_RESULTS) { outcome = new OperationOutcome(); oper.setOutcome(outcome, result); -- cgit 1.2.3-korg