2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.drools.apps.controller.usecases.step;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertSame;
27 import static org.junit.jupiter.api.Assertions.assertTrue;
28 import static org.mockito.ArgumentMatchers.any;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.never;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
34 import java.util.UUID;
35 import java.util.concurrent.CompletableFuture;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.onap.policy.common.utils.coder.StandardCoderObject;
39 import org.onap.policy.controlloop.VirtualControlLoopEvent;
40 import org.onap.policy.controlloop.actor.aai.AaiActor;
41 import org.onap.policy.controlloop.actor.aai.AaiGetPnfOperation;
42 import org.onap.policy.controlloop.actorserviceprovider.ActorService;
43 import org.onap.policy.controlloop.actorserviceprovider.Operation;
44 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
45 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
46 import org.onap.policy.controlloop.actorserviceprovider.Operator;
47 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
48 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
49 import org.onap.policy.controlloop.eventmanager.StepContext;
51 class AaiGetPnfStep2Test {
52 private static final String MY_TARGET = "my-target";
53 private static final UUID REQ_ID = UUID.randomUUID();
55 private final Operator policyOperator = mock(Operator.class);
56 private final Operation policyOperation = mock(Operation.class);
57 private final Actor policyActor = mock(Actor.class);
58 private final ActorService actors = mock(ActorService.class);
59 private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class);
60 private final StepContext stepContext = mock(StepContext.class);
61 private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class);
63 private CompletableFuture<OperationOutcome> future;
65 private AaiGetPnfStep2 step;
72 future = new CompletableFuture<>();
74 when(params.toBuilder()).thenReturn(ControlLoopOperationParams.builder().actorService(actors)
77 // configure policy operation
78 when(actors.getActor(AaiActor.NAME)).thenReturn(policyActor);
79 when(policyActor.getOperator(AaiGetPnfOperation.NAME)).thenReturn(policyOperator);
80 when(policyOperator.buildOperation(any())).thenReturn(policyOperation);
81 when(policyOperation.start()).thenReturn(future);
82 when(stepContext.getProperty(OperationProperties.AAI_TARGET_ENTITY)).thenReturn(MY_TARGET);
84 master = new Step2(stepContext, params, event);
85 step = new AaiGetPnfStep2(master);
89 void testConstructor() {
90 assertEquals(AaiActor.NAME, step.getActorName());
91 assertEquals(AaiGetPnfOperation.NAME, step.getOperationName());
92 assertSame(stepContext, step.stepContext);
93 assertSame(event, step.event);
99 assertTrue(step.start(100));
100 verify(policyOperation).start();
104 * Tests start() when the data has already been retrieved.
107 void testStartAlreadyHaveData() {
108 when(stepContext.contains(AaiGetPnfOperation.getKey(MY_TARGET))).thenReturn(true);
111 assertFalse(step.start(200));
112 verify(policyOperation, never()).start();
117 var data = new StandardCoderObject();
118 var outcome = new OperationOutcome();
119 outcome.setResponse(data);
121 step.success(outcome);
122 verify(stepContext).setProperty(AaiGetPnfOperation.getKey(MY_TARGET), data);