aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/test/java')
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java7
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java200
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java162
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java159
4 files changed, 53 insertions, 475 deletions
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 d2e2872d5..4b05daa23 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
@@ -20,7 +20,6 @@
package org.onap.policy.controlloop.actor.so;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.util.Collections;
@@ -29,7 +28,6 @@ import java.util.LinkedList;
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;
@@ -174,9 +172,4 @@ public abstract class BasicSoOperation extends BasicHttpOperation {
return payload;
}
-
- protected AaiCqResponse makeCqResponse() {
- when(cqResponse.getVfModuleCount(any(), any(), any())).thenReturn(VF_COUNT);
- return cqResponse;
- }
}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
index e9a49545e..6f4ac0ed3 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
@@ -24,12 +24,10 @@ package org.onap.policy.controlloop.actor.so;
import static org.assertj.core.api.Assertions.assertThatCode;
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.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.LocalDateTime;
@@ -37,22 +35,11 @@ import java.time.Month;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-import java.util.function.BiConsumer;
-import java.util.function.Supplier;
import org.junit.Before;
import org.junit.Test;
-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.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.so.SoModelInfo;
@@ -63,13 +50,8 @@ import org.onap.policy.so.SoResponse;
public class SoOperationTest extends BasicSoOperation {
- private static final String VF_COUNT_KEY = SoConstants.VF_COUNT_PREFIX
- + "[my-model-customization-id][my-model-invariant-id][my-model-version-id]";
-
private static final List<String> PROP_NAMES = Collections.emptyList();
- private static final String VERSION_ID = "1.2.3";
-
private SoOperation oper;
/**
@@ -120,77 +102,6 @@ public class SoOperationTest extends BasicSoOperation {
}
@Test
- public void testStartPreprocessorAsync() {
- assertNotNull(oper.startPreprocessorAsync());
- }
-
- @Test
- public void testObtainVfCount_testGetVfCount_testSetVfCount() throws Exception {
- // insert CQ data so it's there for the check
- context.setProperty(AaiCqResponse.CONTEXT_KEY, makeCqResponse());
-
- // shouldn't actually need to do anything
- assertNull(oper.obtainVfCount());
-
- // verify that the count was stored
- Integer vfcount = context.getProperty(VF_COUNT_KEY);
- assertEquals(VF_COUNT, vfcount);
- assertEquals(VF_COUNT.intValue(), oper.getVfCount());
-
- // change the count and then verify that it isn't overwritten by another call
- oper.setVfCount(VF_COUNT + 1);
-
- assertNull(oper.obtainVfCount());
- vfcount = context.getProperty(VF_COUNT_KEY);
- assertEquals(VF_COUNT + 1, vfcount.intValue());
- assertEquals(VF_COUNT + 1, oper.getVfCount());
- }
-
- /**
- * Tests the VF Count methods when properties are being used.
- * @throws Exception if an error occurs
- */
- @Test
- public void testGetVfCount_testSetVfCount_ViaProperties() throws Exception {
- oper.setProperty(OperationProperties.DATA_VF_COUNT, VF_COUNT);
-
- // verify that the count was stored
- assertEquals(VF_COUNT.intValue(), oper.getVfCount());
-
- oper.setVfCount(VF_COUNT + 1);
-
- int count = oper.getProperty(OperationProperties.DATA_VF_COUNT);
- assertEquals(VF_COUNT + 1, count);
- assertEquals(VF_COUNT + 1, oper.getVfCount());
- }
-
- /**
- * Tests obtainVfCount() when it actually has to query.
- */
- @Test
- public void testObtainVfCountQuery() throws Exception {
- CompletableFuture<OperationOutcome> future2 = oper.obtainVfCount();
- assertNotNull(future2);
- assertTrue(executor.runAll(100));
-
- // not done yet
- assertFalse(future2.isDone());
-
- provideCqResponse(makeCqResponse());
-
- assertTrue(executor.runAll(100));
- assertTrue(future2.isDone());
- assertEquals(OperationResult.SUCCESS, future2.get().getResult());
-
- // verify that the count was stored
- Integer vfcount = context.getProperty(VF_COUNT_KEY);
- assertEquals(VF_COUNT, vfcount);
-
- // repeat - shouldn't need to do anything now
- assertNull(oper.obtainVfCount());
- }
-
- @Test
public void testGetRequestState() {
SoResponse resp = new SoResponse();
assertNull(oper.getRequestState(resp));
@@ -295,117 +206,6 @@ public class SoOperationTest extends BasicSoOperation {
}
@Test
- public void testGetItem() {
- AaiCqResponse cq = mock(AaiCqResponse.class);
- params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq);
-
- // in neither property nor custom query
- assertThatIllegalArgumentException().isThrownBy(() -> oper.getItem("propA", cq2 -> null, "not found"))
- .withMessage("not found");
-
- // only in custom query
- assertEquals("valueB", oper.getItem("propB", cq2 -> "valueB", "failureB"));
-
- // both - should choose the property
- oper.setProperty("propC", "valueC");
- assertEquals("valueC", oper.getItem("propC", cq2 -> "valueC2", "failureC"));
-
- // both - should choose the property, even if it's null
- oper.setProperty("propD", null);
- assertNull(oper.getItem("propD", cq2 -> "valueD2", "failureD"));
- }
-
- @Test
- public void testGetVnfItem() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_VNF, GenericVnf::new,
- (cq, instance) -> when(cq.getGenericVnfByVfModuleModelInvariantId(MODEL_INVAR_ID)).thenReturn(instance),
- () -> oper.getVnfItem(oper.prepareSoModelInfo()),
- "missing generic VNF");
- // @formatter:on
- }
-
- @Test
- public void testGetServiceInstance() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_SERVICE, ServiceInstance::new,
- (cq, instance) -> when(cq.getServiceInstance()).thenReturn(instance),
- () -> oper.getServiceInstance(),
- "missing VNF Service Item");
- // @formatter:on
- }
-
- @Test
- public void testGetDefaultTenant() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_DEFAULT_TENANT, Tenant::new,
- (cq, tenant) -> when(cq.getDefaultTenant()).thenReturn(tenant),
- () -> oper.getDefaultTenant(),
- "missing Default Tenant Item");
- // @formatter:on
- }
-
- @Test
- public void testGetVnfModel() {
- GenericVnf vnf = new GenericVnf();
- vnf.setModelVersionId(VERSION_ID);
-
- // @formatter:off
- verifyItems(OperationProperties.AAI_VNF_MODEL, ModelVer::new,
- (cq, model) -> when(cq.getModelVerByVersionId(VERSION_ID)).thenReturn(model),
- () -> oper.getVnfModel(vnf),
- "missing generic VNF Model");
- // @formatter:on
- }
-
- @Test
- public void testGetServiceModel() {
- ServiceInstance service = new ServiceInstance();
- service.setModelVersionId(VERSION_ID);
-
- // @formatter:off
- verifyItems(OperationProperties.AAI_SERVICE_MODEL, ModelVer::new,
- (cq, model) -> when(cq.getModelVerByVersionId(VERSION_ID)).thenReturn(model),
- () -> oper.getServiceModel(service),
- "missing Service Model");
- // @formatter:on
- }
-
- @Test
- public void testGetDefaultCloudRegion() {
- // @formatter:off
- verifyItems(OperationProperties.AAI_DEFAULT_CLOUD_REGION, CloudRegion::new,
- (cq, region) -> when(cq.getDefaultCloudRegion()).thenReturn(region),
- () -> oper.getDefaultCloudRegion(),
- "missing Default Cloud Region");
- // @formatter:on
- }
-
- private <T> void verifyItems(String propName, Supplier<T> maker, BiConsumer<AaiCqResponse, T> setter,
- Supplier<T> getter, String errmsg) {
-
- AaiCqResponse cq = mock(AaiCqResponse.class);
- params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq);
-
- // in neither property nor custom query
- assertThatIllegalArgumentException().isThrownBy(getter::get).withMessage(errmsg);
-
- // only in custom query
- final T item1 = maker.get();
- setter.accept(cq, item1);
- assertSame(item1, getter.get());
-
- // both - should choose the property
- final T item2 = maker.get();
- oper.setProperty(propName, item2);
- assertSame(item2, getter.get());
-
- // both - should choose the property, even if it's null
- oper.setProperty(propName, null);
- assertNull(getter.get());
- }
-
- @Test
public void testGetCoder() throws CoderException {
Coder opcoder = oper.getCoder();
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 9d4d00908..8dca7c844 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
@@ -24,39 +24,30 @@ 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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
-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 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;
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;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
import org.onap.policy.so.SoRequest;
@@ -86,11 +77,15 @@ public class VfModuleCreateTest extends BasicSoOperation {
destroyAfterClass();
}
- @Override
+ /**
+ * Sets up.
+ */
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
oper = new VfModuleCreate(params, config);
+ loadProperties();
}
/**
@@ -103,50 +98,11 @@ public class VfModuleCreateTest extends BasicSoOperation {
.maxPolls(2).build();
config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
- params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
-
- oper = new VfModuleCreate(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("serviceInstantiation/v7/serviceInstances").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 VfModuleCreate(params, config);
- // set the properties
- ServiceInstance instance = new ServiceInstance();
- instance.setServiceInstanceId(SVC_INSTANCE_ID);
- oper.setProperty(OperationProperties.AAI_SERVICE, instance);
-
- ModelVer modelVers = new ModelVer();
- modelVers.setModelName(MODEL_NAME2);
- modelVers.setModelVersion(MODEL_VERS2);
-
- oper.setProperty(OperationProperties.AAI_SERVICE_MODEL, modelVers);
- oper.setProperty(OperationProperties.AAI_VNF_MODEL, modelVers);
-
- 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();
@@ -185,75 +141,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
}
@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 VfModuleCreate(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return super.startGuardAsync();
- }
- };
-
- CompletableFuture<OperationOutcome> 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 VfModuleCreate(params, config).startPreprocessorAsync());
- }
-
- @Test
- public void testStartGuardAsync() throws Exception {
- // remove CQ data so it's forced to query
- context.removeProperty(AaiCqResponse.CONTEXT_KEY);
-
- CompletableFuture<OperationOutcome> 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<OperationOutcome> future2 = oper.startPreprocessorAsync();
- assertTrue(executor.runAll(100));
- assertTrue(future2.isDone());
-
- // get the payload from the request
- ArgumentCaptor<ControlLoopOperationParams> captor = ArgumentCaptor.forClass(ControlLoopOperationParams.class);
- verify(guardOperator).buildOperation(captor.capture());
-
- Map<String, Object> payload = captor.getValue().getPayload();
- assertNotNull(payload);
-
- Integer newCount = (Integer) payload.get(VfModuleCreate.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);
-
when(client.post(any(), any(), any(), any())).thenAnswer(provideResponse(rawResponse));
// use a real executor
@@ -266,6 +154,11 @@ public class VfModuleCreateTest extends BasicSoOperation {
}
};
+ loadProperties();
+
+ final int origCount = 30;
+ oper.setVfCount(origCount);
+
CompletableFuture<OperationOutcome> future2 = oper.start();
outcome = future2.get(5, TimeUnit.SECONDS);
@@ -298,6 +191,8 @@ public class VfModuleCreateTest extends BasicSoOperation {
}
};
+ loadProperties();
+
CompletableFuture<OperationOutcome> future2 = oper.start();
outcome = future2.get(5, TimeUnit.SECONDS);
@@ -317,29 +212,26 @@ public class VfModuleCreateTest extends BasicSoOperation {
verifyRequest("vfModuleCreate.json", pair.getRight());
}
-
- @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);
-
+ private void loadProperties() {
+ // set the properties
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());
+ oper.setProperty(OperationProperties.AAI_SERVICE, instance);
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);
+ oper.setProperty(OperationProperties.AAI_SERVICE_MODEL, modelVers);
+ oper.setProperty(OperationProperties.AAI_VNF_MODEL, modelVers);
+
+ 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);
}
}
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();
@@ -202,75 +166,7 @@ public class VfModuleDeleteTest extends BasicSoOperation {
}
@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<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return super.startGuardAsync();
- }
- };
-
- CompletableFuture<OperationOutcome> 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<OperationOutcome> 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<OperationOutcome> future2 = oper.startPreprocessorAsync();
- assertTrue(executor.runAll(100));
- assertTrue(future2.isDone());
-
- // get the payload from the request
- ArgumentCaptor<ControlLoopOperationParams> captor = ArgumentCaptor.forClass(ControlLoopOperationParams.class);
- verify(guardOperator).buildOperation(captor.capture());
-
- Map<String, Object> 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<OperationOutcome> future2 = oper.start();
outcome = future2.get(5, TimeUnit.SECONDS);
@@ -315,6 +216,8 @@ public class VfModuleDeleteTest extends BasicSoOperation {
}
};
+ loadProperties();
+
CompletableFuture<OperationOutcome> 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);
+ }
}