diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-18 09:39:19 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-08-18 17:11:52 -0400 |
commit | 8722cb8a654ddcdcb472546a58809e041fe84eba (patch) | |
tree | eba3aee017377733f6a44840a58fc322f7e4f807 /models-interactions/model-actors/actor.aai/src/test | |
parent | ca3827f43ada2b160f6966d205ca97d4402a0935 (diff) |
Make targetEntity a property
The target entity is not always known when an Operation is first
constructed, thus it should be treated as an Operation property instead
of being included within the ControlLoopParams. Started the process of
moving it from the Params to the properties.
Also fixed a bug in custom query - it was setting the outcome response
to the String response instead of setting it to the AaiCqResponse
object.
Also added logging when an Operation's properties are set.
Issue-ID: POLICY-2746
Change-Id: I56c0cd90985f6140363548b0b8d031471b586e88
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.aai/src/test')
3 files changed, 26 insertions, 16 deletions
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 f1225373e..8e8b8f150 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 @@ -21,7 +21,6 @@ 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.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.junit.Assert.assertEquals; @@ -114,27 +113,22 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation { HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/query").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().targetEntity(SIM_VSERVER).retry(0).timeoutSec(5).executor(blockingExecutor) - .preprocessed(true).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build(); oper = new AaiCustomQueryOperation(params, config); + oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, SIM_VSERVER); oper.setProperty(OperationProperties.AAI_VSERVER_LINK, MY_LINK); outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); - String resp = outcome.getResponse(); - assertThat(resp).isNotNull().contains("relationship-list"); + assertNotNull(outcome.getResponse()); } @Test public void testConstructor() { assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName()); assertEquals(AaiCustomQueryOperation.NAME, oper.getName()); - - // verify that it works with an empty target entity - params = params.toBuilder().targetEntity("").build(); - assertThatCode(() -> new AaiCustomQueryOperation(params, config)).doesNotThrowAnyException(); } @Test @@ -263,6 +257,15 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation { .withMessage("cannot perform custom query - no resource-link"); } + @Test + public void testSetOutcome() { + outcome = oper.setOutcome(params.makeOutcome(null), PolicyResult.SUCCESS, null, null); + assertNull(outcome.getResponse()); + + outcome = oper.setOutcome(params.makeOutcome(null), PolicyResult.SUCCESS, null, "{}"); + assertTrue(outcome.getResponse() instanceof AaiCqResponse); + } + private String makeTenantReply() throws Exception { Map<String, String> links = Map.of(AaiCustomQueryOperation.RESOURCE_LINK, MY_LINK); List<Map<String, String>> data = Arrays.asList(links); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java index b211db261..13b5b5926 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetPnfOperationTest.java @@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import javax.ws.rs.client.InvocationCallback; @@ -41,6 +42,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; @@ -82,7 +84,7 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation { @Test public void testGetPropertyNames() { - assertThat(oper.getPropertyNames()).isEmpty(); + assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY)); } /** @@ -93,8 +95,9 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation { HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/network/pnfs/pnf").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().targetEntity("OzVServer").retry(0).timeoutSec(5).executor(blockingExecutor).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); oper = new AaiGetPnfOperation(params, config); + oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "OzVServer"); outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); @@ -109,8 +112,9 @@ public class AaiGetPnfOperationTest extends BasicAaiOperation { HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/network/pnfs/pnf").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().targetEntity("getFail").retry(0).timeoutSec(5).executor(blockingExecutor).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); oper = new AaiGetPnfOperation(params, config); + oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "getFail"); outcome = oper.start().get(); assertEquals(PolicyResult.FAILURE, outcome.getResult()); 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 fe0327c10..11604cdb9 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 @@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import javax.ws.rs.client.InvocationCallback; @@ -41,6 +42,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; @@ -82,7 +84,7 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation { @Test public void testGetPropertyNames() { - assertThat(oper.getPropertyNames()).isEmpty(); + assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY)); } /** @@ -93,8 +95,9 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation { HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().targetEntity("OzVServer").retry(0).timeoutSec(5).executor(blockingExecutor).build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); oper = new AaiGetTenantOperation(params, config); + oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "OzVServer"); outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); @@ -109,9 +112,9 @@ public class AaiGetTenantOperationTest extends BasicAaiOperation { HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build(); config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().targetEntity("failedVserver").retry(0).timeoutSec(5).executor(blockingExecutor) - .build(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); oper = new AaiGetTenantOperation(params, config); + oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "failedVserver"); outcome = oper.start().get(); assertEquals(PolicyResult.FAILURE, outcome.getResult()); |