Replace Eclipselink with Hibernate
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / authorative / provider / AuthorativeToscaProviderPolicyTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2021,2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.tosca.authorative.provider;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Properties;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.common.utils.coder.CoderException;
37 import org.onap.policy.common.utils.coder.StandardCoder;
38 import org.onap.policy.common.utils.resources.ResourceUtils;
39 import org.onap.policy.models.base.PfConceptKey;
40 import org.onap.policy.models.base.PfModelException;
41 import org.onap.policy.models.dao.DaoParameters;
42 import org.onap.policy.models.dao.PfDao;
43 import org.onap.policy.models.dao.PfDaoFactory;
44 import org.onap.policy.models.dao.impl.DefaultPfDao;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
50 import org.yaml.snakeyaml.Yaml;
51
52 /**
53  * Test of the {@link AuthorativeToscaProvider} class.
54  *
55  * @author Liam Fallon (liam.fallon@est.tech)
56  */
57 public class AuthorativeToscaProviderPolicyTest {
58     private static final String VERSION = "version";
59     private static final String VCPE_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
60     private static final String POLICY_AND_VERSION = "onap.restart.tca:1.0.0";
61     private static final String POLICY1 = "onap.restart.tca";
62     private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
63     private static final String VERSION_100 = "1.0.0";
64     private PfDao pfDao;
65     private StandardCoder standardCoder;
66
67     /**
68      * Set up the DAO towards the database.
69      *
70      * @throws Exception on database errors
71      */
72     @Before
73     public void setupDao() throws Exception {
74         final DaoParameters daoParameters = new DaoParameters();
75         daoParameters.setPluginClass(DefaultPfDao.class.getName());
76
77         daoParameters.setPersistenceUnit("ToscaConceptTest");
78
79         Properties jdbcProperties = new Properties();
80         jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
81         jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
82         if (System.getProperty("USE-MARIADB") != null) {
83             jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
84             jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
85         } else {
86             jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
87             jdbcProperties.setProperty("javax.persistence.jdbc.url",
88                             "jdbc:h2:mem:AuthorativeToscaProviderPolicyTest");
89         }
90         daoParameters.setJdbcProperties(jdbcProperties);
91
92         pfDao = new PfDaoFactory().createPfDao(daoParameters);
93         pfDao.init(daoParameters);
94     }
95
96     /**
97      * Set up GSON.
98      */
99     @Before
100     public void setupGson() {
101         standardCoder = new StandardCoder();
102     }
103
104     @After
105     public void teardown() {
106         pfDao.close();
107     }
108
109     @Test
110     public void testPoliciesGet() throws Exception {
111         assertThatThrownBy(() -> {
112             new AuthorativeToscaProvider().getPolicies(null, null, null);
113         }).hasMessageMatching(DAO_IS_NULL);
114
115         assertThatThrownBy(() -> {
116             new AuthorativeToscaProvider().getPolicyList(null, null, null);
117         }).hasMessageMatching(DAO_IS_NULL);
118
119         createPolicyTypes();
120
121         ToscaServiceTemplate toscaServiceTemplate =
122                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
123
124         assertNotNull(toscaServiceTemplate);
125         ToscaServiceTemplate createdServiceTemplate =
126                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
127
128         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
129
130         ToscaPolicy beforePolicy =
131                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
132         ToscaPolicy createdPolicy =
133                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
134         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
135         assertEquals(beforePolicy.getType(), createdPolicy.getType());
136
137         ToscaServiceTemplate gotServiceTemplate =
138                 new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
139
140         ToscaPolicy gotPolicy =
141                 gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
142         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
143         assertEquals(beforePolicy.getType(), gotPolicy.getType());
144
145         List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
146         assertEquals(1, gotPolicyList.size());
147         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
148
149         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, null);
150         assertEquals(1, gotPolicyList.size());
151         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
152
153         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, null);
154         assertEquals(1, gotPolicyList.size());
155         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
156
157         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, VERSION_100);
158         assertEquals(1, gotPolicyList.size());
159         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
160
161         assertTrue(new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100).isEmpty());
162     }
163
164     @Test
165     public void testPoliciesGetFiltered() throws Exception {
166         assertThatThrownBy(() -> {
167             new AuthorativeToscaProvider().getFilteredPolicies(null, null);
168         }).hasMessageMatching(DAO_IS_NULL);
169
170         assertThatThrownBy(() -> {
171             new AuthorativeToscaProvider().getFilteredPolicies(null,
172                     ToscaTypedEntityFilter.<ToscaPolicy>builder().build());
173         }).hasMessageMatching(DAO_IS_NULL);
174
175         assertThatThrownBy(() -> {
176             new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null);
177         }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
178
179         assertThatThrownBy(() -> {
180             new AuthorativeToscaProvider().getFilteredPolicyList(null, null);
181         }).hasMessageMatching(DAO_IS_NULL);
182
183         assertThatThrownBy(() -> {
184             new AuthorativeToscaProvider().getFilteredPolicyList(null,
185                     ToscaTypedEntityFilter.<ToscaPolicy>builder().build());
186         }).hasMessageMatching(DAO_IS_NULL);
187
188         assertThatThrownBy(() -> {
189             new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
190         }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
191
192         createPolicyTypes();
193
194         ToscaServiceTemplate toscaServiceTemplate =
195                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
196
197         assertNotNull(toscaServiceTemplate);
198         ToscaServiceTemplate createdServiceTemplate =
199                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
200
201         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
202
203         ToscaPolicy beforePolicy =
204                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
205         ToscaPolicy createdPolicy =
206                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
207         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
208         assertEquals(beforePolicy.getType(), createdPolicy.getType());
209
210         ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
211                 ToscaTypedEntityFilter.<ToscaPolicy>builder().build());
212
213         ToscaPolicy gotPolicy =
214                 gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
215         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
216         assertEquals(beforePolicy.getType(), gotPolicy.getType());
217
218         gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
219                 ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build());
220
221         gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
222         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
223         assertEquals(beforePolicy.getType(), gotPolicy.getType());
224
225         gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
226                 ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build());
227
228         gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
229         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
230         assertEquals(beforePolicy.getType(), gotPolicy.getType());
231
232         List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
233         assertEquals(1, gotPolicyList.size());
234         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
235
236         gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
237                 ToscaTypedEntityFilter.<ToscaPolicy>builder().build());
238         assertEquals(1, gotPolicyList.size());
239         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
240
241         gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
242                 ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).build());
243         assertEquals(1, gotPolicyList.size());
244         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
245
246         gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
247                 ToscaTypedEntityFilter.<ToscaPolicy>builder().name(policyKey.getName()).version(VERSION_100).build());
248         assertEquals(1, gotPolicyList.size());
249         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
250     }
251
252     @Test
253     public void testPolicyCreate() throws Exception {
254         assertThatThrownBy(() -> {
255             new AuthorativeToscaProvider().createPolicies(null, null);
256         }).hasMessageMatching(DAO_IS_NULL);
257
258         assertThatThrownBy(() -> {
259             new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate());
260         }).hasMessageMatching(DAO_IS_NULL);
261
262         assertThatThrownBy(() -> {
263             new AuthorativeToscaProvider().createPolicies(pfDao, null);
264         }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
265
266         createPolicyTypes();
267
268         ToscaServiceTemplate toscaServiceTemplate =
269                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
270
271         assertNotNull(toscaServiceTemplate);
272         ToscaServiceTemplate createdServiceTemplate =
273                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
274
275         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
276
277         ToscaPolicy beforePolicy =
278                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
279         ToscaPolicy createdPolicy =
280                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
281         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
282         assertEquals(beforePolicy.getType(), createdPolicy.getType());
283     }
284
285     @Test
286     public void testPolicyUpdate() throws Exception {
287         assertThatThrownBy(() -> {
288             new AuthorativeToscaProvider().createPolicies(null, null);
289         }).hasMessageMatching(DAO_IS_NULL);
290
291         assertThatThrownBy(() -> {
292             new AuthorativeToscaProvider().updatePolicies(null, null);
293         }).hasMessageMatching(DAO_IS_NULL);
294
295         assertThatThrownBy(() -> {
296             new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate());
297         }).hasMessageMatching(DAO_IS_NULL);
298
299         assertThatThrownBy(() -> {
300             new AuthorativeToscaProvider().updatePolicies(pfDao, null);
301         }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
302
303         createPolicyTypes();
304
305         ToscaServiceTemplate toscaServiceTemplate =
306                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
307
308         assertNotNull(toscaServiceTemplate);
309         ToscaServiceTemplate createdServiceTemplate =
310                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
311
312         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
313
314         ToscaPolicy beforePolicy =
315                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
316         ToscaPolicy createdPolicy =
317                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
318         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
319         assertEquals(beforePolicy.getType(), createdPolicy.getType());
320
321         ToscaServiceTemplate updatedServiceTemplate =
322                 new AuthorativeToscaProvider().updatePolicies(pfDao, toscaServiceTemplate);
323
324         ToscaPolicy updatedPolicy =
325                 updatedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
326         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, updatedPolicy));
327         assertEquals(beforePolicy.getType(), updatedPolicy.getType());
328     }
329
330     @Test
331     public void testPoliciesDelete() throws Exception {
332         assertThatThrownBy(() -> {
333             new AuthorativeToscaProvider().deletePolicy(null, null, null);
334         }).hasMessageMatching(DAO_IS_NULL);
335
336         assertThatThrownBy(() -> {
337             new AuthorativeToscaProvider().deletePolicy(null, null, VERSION);
338         }).hasMessageMatching(DAO_IS_NULL);
339
340         assertThatThrownBy(() -> {
341             new AuthorativeToscaProvider().deletePolicy(null, "name", null);
342         }).hasMessageMatching(DAO_IS_NULL);
343
344         assertThatThrownBy(() -> {
345             new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION);
346         }).hasMessageMatching(DAO_IS_NULL);
347
348         assertThatThrownBy(() -> {
349             new AuthorativeToscaProvider().deletePolicy(pfDao, null, null);
350         }).hasMessageMatching("^name is marked .*on.*ull but is null$");
351
352         assertThatThrownBy(() -> {
353             new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION);
354         }).hasMessageMatching("^name is marked .*on.*ull but is null$");
355
356         assertThatThrownBy(() -> {
357             new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
358         }).hasMessageMatching("^version is marked .*on.*ull but is null$");
359
360         createPolicyTypes();
361
362         ToscaServiceTemplate toscaServiceTemplate =
363                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
364
365         assertNotNull(toscaServiceTemplate);
366         ToscaServiceTemplate createdServiceTemplate =
367                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
368
369         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
370
371         ToscaPolicy beforePolicy =
372                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
373         ToscaPolicy createdPolicy =
374                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
375         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
376         assertEquals(beforePolicy.getType(), createdPolicy.getType());
377
378         ToscaServiceTemplate deletedServiceTemplate =
379                 new AuthorativeToscaProvider().deletePolicy(pfDao, policyKey.getName(), policyKey.getVersion());
380
381         ToscaPolicy deletedPolicy =
382                 deletedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
383         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
384         assertEquals(beforePolicy.getType(), deletedPolicy.getType());
385
386         // @formatter:off
387         assertThatThrownBy(
388             () -> new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()))
389                     .hasMessageMatching("policies for onap.restart.tca:1.0.0 do not exist");
390         // @formatter:on
391     }
392
393     @Test
394     public void testAssertPoliciesExist() {
395         ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate();
396
397         assertThatThrownBy(() -> {
398             new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
399         }).hasMessageMatching("^version is marked .*on.*ull but is null$");
400
401         assertThatThrownBy(() -> {
402             new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
403         }).hasMessage("topology template not specified on service template");
404
405         testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
406         assertThatThrownBy(() -> {
407             new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
408         }).hasMessage("no policies specified on topology template of service template");
409
410         testServiceTemplate.getToscaTopologyTemplate().setPolicies(new ArrayList<>());
411         assertThatThrownBy(() -> {
412             new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
413         }).hasMessage("An incoming list of concepts must have at least one entry");
414     }
415
416     @Test
417     public void testEntityMaps() throws CoderException, PfModelException {
418         Object yamlObject =
419                 new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
420         String yamlAsJsonString = new StandardCoder().encode(yamlObject);
421
422         ToscaServiceTemplate toscaServiceTemplatePolicyType =
423                 standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
424
425         assertNotNull(toscaServiceTemplatePolicyType);
426         new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
427
428         assertEquals(3, toscaServiceTemplatePolicyType.getDataTypesAsMap().size());
429         assertEquals(2, toscaServiceTemplatePolicyType.getPolicyTypesAsMap().size());
430
431         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
432                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
433                 ToscaServiceTemplate.class);
434
435         assertNotNull(toscaServiceTemplate);
436         ToscaServiceTemplate createdServiceTemplate =
437                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
438
439         PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
440
441         ToscaPolicy beforePolicy =
442                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
443         ToscaPolicy createdPolicy =
444                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
445         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
446         assertEquals(beforePolicy.getType(), createdPolicy.getType());
447
448         assertEquals(1, toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
449         assertEquals(1, createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
450
451         Map<String, ToscaPolicy> policyMapItem = createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0);
452         createdServiceTemplate.getToscaTopologyTemplate().getPolicies().add(policyMapItem);
453
454         assertThatThrownBy(() -> {
455             createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap();
456         }).hasMessageContaining("list of map of entities contains more than one entity with key");
457
458
459         ToscaDataType duplDataType = toscaServiceTemplatePolicyType.getDataTypes().values().iterator().next();
460         toscaServiceTemplatePolicyType.getDataTypes().put("DuplicateDataType", duplDataType);
461
462         assertThatThrownBy(() -> {
463             toscaServiceTemplatePolicyType.getDataTypesAsMap();
464         }).hasMessageContaining("list of map of entities contains more than one entity with key");
465     }
466
467     private void createPolicyTypes() throws CoderException, PfModelException {
468         Object yamlObject =
469                 new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
470         String yamlAsJsonString = new StandardCoder().encode(yamlObject);
471
472         ToscaServiceTemplate toscaServiceTemplatePolicyType =
473                 standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
474
475         assertNotNull(toscaServiceTemplatePolicyType);
476         new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
477     }
478 }