Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.appc / src / test / java / org / onap / policy / controlloop / actor / appc / ModifyConfigOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.appc;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.List;
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.policy.appc.Request;
38 import org.onap.policy.appc.Response;
39 import org.onap.policy.common.utils.coder.CoderException;
40 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
41 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
42 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
43 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
44
45 @RunWith(MockitoJUnitRunner.class)
46 public class ModifyConfigOperationTest extends BasicAppcOperation {
47
48     private ModifyConfigOperation oper;
49
50
51     public ModifyConfigOperationTest() {
52         super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
53     }
54
55     @BeforeClass
56     public static void setUpBeforeClass() throws Exception {
57         // use same topic name for both sides
58         initBeforeClass(MY_SINK, MY_SINK);
59     }
60
61     @AfterClass
62     public static void tearDownAfterClass() {
63         destroyAfterClass();
64     }
65
66     @Before
67     @Override
68     public void setUp() throws Exception {
69         super.setUp();
70
71         oper = new ModifyConfigOperation(params, config);
72     }
73
74     @After
75     @Override
76     public void tearDown() {
77         super.tearDown();
78     }
79
80     /**
81      * Tests "success" case with simulator.
82      */
83     @Test
84     public void testSuccess() throws Exception {
85         BidirectionalTopicParams opParams =
86                         BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SINK).build();
87         config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcOperation.SELECTOR_KEYS);
88
89         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
90
91         oper = new ModifyConfigOperation(params, config);
92
93         oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf);
94
95         outcome = oper.start().get();
96         assertEquals(OperationResult.SUCCESS, outcome.getResult());
97         assertTrue(outcome.getResponse() instanceof Response);
98     }
99
100     @Test
101     public void testConstructor() {
102         assertEquals(DEFAULT_ACTOR, oper.getActorName());
103         assertEquals(ModifyConfigOperation.NAME, oper.getName());
104     }
105
106     @Test
107     public void testGetPropertyNames() {
108         assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_RESOURCE_VNF));
109     }
110
111     @Test
112     public void testMakeRequest() throws CoderException {
113         oper.setProperty(OperationProperties.AAI_RESOURCE_VNF, genvnf);
114
115         oper.generateSubRequestId(2);
116         Request request = oper.makeRequest(2);
117         assertNotNull(request);
118         assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY));
119
120         verifyRequest("modifyConfig.json", request, IGNORE_FIELDS);
121     }
122 }