Upgrade and clean up dependencies
[policy/models.git] / models-interactions / model-actors / actor.vfc / src / test / java / org / onap / policy / controlloop / actor / vfc / BasicVfcOperation.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.mockito.Mockito.lenient;
25
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;
34
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;
39
40     @Mock
41     protected HttpPollingConfig config;
42
43     protected VfcResponse response;
44
45     /**
46      * Constructs the object using a default actor and operation name.
47      */
48     public BasicVfcOperation() {
49         super();
50     }
51
52     /**
53      * Constructs the object.
54      *
55      * @param actor actor name
56      * @param operation operation name
57      */
58     public BasicVfcOperation(String actor, String operation) {
59         super(actor, operation);
60     }
61
62     /**
63      * Starts the simulator.
64      */
65     protected static void initBeforeClass() throws Exception {
66         Util.buildVfcSim();
67
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);
71     }
72
73     protected static void destroyAfterClass() {
74         HttpClientFactoryInstance.getClientFactory().destroy();
75         HttpServletServerFactoryInstance.getServerFactory().destroy();
76     }
77
78     /**
79      * Initializes mocks and sets up.
80      */
81     public void setUp() throws Exception {
82         super.setUpBasic();
83
84         response = new VfcResponse();
85
86         // PLD
87
88         lenient().when(rawResponse.getStatus()).thenReturn(200);
89         lenient().when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response));
90
91         initConfig();
92     }
93
94     @Override
95     protected void initConfig() {
96         super.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);
101     }
102
103 }