aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnr
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-08-21 13:43:08 -0400
committerJim Hahn <jrh3@att.com>2020-10-27 14:55:15 -0400
commit19ef8b24a98c09a349e6ae7309f535a0135463f6 (patch)
treed988e5a58865ae6f3a38dcb31e4f195f18e59946 /models-interactions/model-actors/actor.sdnr
parent6b29d2c19e288148171db0c0e446e18dcd46effd (diff)
Make Actors event-agnostic
Removed event and event-context code from the Actor code. Also removed the preprocessing steps from the Actor code, giving the application complete control over any preprocessing. Also fixed a bug wherein the APPC actor was treating the AAI_RESOURCE_VNF property as a String instead of as a GenericVnf. Issue-ID: POLICY-2746-actor Change-Id: Ibc05fe39ffedc0bc461abf10e6a960861ac70119 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.sdnr')
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java22
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java23
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java61
3 files changed, 2 insertions, 104 deletions
diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
index 308ddd9bd..14f77a687 100644
--- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
+++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
@@ -21,7 +21,6 @@
package org.onap.policy.controlloop.actor.sdnr;
import java.util.List;
-import java.util.concurrent.CompletableFuture;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
@@ -70,11 +69,6 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
return List.of(getSubRequestId());
}
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- return startGuardAsync();
- }
-
/*
* NOTE: This should avoid throwing exceptions, so that a ControlLoopResponse can be
* added to the outcome. Consequently, it returns FAILURE if a required field is
@@ -156,7 +150,7 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
requestCommonHeader.setSubRequestId(subRequestId);
sdnrRequest.setCommonHeader(requestCommonHeader);
- sdnrRequest.setPayload(getEventPayload());
+ sdnrRequest.setPayload(getProperty(OperationProperties.EVENT_PAYLOAD));
sdnrRequest.setAction(params.getOperation());
/*
@@ -169,18 +163,4 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
/* Return the request to be sent through dmaap. */
return dmaapRequest;
}
-
- /**
- * Gets the event payload, first checking for it in the properties and then in the
- * event.
- *
- * @return the event payload
- */
- protected String getEventPayload() {
- if (containsProperty(OperationProperties.EVENT_PAYLOAD)) {
- return getProperty(OperationProperties.EVENT_PAYLOAD);
- }
-
- return params.getContext().getEvent().getPayload();
- }
}
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java
index 912d27316..64e88aa6e 100644
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java
+++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java
@@ -20,7 +20,6 @@
package org.onap.policy.controlloop.actor.sdnr;
-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.assertTrue;
@@ -38,8 +37,6 @@ import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.impl.OperationMaker;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.sdnr.PciBody;
import org.onap.policy.sdnr.PciMessage;
import org.onap.policy.sdnr.PciResponse;
@@ -47,7 +44,6 @@ import org.onap.policy.sdnr.Status;
import org.onap.policy.sdnr.util.StatusCodeEnum;
import org.onap.policy.simulators.SdnrTopicServer;
import org.onap.policy.simulators.TopicServer;
-import org.powermock.reflect.Whitebox;
public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation<PciMessage> {
@@ -122,25 +118,6 @@ public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperatio
}
/**
- * Verifies that an exception is thrown if a field is missing from the enrichment
- * data.
- *
- * @param fieldName name of the field to be removed from the enrichment data
- * @param expectedText text expected in the exception message
- */
- protected void verifyMissing(String fieldName, String expectedText,
- OperationMaker<BidirectionalTopicConfig, SdnrOperation> maker) {
-
- makeContext();
- enrichment.remove(fieldName);
-
- SdnrOperation oper = maker.apply(params, config);
-
- assertThatIllegalArgumentException().isThrownBy(() -> Whitebox.invokeMethod(oper, "makeRequest", 1))
- .withMessageContaining("missing").withMessageContaining(expectedText);
- }
-
- /**
* Provides a response to the listener.
*
* @param listener listener to which to provide the response
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
index 90452a9af..3a8f0b7e1 100644
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
+++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
@@ -22,28 +22,20 @@ package org.onap.policy.controlloop.actor.sdnr;
import static org.assertj.core.api.Assertions.assertThat;
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.util.Arrays;
import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
-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.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
@@ -134,12 +126,7 @@ public class SdnrOperationTest extends BasicSdnrOperation {
params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
- operation = new SdnrOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- return null;
- }
- };
+ operation = new SdnrOperation(params, config);
outcome = operation.start().get();
assertEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -147,34 +134,6 @@ public class SdnrOperationTest extends BasicSdnrOperation {
}
@Test
- public void testStartPreprocessorAsync() throws Exception {
- final CompletableFuture<OperationOutcome> future2 = new CompletableFuture<>();
- context = mock(ControlLoopEventContext.class);
- when(context.getEvent()).thenReturn(event);
- params = params.toBuilder().context(context).build();
-
- AtomicBoolean guardStarted = new AtomicBoolean();
-
- operation = new SdnrOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return super.startGuardAsync();
- }
- };
- CompletableFuture<OperationOutcome> future3 = operation.startPreprocessorAsync();
-
- assertNotNull(future3);
- assertFalse(future.isDone());
- assertTrue(guardStarted.get());
-
- future2.complete(params.makeOutcome(null));
- assertTrue(executor.runAll(100));
- assertTrue(future3.isDone());
- assertEquals(OperationResult.SUCCESS, future3.get().getResult());
- }
-
- @Test
public void testDetmStatusStringResponse() {
final org.onap.policy.sdnr.Status status = response.getBody().getOutput().getStatus();
@@ -236,24 +195,6 @@ public class SdnrOperationTest extends BasicSdnrOperation {
checkOutcome();
}
- @Test
- public void testGetEventPayload() {
- // in neither property nor event
- assertNull(operation.getEventPayload());
-
- // only in event
- event.setPayload("valueA2");
- assertEquals("valueA2", operation.getEventPayload());
-
- // both - should choose the property
- operation.setProperty(OperationProperties.EVENT_PAYLOAD, "valueB");
- assertEquals("valueB", operation.getEventPayload());
-
- // both - should choose the property, even if it's null
- operation.setProperty(OperationProperties.EVENT_PAYLOAD, null);
- assertNull(operation.getEventPayload());
- }
-
protected void checkOutcome() {
assertSame(outcome, operation.setOutcome(outcome, OperationResult.SUCCESS, response));
assertEquals(OperationResult.SUCCESS, outcome.getResult());