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