Merge "Add SO VF Module Delete Operation"
[policy/models.git] / models-interactions / model-actors / actor.so / src / test / java / org / onap / policy / controlloop / actor / so / BasicSoOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.so;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.when;
25
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 import java.util.List;
30 import java.util.Map;
31 import org.mockito.Mock;
32 import org.onap.policy.aai.AaiCqResponse;
33 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
34 import org.onap.policy.controlloop.actorserviceprovider.Util;
35 import org.onap.policy.controlloop.policy.Target;
36 import org.onap.policy.so.SoRequest;
37 import org.onap.policy.so.SoRequestParameters;
38 import org.onap.policy.so.SoRequestReferences;
39 import org.onap.policy.so.SoRequestStatus;
40 import org.onap.policy.so.SoResponse;
41
42 /**
43  * Superclass for various operator tests.
44  */
45 public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
46     protected static final String[] IGNORE_FIELDS = {"RequestID", "subRequestID", "seconds", "nanos"};
47
48     public static final String MODEL_CUSTOM_ID = "my-model-customization-id";
49     public static final String MODEL_INVAR_ID = "my-model-invariant-id";
50     public static final String MODEL_NAME = "my-model-name";
51     public static final String MODEL_VERSION = "my-model-version";
52     public static final String MODEL_VERS_ID = "my-model-version-id";
53     public static final String SUBSCRIPTION_SVC_TYPE = "my-subscription-service-type";
54     public static final String MY_PATH = "my-path";
55     public static final String PATH_GET = "my-path-get/";
56     public static final int MAX_GETS = 3;
57     public static final int WAIT_SEC_GETS = 20;
58     public static final Integer VF_COUNT = 10;
59
60     @Mock
61     protected SoConfig config;
62
63     protected Target target;
64     protected SoResponse response;
65
66     /**
67      * Constructs the object using a default actor and operation name.
68      */
69     public BasicSoOperation() {
70         super();
71     }
72
73     /**
74      * Constructs the object.
75      *
76      * @param actor actor name
77      * @param operation operation name
78      */
79     public BasicSoOperation(String actor, String operation) {
80         super(actor, operation);
81     }
82
83     /**
84      * Initializes mocks and sets up.
85      */
86     public void setUp() throws Exception {
87         super.setUpBasic();
88
89         response = new SoResponse();
90
91         SoRequest request = new SoRequest();
92         response.setRequest(request);
93
94         SoRequestStatus status = new SoRequestStatus();
95         request.setRequestStatus(status);
96         status.setRequestState(SoOperation.COMPLETE);
97
98         SoRequestReferences ref = new SoRequestReferences();
99         response.setRequestReferences(ref);
100         ref.setRequestId(REQ_ID.toString());
101
102         when(rawResponse.getStatus()).thenReturn(200);
103         when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response));
104
105         initConfig();
106     }
107
108     @Override
109     protected void initConfig() {
110         super.initConfig();
111         when(config.getClient()).thenReturn(client);
112         when(config.getPath()).thenReturn(MY_PATH);
113         when(config.getMaxGets()).thenReturn(MAX_GETS);
114         when(config.getPathGet()).thenReturn(PATH_GET);
115         when(config.getWaitSecGet()).thenReturn(WAIT_SEC_GETS);
116     }
117
118     @Override
119     protected void makeContext() {
120         super.makeContext();
121
122         target = new Target();
123         target.setModelCustomizationId(MODEL_CUSTOM_ID);
124         target.setModelInvariantId(MODEL_INVAR_ID);
125         target.setModelName(MODEL_NAME);
126         target.setModelVersion(MODEL_VERSION);
127         target.setModelVersionId(MODEL_VERS_ID);
128
129         params = params.toBuilder().target(target).build();
130     }
131
132     @Override
133     protected Map<String, Object> makePayload() {
134         Map<String, Object> payload = new HashMap<>();
135
136         // request parameters
137         SoRequestParameters reqParams = new SoRequestParameters();
138         reqParams.setSubscriptionServiceType(SUBSCRIPTION_SVC_TYPE);
139         payload.put(SoOperation.REQ_PARAM_NM, Util.translate("", reqParams, String.class));
140
141         // config parameters
142         List<Map<String, String>> config = new LinkedList<>();
143         config.add(Collections.emptyMap());
144         payload.put(SoOperation.CONFIG_PARAM_NM, Util.translate("", config, String.class));
145
146         return payload;
147     }
148
149     protected AaiCqResponse makeCqResponse() {
150         when(cqResponse.getVfModuleCount(any(), any(), any())).thenReturn(VF_COUNT);
151         return cqResponse;
152     }
153 }