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.mockito.Mockito.lenient;
26 import org.mockito.Mock;
27 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
28 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
29 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
30 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
32 import org.onap.policy.simulators.Util;
33 import org.onap.policy.vfc.VfcResponse;
35 public abstract class BasicVfcOperation extends BasicHttpOperation {
36 public static final String POLL_PATH = "my-path-get/";
37 public static final int MAX_POLLS = 3;
38 public static final int POLL_WAIT_SEC = 20;
41 protected HttpPollingConfig config;
43 protected VfcResponse response;
46 * Constructs the object using a default actor and operation name.
48 public BasicVfcOperation() {
53 * Constructs the object.
55 * @param actor actor name
56 * @param operation operation name
58 public BasicVfcOperation(String actor, String operation) {
59 super(actor, operation);
63 * Starts the simulator.
65 protected static void initBeforeClass() throws Exception {
68 BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("api/nslcm/v1/")
69 .hostname("localhost").managed(true).port(Util.VFCSIM_SERVER_PORT).build();
70 HttpClientFactoryInstance.getClientFactory().build(clientParams);
73 protected static void destroyAfterClass() {
74 HttpClientFactoryInstance.getClientFactory().destroy();
75 HttpServletServerFactoryInstance.getServerFactory().destroy();
79 * Initializes mocks and sets up.
81 public void setUp() throws Exception {
84 response = new VfcResponse();
88 lenient().when(rawResponse.getStatus()).thenReturn(200);
89 lenient().when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response));
95 protected void initConfig() {
97 lenient().when(config.getClient()).thenReturn(client);
98 lenient().when(config.getMaxPolls()).thenReturn(MAX_POLLS);
99 lenient().when(config.getPollPath()).thenReturn(POLL_PATH);
100 lenient().when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC);