diff options
Diffstat (limited to 'models-interactions/model-actors/actor.sdnc/src/test/java/org/onap')
3 files changed, 95 insertions, 8 deletions
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 56b64e491..f80299f93 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 @@ -32,6 +32,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; @@ -39,6 +40,10 @@ import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; public class BandwidthOnDemandOperationTest extends BasicSdncOperation { + private static final String MY_SERVICE = "my-service"; + private static final String MY_VNF = "my-vnf"; + private static final String MY_BANDWIDTH = "my-bandwidth"; + private static final String MY_CHANGE_TIME = "my-change-time"; private BandwidthOnDemandOperation oper; @@ -76,7 +81,7 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { // @formatter:off assertThat(oper.getPropertyNames()).isEqualTo( List.of( - OperationProperties.ENRICHMENT_SERVICE_INSTANCE_ID, + OperationProperties.ENRICHMENT_SERVICE_ID, OperationProperties.ENRICHMENT_BANDWIDTH, OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, OperationProperties.ENRICHMENT_VNF_ID)); @@ -93,9 +98,14 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { .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(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build(); oper = new BandwidthOnDemandOperation(params, config); + oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); + oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH); + oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME); + oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF); + outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SdncResponse); @@ -105,7 +115,7 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { public void testMakeRequest() throws Exception { oper.generateSubRequestId(1); SdncRequest request = oper.makeRequest(1); - assertEquals("my-service", request.getNsInstanceId()); + assertEquals(MY_SERVICE, request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); assertEquals("/my-path/", request.getUrl()); assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); @@ -119,9 +129,26 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS); } + @Test + public void testMakeRequestViaProperties() throws Exception { + // clear the enrichment data and remake the operation + event.setAai(null); + context = new ControlLoopEventContext(event); + params = params.toBuilder().context(context).build(); + oper = new BandwidthOnDemandOperation(params, config); + + oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); + oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH, MY_BANDWIDTH); + oper.setProperty(OperationProperties.ENRICHMENT_BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME); + oper.setProperty(OperationProperties.ENRICHMENT_VNF_ID, MY_VNF); + + verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS); + } + @Override protected Map<String, String> makeEnrichment() { - return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, "my-service", BandwidthOnDemandOperation.VNF_ID, - "my-vnf"); + return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, MY_SERVICE, BandwidthOnDemandOperation.BANDWIDTH, + MY_BANDWIDTH, BandwidthOnDemandOperation.BANDWIDTH_CHANGE_TIME, MY_CHANGE_TIME, + BandwidthOnDemandOperation.VNF_ID, MY_VNF); } } 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 9f06805f6..b71e567bf 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 @@ -32,6 +32,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; import org.onap.policy.controlloop.policy.PolicyResult; @@ -39,6 +40,8 @@ import org.onap.policy.sdnc.SdncRequest; import org.onap.policy.sdnc.SdncResponse; public class RerouteOperationTest extends BasicSdncOperation { + private static final String MY_SERVICE = "my-service"; + private static final String MY_NETWORK = "my-network"; private RerouteOperation oper; @@ -74,9 +77,12 @@ public class RerouteOperationTest extends BasicSdncOperation { .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(); + params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build(); oper = new RerouteOperation(params, config); + oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); + oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK); + outcome = oper.start().get(); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof SdncResponse); @@ -102,7 +108,7 @@ public class RerouteOperationTest extends BasicSdncOperation { public void testMakeRequest() throws Exception { oper.generateSubRequestId(1); SdncRequest request = oper.makeRequest(1); - assertEquals("my-service", request.getNsInstanceId()); + assertEquals(MY_SERVICE, request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); assertEquals("/my-path/", request.getUrl()); assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); @@ -117,8 +123,22 @@ public class RerouteOperationTest extends BasicSdncOperation { verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS); } + @Test + public void testMakeRequestViaProperties() throws Exception { + // clear the enrichment data and remake the operation + event.setAai(null); + context = new ControlLoopEventContext(event); + params = params.toBuilder().context(context).build(); + oper = new RerouteOperation(params, config); + + oper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, MY_SERVICE); + oper.setProperty(OperationProperties.ENRICHMENT_NETWORK_ID, MY_NETWORK); + + verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS); + } + @Override protected Map<String, String> makeEnrichment() { - return Map.of(RerouteOperation.SERVICE_ID_KEY, "my-service", RerouteOperation.NETWORK_ID_KEY, "my-network"); + return Map.of(RerouteOperation.SERVICE_ID_KEY, MY_SERVICE, RerouteOperation.NETWORK_ID_KEY, MY_NETWORK); } } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java index fb9f71b05..4ba12c6ca 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java @@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.Collections; @@ -30,6 +31,7 @@ import java.util.Map; import java.util.TreeMap; import org.junit.Before; import org.junit.Test; +import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.sdnc.SdncHealRequest; import org.onap.policy.sdnc.SdncHealRequestHeaderInfo; import org.onap.policy.sdnc.SdncRequest; @@ -101,6 +103,44 @@ public class SdncOperationTest extends BasicSdncOperation { assertFalse(oper.isSuccess(null, response)); } + @Test + public void testGetOptProperty() { + // in neither property nor enrichment + assertNull(oper.getOptProperty("propA", "propA2")); + + // both - should choose the property + remakeOper(Map.of("propB2", "valueB2")); + oper.setProperty("propB", "valueB"); + assertEquals("valueB", oper.getOptProperty("propB", "propB2")); + + // both - should choose the property, even if it's null + remakeOper(Map.of("propC2", "valueC2")); + oper.setProperty("propC", null); + assertNull(oper.getOptProperty("propC", "propC2")); + + // only in enrichment data + remakeOper(Map.of("propD2", "valueD2")); + assertEquals("valueD2", oper.getOptProperty("propD", "propD2")); + } + + /** + * Remakes the operation, with the specified A&AI enrichment data. + * + * @param aai A&AI enrichment data + */ + private void remakeOper(Map<String, String> aai) { + event.setAai(aai); + context = new ControlLoopEventContext(event); + params = params.toBuilder().context(context).build(); + + oper = new SdncOperation(params, config, Collections.emptyList()) { + @Override + protected SdncRequest makeRequest(int attempt) { + return request; + } + }; + } + @Override protected Map<String, String> makeEnrichment() { return new TreeMap<>(); |