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.aai.AaiCqResponse;
39 import org.onap.policy.controlloop.VirtualControlLoopEvent;
40 import org.onap.policy.controlloop.actor.aai.AaiActor;
41 import org.onap.policy.controlloop.actor.aai.AaiCustomQueryOperation;
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.Operator;
46 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
47 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
48 import org.onap.policy.controlloop.eventmanager.StepContext;
50 class AaiCqStep2Test {
51 private static final UUID REQ_ID = UUID.randomUUID();
53 private final Operator policyOperator = mock(Operator.class);
54 private final Operation policyOperation = mock(Operation.class);
55 private final Actor policyActor = mock(Actor.class);
56 private final ActorService actors = mock(ActorService.class);
57 private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class);
58 private final StepContext stepContext = mock(StepContext.class);
59 private final VirtualControlLoopEvent event = mock(VirtualControlLoopEvent.class);
61 private CompletableFuture<OperationOutcome> future;
63 private AaiCqStep2 step;
70 future = new CompletableFuture<>();
72 when(params.toBuilder()).thenReturn(ControlLoopOperationParams.builder().actorService(actors)
75 // configure policy operation
76 when(actors.getActor(AaiActor.NAME)).thenReturn(policyActor);
77 when(policyActor.getOperator(AaiCustomQueryOperation.NAME)).thenReturn(policyOperator);
78 when(policyOperator.buildOperation(any())).thenReturn(policyOperation);
79 when(policyOperation.start()).thenReturn(future);
81 master = new Step2(stepContext, params, event);
82 step = new AaiCqStep2(master);
86 void testConstructor() {
87 assertEquals(AaiActor.NAME, step.getActorName());
88 assertEquals(AaiCustomQueryOperation.NAME, step.getOperationName());
89 assertSame(stepContext, step.stepContext);
90 assertSame(event, step.event);
96 assertTrue(step.start(100));
97 verify(policyOperation).start();
101 * Tests start() when the data has already been retrieved.
104 void testStartAlreadyHaveData() {
105 when(stepContext.contains(AaiCqResponse.CONTEXT_KEY)).thenReturn(true);
108 assertFalse(step.start(200));
109 verify(policyOperation, never()).start();
114 var data = new AaiCqResponse("{}");
115 var outcome = new OperationOutcome();
116 outcome.setResponse(data);
118 step.success(outcome);
119 verify(stepContext).setProperty(AaiCqResponse.CONTEXT_KEY, data);