diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-04 16:27:18 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-08-06 19:19:46 -0400 |
commit | deed677c3dc8751209d50e7d35132c929fe6800d (patch) | |
tree | 01f3149d4a03206e134d889d50834ae8d141a0ce /models-interactions/model-actors/actor.appc | |
parent | 364ef26929f06637bca03dd7bfb5e8ac69b611f8 (diff) |
Modify Actors to use properties when provided
Modified the Actors to use properties when the application provides them
instead of going to the event context for the data. This sometimes entailed
moving code out of the Operation subclass constructor that used or validated
the context data.
Combined some property names and renamed others.
Changed VF Count from AtomicInteger to Integer.
Issue-ID: POLICY-2746
Change-Id: Ib8730538309bb77d2f4f6161e9a20a49362d8972
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.appc')
2 files changed, 54 insertions, 16 deletions
diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java index 680bd9cc7..13ddaf4a9 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java @@ -69,7 +69,19 @@ public class ModifyConfigOperation extends AppcOperation { @Override protected Request makeRequest(int attempt) { + return makeRequest(attempt, getVnfId()); + } + + protected String getVnfId() { + GenericVnf vnf = this.getProperty(OperationProperties.AAI_RESOURCE_VNF); + if (vnf != null) { + return vnf.getVnfId(); + } + AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); + if (cq == null) { + throw new IllegalStateException("target vnf-id could not be determined"); + } GenericVnf genvnf = cq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID()); if (genvnf == null) { @@ -77,6 +89,6 @@ public class ModifyConfigOperation extends AppcOperation { throw new IllegalArgumentException("target vnf-id could not be found"); } - return makeRequest(attempt, genvnf.getVnfId()); + return genvnf.getVnfId(); } } 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 9c602f52e..3b63514e9 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 @@ -22,6 +22,7 @@ package org.onap.policy.controlloop.actor.appc; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -42,6 +43,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.mockito.Mock; import org.onap.aai.domain.yang.GenericVnf; import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.appc.Request; @@ -56,8 +58,14 @@ import org.onap.policy.controlloop.policy.PolicyResult; public class ModifyConfigOperationTest extends BasicAppcOperation { + @Mock + private GenericVnf genvnf; + @Mock + private AaiCqResponse cq; + private ModifyConfigOperation oper; + public ModifyConfigOperationTest() { super(DEFAULT_ACTOR, ModifyConfigOperation.NAME); } @@ -77,6 +85,9 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { @Override public void setUp() throws Exception { super.setUp(); + when(genvnf.getVnfId()).thenReturn(MY_VNF); + when(cq.getGenericVnfByModelInvariantId(any())).thenReturn(genvnf); + oper = new ModifyConfigOperation(params, config); } @@ -95,14 +106,9 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SINK).build(); config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcOperation.SELECTOR_KEYS); - AaiCqResponse cq = mock(AaiCqResponse.class); - GenericVnf genvnf = mock(GenericVnf.class); - when(genvnf.getVnfId()).thenReturn(MY_VNF); - when(cq.getGenericVnfByModelInvariantId(any())).thenReturn(genvnf); - params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq); - params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build(); oper = new ModifyConfigOperation(params, config) { @Override @@ -111,6 +117,8 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { } }; + oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf); + outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof Response); @@ -168,23 +176,41 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { @Test public void testMakeRequest() throws CoderException { - AaiCqResponse cq = new AaiCqResponse("{}"); + oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf); + + oper.generateSubRequestId(2); + Request request = oper.makeRequest(2); + assertNotNull(request); + assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY)); + + verifyRequest("modifyConfig.json", request, IGNORE_FIELDS); + } + + @Test + public void testGetVnfIdViaProperty() throws CoderException { + oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf); + assertEquals(MY_VNF, oper.getVnfId()); + } + + @Test + public void testGetVnfId() throws CoderException { + // no CQ data + assertThatIllegalStateException().isThrownBy(() -> oper.getVnfId()) + .withMessage("target vnf-id could not be determined"); + + cq = new AaiCqResponse("{}"); // missing vnf-id params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq); - assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest(1)); + assertThatIllegalArgumentException().isThrownBy(() -> oper.getVnfId()) + .withMessage("target vnf-id could not be found"); // populate the CQ data with a vnf-id - GenericVnf genvnf = new GenericVnf(); + genvnf = new GenericVnf(); genvnf.setVnfId(MY_VNF); genvnf.setModelInvariantId(RESOURCE_ID); cq.setInventoryResponseItems(Arrays.asList(genvnf)); - oper.generateSubRequestId(2); - Request request = oper.makeRequest(2); - assertNotNull(request); - assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY)); - - verifyRequest("modifyConfig.json", request, IGNORE_FIELDS); + assertEquals(MY_VNF, oper.getVnfId()); } } |