Remove unused imports in models
[policy/models.git] / models-provider / src / test / java / org / onap / policy / models / provider / impl / DummyPolicyModelsProviderImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2022 Nordix Foundation.
4  *  Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5  *  Modifications Copyright (C) 2020, 2022 Bell Canada. 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.provider.impl;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.Map;
29 import javax.ws.rs.core.Response;
30 import lombok.NonNull;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32 import org.onap.policy.common.utils.resources.ResourceUtils;
33 import org.onap.policy.models.base.PfModelException;
34 import org.onap.policy.models.base.PfModelRuntimeException;
35 import org.onap.policy.models.pdp.concepts.Pdp;
36 import org.onap.policy.models.pdp.concepts.PdpGroup;
37 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
38 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
39 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
40 import org.onap.policy.models.provider.PolicyModelsProvider;
41 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
50
51 /**
52  * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
53  *
54  * @author Liam Fallon (liam.fallon@est.tech)
55  * @author Chenfei Gao (cgao@research.att.com)
56  */
57 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
58     /**
59      * Constructor that takes the parameters.
60      *
61      * @param parameters the parameters for the provider
62      */
63     public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
64         // Default constructor
65     }
66
67     @Override
68     public void init() throws PfModelException {
69         // Not required on the dummy provider
70     }
71
72     @Override
73     public void close() {
74         // Not required on the dummy provider
75     }
76
77
78     @Override
79     public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
80         return new ArrayList<>();
81     }
82
83     @Override
84     public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
85             @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException {
86         return new ArrayList<>();
87     }
88
89     @Override
90     public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
91             throws PfModelException {
92         return serviceTemplate;
93     }
94
95     @Override
96     public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
97             throws PfModelException {
98         return serviceTemplate;
99     }
100
101     @Override
102     public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
103             throws PfModelException {
104         return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
105     }
106
107     @Override
108     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
109         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
110     }
111
112     @Override
113     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
114         return new ArrayList<>();
115     }
116
117     @Override
118     public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter)
119             throws PfModelException {
120         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
121     }
122
123     @Override
124     public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) {
125         return new ArrayList<>();
126     }
127
128     @Override
129     public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
130         return serviceTemplate;
131     }
132
133     @Override
134     public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
135         return serviceTemplate;
136     }
137
138     @Override
139     public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
140         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
141     }
142
143     @Override
144     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
145         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
146     }
147
148     @Override
149     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
150         return new ArrayList<>();
151     }
152
153     @Override
154     public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter)
155             throws PfModelException {
156         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
157     }
158
159     @Override
160     public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException {
161         return new ArrayList<>();
162     }
163
164     @Override
165     public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
166         return serviceTemplate;
167     }
168
169     @Override
170     public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
171         return serviceTemplate;
172     }
173
174     @Override
175     public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
176         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
177     }
178
179     @Override
180     public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
181         throws PfModelException {
182         return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
183     }
184
185     @Override
186     public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
187         throws PfModelRuntimeException, PfModelException {
188         return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
189     }
190
191     @Override
192     public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version)
193         throws PfModelException {
194         return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
195     }
196
197     @Override
198     public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(@NonNull String name,
199                                                                                       @NonNull String version)
200         throws PfModelException {
201         return new ArrayList<>();
202     }
203
204     @Override
205     public List<ToscaNodeTemplate> getToscaNodeTemplate(final String name, final String version)
206         throws PfModelException {
207         return new ArrayList<>();
208     }
209
210     @Override
211     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
212         return new ArrayList<>();
213     }
214
215     @Override
216     public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
217         return new ArrayList<>();
218     }
219
220     @Override
221     public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
222         return new ArrayList<>();
223     }
224
225     @Override
226     public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
227         return new ArrayList<>();
228     }
229
230     @Override
231     public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
232         // Not implemented
233     }
234
235     @Override
236     public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
237         // Not implemented
238     }
239
240     @Override
241     public PdpGroup deletePdpGroup(final String name) throws PfModelException {
242         return null;
243     }
244
245     @Override
246     public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
247         // Not implemented
248         return new ArrayList<>();
249     }
250
251     @Override
252     public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
253             throws PfModelException {
254         // Not implemented
255         return new ArrayList<>();
256     }
257
258     @Override
259     public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
260         // Not implemented
261         return new ArrayList<>();
262     }
263
264     @Override
265     public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
266             Collection<PdpPolicyStatus> deleteObjs) {
267         // Not implemented
268     }
269
270     /**
271      * Return a ToscaServicetemplate dummy response.
272      *
273      * @param fileName the file name containing the dummy response
274      * @return the ToscaServiceTemplate with the dummy response
275      */
276     protected ToscaServiceTemplate getDummyResponse(final String fileName) {
277         var standardCoder = new StandardCoder();
278         ToscaServiceTemplate serviceTemplate;
279
280         try {
281             serviceTemplate =
282                     standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
283             if (serviceTemplate == null) {
284                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
285             }
286         } catch (Exception exc) {
287             throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
288         }
289
290         return serviceTemplate;
291     }
292
293     /**
294      * Return a tosca node template dummy response.
295      *
296      * @param fileName the file name containing the dummy response
297      * @return the service template with the dummy response
298      */
299     protected ToscaServiceTemplate getDummyNodeTemplateResponse(final String fileName) {
300         var standardCoder = new StandardCoder();
301         ToscaServiceTemplate serviceTemplate;
302
303         try {
304             serviceTemplate =
305                 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
306             if (serviceTemplate == null) {
307                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
308             }
309         } catch (Exception exc) {
310             throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
311         }
312
313         return serviceTemplate;
314     }
315 }