2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2019-2020 Nordix Foundation.
 
   4  *  Modifications Copyright (C) 2019 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
 
  10  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.models.tosca.authorative.provider;
 
  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;
 
  29 import java.util.ArrayList;
 
  30 import java.util.List;
 
  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.ToscaPolicy;
 
  47 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
 
  48 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
  49 import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
 
  50 import org.yaml.snakeyaml.Yaml;
 
  53  * Test of the {@link AuthorativeToscaProvider} class.
 
  55  * @author Liam Fallon (liam.fallon@est.tech)
 
  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";
 
  65     private StandardCoder standardCoder;
 
  68      * Set up the DAO towards the database.
 
  70      * @throws Exception on database errors
 
  73     public void setupDao() throws Exception {
 
  74         final DaoParameters daoParameters = new DaoParameters();
 
  75         daoParameters.setPluginClass(DefaultPfDao.class.getName());
 
  77         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
  79         Properties jdbcProperties = new Properties();
 
  80         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy");
 
  81         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY");
 
  83         // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
 
  84         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
 
  85         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
 
  87         daoParameters.setJdbcProperties(jdbcProperties);
 
  89         pfDao = new PfDaoFactory().createPfDao(daoParameters);
 
  90         pfDao.init(daoParameters);
 
  97     public void setupGson() {
 
  98         standardCoder = new StandardCoder();
 
 102     public void teardown() {
 
 107     public void testPoliciesGet() throws Exception {
 
 108         assertThatThrownBy(() -> {
 
 109             new AuthorativeToscaProvider().getPolicies(null, null, null);
 
 110         }).hasMessageMatching(DAO_IS_NULL);
 
 112         assertThatThrownBy(() -> {
 
 113             new AuthorativeToscaProvider().getPolicyList(null, null, null);
 
 114         }).hasMessageMatching(DAO_IS_NULL);
 
 118         ToscaServiceTemplate toscaServiceTemplate =
 
 119                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
 
 121         assertNotNull(toscaServiceTemplate);
 
 122         ToscaServiceTemplate createdServiceTemplate =
 
 123                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
 
 125         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
 
 127         ToscaPolicy beforePolicy =
 
 128                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 129         ToscaPolicy createdPolicy =
 
 130                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 131         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 132         assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
 
 134         ToscaServiceTemplate gotServiceTemplate =
 
 135                 new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
 
 137         ToscaPolicy gotPolicy =
 
 138                 gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 139         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
 
 140         assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
 
 142         List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
 
 143         assertEquals(1, gotPolicyList.size());
 
 144         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 146         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, null);
 
 147         assertEquals(1, gotPolicyList.size());
 
 148         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 150         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, null);
 
 151         assertEquals(1, gotPolicyList.size());
 
 152         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 154         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, VERSION_100);
 
 155         assertEquals(1, gotPolicyList.size());
 
 156         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 158         assertTrue(new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100).isEmpty());
 
 162     public void testPoliciesGetFiltered() throws Exception {
 
 163         assertThatThrownBy(() -> {
 
 164             new AuthorativeToscaProvider().getFilteredPolicies(null, null);
 
 165         }).hasMessageMatching(DAO_IS_NULL);
 
 167         assertThatThrownBy(() -> {
 
 168             new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build());
 
 169         }).hasMessageMatching(DAO_IS_NULL);
 
 171         assertThatThrownBy(() -> {
 
 172             new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null);
 
 173         }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
 
 175         assertThatThrownBy(() -> {
 
 176             new AuthorativeToscaProvider().getFilteredPolicyList(null, null);
 
 177         }).hasMessageMatching(DAO_IS_NULL);
 
 179         assertThatThrownBy(() -> {
 
 180             new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build());
 
 181         }).hasMessageMatching(DAO_IS_NULL);
 
 183         assertThatThrownBy(() -> {
 
 184             new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
 
 185         }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
 
 189         ToscaServiceTemplate toscaServiceTemplate =
 
 190                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
 
 192         assertNotNull(toscaServiceTemplate);
 
 193         ToscaServiceTemplate createdServiceTemplate =
 
 194                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
 
 196         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
 
 198         ToscaPolicy beforePolicy =
 
 199                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 200         ToscaPolicy createdPolicy =
 
 201                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 202         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 203         assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
 
 205         ToscaServiceTemplate gotServiceTemplate =
 
 206                 new AuthorativeToscaProvider().getFilteredPolicies(pfDao, ToscaPolicyFilter.builder().build());
 
 208         ToscaPolicy gotPolicy =
 
 209                 gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 210         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
 
 211         assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
 
 213         gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
 
 214                 ToscaPolicyFilter.builder().name(policyKey.getName()).build());
 
 216         gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 217         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
 
 218         assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
 
 220         gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
 
 221                 ToscaPolicyFilter.builder().name(policyKey.getName()).version(VERSION_100).build());
 
 223         gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 224         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
 
 225         assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
 
 227         List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
 
 228         assertEquals(1, gotPolicyList.size());
 
 229         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 232                 new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, ToscaPolicyFilter.builder().build());
 
 233         assertEquals(1, gotPolicyList.size());
 
 234         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 236         gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
 
 237                 ToscaPolicyFilter.builder().name(policyKey.getName()).build());
 
 238         assertEquals(1, gotPolicyList.size());
 
 239         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 241         gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
 
 242                 ToscaPolicyFilter.builder().name(policyKey.getName()).version(VERSION_100).build());
 
 243         assertEquals(1, gotPolicyList.size());
 
 244         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
 
 248     public void testPolicyCreate() throws Exception {
 
 249         assertThatThrownBy(() -> {
 
 250             new AuthorativeToscaProvider().createPolicies(null, null);
 
 251         }).hasMessageMatching(DAO_IS_NULL);
 
 253         assertThatThrownBy(() -> {
 
 254             new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate());
 
 255         }).hasMessageMatching(DAO_IS_NULL);
 
 257         assertThatThrownBy(() -> {
 
 258             new AuthorativeToscaProvider().createPolicies(pfDao, null);
 
 259         }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
 
 263         ToscaServiceTemplate toscaServiceTemplate =
 
 264                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
 
 266         assertNotNull(toscaServiceTemplate);
 
 267         ToscaServiceTemplate createdServiceTemplate =
 
 268                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
 
 270         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
 
 272         ToscaPolicy beforePolicy =
 
 273                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 274         ToscaPolicy createdPolicy =
 
 275                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 276         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 277         assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
 
 281     public void testPolicyUpdate() throws Exception {
 
 282         assertThatThrownBy(() -> {
 
 283             new AuthorativeToscaProvider().createPolicies(null, null);
 
 284         }).hasMessageMatching(DAO_IS_NULL);
 
 286         assertThatThrownBy(() -> {
 
 287             new AuthorativeToscaProvider().updatePolicies(null, null);
 
 288         }).hasMessageMatching(DAO_IS_NULL);
 
 290         assertThatThrownBy(() -> {
 
 291             new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate());
 
 292         }).hasMessageMatching(DAO_IS_NULL);
 
 294         assertThatThrownBy(() -> {
 
 295             new AuthorativeToscaProvider().updatePolicies(pfDao, null);
 
 296         }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
 
 300         ToscaServiceTemplate toscaServiceTemplate =
 
 301                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
 
 303         assertNotNull(toscaServiceTemplate);
 
 304         ToscaServiceTemplate createdServiceTemplate =
 
 305                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
 
 307         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
 
 309         ToscaPolicy beforePolicy =
 
 310                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 311         ToscaPolicy createdPolicy =
 
 312                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 313         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 314         assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
 
 316         ToscaServiceTemplate updatedServiceTemplate =
 
 317                 new AuthorativeToscaProvider().updatePolicies(pfDao, toscaServiceTemplate);
 
 319         ToscaPolicy updatedPolicy =
 
 320                 updatedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 321         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, updatedPolicy));
 
 322         assertTrue(beforePolicy.getType().equals(updatedPolicy.getType()));
 
 326     public void testPoliciesDelete() throws Exception {
 
 327         assertThatThrownBy(() -> {
 
 328             new AuthorativeToscaProvider().deletePolicy(null, null, null);
 
 329         }).hasMessageMatching(DAO_IS_NULL);
 
 331         assertThatThrownBy(() -> {
 
 332             new AuthorativeToscaProvider().deletePolicy(null, null, VERSION);
 
 333         }).hasMessageMatching(DAO_IS_NULL);
 
 335         assertThatThrownBy(() -> {
 
 336             new AuthorativeToscaProvider().deletePolicy(null, "name", null);
 
 337         }).hasMessageMatching(DAO_IS_NULL);
 
 339         assertThatThrownBy(() -> {
 
 340             new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION);
 
 341         }).hasMessageMatching(DAO_IS_NULL);
 
 343         assertThatThrownBy(() -> {
 
 344             new AuthorativeToscaProvider().deletePolicy(pfDao, null, null);
 
 345         }).hasMessageMatching("^name is marked .*on.*ull but is null$");
 
 347         assertThatThrownBy(() -> {
 
 348             new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION);
 
 349         }).hasMessageMatching("^name is marked .*on.*ull but is null$");
 
 351         assertThatThrownBy(() -> {
 
 352             new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
 
 353         }).hasMessageMatching("^version is marked .*on.*ull but is null$");
 
 357         ToscaServiceTemplate toscaServiceTemplate =
 
 358                 standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
 
 360         assertNotNull(toscaServiceTemplate);
 
 361         ToscaServiceTemplate createdServiceTemplate =
 
 362                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
 
 364         PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
 
 366         ToscaPolicy beforePolicy =
 
 367                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 368         ToscaPolicy createdPolicy =
 
 369                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 370         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 371         assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
 
 373         ToscaServiceTemplate deletedServiceTemplate =
 
 374                 new AuthorativeToscaProvider().deletePolicy(pfDao, policyKey.getName(), policyKey.getVersion());
 
 376         ToscaPolicy deletedPolicy =
 
 377                 deletedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 378         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 379         assertTrue(beforePolicy.getType().equals(deletedPolicy.getType()));
 
 383             () -> new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()))
 
 384                     .hasMessageMatching("policies for onap.restart.tca:1.0.0 do not exist");
 
 389     public void testAssertPoliciesExist() {
 
 390         ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate();
 
 392         assertThatThrownBy(() -> {
 
 393             new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
 
 394         }).hasMessageMatching("^version is marked .*on.*ull but is null$");
 
 396         assertThatThrownBy(() -> {
 
 397             new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
 
 398         }).hasMessage("topology template not specified on service template");
 
 400         testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
 
 401         assertThatThrownBy(() -> {
 
 402             new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
 
 403         }).hasMessage("no policies specified on topology template of service template");
 
 405         testServiceTemplate.getToscaTopologyTemplate().setPolicies(new ArrayList<>());
 
 406         assertThatThrownBy(() -> {
 
 407             new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
 
 408         }).hasMessage("An incoming list of concepts must have at least one entry");
 
 412     public void testEntityMaps() throws CoderException, PfModelException {
 
 413         Object yamlObject = new Yaml().load(
 
 414                 ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
 
 415         String yamlAsJsonString = new StandardCoder().encode(yamlObject);
 
 417         ToscaServiceTemplate toscaServiceTemplatePolicyType =
 
 418                 standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
 420         assertNotNull(toscaServiceTemplatePolicyType);
 
 421         new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
 
 423         assertEquals(3, toscaServiceTemplatePolicyType.getDataTypesAsMap().size());
 
 424         assertEquals(2, toscaServiceTemplatePolicyType.getPolicyTypesAsMap().size());
 
 426         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
 
 427                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
 
 428                 ToscaServiceTemplate.class);
 
 430         assertNotNull(toscaServiceTemplate);
 
 431         ToscaServiceTemplate createdServiceTemplate =
 
 432                 new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
 
 434         PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
 
 436         ToscaPolicy beforePolicy =
 
 437                 toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 438         ToscaPolicy createdPolicy =
 
 439                 createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
 
 440         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
 
 441         assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
 
 443         assertEquals(1, toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
 
 444         assertEquals(1, createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
 
 446         Map<String, ToscaPolicy> policyMapItem = createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0);
 
 447         createdServiceTemplate.getToscaTopologyTemplate().getPolicies().add(policyMapItem);
 
 449         assertThatThrownBy(() -> {
 
 450             createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap();
 
 451         }).hasMessageContaining("list of map of entities contains more than one entity with key");
 
 454     private void createPolicyTypes() throws CoderException, PfModelException {
 
 455         Object yamlObject = new Yaml().load(
 
 456                 ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
 
 457         String yamlAsJsonString = new StandardCoder().encode(yamlObject);
 
 459         ToscaServiceTemplate toscaServiceTemplatePolicyType =
 
 460                 standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
 462         assertNotNull(toscaServiceTemplatePolicyType);
 
 463         new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);