Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.vfc / src / test / java / org / onap / policy / controlloop / actor / vfc / RestartTest.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.vfc;
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 java.util.concurrent.CompletableFuture;
31 import org.apache.commons.lang3.tuple.Pair;
32 import org.junit.AfterClass;
33 import org.junit.Before;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
39 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
40 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
41 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
42 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
43 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
44 import org.onap.policy.vfc.VfcRequest;
45 import org.onap.policy.vfc.VfcResponse;
46
47 @RunWith(MockitoJUnitRunner.class)
48 public class RestartTest extends BasicVfcOperation {
49     private static final String TEST_SERVICE_INSTANCE_ID = "test-service-instance-id";
50     private static final String TEST_VSERVER_ID = "test-vserver-id";
51     private static final String TEST_VSERVER_NAME = "test-vserver-name";
52     private static final String TEST_GENERIC_VNF_ID = "test-generic-vnf-id";
53
54     private Restart restartOper;
55
56
57     @BeforeClass
58     public static void setUpBeforeClass() throws Exception {
59         initBeforeClass();
60     }
61
62     @AfterClass
63     public static void tearDownAfterClass() {
64         destroyAfterClass();
65     }
66
67     /**
68      * setup restart operation.
69      */
70     @Before
71     public void setup() throws Exception {
72         super.setUp();
73
74         restartOper = new Restart(params, config);
75
76         loadProperties();
77     }
78
79     /**
80      * Tests "success" case with simulator.
81      */
82     @Test
83     public void testSuccess() throws Exception {
84         HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("ns").pollPath("jobs")
85                         .maxPolls(1).build();
86         config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
87
88         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
89
90         restartOper = new Restart(params, config);
91
92         loadProperties();
93
94         // run the operation
95         outcome = restartOper.start().get();
96         assertEquals(OperationResult.SUCCESS, outcome.getResult());
97         assertTrue(outcome.getResponse() instanceof VfcResponse);
98     }
99
100     @Test
101     public void testConstructor() {
102         CompletableFuture<OperationOutcome> futureRes = restartOper.startOperationAsync(1, outcome);
103         assertNotNull(futureRes);
104         assertEquals(0, restartOper.getPollCount());
105     }
106
107     @Test
108     public void testGetPropertyNames() {
109         // @formatter:off
110         assertThat(restartOper.getPropertyNames()).isEqualTo(
111                         List.of(
112                             OperationProperties.ENRICHMENT_SERVICE_ID,
113                             OperationProperties.ENRICHMENT_VSERVER_ID,
114                             OperationProperties.ENRICHMENT_VSERVER_NAME,
115                             OperationProperties.ENRICHMENT_GENERIC_VNF_ID));
116         // @formatter:on
117     }
118
119     @Test
120     public void testMakeRequest() {
121         Pair<String, VfcRequest> resultPair = restartOper.makeRequest();
122         assertNotNull(resultPair.getLeft());
123         assertNotNull(resultPair.getRight());
124     }
125
126     private void loadProperties() {
127         restartOper.setProperty(OperationProperties.ENRICHMENT_SERVICE_ID, TEST_SERVICE_INSTANCE_ID);
128         restartOper.setProperty(OperationProperties.ENRICHMENT_VSERVER_ID, TEST_VSERVER_ID);
129         restartOper.setProperty(OperationProperties.ENRICHMENT_VSERVER_NAME, TEST_VSERVER_NAME);
130         restartOper.setProperty(OperationProperties.ENRICHMENT_GENERIC_VNF_ID, TEST_GENERIC_VNF_ID);
131     }
132 }