2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.so;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.when;
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 import java.util.List;
31 import org.mockito.Mock;
32 import org.onap.policy.aai.AaiCqResponse;
33 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
34 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
35 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
36 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
37 import org.onap.policy.controlloop.actorserviceprovider.Util;
38 import org.onap.policy.controlloop.policy.Target;
39 import org.onap.policy.simulators.SoSimulatorJaxRs;
40 import org.onap.policy.so.SoRequest;
41 import org.onap.policy.so.SoRequestParameters;
42 import org.onap.policy.so.SoRequestReferences;
43 import org.onap.policy.so.SoRequestStatus;
44 import org.onap.policy.so.SoResponse;
47 * Superclass for various operator tests.
49 public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
50 protected static final String[] IGNORE_FIELDS = {"RequestID", "subRequestID", "seconds", "nanos"};
52 public static final String MODEL_CUSTOM_ID = "my-model-customization-id";
53 public static final String MODEL_INVAR_ID = "my-model-invariant-id";
54 public static final String MODEL_NAME = "my-model-name";
55 public static final String MODEL_VERSION = "my-model-version";
56 public static final String MODEL_VERS_ID = "my-model-version-id";
57 public static final String SUBSCRIPTION_SVC_TYPE = "my-subscription-service-type";
58 public static final String MY_PATH = "my-path";
59 public static final String PATH_GET = "my-path-get/";
60 public static final int MAX_GETS = 3;
61 public static final int WAIT_SEC_GETS = 20;
62 public static final Integer VF_COUNT = 10;
65 protected SoConfig config;
67 protected Target target;
68 protected SoResponse response;
71 * Constructs the object using a default actor and operation name.
73 public BasicSoOperation() {
78 * Constructs the object.
80 * @param actor actor name
81 * @param operation operation name
83 public BasicSoOperation(String actor, String operation) {
84 super(actor, operation);
88 * Starts the simulator.
90 protected static void initBeforeClass() throws Exception {
91 org.onap.policy.simulators.Util.buildSoSim();
93 BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("").hostname("localhost")
94 .managed(true).port(org.onap.policy.simulators.Util.SOSIM_SERVER_PORT)
96 HttpClientFactoryInstance.getClientFactory().build(clientParams);
98 SoSimulatorJaxRs.setRequirePolling(true);
101 protected static void destroyAfterClass() {
102 SoSimulatorJaxRs.setRequirePolling(false);
103 HttpClientFactoryInstance.getClientFactory().destroy();
104 HttpServletServerFactoryInstance.getServerFactory().destroy();
108 * Initializes mocks and sets up.
110 public void setUp() throws Exception {
113 response = new SoResponse();
115 SoRequest request = new SoRequest();
116 response.setRequest(request);
118 SoRequestStatus status = new SoRequestStatus();
119 request.setRequestStatus(status);
120 status.setRequestState(SoOperation.COMPLETE);
122 SoRequestReferences ref = new SoRequestReferences();
123 response.setRequestReferences(ref);
124 ref.setRequestId(REQ_ID.toString());
126 when(rawResponse.getStatus()).thenReturn(200);
127 when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response));
133 protected void initConfig() {
135 when(config.getClient()).thenReturn(client);
136 when(config.getPath()).thenReturn(MY_PATH);
137 when(config.getMaxGets()).thenReturn(MAX_GETS);
138 when(config.getPathGet()).thenReturn(PATH_GET);
139 when(config.getWaitSecGet()).thenReturn(WAIT_SEC_GETS);
143 protected void makeContext() {
146 target = new Target();
147 target.setModelCustomizationId(MODEL_CUSTOM_ID);
148 target.setModelInvariantId(MODEL_INVAR_ID);
149 target.setModelName(MODEL_NAME);
150 target.setModelVersion(MODEL_VERSION);
151 target.setModelVersionId(MODEL_VERS_ID);
153 params = params.toBuilder().target(target).build();
157 protected Map<String, Object> makePayload() {
158 Map<String, Object> payload = new HashMap<>();
160 // request parameters
161 SoRequestParameters reqParams = new SoRequestParameters();
162 reqParams.setSubscriptionServiceType(SUBSCRIPTION_SVC_TYPE);
163 payload.put(SoOperation.REQ_PARAM_NM, Util.translate("", reqParams, String.class));
166 List<Map<String, String>> config = new LinkedList<>();
167 config.add(Collections.emptyMap());
168 payload.put(SoOperation.CONFIG_PARAM_NM, Util.translate("", config, String.class));
173 protected AaiCqResponse makeCqResponse() {
174 when(cqResponse.getVfModuleCount(any(), any(), any())).thenReturn(VF_COUNT);