diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-01 11:03:31 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-01 12:04:48 -0400 |
commit | 88fedd4d3edbb581eabe20074a65c32b635fc3b2 (patch) | |
tree | b932b653aa2d89557f08570d51fc5204459dae93 /models-interactions/model-actors/actor.appc/src/test/java | |
parent | 3a99e95994963c8fd04d7c038cf6b0263b2bbdeb (diff) |
Set sub request ID before start callback
Modified new actor code to generate the sub request ID
before invoking the start callback.
Issue-ID: POLICY-2461
Change-Id: I4adabd6efda2c30c0e2da31f95f01dd5fe546c0a
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.appc/src/test/java')
2 files changed, 31 insertions, 45 deletions
diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java index 7f7ac7a54..4c6477d93 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java @@ -22,14 +22,12 @@ package org.onap.policy.controlloop.actor.appc; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import java.util.Arrays; import java.util.Map; import java.util.TreeMap; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -40,6 +38,8 @@ import org.onap.policy.appc.Request; import org.onap.policy.appc.ResponseCode; import org.onap.policy.appc.ResponseStatus; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.policy.PolicyResult; public class AppcOperationTest extends BasicAppcOperation { @@ -64,12 +64,7 @@ public class AppcOperationTest extends BasicAppcOperation { public void setUp() throws Exception { super.setUp(); - oper = new AppcOperation(params, config) { - @Override - protected Pair<String, Request> makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; + oper = new MyOper(params, config); } @After @@ -91,11 +86,11 @@ public class AppcOperationTest extends BasicAppcOperation { @Test public void testMakeRequest() { - Pair<String, Request> result = oper.makeRequest(2, MY_VNF); - String subreq = result.getLeft(); + oper.generateSubRequestId(2); + String subreq = oper.getSubRequestId(); assertNotNull(subreq); - Request request = result.getRight(); + Request request = oper.makeRequest(2, MY_VNF); assertEquals(DEFAULT_OPERATION, request.getAction()); assertNotNull(request.getPayload()); @@ -106,27 +101,18 @@ public class AppcOperationTest extends BasicAppcOperation { assertEquals(subreq, header.getSubRequestId()); - // a subsequent request should have a different sub-request id - result = oper.makeRequest(2, MY_VNF); - assertNotEquals(subreq, result.getLeft()); - - assertNotNull(result.getLeft()); - assertEquals(result.getLeft(), result.getRight().getCommonHeader().getSubRequestId()); + request = oper.makeRequest(2, MY_VNF); + assertEquals(subreq, request.getCommonHeader().getSubRequestId()); // repeat using a null payload params = params.toBuilder().payload(null).build(); - oper = new AppcOperation(params, config) { - @Override - protected Pair<String, Request> makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; - assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getRight().getPayload()); + oper = new MyOper(params, config); + assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getPayload()); } @Test public void testConvertPayload() { - Request request = oper.makeRequest(2, MY_VNF).getRight(); + Request request = oper.makeRequest(2, MY_VNF); // @formatter:off assertEquals( @@ -145,13 +131,8 @@ public class AppcOperationTest extends BasicAppcOperation { params = params.toBuilder().payload(payload).build(); - oper = new AppcOperation(params, config) { - @Override - protected Pair<String, Request> makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; - request = oper.makeRequest(2, MY_VNF).getRight(); + oper = new MyOper(params, config); + request = oper.makeRequest(2, MY_VNF); // @formatter:off assertEquals( @@ -171,13 +152,8 @@ public class AppcOperationTest extends BasicAppcOperation { payload.put(KEY3, "def"); params = params.toBuilder().payload(payload).build(); - oper = new AppcOperation(params, config) { - @Override - protected Pair<String, Request> makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; - request = oper.makeRequest(2, MY_VNF).getRight(); + oper = new MyOper(params, config); + request = oper.makeRequest(2, MY_VNF); payload.put(AppcOperation.VNF_ID_KEY, MY_VNF); payload.put(KEY1, "abc"); @@ -189,7 +165,8 @@ public class AppcOperationTest extends BasicAppcOperation { @Test public void testGetExpectedKeyValues() { - Request request = oper.makeRequest(2, MY_VNF).getRight(); + oper.generateSubRequestId(2); + Request request = oper.makeRequest(2, MY_VNF); assertEquals(Arrays.asList(request.getCommonHeader().getSubRequestId()), oper.getExpectedKeyValues(50, request)); } @@ -250,4 +227,16 @@ public class AppcOperationTest extends BasicAppcOperation { assertEquals(MY_DESCRIPTION, outcome.getMessage()); } } + + private static class MyOper extends AppcOperation { + + public MyOper(ControlLoopOperationParams params, BidirectionalTopicConfig config) { + super(params, config); + } + + @Override + protected Request makeRequest(int attempt) { + return makeRequest(attempt, MY_VNF); + } + } } diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java index 743896c18..4f4f506ce 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java @@ -34,7 +34,6 @@ import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -161,10 +160,8 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { genvnf.setModelInvariantId(RESOURCE_ID); cq.setInventoryResponseItems(Arrays.asList(genvnf)); - Pair<String, Request> result = oper.makeRequest(2); - assertNotNull(result.getLeft()); - - Request request = result.getRight(); + oper.generateSubRequestId(2); + Request request = oper.makeRequest(2); assertNotNull(request); assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY)); |