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