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/actor.sdnc/src | |
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/actor.sdnc/src')
6 files changed, 91 insertions, 11 deletions
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); |