aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnr/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-08 12:37:20 -0400
committerJim Hahn <jrh3@att.com>2020-04-08 14:36:45 -0400
commitdf6d6bb862fb0af49a8873479f9e3b609553deca (patch)
treebc5ef9a08ccb0c0a4a27951c56c5b42350d297ea /models-interactions/model-actors/actor.sdnr/src/test
parent9b3ff5f270572a6760ff07dda9577cdadb53b088 (diff)
SDNR Actor enhancements
Made the following changes: - Enhanced SDNR Actor to support any operation name specified within the policy, constructing the same request, but passing a different "RPC name" and "Action" in the request. - Added ControlLoopResponse to OperationOutcome - Modified SDNR Actor to populate ControlLoopResponse Issue-ID: POLICY-2468 Change-Id: I50ee0674077d975f3cd211454656edc47d78520f Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.sdnr/src/test')
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java140
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java13
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java98
3 files changed, 95 insertions, 156 deletions
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java
deleted file mode 100644
index 27ffb5225..000000000
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*--
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.actor.sdnr;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-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.common.utils.coder.CoderException;
-import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
-import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.sdnr.PciMessage;
-
-public class ModifyConfigOperationTest extends BasicSdnrOperation {
-
- private ModifyConfigOperation oper;
-
- public ModifyConfigOperationTest() {
- super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
- }
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
- }
-
- @AfterClass
- public static void tearDownAfterClass() {
- destroyAfterClass();
- }
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- oper = new ModifyConfigOperation(params, config);
- }
-
- @After
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Tests "success" case with simulator.
- */
- @Test
- public void testSuccess() throws Exception {
- BidirectionalTopicParams opParams =
- BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build();
- config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, SdnrOperation.SELECTOR_KEYS);
-
- params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
-
- oper = new ModifyConfigOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- return null;
- }
- };
-
- outcome = oper.start().get();
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
- }
-
- @Test
- public void testConstructor() {
- assertEquals(DEFAULT_ACTOR, oper.getActorName());
- assertEquals(ModifyConfigOperation.NAME, oper.getName());
- }
-
- @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();
-
- oper = new ModifyConfigOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return super.startGuardAsync();
- }
- };
- CompletableFuture<OperationOutcome> future3 = oper.startPreprocessorAsync();
-
- assertNotNull(future3);
- assertFalse(future.isDone());
- assertTrue(guardStarted.get());
-
- future2.complete(params.makeOutcome());
- assertTrue(executor.runAll(100));
- assertTrue(future3.isDone());
- assertEquals(PolicyResult.SUCCESS, future3.get().getResult());
- }
-
- @Test
- public void testMakeRequest() throws CoderException {
- oper.generateSubRequestId(1);
-
- PciMessage request = oper.makeRequest(1);
- assertNotNull(request);
- }
-}
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java
index 8101b12fd..12a1666a0 100644
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java
@@ -22,18 +22,19 @@ package org.onap.policy.controlloop.actor.sdnr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.time.Instant;
import java.util.HashMap;
import java.util.UUID;
-
import org.junit.Test;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.controlloop.policy.TargetType;
@@ -94,6 +95,16 @@ public class SdnrActorServiceProviderTest {
}
@Test
+ public void testGetOperator() {
+ SdnrActorServiceProvider sp = new SdnrActorServiceProvider();
+
+ // should always return the same operator regardless of the name
+ Operator oper = sp.getOperator("unknown");
+ assertNotNull(oper);
+ assertSame(oper, sp.getOperator("another"));
+ }
+
+ @Test
public void testGetControlLoopResponse() {
PciRequest sdnrRequest;
sdnrRequest = SdnrActorServiceProvider.constructRequest(onsetEvent, operation, policy).getBody();
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 836b1ae57..2bb0d9469 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
@@ -20,22 +20,33 @@
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.assertNotNull;
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.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.ControlLoopResponse;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+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;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdnr.PciCommonHeader;
import org.onap.policy.sdnr.PciMessage;
+import org.onap.policy.sdnr.PciRequest;
import org.onap.policy.sdnr.util.StatusCodeEnum;
public class SdnrOperationTest extends BasicSdnrOperation {
@@ -60,7 +71,7 @@ public class SdnrOperationTest extends BasicSdnrOperation {
public void setUp() throws Exception {
super.setUp();
- operation = new SdnrOperation(params, config) {};
+ operation = new SdnrOperation(params, config);
}
@After
@@ -84,8 +95,13 @@ public class SdnrOperationTest extends BasicSdnrOperation {
assertNotNull(request.getBody());
assertEquals("1.0", request.getVersion());
assertEquals("request", request.getType());
+ assertEquals(DEFAULT_OPERATION.toLowerCase(), request.getRpcName());
- PciCommonHeader header = request.getBody().getInput().getCommonHeader();
+ PciRequest input = request.getBody().getInput();
+ assertNotNull(input);
+ assertEquals(DEFAULT_OPERATION, input.getAction());
+
+ PciCommonHeader header = input.getCommonHeader();
assertNotNull(header);
assertEquals(params.getRequestId(), header.getRequestId());
}
@@ -99,9 +115,66 @@ public class SdnrOperationTest extends BasicSdnrOperation {
operation.getExpectedKeyValues(50, request));
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ BidirectionalTopicParams opParams =
+ BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build();
+ config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, SdnrOperation.SELECTOR_KEYS);
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+ operation = new SdnrOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ return null;
+ }
+ };
+
+ outcome = operation.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+
+ ControlLoopResponse clresp = outcome.getControlLoopResponse();
+ assertNotNull(clresp);
+
+ assertEquals(DEFAULT_ACTOR, clresp.getFrom());
+ assertEquals("DCAE", clresp.getTarget());
+ assertEquals(CL_NAME, clresp.getClosedLoopControlName());
+ assertEquals(EVENT_POLICY_NAME, clresp.getPolicyName());
+ assertEquals(EVENT_POLICY_VERSION, clresp.getPolicyVersion());
+ assertEquals(EVENT_VERSION, clresp.getVersion());
+ assertEquals(REQ_ID, clresp.getRequestId());
+ assertNotNull(clresp.getPayload());
+ }
+
@Test
- public void testStartPreprocessorAsync() {
- assertNotNull(operation.startPreprocessorAsync());
+ 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());
+ assertTrue(executor.runAll(100));
+ assertTrue(future3.isDone());
+ assertEquals(PolicyResult.SUCCESS, future3.get().getResult());
}
@Test
@@ -110,14 +183,12 @@ public class SdnrOperationTest extends BasicSdnrOperation {
// null status
response.getBody().getOutput().setStatus(null);
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR response is missing the response status");
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
response.getBody().getOutput().setStatus(status);
// invalid code
status.setCode(-45);
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("unknown SDNR response status code: -45");
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.ACCEPTED.toString());
@@ -130,18 +201,15 @@ public class SdnrOperationTest extends BasicSdnrOperation {
status.setValue(StatusCodeEnum.REJECT.toString());
status.setCode(StatusCodeEnum.toValue(StatusCodeEnum.REJECT));
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString());
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.REJECT.toString());
status.setCode(313);
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString());
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.ERROR.toString());
status.setCode(StatusCodeEnum.toValue(StatusCodeEnum.ERROR));
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.ERROR.toString());
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.FAILURE.toString());
status.setCode(450);