2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.appc;
23 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertSame;
28 import static org.junit.Assert.assertTrue;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.ArgumentMatchers.eq;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
34 import java.util.Arrays;
35 import java.util.concurrent.CompletableFuture;
36 import java.util.concurrent.atomic.AtomicBoolean;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.onap.aai.domain.yang.GenericVnf;
40 import org.onap.policy.aai.AaiCqResponse;
41 import org.onap.policy.appc.Request;
42 import org.onap.policy.common.utils.coder.CoderException;
43 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
44 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
46 public class ModifyConfigOperationTest extends BasicAppcOperation {
48 private ModifyConfigOperation oper;
50 public ModifyConfigOperationTest() {
51 super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
55 public void setUp() throws Exception {
57 oper = new ModifyConfigOperation(params, config);
61 public void testModifyConfigOperation() {
62 assertEquals(DEFAULT_ACTOR, oper.getActorName());
63 assertEquals(ModifyConfigOperation.NAME, oper.getName());
67 public void testStartPreprocessorAsync() {
68 CompletableFuture<OperationOutcome> future = new CompletableFuture<>();
69 context = mock(ControlLoopEventContext.class);
70 when(context.obtain(eq(AaiCqResponse.CONTEXT_KEY), any())).thenReturn(future);
71 params = params.toBuilder().context(context).build();
73 AtomicBoolean guardStarted = new AtomicBoolean();
75 oper = new ModifyConfigOperation(params, config) {
77 protected CompletableFuture<OperationOutcome> startGuardAsync() {
78 guardStarted.set(true);
79 return super.startGuardAsync();
83 assertSame(future, oper.startPreprocessorAsync());
84 assertFalse(future.isDone());
85 assertTrue(guardStarted.get());
89 public void testMakeRequest() throws CoderException {
90 AaiCqResponse cq = new AaiCqResponse("{}");
93 params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq);
94 assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest(1));
96 // populate the CQ data with a vnf-id
97 GenericVnf genvnf = new GenericVnf();
98 genvnf.setVnfId(MY_VNF);
99 genvnf.setModelInvariantId(RESOURCE_ID);
100 cq.setInventoryResponseItems(Arrays.asList(genvnf));
102 Request request = oper.makeRequest(2);
103 assertNotNull(request);
104 assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY));
106 verifyRequest("modifyConfig.json", request, IGNORE_FIELDS);