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;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import static org.junit.jupiter.api.Assertions.assertNull;
28 import static org.junit.jupiter.api.Assertions.assertSame;
29 import static org.mockito.ArgumentMatchers.anyString;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
33 import java.util.List;
35 import java.util.concurrent.CompletableFuture;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.onap.aai.domain.yang.GenericVnf;
39 import org.onap.policy.controlloop.VirtualControlLoopEvent;
40 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
41 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
42 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
43 import org.onap.policy.controlloop.eventmanager.StepContext;
45 class LockOperation2Test {
46 private static final String MY_PNF = "my-pnf";
47 private static final String MY_VNF = "my-vnf";
48 private static final String MY_ACTOR = "my-actor";
49 private static final String MY_OPERATION = "my-operation";
51 private final StepContext stepContext = mock(StepContext.class);
52 private final ControlLoopOperationParams params = mock(ControlLoopOperationParams.class);
54 private VirtualControlLoopEvent event;
55 private CompletableFuture<OperationOutcome> future;
56 private GenericVnf vnf;
57 private LockOperation2 oper;
64 event = new VirtualControlLoopEvent();
65 event.setTarget("pnf.pnf-name");
66 event.setAai(Map.of("pnf.pnf-name", MY_PNF));
68 future = new CompletableFuture<>();
70 vnf = new GenericVnf();
73 when(stepContext.requestLock(anyString())).thenReturn(future);
75 when(params.getActor()).thenReturn(MY_ACTOR);
76 when(params.getOperation()).thenReturn(MY_OPERATION);
78 oper = new LockOperation2(stepContext, params);
82 void testGetPropertyNames() {
83 assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY));
89 assertThatIllegalStateException().isThrownBy(() -> oper.start())
90 .withMessage("target lock entity has not been determined yet");
92 oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "some-target");
93 assertSame(future, oper.start());
97 void testSetProperty() {
98 oper.setProperty("unknown-property", "some data");
99 assertNull(oper.getTargetEntity());
101 oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "other data");
102 assertEquals("other data", oper.getTargetEntity());
106 void testGetActorName_testGetName() {
107 assertEquals(MY_ACTOR, oper.getActorName());
108 assertEquals(MY_OPERATION, oper.getName());