From 19ef8b24a98c09a349e6ae7309f535a0135463f6 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 21 Aug 2020 13:43:08 -0400 Subject: 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 --- .../controlloop/actor/sdnr/BasicSdnrOperation.java | 23 -------- .../controlloop/actor/sdnr/SdnrOperationTest.java | 61 +--------------------- 2 files changed, 1 insertion(+), 83 deletions(-) (limited to 'models-interactions/model-actors/actor.sdnr/src/test') 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 { @@ -121,25 +117,6 @@ public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperatio assertEquals(OperationResult.SUCCESS, outcome.getResult()); } - /** - * 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 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. * 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,46 +126,13 @@ public class SdnrOperationTest extends BasicSdnrOperation { params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build(); - operation = new SdnrOperation(params, config) { - @Override - protected CompletableFuture startGuardAsync() { - return null; - } - }; + operation = new SdnrOperation(params, config); outcome = operation.start().get(); assertEquals(OperationResult.SUCCESS, outcome.getResult()); assertTrue(outcome.getResponse() instanceof PciMessage); } - @Test - public void testStartPreprocessorAsync() throws Exception { - final CompletableFuture 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 startGuardAsync() { - guardStarted.set(true); - return super.startGuardAsync(); - } - }; - CompletableFuture 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()); -- cgit 1.2.3-korg