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.java12
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java8
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java13
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java59
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java78
5 files changed, 141 insertions, 29 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 3a2aaf849..35f1ef823 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,6 +20,7 @@
package org.onap.policy.controlloop.actor.so;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.util.Collections;
@@ -28,6 +29,7 @@ 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.controlloop.actor.test.BasicHttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.policy.Target;
@@ -52,6 +54,7 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
public static final String PATH_GET = "my-path-get/";
public static final int MAX_GETS = 3;
public static final int WAIT_SEC_GETS = 20;
+ public static final Integer VF_COUNT = 10;
@Mock
protected SoConfig config;
@@ -125,8 +128,8 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
}
@Override
- protected Map<String, String> makePayload() {
- Map<String, String> payload = new HashMap<>();
+ protected Map<String, Object> makePayload() {
+ Map<String, Object> payload = new HashMap<>();
// request parameters
SoRequestParameters reqParams = new SoRequestParameters();
@@ -140,4 +143,9 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
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/SoActorParamsTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java
index f463fcb94..5fb647253 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java
@@ -31,6 +31,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.controlloop.actorserviceprovider.Util;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.CommonActorParams;
public class SoActorParamsTest {
@@ -67,14 +68,15 @@ public class SoActorParamsTest {
assertTrue(params.validate(CONTAINER).isValid());
// only a few fields are required
- SoActorParams sparse = Util.translate(CONTAINER, Map.of("operation", operations), SoActorParams.class);
+ SoActorParams sparse = Util.translate(CONTAINER, Map.of(CommonActorParams.OPERATIONS_FIELD, operations),
+ SoActorParams.class);
assertTrue(sparse.validate(CONTAINER).isValid());
testValidateField("maxGets", "minimum", params2 -> params2.setMaxGets(-1));
testValidateField("waitSecGet", "minimum", params2 -> params2.setWaitSecGet(0));
// check fields from superclass
- testValidateField("operation", "null", params2 -> params2.setOperation(null));
+ testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null));
testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1));
// check edge cases
@@ -105,7 +107,7 @@ public class SoActorParamsTest {
SoActorParams params2 = new SoActorParams();
params2.setClientName(CLIENT);
params2.setTimeoutSec(TIMEOUT);
- params2.setOperation(operations);
+ params2.setOperations(operations);
params2.setWaitSecGet(WAIT_SEC_GETS);
params2.setMaxGets(MAX_GETS);
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
index a9d5b8192..b73a65e44 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
@@ -23,6 +23,7 @@
package org.onap.policy.controlloop.actor.so;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -41,6 +42,7 @@ import org.junit.Test;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actor.test.BasicActor;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.so.SoOperationType;
@@ -48,7 +50,7 @@ import org.onap.policy.so.SoRequest;
import org.onap.policy.so.SoRequestParameters;
import org.onap.policy.so.util.Serialization;
-public class SoActorServiceProviderTest {
+public class SoActorServiceProviderTest extends BasicActor {
private static final String C_VALUE = "cvalue";
private static final String A_VALUE = "avalue";
@@ -79,8 +81,15 @@ public class SoActorServiceProviderTest {
}
@Test
+ public void testActorService() {
+ // verify that it all plugs into the ActorService
+ verifyActorService(SoActorServiceProvider.NAME, "service.yaml");
+ }
+
+ @Test
public void testSendRequest() {
- SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null, null, null, null);
+ assertThatCode(() -> SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null, null, null,
+ null)).doesNotThrowAnyException();
}
@Test
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 871d37032..b2ae5727b 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
@@ -20,8 +20,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.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -35,7 +37,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 java.util.function.Consumer;
import java.util.function.Supplier;
import org.junit.Before;
@@ -82,19 +83,55 @@ public class SoOperationTest extends BasicSoOperation {
}
@Test
+ public void testValidateTarget() {
+ // check when various fields are null
+ verifyNotNull("model-customization-id", target::getModelCustomizationId, target::setModelCustomizationId);
+ verifyNotNull("model-invariant-id", target::getModelInvariantId, target::setModelInvariantId);
+ verifyNotNull("model-version-id", target::getModelVersionId, target::setModelVersionId);
+
+ // verify it's still valid
+ assertThatCode(() -> new VfModuleCreate(params, config)).doesNotThrowAnyException();
+
+ // check when Target, itself, is null
+ params = params.toBuilder().target(null).build();
+ assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleCreate(params, config))
+ .withMessageContaining("Target information");
+ }
+
+ private void verifyNotNull(String expectedText, Supplier<String> getter, Consumer<String> setter) {
+ String originalValue = getter.get();
+
+ // try with null
+ setter.accept(null);
+ assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleCreate(params, config))
+ .withMessageContaining(expectedText);
+
+ setter.accept(originalValue);
+ }
+
+ @Test
public void testStartPreprocessorAsync() {
- AtomicBoolean guardStarted = new AtomicBoolean();
+ assertNotNull(oper.startPreprocessorAsync());
+ }
- oper = new SoOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return super.startGuardAsync();
- }
- };
+ @Test
+ public void testStoreVfCountRunGuard() throws Exception {
+ // insert CQ data so it's there for the guard
+ context.setProperty(AaiCqResponse.CONTEXT_KEY, makeCqResponse());
+
+ // cause guard to fail
+ OperationOutcome outcome2 = params.makeOutcome();
+ outcome2.setResult(PolicyResult.FAILURE);
+ when(guardOperation.start()).thenReturn(CompletableFuture.completedFuture(outcome2));
+
+ CompletableFuture<OperationOutcome> future2 = oper.storeVfCountRunGuard();
+ assertTrue(executor.runAll(100));
+ assertTrue(future2.isDone());
+ assertEquals(PolicyResult.FAILURE, future2.get().getResult());
- assertNull(oper.startPreprocessorAsync());
- assertTrue(guardStarted.get());
+ // verify that the count was stored
+ Integer vfcount = context.getProperty(SoConstants.CONTEXT_KEY_VF_COUNT);
+ assertEquals(VF_COUNT, vfcount);
}
@Test
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 6c3cfbf66..63cf744c1 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
@@ -20,15 +20,17 @@
package org.onap.policy.controlloop.actor.so;
+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.assertSame;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
@@ -36,6 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
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;
@@ -44,7 +47,7 @@ import org.onap.aai.domain.yang.Tenant;
import org.onap.policy.aai.AaiCqResponse;
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.ControlLoopOperationParams;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.so.SoRequest;
@@ -71,14 +74,17 @@ public class VfModuleCreateTest extends BasicSoOperation {
public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(VfModuleCreate.NAME, oper.getName());
+
+ // verify that target validation is done
+ params = params.toBuilder().target(null).build();
+ assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleCreate(params, config))
+ .withMessageContaining("Target information");
}
@Test
- public void testStartPreprocessorAsync() {
- CompletableFuture<OperationOutcome> future = new CompletableFuture<>();
- context = mock(ControlLoopEventContext.class);
- when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(future);
- params = params.toBuilder().context(context).build();
+ public void testStartPreprocessorAsync() throws Exception {
+ // put the count in the context so that it will skip the custom query
+ params.getContext().setProperty(SoConstants.CONTEXT_KEY_VF_COUNT, 20);
AtomicBoolean guardStarted = new AtomicBoolean();
@@ -90,13 +96,60 @@ public class VfModuleCreateTest extends BasicSoOperation {
}
};
- assertSame(future, oper.startPreprocessorAsync());
- assertFalse(future.isDone());
+ CompletableFuture<OperationOutcome> future3 = oper.startPreprocessorAsync();
+ assertNotNull(future3);
assertTrue(guardStarted.get());
}
@Test
- public void testStartOperationAsync() throws Exception {
+ 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(PolicyResult.SUCCESS, future2.get().getResult());
+ }
+
+ @Test
+ public void testMakeGuardPayload() {
+ final int origCount = 30;
+ params.getContext().setProperty(SoConstants.CONTEXT_KEY_VF_COUNT, 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);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> resource = (Map<String, Object>) payload.get("resource");
+ assertNotNull(resource);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> guard = (Map<String, Object>) resource.get("guard");
+ assertNotNull(guard);
+
+ Integer newCount = (Integer) guard.get(VfModuleCreate.PAYLOAD_KEY_VF_COUNT);
+ assertNotNull(newCount);
+ assertEquals(origCount + 1, newCount.intValue());
+ }
+
+ @Test
+ public void testStartOperationAsync_testSuccessfulCompletion() throws Exception {
+ final int origCount = 30;
+ params.getContext().setProperty(SoConstants.CONTEXT_KEY_VF_COUNT, origCount);
+
when(client.post(any(), any(), any(), any())).thenAnswer(provideResponse(rawResponse));
// use a real executor
@@ -113,6 +166,9 @@ public class VfModuleCreateTest extends BasicSoOperation {
outcome = future2.get(500, TimeUnit.SECONDS);
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+
+ Integer newCount = (Integer) params.getContext().getProperty(SoConstants.CONTEXT_KEY_VF_COUNT);
+ assertEquals(origCount + 1, newCount.intValue());
}
/**