diff options
author | Jim Hahn <jrh3@att.com> | 2020-03-27 12:35:23 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-03-30 09:01:15 -0400 |
commit | 61a84fecc1eae8640fec2860f4b50102ed0baa64 (patch) | |
tree | 32ba4cf68bd9f6c4f97e92f665ab2de7ad788dc6 /models-interactions/model-actors | |
parent | 3a374cbc9f4bef8856c3e78be1a6b4c5274cd744 (diff) |
Test new actors against simulators
Also modified HttpParams to allow "path" to be blank to support any
cases that really have no "path" to append to the context URI base
path.
Issue-ID: POLICY-2405
Change-Id: I49eebde6759659d2804b5a11c1504c37674bd0c4
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors')
31 files changed, 780 insertions, 32 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 dae443593..cf19ef65d 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 @@ -39,7 +39,9 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -47,6 +49,7 @@ import org.mockito.Mock; import org.onap.policy.aai.AaiConstants; import org.onap.policy.aai.AaiCqResponse; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; +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.Operation; @@ -54,6 +57,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; import org.onap.policy.controlloop.policy.PolicyResult; @@ -62,7 +66,8 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S private static final StandardCoder coder = new StandardCoder(); private static final String MY_LINK = "my-link"; - private static final String MY_VSERVER = "my-verserver-name"; + private static final String MY_VSERVER = "my-vserver-name"; + private static final String SIM_VSERVER = "OzVServer"; @Captor private ArgumentCaptor<Entity<Map<String, String>>> entityCaptor; @@ -76,6 +81,16 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S super(AaiConstants.ACTOR_NAME, AaiCustomQueryOperation.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Sets up. */ @@ -93,8 +108,25 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S oper = new AaiCustomQueryOperation(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/query").build(); + config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + preloadTenantData(); + + params = params.toBuilder().targetEntity(SIM_VSERVER).retry(0).timeoutSec(5).executor(blockingExecutor).build(); + oper = new AaiCustomQueryOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test - public void testAaiCustomQueryOperation() { + public void testConstructor() { assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName()); assertEquals(AaiCustomQueryOperation.NAME, oper.getName()); assertEquals(MY_VSERVER, oper.getVserver()); @@ -215,6 +247,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S private void preloadTenantData(StandardCoderObject data) { context.setProperty(AaiGetOperation.getTenantKey(MY_VSERVER), data); + context.setProperty(AaiGetOperation.getTenantKey(SIM_VSERVER), data); } private PolicyResult getResult(CompletableFuture<OperationOutcome> future2) diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java index b0420456e..9a288192f 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java @@ -31,16 +31,20 @@ import static org.mockito.Mockito.when; import java.util.Map; import java.util.concurrent.CompletableFuture; import javax.ws.rs.client.InvocationCallback; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.aai.AaiConstants; +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.parameters.HttpConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; public class AaiGetOperationTest extends BasicAaiOperation<Void> { - private static final String INPUT_FIELD = "input"; private static final String TEXT = "my-text"; @@ -50,6 +54,16 @@ public class AaiGetOperationTest extends BasicAaiOperation<Void> { super(AaiConstants.ACTOR_NAME, AaiGetOperation.TENANT); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Sets up. */ @@ -59,6 +73,37 @@ public class AaiGetOperationTest extends BasicAaiOperation<Void> { oper = new AaiGetOperation(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + 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(); + oper = new AaiGetOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + + /** + * Tests "failure" case with simulator. + */ + @Test + public void testFailure() throws Exception { + 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(); + oper = new AaiGetOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.FAILURE, outcome.getResult()); + } + @Test public void testGetRetry() { // use default if null retry diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java index 00485c935..2715bfe29 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java @@ -23,7 +23,11 @@ package org.onap.policy.controlloop.actor.aai; import static org.junit.Assert.assertEquals; import java.util.Map; +import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; +import org.onap.policy.simulators.Util; /** * Superclass for various operator tests. @@ -47,6 +51,22 @@ public abstract class BasicAaiOperation<Q> extends BasicHttpOperation<Q> { super(actor, operation); } + /** + * Starts the simulator. + */ + protected static void initBeforeClass() throws Exception { + Util.buildAaiSim(); + + BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("aai/") + .hostname("localhost").managed(true).port(Util.AAISIM_SERVER_PORT).build(); + HttpClientFactoryInstance.getClientFactory().build(clientParams); + } + + protected static void destroyAfterClass() { + HttpClientFactoryInstance.getClientFactory().destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + } + protected void verifyHeaders(Map<String, Object> headers) { assertEquals("POLICY", headers.get("X-FromAppId").toString()); assertEquals(params.getRequestId().toString(), headers.get("X-TransactionId")); 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 30450d02a..7f7ac7a54 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 @@ -30,7 +30,10 @@ 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; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; @@ -42,10 +45,22 @@ import org.onap.policy.controlloop.policy.PolicyResult; public class AppcOperationTest extends BasicAppcOperation { private AppcOperation oper; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + // use same topic name for both sides + initBeforeClass(MY_SINK, MY_SINK); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Sets up. */ @Before + @Override public void setUp() throws Exception { super.setUp(); @@ -57,8 +72,14 @@ public class AppcOperationTest extends BasicAppcOperation { }; } + @After + @Override + public void tearDown() { + super.tearDown(); + } + @Test - public void testAppcOperation() { + public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(DEFAULT_OPERATION, oper.getName()); } diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java index 06ad1661d..546a38d3a 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java @@ -35,6 +35,8 @@ import java.util.function.BiConsumer; import org.onap.policy.appc.Response; import org.onap.policy.appc.ResponseCode; import org.onap.policy.appc.ResponseStatus; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation; @@ -44,6 +46,8 @@ 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.controlloop.policy.Target; +import org.onap.policy.simulators.AppcLegacyTopicServer; +import org.onap.policy.simulators.TopicServer; import org.powermock.reflect.Whitebox; /** @@ -94,6 +98,15 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio status.setDescription(MY_DESCRIPTION); } + public void tearDown() { + super.tearDownBasic(); + } + + @SuppressWarnings("rawtypes") + protected TopicServer makeServer(TopicSink sink, TopicSource source) { + return new AppcLegacyTopicServer(sink, source); + } + /** * Runs the operation and verifies that the response is successful. * 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 95629bccf..743896c18 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 @@ -35,7 +35,10 @@ 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; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.aai.domain.yang.GenericVnf; import org.onap.policy.aai.AaiCqResponse; @@ -43,6 +46,8 @@ import org.onap.policy.appc.Request; 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.actorserviceprovider.parameters.BidirectionalTopicConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; import org.onap.policy.controlloop.policy.PolicyResult; public class ModifyConfigOperationTest extends BasicAppcOperation { @@ -53,14 +58,61 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { super(DEFAULT_ACTOR, ModifyConfigOperation.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + // use same topic name for both sides + initBeforeClass(MY_SINK, MY_SINK); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + @Before + @Override public void setUp() throws Exception { super.setUp(); oper = new ModifyConfigOperation(params, config); } + @After + @Override + public void tearDown() { + super.tearDown(); + } + + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + BidirectionalTopicParams opParams = + 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(); + + oper = new ModifyConfigOperation(params, config) { + @Override + protected CompletableFuture<OperationOutcome> startGuardAsync() { + return null; + } + }; + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test - public void testModifyConfigOperation() { + public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(ModifyConfigOperation.NAME, oper.getName()); } diff --git a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java index 8e6a603eb..9744d829b 100644 --- a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java +++ b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java @@ -37,13 +37,18 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; +import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.appclcm.AppcLcmBody; import org.onap.policy.appclcm.AppcLcmCommonHeader; import org.onap.policy.appclcm.AppcLcmDmaapWrapper; import org.onap.policy.appclcm.AppcLcmOutput; import org.onap.policy.appclcm.AppcLcmResponseStatus; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -52,8 +57,12 @@ import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.controlloop.policy.Target; +import org.onap.policy.simulators.AppcLcmTopicServer; +import org.onap.policy.simulators.TopicServer; public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { @@ -68,6 +77,16 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { private AppcLcmDmaapWrapper response; private AppcLcmOperation oper; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(MY_SINK, MY_SOURCE); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Sets up. */ @@ -80,6 +99,38 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { oper = new AppcLcmOperation(params, config); } + @After + public void tearDown() { + super.tearDownBasic(); + } + + @SuppressWarnings("rawtypes") + protected TopicServer makeServer(TopicSink sink, TopicSource source) { + return new AppcLcmTopicServer(sink, source); + } + + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + BidirectionalTopicParams opParams = + BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build(); + config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcLcmOperation.SELECTOR_KEYS); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + + oper = new AppcLcmOperation(params, config) { + @Override + protected CompletableFuture<OperationOutcome> startGuardAsync() { + return null; + } + }; + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); diff --git a/models-interactions/model-actors/actor.guard/pom.xml b/models-interactions/model-actors/actor.guard/pom.xml index 99e616471..dc40561d0 100644 --- a/models-interactions/model-actors/actor.guard/pom.xml +++ b/models-interactions/model-actors/actor.guard/pom.xml @@ -69,6 +69,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.onap.policy.models.policy-models-interactions</groupId> + <artifactId>simulators</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> <scope>test</scope> 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 13a241124..3d1538312 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 @@ -35,9 +35,14 @@ import java.util.Map; import java.util.TreeMap; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mock; +import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -45,6 +50,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.models.decisions.concepts.DecisionResponse; +import org.onap.policy.simulators.GuardSimulatorJaxRs; public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { @@ -57,6 +63,25 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { private GuardOperation oper; /** + * Starts the simulator. + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + org.onap.policy.simulators.Util.buildGuardSim(); + + BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("policy/pdpx/v1/") + .hostname("localhost").managed(true).port(org.onap.policy.simulators.Util.GUARDSIM_SERVER_PORT) + .build(); + HttpClientFactoryInstance.getClientFactory().build(clientParams); + } + + @AfterClass + public static void tearDownAfterClass() { + HttpClientFactoryInstance.getClientFactory().destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + } + + /** * Sets up. */ @Before @@ -81,6 +106,37 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { oper = new GuardOperation(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + GuardParams opParams = GuardParams.builder().clientName(MY_CLIENT).path("decision").build(); + config = new GuardConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + oper = new GuardOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + + /** + * Tests "failure" case with simulator. + */ + @Test + public void testFailure() throws Exception { + GuardParams opParams = GuardParams.builder().clientName(MY_CLIENT).path("decision").build(); + config = new GuardConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor) + .payload(Map.of("clname", GuardSimulatorJaxRs.DENY_CLNAME)).build(); + oper = new GuardOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.FAILURE, outcome.getResult()); + } + @Test public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java index ff1881302..daced6e81 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java @@ -39,8 +39,6 @@ import org.onap.policy.sdnc.SdncRequest; public class BandwidthOnDemandOperation extends SdncOperation { public static final String NAME = "BandwidthOnDemand"; - public static final String URI = "/GENERIC-RESOURCE-API:vf-module-topology-operation"; - // fields in the enrichment data public static final String SERVICE_ID_KEY = "service-instance.service-instance-id"; public static final String VNF_ID = "vnfId"; @@ -92,7 +90,7 @@ public class BandwidthOnDemandOperation extends SdncOperation { SdncRequest request = new SdncRequest(); request.setNsInstanceId(serviceInstance); request.setRequestId(context.getRequestId()); - request.setUrl(URI); + request.setUrl("/" + getPath()); SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo(); vnfInfo.setVnfId(context.getEnrichment().get(VNF_ID)); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java index 753da1bb1..2e0d7b855 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java @@ -35,8 +35,6 @@ import org.onap.policy.sdnc.SdncRequest; public class RerouteOperation extends SdncOperation { public static final String NAME = "Reroute"; - public static final String URI = "/GENERIC-RESOURCE-API:network-topology-operation"; - // fields in the enrichment data public static final String SERVICE_ID_KEY = "service-instance.service-instance-id"; public static final String NETWORK_ID_KEY = "network-information.network-id"; @@ -79,7 +77,7 @@ public class RerouteOperation extends SdncOperation { SdncRequest request = new SdncRequest(); request.setNsInstanceId(serviceInstance); request.setRequestId(context.getRequestId()); - request.setUrl(URI); + request.setUrl("/" + getPath()); SdncHealRequest healRequest = new SdncHealRequest(); healRequest.setRequestHeaderInfo(headerInfo); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java index 1aed75ce6..0c0558282 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java @@ -68,7 +68,7 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> { Map<String, Object> headers = makeHeaders(); headers.put("Accept", MediaType.APPLICATION_JSON); - String path = getPath() + request.getUrl(); + String path = getPath(); String url = getClient().getBaseUrl() + path; logMessage(EventType.OUT, CommInfrastructure.REST, url, request); 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 ade25133c..8e26c68f4 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 @@ -24,8 +24,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.Map; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +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; public class BandwidthOnDemandOperationTest extends BasicSdncOperation { @@ -36,6 +42,16 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Set up. */ @@ -46,17 +62,33 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { } @Test - public void testBandwidthOnDemandOperator() { + public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(BandwidthOnDemandOperation.NAME, oper.getName()); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT) + .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build(); + config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + oper = new BandwidthOnDemandOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test public void testMakeRequest() throws Exception { SdncRequest request = oper.makeRequest(1); assertEquals("my-service", request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); - assertEquals(BandwidthOnDemandOperation.URI, request.getUrl()); + assertEquals("/my-path/", request.getUrl()); assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); verifyRequest("bod.json", request, IGNORE_FIELDS); 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 73b81433a..bb1285ea3 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 @@ -33,6 +33,9 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -42,6 +45,7 @@ import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; import org.onap.policy.sdnc.SdncResponseOutput; +import org.onap.policy.simulators.Util; import org.powermock.reflect.Whitebox; /** @@ -73,6 +77,22 @@ public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest> } /** + * Starts the simulator. + */ + protected static void initBeforeClass() throws Exception { + Util.buildSdncSim(); + + BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("restconf/operations/") + .hostname("localhost").managed(true).port(Util.SDNCSIM_SERVER_PORT).build(); + HttpClientFactoryInstance.getClientFactory().build(clientParams); + } + + protected static void destroyAfterClass() { + HttpClientFactoryInstance.getClientFactory().destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + } + + /** * Initializes mocks and sets up. */ public void setUp() throws Exception { 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 30ddd8781..97cdcb054 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 @@ -24,8 +24,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.Map; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +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; public class RerouteOperationTest extends BasicSdncOperation { @@ -36,6 +42,16 @@ public class RerouteOperationTest extends BasicSdncOperation { super(DEFAULT_ACTOR, RerouteOperation.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Set up. */ @@ -45,8 +61,24 @@ public class RerouteOperationTest extends BasicSdncOperation { oper = new RerouteOperation(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT) + .path("GENERIC-RESOURCE-API:network-topology-operation").build(); + config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + oper = new RerouteOperation(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test - public void testRerouteOperator() { + public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(RerouteOperation.NAME, oper.getName()); } @@ -56,7 +88,7 @@ public class RerouteOperationTest extends BasicSdncOperation { SdncRequest request = oper.makeRequest(1); assertEquals("my-service", request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); - assertEquals(RerouteOperation.URI, request.getUrl()); + assertEquals("/my-path/", request.getUrl()); assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); verifyRequest("reroute.json", request, IGNORE_FIELDS); 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 27d7d435c..15f919b21 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 @@ -31,6 +31,8 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import java.util.function.BiConsumer; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -43,6 +45,8 @@ import org.onap.policy.sdnr.PciMessage; import org.onap.policy.sdnr.PciResponse; import org.onap.policy.sdnr.Status; import org.onap.policy.sdnr.util.StatusCodeEnum; +import org.onap.policy.simulators.SdnrTopicServer; +import org.onap.policy.simulators.TopicServer; import org.powermock.reflect.Whitebox; public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation { @@ -86,6 +90,15 @@ public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperatio status.setValue(StatusCodeEnum.SUCCESS.toString()); } + public void tearDown() { + super.tearDownBasic(); + } + + @SuppressWarnings("rawtypes") + protected TopicServer makeServer(TopicSink sink, TopicSource source) { + return new SdnrTopicServer(sink, source); + } + /** * Runs the operation and verifies that the response is successful. * 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 3165d5814..e3e3c9925 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 @@ -30,11 +30,17 @@ import static org.mockito.Mockito.when; 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; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdnr.PciMessage; @@ -46,15 +52,53 @@ public class ModifyConfigOperationTest extends BasicSdnrOperation { super(DEFAULT_ACTOR, ModifyConfigOperation.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + @Before public void setUp() throws Exception { super.setUp(); oper = new ModifyConfigOperation(params, config); } + @After + @Override + public void tearDown() { + super.tearDown(); + } + + + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + BidirectionalTopicParams opParams = + BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build(); + config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, SdnrOperation.SELECTOR_KEYS); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + + oper = new ModifyConfigOperation(params, config) { + @Override + protected CompletableFuture<OperationOutcome> startGuardAsync() { + return null; + } + }; + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } @Test - public void testModifyConfigOperation() { + public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); assertEquals(ModifyConfigOperation.NAME, oper.getName()); } 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 5f6a5df3b..8f58f7d87 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 @@ -27,8 +27,12 @@ import static org.junit.Assert.assertSame; import java.util.Arrays; import org.apache.commons.lang3.tuple.Pair; +import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.sdnr.PciCommonHeader; @@ -39,16 +43,33 @@ public class SdnrOperationTest extends BasicSdnrOperation { private SdnrOperation operation; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * Setup. */ @Before + @Override public void setUp() throws Exception { super.setUp(); operation = new SdnrOperation(params, config) {}; } + @After + @Override + public void tearDown() { + super.tearDown(); + } + @Test public void testSdnrOperation() { assertEquals(DEFAULT_ACTOR, operation.getActorName()); diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java index f33d501b6..e6a3615ad 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java @@ -30,6 +30,9 @@ import java.util.List; import java.util.Map; import org.mockito.Mock; import org.onap.policy.aai.AaiCqResponse; +import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.policy.Target; @@ -81,6 +84,23 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> { } /** + * Starts the simulator. + */ + protected static void initBeforeClass() throws Exception { + org.onap.policy.simulators.Util.buildSoSim(); + + BusTopicParams clientParams = + BusTopicParams.builder().clientName(MY_CLIENT).basePath("").hostname("localhost") + .managed(true).port(org.onap.policy.simulators.Util.SOSIM_SERVER_PORT).build(); + HttpClientFactoryInstance.getClientFactory().build(clientParams); + } + + protected static void destroyAfterClass() { + HttpClientFactoryInstance.getClientFactory().destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + } + + /** * Initializes mocks and sets up. */ public void setUp() throws Exception { 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 1d5d44cc8..918559a20 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 @@ -36,7 +36,9 @@ import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.lang3.tuple.Pair; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.onap.aai.domain.yang.CloudRegion; @@ -45,6 +47,7 @@ import org.onap.aai.domain.yang.ModelVer; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.Tenant; import org.onap.policy.aai.AaiCqResponse; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; @@ -63,6 +66,15 @@ public class VfModuleCreateTest extends BasicSoOperation { super(DEFAULT_ACTOR, VfModuleCreate.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } @Before public void setUp() throws Exception { @@ -70,6 +82,22 @@ public class VfModuleCreateTest extends BasicSoOperation { oper = new VfModuleCreate(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstantiation/v7/serviceInstances") + .pathGet("orchestrationRequests/v5/").build(); + config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + oper = new VfModuleCreate(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); 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 cb2bceffd..16775fe5d 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 @@ -48,7 +48,9 @@ import javax.ws.rs.client.InvocationCallback; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.apache.commons.lang3.tuple.Pair; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; @@ -58,6 +60,7 @@ import org.onap.aai.domain.yang.ModelVer; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.Tenant; import org.onap.policy.aai.AaiCqResponse; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -89,6 +92,15 @@ public class VfModuleDeleteTest extends BasicSoOperation { super(DEFAULT_ACTOR, VfModuleDelete.NAME); } + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } /** * Sets up. @@ -104,6 +116,22 @@ public class VfModuleDeleteTest extends BasicSoOperation { oper = new MyOperation(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7") + .pathGet("orchestrationRequests/v5/").build(); + config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + oper = new VfModuleDelete(params, config); + + outcome = oper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test public void testConstructor() { assertEquals(DEFAULT_ACTOR, oper.getActorName()); diff --git a/models-interactions/model-actors/actor.test/pom.xml b/models-interactions/model-actors/actor.test/pom.xml index c67e64857..16af025cb 100644 --- a/models-interactions/model-actors/actor.test/pom.xml +++ b/models-interactions/model-actors/actor.test/pom.xml @@ -59,6 +59,11 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.onap.policy.models.policy-models-interactions</groupId> + <artifactId>simulators</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.onap.policy.common</groupId> <artifactId>utils-test</artifactId> <version>${policy.common.version}</version> diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java index bba2bc13a..c8b69677f 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java @@ -20,27 +20,50 @@ package org.onap.policy.controlloop.actor.test; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; +import java.util.List; import java.util.function.BiConsumer; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.event.comm.TopicSource; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; +import org.onap.policy.common.endpoints.parameters.TopicParameters; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler; +import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager; import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder; +import org.onap.policy.simulators.TopicServer; +import org.onap.policy.simulators.Util; /** * Superclass for various BidirectionalTopicOperation tests. */ -public class BasicBidirectionalTopicOperation extends BasicOperation { +public abstract class BasicBidirectionalTopicOperation extends BasicOperation { protected static final String MY_SINK = "my-sink"; protected static final String MY_SOURCE = "my-source"; protected static final int TIMEOUT_SEC = 10; protected static final long TIMEOUT_MS = 1000L * TIMEOUT_SEC; + // sink and source used by the TopicServer + private static TopicSink serverSink; + private static TopicSource serverSource; + private static BidirectionalTopicHandler realTopicHandler; + + protected static BidirectionalTopicManager topicMgr = (sink, source) -> { + // note: the sink and source names are swapped for the simulator + assertEquals(serverSource.getTopic(), sink); + assertEquals(serverSink.getTopic(), source); + return realTopicHandler; + }; + @Captor protected ArgumentCaptor<BiConsumer<String, StandardCoderObject>> listenerCaptor; @@ -51,6 +74,9 @@ public class BasicBidirectionalTopicOperation extends BasicOperation { @Mock protected BidirectionalTopicConfig config; + @SuppressWarnings("rawtypes") + private TopicServer topicServer; + /** * Constructs the object using a default actor and operation name. */ @@ -69,14 +95,75 @@ public class BasicBidirectionalTopicOperation extends BasicOperation { } /** + * Starts the topic. + */ + protected static void initBeforeClass(String sinkTopic, String sourceTopic) throws Exception { + + Util.buildDmaapSim(); + + // note: the sink and source names are swapped for the simulator + TopicParameters ptopic = new TopicParameters(); + ptopic.setTopic(sourceTopic); + ptopic.setManaged(true); + ptopic.setServers(List.of("localhost")); + ptopic.setTopicCommInfrastructure("dmaap"); + ptopic.setFetchTimeout(500); + serverSink = TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0); + + ptopic.setTopic(sinkTopic); + serverSource = TopicEndpointManager.getManager().addTopicSources(List.of(ptopic)).get(0); + + serverSink.start(); + serverSource.start(); + + if (!sinkTopic.equals(sourceTopic)) { + // sink and source are different - create other ends for the actor + initActorTopics(sinkTopic, sourceTopic, ptopic); + } + + realTopicHandler = new BidirectionalTopicHandler(sinkTopic, sourceTopic); + realTopicHandler.start(); + } + + private static void initActorTopics(String sinkTopic, String sourceTopic, TopicParameters ptopic) { + // create sink and source for the actor, too + ptopic.setTopic(sinkTopic); + TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0).start(); + + ptopic.setTopic(sourceTopic); + TopicEndpointManager.getManager().addTopicSources(List.of(ptopic)).get(0).start(); + } + + protected static void destroyAfterClass() { + TopicEndpointManager.getManager().shutdown(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + HttpClientFactoryInstance.getClientFactory().destroy(); + } + + /** * Initializes mocks and sets up. */ @Override public void setUpBasic() { super.setUpBasic(); + topicServer = makeServer(serverSink, serverSource); initConfig(); } + public void tearDownBasic() { + topicServer.shutdown(); + } + + /** + * Makes a simulator for the given sink and source. + * + * @param sink topic to which the simulator should publish responses + * @param source topic from which the simulator should receive messages + * @return a new topic server/simulator + */ + @SuppressWarnings("rawtypes") + protected abstract TopicServer makeServer(TopicSink sink, TopicSource source); + /** * Initializes a configuration. */ diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java index d6940d299..3b1871f20 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.TreeMap; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; import javax.ws.rs.core.Response; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -59,6 +60,12 @@ public class BasicOperation { protected static final String DEFAULT_OPERATION = "default-operation"; protected static final String TARGET_ENTITY = "my-target"; + protected static final Executor blockingExecutor = command -> { + Thread thread = new Thread(command); + thread.setDaemon(true); + thread.start(); + }; + protected final String actorName; protected final String operationName; protected Coder coder = new StandardCoder(); diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java index 101f130a3..afb8f075e 100644 --- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java @@ -28,12 +28,18 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import java.util.function.BiConsumer; +import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.utils.coder.StandardCoderObject; +import org.onap.policy.simulators.TopicServer; public class BasicBidirectionalTopicOperationTest { private static final String ACTOR = "my-actor"; @@ -44,6 +50,16 @@ public class BasicBidirectionalTopicOperationTest { private BasicBidirectionalTopicOperation oper; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + BasicBidirectionalTopicOperation.initBeforeClass(BasicBidirectionalTopicOperation.MY_SINK, + BasicBidirectionalTopicOperation.MY_SOURCE); + } + + @AfterClass + public static void tearDownAfterClass() { + BasicBidirectionalTopicOperation.destroyAfterClass(); + } /** * Sets up. @@ -52,13 +68,28 @@ public class BasicBidirectionalTopicOperationTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - oper = new BasicBidirectionalTopicOperation(ACTOR, OPERATION); + oper = new MyOperation(ACTOR, OPERATION); oper.setUpBasic(); } + @After + public void tearDown() { + oper.tearDownBasic(); + } + + @Test + public void testTopicMgr() { + assertNotNull(BasicBidirectionalTopicOperation.topicMgr.getTopicHandler( + BasicBidirectionalTopicOperation.MY_SINK, BasicBidirectionalTopicOperation.MY_SOURCE)); + } + @Test public void testBasicBidirectionalTopicOperation() { - oper = new BasicBidirectionalTopicOperation(); + oper.tearDownBasic(); + + oper = new MyOperation(); + oper.setUpBasic(); + assertEquals(BasicOperation.DEFAULT_ACTOR, oper.actorName); assertEquals(BasicOperation.DEFAULT_OPERATION, oper.operationName); } @@ -101,4 +132,31 @@ public class BasicBidirectionalTopicOperationTest { assertThatIllegalArgumentException().isThrownBy(() -> oper.provideResponse(listener, "{invalid json")) .withMessage("response is not a Map"); } + + private static class MyOperation extends BasicBidirectionalTopicOperation { + public MyOperation() { + super(); + } + + /** + * Constructs the object. + * + * @param actor actor name + * @param operation operation name + */ + public MyOperation(String actor, String operation) { + super(actor, operation); + } + + @Override + @SuppressWarnings("rawtypes") + protected TopicServer makeServer(TopicSink sink, TopicSource source) { + return new TopicServer<String>(sink, source, null, String.class) { + @Override + protected String process(String request) { + return null; + } + }; + } + } } diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java index 2c5cf8eda..e3df16d9b 100644 --- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java +++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java @@ -20,6 +20,7 @@ package org.onap.policy.controlloop.actor.vfc; +import java.util.Map; import java.util.concurrent.CompletableFuture; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; @@ -47,7 +48,10 @@ public class Restart extends VfcOperation { String path = getPath() + pair.getLeft(); String url = getClient().getBaseUrl() + path; - return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, null)); + Map<String, Object> headers = makeHeaders(); + headers.put("Accept", MediaType.APPLICATION_JSON); + + return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers)); } /** @@ -58,7 +62,7 @@ public class Restart extends VfcOperation { protected Pair<String, VfcRequest> makeRequest() { VfcRequest request = super.constructVfcRequest(); - String requestUrl = "/ns/" + request.getNsInstanceId() + "/heal"; + String requestUrl = "/" + request.getNsInstanceId() + "/heal"; return Pair.of(requestUrl, request); } } diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java index be62bbb3f..47371d2b3 100644 --- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java +++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java @@ -23,7 +23,11 @@ package org.onap.policy.controlloop.actor.vfc; import static org.mockito.Mockito.when; import org.mockito.Mock; +import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.controlloop.actor.test.BasicHttpOperation; +import org.onap.policy.simulators.Util; import org.onap.policy.vfc.VfcRequest; import org.onap.policy.vfc.VfcResponse; @@ -55,6 +59,22 @@ public abstract class BasicVfcOperation extends BasicHttpOperation<VfcRequest> { } /** + * Starts the simulator. + */ + protected static void initBeforeClass() throws Exception { + Util.buildVfcSim(); + + BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("api/nslcm/v1/") + .hostname("localhost").managed(true).port(Util.VFCSIM_SERVER_PORT).build(); + HttpClientFactoryInstance.getClientFactory().build(clientParams); + } + + protected static void destroyAfterClass() { + HttpClientFactoryInstance.getClientFactory().destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + } + + /** * Initializes mocks and sets up. */ public void setUp() throws Exception { 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 dd6c4cf69..5fe4973ce 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 @@ -25,14 +25,28 @@ import static org.junit.Assert.assertNotNull; import java.util.concurrent.CompletableFuture; import org.apache.commons.lang3.tuple.Pair; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +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; public class RestartTest extends BasicVfcOperation { private Restart restartOper; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + initBeforeClass(); + } + + @AfterClass + public static void tearDownAfterClass() { + destroyAfterClass(); + } + /** * setup restart operation. */ @@ -45,8 +59,23 @@ public class RestartTest extends BasicVfcOperation { restartOper = new Restart(params, config); } + /** + * Tests "success" case with simulator. + */ + @Test + public void testSuccess() throws Exception { + VfcParams opParams = VfcParams.builder().clientName(MY_CLIENT).path("ns").pathGet("jobs").maxGets(1).build(); + config = new VfcConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); + + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); + restartOper = new Restart(params, config); + + outcome = restartOper.start().get(); + assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + } + @Test - public void testStartOperationAsync() { + public void testConstructor() { CompletableFuture<OperationOutcome> futureRes = restartOper.startOperationAsync(1, outcome); assertNotNull(futureRes); assertEquals(0, restartOper.getGetCount()); 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 4fe0cd4a6..4d98b97c9 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 @@ -44,8 +44,8 @@ public class VfcOperationTest extends BasicVfcOperation { /** * setUp. */ - @Override @Before + @Override public void setUp() throws Exception { super.setUp(); @@ -84,7 +84,7 @@ public class VfcOperationTest extends BasicVfcOperation { response.setJobId("sampleJobId"); CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertFalse(future2.isDone()); - //assertSame(outcome, future2.get()); TODO Hanging + // assertSame(outcome, future2.get()); TODO Hanging assertEquals(PolicyResult.SUCCESS, outcome.getResult()); response.getResponseDescriptor().setStatus("FinisHeD"); @@ -100,11 +100,12 @@ public class VfcOperationTest extends BasicVfcOperation { assertEquals(PolicyResult.FAILURE, outcome.getResult()); // 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());*/ + /* + * 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()); + */ } @Test @@ -115,7 +116,9 @@ public class VfcOperationTest extends BasicVfcOperation { VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class); Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor); - Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE"); // TODO use actual request state value + + // TODO use actual request state value + Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE"); assertNotNull(oper.getRequestState(mockResponse)); } diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParams.java index 57270ac65..be1f0f8c2 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParams.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParams.java @@ -32,7 +32,6 @@ import org.onap.policy.common.parameters.annotations.NotNull; * Parameters used by Operators that connect to a server via HTTP. */ @NotNull -@NotBlank @Data @SuperBuilder(toBuilder = true) public class HttpParams { @@ -40,6 +39,7 @@ public class HttpParams { /** * Name of the HttpClient, as found in the HttpClientFactory. */ + @NotBlank private String clientName; /** diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java index 8d4d44685..f4c6a2089 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java @@ -54,6 +54,10 @@ public class HttpParamsTest { testValidateField("timeoutSec", "minimum", bldr -> bldr.timeoutSec(-1)); // check edge cases + assertFalse(params.toBuilder().clientName("").build().validate(CONTAINER).isValid()); + + assertTrue(params.toBuilder().path("").build().validate(CONTAINER).isValid()); + assertFalse(params.toBuilder().timeoutSec(0).build().validate(CONTAINER).isValid()); assertTrue(params.toBuilder().timeoutSec(1).build().validate(CONTAINER).isValid()); } |