2 * ============LICENSE_START=======================================================
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
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.controlloop.actor.vfc;
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;
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;
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";
54 private Restart restartOper;
58 public static void setUpBeforeClass() throws Exception {
63 public static void tearDownAfterClass() {
68 * setup restart operation.
71 public void setup() throws Exception {
74 restartOper = new Restart(params, config);
80 * Tests "success" case with simulator.
83 public void testSuccess() throws Exception {
84 HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("ns").pollPath("jobs")
86 config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
88 params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
90 restartOper = new Restart(params, config);
95 outcome = restartOper.start().get();
96 assertEquals(OperationResult.SUCCESS, outcome.getResult());
97 assertTrue(outcome.getResponse() instanceof VfcResponse);
101 public void testConstructor() {
102 CompletableFuture<OperationOutcome> futureRes = restartOper.startOperationAsync(1, outcome);
103 assertNotNull(futureRes);
104 assertEquals(0, restartOper.getPollCount());
108 public void testGetPropertyNames() {
110 assertThat(restartOper.getPropertyNames()).isEqualTo(
112 OperationProperties.ENRICHMENT_SERVICE_ID,
113 OperationProperties.ENRICHMENT_VSERVER_ID,
114 OperationProperties.ENRICHMENT_VSERVER_NAME,
115 OperationProperties.ENRICHMENT_GENERIC_VNF_ID));
120 public void testMakeRequest() {
121 Pair<String, VfcRequest> resultPair = restartOper.makeRequest();
122 assertNotNull(resultPair.getLeft());
123 assertNotNull(resultPair.getRight());
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);