X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-actors%2Factor.so%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontrolloop%2Factor%2Fso%2FVfModuleDeleteTest.java;h=3bce9b0f8ccd8c17e0cbbfc8f7ba99d59d5427d5;hb=19ef8b24a98c09a349e6ae7309f535a0135463f6;hp=300d73b539a74fadd49f1e8522ee2e83ebcff090;hpb=6b29d2c19e288148171db0c0e446e18dcd46effd;p=policy%2Fmodels.git 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 300d73b53..3bce9b0f8 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 @@ -24,9 +24,7 @@ package org.onap.policy.controlloop.actor.so; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 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.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -47,7 +45,6 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import javax.ws.rs.client.InvocationCallback; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -60,10 +57,8 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.GenericVnf; -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; @@ -77,8 +72,6 @@ import org.onap.policy.so.SoResponse; public class VfModuleDeleteTest extends BasicSoOperation { private static final String EXPECTED_EXCEPTION = "expected exception"; - private static final String MODEL_NAME2 = "my-model-name-B"; - private static final String MODEL_VERS2 = "my-model-version-B"; private static final String SVC_INSTANCE_ID = "my-service-instance-id"; private static final String VNF_ID = "my-vnf-id"; @@ -119,6 +112,8 @@ public class VfModuleDeleteTest extends BasicSoOperation { configureResponse(coder.encode(response)); oper = new MyOperation(params, config); + + loadProperties(); } /** @@ -130,42 +125,11 @@ public class VfModuleDeleteTest extends BasicSoOperation { .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); - - oper = new VfModuleDelete(params, config); - - outcome = oper.start().get(); - assertEquals(OperationResult.SUCCESS, outcome.getResult()); - assertTrue(outcome.getResponse() instanceof SoResponse); - } - - /** - * Tests "success" case with simulator, using properties instead of custom query data. - */ - @Test - public void testSuccessViaProperties() throws Exception { - HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7") - .pollPath("orchestrationRequests/v5/").maxPolls(2).build(); - config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory()); - params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).preprocessed(true).build(); - params.getContext().removeProperty(AaiCqResponse.CONTEXT_KEY); oper = new VfModuleDelete(params, config); - // set the properties - ServiceInstance instance = new ServiceInstance(); - instance.setServiceInstanceId(SVC_INSTANCE_ID); - oper.setProperty(OperationProperties.AAI_SERVICE, instance); - - GenericVnf vnf = new GenericVnf(); - vnf.setVnfId(VNF_ID); - oper.setProperty(OperationProperties.AAI_VNF, vnf); - - oper.setProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, new CloudRegion()); - oper.setProperty(OperationProperties.AAI_DEFAULT_TENANT, new Tenant()); - - oper.setProperty(OperationProperties.DATA_VF_COUNT, VF_COUNT); + loadProperties(); // run the operation outcome = oper.start().get(); @@ -201,76 +165,8 @@ public class VfModuleDeleteTest extends BasicSoOperation { // @formatter:on } - @Test - public void testStartPreprocessorAsync() throws Exception { - // insert CQ data so it's there for the check - context.setProperty(AaiCqResponse.CONTEXT_KEY, makeCqResponse()); - - AtomicBoolean guardStarted = new AtomicBoolean(); - - oper = new MyOperation(params, config) { - @Override - protected CompletableFuture startGuardAsync() { - guardStarted.set(true); - return super.startGuardAsync(); - } - }; - - CompletableFuture future3 = oper.startPreprocessorAsync(); - assertNotNull(future3); - assertTrue(guardStarted.get()); - } - - /** - * Tests startPreprocessorAsync(), when preprocessing is disabled. - */ - @Test - public void testStartPreprocessorAsyncDisabled() { - params = params.toBuilder().preprocessed(true).build(); - assertNull(new MyOperation(params, config).startPreprocessorAsync()); - } - - @Test - public void testStartGuardAsync() throws Exception { - // remove CQ data so it's forced to query - context.removeProperty(AaiCqResponse.CONTEXT_KEY); - - CompletableFuture future2 = oper.startPreprocessorAsync(); - assertTrue(executor.runAll(100)); - assertFalse(future2.isDone()); - - provideCqResponse(makeCqResponse()); - assertTrue(executor.runAll(100)); - assertTrue(future2.isDone()); - assertEquals(OperationResult.SUCCESS, future2.get().getResult()); - } - - @Test - public void testMakeGuardPayload() { - final int origCount = 30; - oper.setVfCount(origCount); - - CompletableFuture future2 = oper.startPreprocessorAsync(); - assertTrue(executor.runAll(100)); - assertTrue(future2.isDone()); - - // get the payload from the request - ArgumentCaptor captor = ArgumentCaptor.forClass(ControlLoopOperationParams.class); - verify(guardOperator).buildOperation(captor.capture()); - - Map payload = captor.getValue().getPayload(); - assertNotNull(payload); - - Integer newCount = (Integer) payload.get(VfModuleDelete.PAYLOAD_KEY_VF_COUNT); - assertNotNull(newCount); - assertEquals(origCount - 1, newCount.intValue()); - } - @Test public void testStartOperationAsync_testSuccessfulCompletion() throws Exception { - final int origCount = 30; - oper.setVfCount(origCount); - // use a real executor params = params.toBuilder().executor(ForkJoinPool.commonPool()).build(); @@ -281,6 +177,11 @@ public class VfModuleDeleteTest extends BasicSoOperation { } }; + loadProperties(); + + final int origCount = 30; + oper.setVfCount(origCount); + CompletableFuture future2 = oper.start(); outcome = future2.get(5, TimeUnit.SECONDS); @@ -315,6 +216,8 @@ public class VfModuleDeleteTest extends BasicSoOperation { } }; + loadProperties(); + CompletableFuture future2 = oper.start(); outcome = future2.get(5, TimeUnit.SECONDS); @@ -454,32 +357,6 @@ public class VfModuleDeleteTest extends BasicSoOperation { assertNotNull(new MyOperation(params, config).makeHttpClient()); } - - @Override - protected void makeContext() { - super.makeContext(); - - AaiCqResponse cq = mock(AaiCqResponse.class); - - GenericVnf vnf = new GenericVnf(); - when(cq.getGenericVnfByVfModuleModelInvariantId(MODEL_INVAR_ID)).thenReturn(vnf); - vnf.setVnfId(VNF_ID); - - ServiceInstance instance = new ServiceInstance(); - when(cq.getServiceInstance()).thenReturn(instance); - instance.setServiceInstanceId(SVC_INSTANCE_ID); - - when(cq.getDefaultTenant()).thenReturn(new Tenant()); - when(cq.getDefaultCloudRegion()).thenReturn(new CloudRegion()); - - ModelVer modelVers = new ModelVer(); - when(cq.getModelVerByVersionId(any())).thenReturn(modelVers); - modelVers.setModelName(MODEL_NAME2); - modelVers.setModelVersion(MODEL_VERS2); - - params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq); - } - private void initHostPort() { when(client.getBaseUrl()).thenReturn("http://my-host:6969/"); } @@ -505,4 +382,20 @@ public class VfModuleDeleteTest extends BasicSoOperation { return javaClient; } } + + private void loadProperties() { + // set the properties + ServiceInstance instance = new ServiceInstance(); + instance.setServiceInstanceId(SVC_INSTANCE_ID); + oper.setProperty(OperationProperties.AAI_SERVICE, instance); + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId(VNF_ID); + oper.setProperty(OperationProperties.AAI_VNF, vnf); + + oper.setProperty(OperationProperties.AAI_DEFAULT_CLOUD_REGION, new CloudRegion()); + oper.setProperty(OperationProperties.AAI_DEFAULT_TENANT, new Tenant()); + + oper.setProperty(OperationProperties.DATA_VF_COUNT, VF_COUNT); + } }