2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2019-2021, 2023-2024 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
 
  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.simple.provider;
 
  24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
  25 import static org.junit.jupiter.api.Assertions.assertEquals;
 
  26 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
  27 import static org.junit.jupiter.api.Assertions.assertNull;
 
  29 import java.util.ArrayList;
 
  30 import java.util.LinkedHashMap;
 
  31 import java.util.Properties;
 
  32 import java.util.TreeMap;
 
  33 import org.junit.jupiter.api.AfterEach;
 
  34 import org.junit.jupiter.api.BeforeEach;
 
  35 import org.junit.jupiter.api.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.base.PfReferenceKey;
 
  42 import org.onap.policy.models.base.Validated;
 
  43 import org.onap.policy.models.dao.DaoParameters;
 
  44 import org.onap.policy.models.dao.PfDao;
 
  45 import org.onap.policy.models.dao.PfDaoFactory;
 
  46 import org.onap.policy.models.dao.impl.DefaultPfDao;
 
  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.provider.AuthorativeToscaProvider;
 
  50 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
 
  51 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
 
  52 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
 
  53 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 
  54 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 
  55 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
 
  56 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
 
  57 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
 
  58 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 
  59 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
 
  60 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
 
  61 import org.yaml.snakeyaml.Yaml;
 
  64  * Test the {@link SimpleToscaProvider} class.
 
  66  * @author Liam Fallon (liam.fallon@est.tech)
 
  68 class SimpleToscaProviderTest {
 
  69     private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$";
 
  70     private static final String INCOMING_TEMPLATE_IS_NULL = "^incomingServiceTemplate is marked .*on.*ull but is null$";
 
  71     private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
 
  72     private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
 
  75     private StandardCoder standardCoder;
 
  78      * Set up the DAO towards the database.
 
  80      * @throws Exception on database errors
 
  83     void setupDao() throws Exception {
 
  84         final DaoParameters daoParameters = new DaoParameters();
 
  85         daoParameters.setPluginClass(DefaultPfDao.class.getName());
 
  87         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
  89         Properties jdbcProperties = new Properties();
 
  90         jdbcProperties.setProperty("jakarta.persistence.jdbc.user", "policy");
 
  91         jdbcProperties.setProperty("jakarta.persistence.jdbc.password", "P01icY");
 
  93         if (System.getProperty("USE-MARIADB") != null) {
 
  94             jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
 
  95             jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
 
  97             jdbcProperties.setProperty("jakarta.persistence.jdbc.driver", "org.h2.Driver");
 
  98             jdbcProperties.setProperty("jakarta.persistence.jdbc.url", "jdbc:h2:mem:SimpleToscaProviderTest");
 
 101         daoParameters.setJdbcProperties(jdbcProperties);
 
 103         pfDao = new PfDaoFactory().createPfDao(daoParameters);
 
 104         pfDao.init(daoParameters);
 
 112         standardCoder = new StandardCoder();
 
 121     void testCreateUpdateGetDeleteDataType() throws PfModelException {
 
 122         PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1");
 
 123         JpaToscaDataType dataType0 = new JpaToscaDataType();
 
 124         dataType0.setKey(dataType0Key);
 
 125         dataType0.setConstraints(new ArrayList<JpaToscaConstraint>());
 
 126         dataType0.setMetadata(new TreeMap<String, String>());
 
 127         dataType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 129         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 130         serviceTemplate.setDataTypes(new JpaToscaDataTypes());
 
 131         serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
 
 133         JpaToscaServiceTemplate createdServiceTemplate =
 
 134             new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 136         assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size());
 
 137         assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key));
 
 138         assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
 
 140         dataType0.setDescription("Updated Description");
 
 142         JpaToscaServiceTemplate updatedServiceTemplate =
 
 143             new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate);
 
 145         assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key));
 
 146         assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
 
 148         JpaToscaServiceTemplate gotServiceTemplate =
 
 149             new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion());
 
 151         assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key));
 
 152         assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
 
 154         assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, new PfConceptKey("IDontExist:0.0.1")))
 
 155             .hasMessage("data type IDontExist:0.0.1 not found");
 
 157         JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
 
 159         assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
 
 160         assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
 
 162         // Create the data type again
 
 163         new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 165         updatedServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
 166         JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1"));
 
 167         updatedServiceTemplate.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0);
 
 168         new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate);
 
 170         deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
 
 172         assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
 
 173         assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
 
 175         assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
 
 176             .hasMessage("no data types found");
 
 178         // Create the data type again
 
 179         new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 181         JpaToscaPolicyType pt0v2 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.2"));
 
 182         JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0v2.getKey(), "prop0"));
 
 183         prop0.setType(dataType0Key);
 
 184         pt0v2.setProperties(new LinkedHashMap<>());
 
 185         pt0v2.getProperties().put(prop0.getKey().getLocalName(), prop0);
 
 186         updatedServiceTemplate.getPolicyTypes().getConceptMap().put(pt0v2.getKey(), pt0v2);
 
 187         new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate);
 
 189         assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
 
 190             .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
 
 192         JpaToscaDataType dataType0v2 = new JpaToscaDataType(new PfConceptKey("DataType0:0.0.2"));
 
 193         dataType0v2.setConstraints(new ArrayList<JpaToscaConstraint>());
 
 194         dataType0v2.setMetadata(new TreeMap<String, String>());
 
 195         dataType0v2.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 196         updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2);
 
 197         new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate);
 
 199         deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey());
 
 201         assertEquals(dataType0v2, deletedServiceTemplate.getDataTypes().get(dataType0v2.getKey()));
 
 202         assertNull(deletedServiceTemplate.getDataTypes().get(dataType0v2.getKey()).getDescription());
 
 204         assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
 
 205             .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
 
 207         JpaToscaDataType dataType1 = new JpaToscaDataType(new PfConceptKey("DataType1:0.0.3"));
 
 208         JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dataType1.getKey(), "prop1"));
 
 209         prop1.setType(dataType0v2.getKey());
 
 210         dataType1.setProperties(new LinkedHashMap<>());
 
 211         dataType1.getProperties().put(prop1.getKey().getLocalName(), prop1);
 
 212         updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType1.getKey(), dataType1);
 
 213         new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate);
 
 215         assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey()))
 
 216             .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3");
 
 220     void testCreateUpdateGetDeletePolicyType() throws PfModelException {
 
 221         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 223         PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1");
 
 224         JpaToscaDataType dataType0 = new JpaToscaDataType();
 
 225         dataType0.setKey(dataType0Key);
 
 226         serviceTemplate.setDataTypes(new JpaToscaDataTypes());
 
 227         serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
 
 229         PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1");
 
 230         JpaToscaPolicyType policyType0 = new JpaToscaPolicyType();
 
 231         policyType0.setKey(policyType0Key);
 
 232         policyType0.setMetadata(new TreeMap<String, String>());
 
 233         policyType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 234         policyType0.setTargets(new ArrayList<PfConceptKey>());
 
 235         policyType0.setTriggers(new ArrayList<JpaToscaTrigger>());
 
 236         serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
 237         serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
 
 239         JpaToscaServiceTemplate createdServiceTemplate =
 
 240             new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 242         assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size());
 
 243         assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 244         assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 246         policyType0.setDescription("Updated Description");
 
 248         JpaToscaServiceTemplate updatedServiceTemplate =
 
 249             new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
 
 251         assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 252         assertEquals("Updated Description",
 
 253             updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 255         JpaToscaServiceTemplate gotServiceTemplate =
 
 256             new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
 
 258         assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 259         assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 261         assertThatThrownBy(() -> {
 
 262             new SimpleToscaProvider().deletePolicyType(pfDao, new PfConceptKey("IDontExist:0.0.1"));
 
 263         }).hasMessage("policy type IDontExist:0.0.1 not found");
 
 265         JpaToscaPolicyType pt1 = new JpaToscaPolicyType(new PfConceptKey("pt1:0.0.2"));
 
 266         pt1.setDerivedFrom(policyType0Key);
 
 267         serviceTemplate.getPolicyTypes().getConceptMap().put(pt1.getKey(), pt1);
 
 268         new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 270         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
 
 271             .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
 
 273         serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
 
 274         serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
 
 276         JpaToscaPolicy p0 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.1"));
 
 277         p0.setType(policyType0Key);
 
 278         serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p0.getKey(), p0);
 
 280         JpaToscaPolicy p1 = new JpaToscaPolicy(new PfConceptKey("p1:0.0.1"));
 
 281         p1.setType(pt1.getKey());
 
 282         serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p1.getKey(), p1);
 
 283         new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
 
 285         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
 
 286             .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
 
 288         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey()))
 
 289             .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1");
 
 291         new SimpleToscaProvider().deletePolicy(pfDao, p1.getKey());
 
 293         new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey());
 
 295         new SimpleToscaProvider().deletePolicy(pfDao, p0.getKey());
 
 297         JpaToscaServiceTemplate deletedServiceTemplate =
 
 298             new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
 
 300         assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 301         assertEquals("Updated Description",
 
 302             deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 304         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
 
 305             .hasMessage("no policy types found");
 
 307         JpaToscaServiceTemplate newServiceTemplate =
 
 308             new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 309         assertEquals(serviceTemplate, newServiceTemplate);
 
 313     void testCreateUpdateGetDeletePolicyTypeWithDataType() throws PfModelException {
 
 314         PfConceptKey policyType0Key = new PfConceptKey("PolicyType0", "0.0.1");
 
 315         JpaToscaPolicyType policyType0 = new JpaToscaPolicyType();
 
 316         policyType0.setKey(policyType0Key);
 
 317         policyType0.setMetadata(new TreeMap<String, String>());
 
 318         policyType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 319         policyType0.setTargets(new ArrayList<PfConceptKey>());
 
 320         policyType0.setTriggers(new ArrayList<JpaToscaTrigger>());
 
 322         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 323         serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
 324         serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
 
 326         JpaToscaServiceTemplate createdServiceTemplate =
 
 327             new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 329         assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 330         assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 332         policyType0.setDescription("Updated Description");
 
 334         JpaToscaServiceTemplate updatedServiceTemplate =
 
 335             new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
 
 337         assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 338         assertEquals("Updated Description",
 
 339             updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 341         JpaToscaServiceTemplate gotServiceTemplate =
 
 342             new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
 
 344         assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 345         assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 347         JpaToscaServiceTemplate deletedServiceTemplate =
 
 348             new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
 
 350         assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
 
 351         assertEquals("Updated Description",
 
 352             deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
 
 354         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
 
 355             .hasMessage("no policy types found");
 
 359     void testPoliciesGet() throws Exception {
 
 360         ToscaServiceTemplate toscaServiceTemplate =
 
 361             standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
 
 365         JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
 
 366         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 368         assertNotNull(originalServiceTemplate);
 
 369         JpaToscaServiceTemplate createdServiceTemplate =
 
 370             new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
 
 372         assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
 
 373             createdServiceTemplate.getTopologyTemplate().getPolicies());
 
 375         PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
 
 377         JpaToscaServiceTemplate gotServiceTemplate =
 
 378             new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
 
 380         assertEquals(0, originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)
 
 381             .compareTo(gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)));
 
 383         JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey);
 
 384         assertEquals(1, deletedServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size());
 
 388     void testPolicyCreate() throws Exception {
 
 389         ToscaServiceTemplate toscaServiceTemplate =
 
 390             standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
 
 394         JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
 
 395         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 397         assertNotNull(originalServiceTemplate);
 
 398         JpaToscaServiceTemplate createdServiceTemplate =
 
 399             new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
 
 401         assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
 
 402             createdServiceTemplate.getTopologyTemplate().getPolicies());
 
 406     void testPolicyCreateTypeAndVersion() throws Exception {
 
 407         ToscaServiceTemplate toscaServiceTemplate =
 
 408             standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
 
 412         ToscaPolicy toscaPolicy =
 
 413             toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next();
 
 415         JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
 
 417         final String originalPolicyType = toscaPolicy.getType();
 
 418         final String originalPolicyTypeVersion = toscaPolicy.getTypeVersion();
 
 419         toscaPolicy.setType(null);
 
 420         toscaPolicy.setTypeVersion(null);
 
 422         assertThatThrownBy(() -> {
 
 423             originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 424         }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field");
 
 426         toscaPolicy.setType("IDontExist");
 
 427         assertThatThrownBy(() -> {
 
 428             originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 429         }).hasMessage("Version not specified, the version of this TOSCA entity must be "
 
 430             + "specified in the type_version field");
 
 432         toscaPolicy.setTypeVersion("hello");
 
 433         assertThatThrownBy(() -> {
 
 434             originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 435         }).hasMessageContaining("value \"hello\", does not match regular expression");
 
 437         toscaPolicy.setTypeVersion("99.100.101");
 
 438         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 440         assertThatThrownBy(() -> {
 
 441             new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
 
 442         }).hasMessageContaining("policy type").hasMessageContaining("IDontExist:99.100.101")
 
 443             .hasMessageContaining(Validated.NOT_FOUND);
 
 445         toscaPolicy.setType("IDontExist");
 
 446         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 448         toscaPolicy.setType(null);
 
 450         assertThatThrownBy(() -> {
 
 451             originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 452         }).hasMessage("Type not specified, the type of this TOSCA entity must be specified in the type field");
 
 454         toscaPolicy.setType(originalPolicyType);
 
 455         toscaPolicy.setTypeVersion(originalPolicyTypeVersion);
 
 457         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 458         JpaToscaServiceTemplate createdServiceTemplate =
 
 459             new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
 
 460         assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
 
 461             createdServiceTemplate.getTopologyTemplate().getPolicies());
 
 465     void testPolicyUpdate() throws Exception {
 
 466         ToscaServiceTemplate toscaServiceTemplate =
 
 467             standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
 
 471         JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
 
 472         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 474         assertNotNull(originalServiceTemplate);
 
 475         JpaToscaServiceTemplate updatedServiceTemplate =
 
 476             new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate);
 
 478         assertEquals(originalServiceTemplate, updatedServiceTemplate);
 
 482     void testPoliciesDelete() throws Exception {
 
 483         ToscaServiceTemplate toscaServiceTemplate =
 
 484             standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
 
 488         JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
 
 489         originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
 
 491         assertNotNull(originalServiceTemplate);
 
 492         JpaToscaServiceTemplate createdServiceTemplate =
 
 493             new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
 
 495         assertEquals(originalServiceTemplate.getTopologyTemplate(), createdServiceTemplate.getTopologyTemplate());
 
 497         PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
 
 499         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey("IDontExist:0.0.1")))
 
 500             .hasMessage("policy IDontExist:0.0.1 not found");
 
 502         JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey);
 
 504         assertEquals(0, originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)
 
 505             .compareTo(deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)));
 
 507         assertThatThrownBy(() -> {
 
 508             new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
 
 509         }).hasMessage("policies for onap.restart.tca:1.0.0 do not exist");
 
 511         assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey))
 
 512             .hasMessage("no policies found");
 
 514         new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
 
 518     void testAssertPoliciesExist() {
 
 519         JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate();
 
 521         assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
 
 522             .hasMessage("topology template not specified on service template");
 
 524         testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
 
 525         assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
 
 526             .hasMessage("no policies specified on topology template of service template");
 
 528         testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
 
 529         assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
 
 530             .hasMessage("list of policies specified on topology template of service template is empty");
 
 534     void testGetServiceTemplate() {
 
 535         assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao))
 
 536             .hasMessage("service template not found in database");
 
 540     void testAppendToServiceTemplate() {
 
 541         JpaToscaServiceTemplate serviceTemplateFragment = new JpaToscaServiceTemplate();
 
 542         serviceTemplateFragment.setPolicyTypes(new JpaToscaPolicyTypes());
 
 543         JpaToscaPolicyType badPt = new JpaToscaPolicyType();
 
 544         serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt);
 
 546         assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment))
 
 547             .hasMessageContaining("key on concept entry").hasMessageContaining("NULL:0.0.0")
 
 548             .hasMessageContaining(Validated.IS_A_NULL_KEY);
 
 552     void testGetDataTypesCornerCases() throws PfModelException {
 
 553         assertThatThrownBy(() -> {
 
 554             new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1");
 
 555         }).hasMessageMatching("service template not found in database");
 
 557         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 558         serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
 559         JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1"));
 
 560         serviceTemplate.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0);
 
 562         new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 564         assertThatThrownBy(() -> {
 
 565             new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1");
 
 566         }).hasMessageMatching("data types for hello:0.0.1 do not exist");
 
 568         serviceTemplate.setDataTypes(new JpaToscaDataTypes());
 
 570         JpaToscaDataType dt01 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
 
 571         dt01.setConstraints(new ArrayList<JpaToscaConstraint>());
 
 572         dt01.setMetadata(new TreeMap<String, String>());
 
 573         dt01.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 574         serviceTemplate.getDataTypes().getConceptMap().put(dt01.getKey(), dt01);
 
 576         new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 578         assertThatThrownBy(() -> {
 
 579             new SimpleToscaProvider().getDataTypes(pfDao, "hello", "0.0.1");
 
 580         }).hasMessageMatching("data types for hello:0.0.1 do not exist");
 
 582         JpaToscaServiceTemplate gotSt =
 
 583             new SimpleToscaProvider().getDataTypes(pfDao, dt01.getName(), dt01.getVersion());
 
 585         assertEquals(dt01, gotSt.getDataTypes().get(dt01.getKey()));
 
 586         assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName()));
 
 587         assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName(), null));
 
 588         assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName(), dt01.getVersion()));
 
 589         assertEquals(1, gotSt.getDataTypes().getAll(null).size());
 
 590         assertEquals(1, gotSt.getDataTypes().getAll(null, null).size());
 
 591         assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), null).size());
 
 592         assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), dt01.getVersion()).size());
 
 594         JpaToscaDataType dt02 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.2"));
 
 595         dt02.setConstraints(new ArrayList<JpaToscaConstraint>());
 
 596         dt02.setMetadata(new TreeMap<String, String>());
 
 597         dt02.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 598         serviceTemplate.getDataTypes().getConceptMap().put(dt02.getKey(), dt02);
 
 600         new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 601         gotSt = new SimpleToscaProvider().getDataTypes(pfDao, dt01.getName(), null);
 
 603         assertEquals(dt01, gotSt.getDataTypes().get(dt01.getKey()));
 
 604         assertEquals(dt02, gotSt.getDataTypes().get(dt01.getName()));
 
 605         assertEquals(dt02, gotSt.getDataTypes().get(dt01.getName(), null));
 
 606         assertEquals(dt01, gotSt.getDataTypes().get(dt01.getName(), dt01.getVersion()));
 
 607         assertEquals(dt02, gotSt.getDataTypes().get(dt01.getName(), dt02.getVersion()));
 
 608         assertEquals(2, gotSt.getDataTypes().getAll(null).size());
 
 609         assertEquals(2, gotSt.getDataTypes().getAll(null, null).size());
 
 610         assertEquals(2, gotSt.getDataTypes().getAll(dt01.getName(), null).size());
 
 611         assertEquals(1, gotSt.getDataTypes().getAll(dt01.getName(), dt02.getVersion()).size());
 
 615     void testGetPolicyTypesCornerCases() throws PfModelException {
 
 616         assertThatThrownBy(() -> {
 
 617             new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1");
 
 618         }).hasMessageMatching("service template not found in database");
 
 620         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 621         serviceTemplate.setDataTypes(new JpaToscaDataTypes());
 
 622         JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
 
 623         serviceTemplate.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
 
 625         new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 627         assertThatThrownBy(() -> {
 
 628             new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1");
 
 629         }).hasMessageMatching("policy types for hello:0.0.1 do not exist");
 
 631         serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
 633         JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.1"));
 
 634         pt01.setMetadata(new TreeMap<String, String>());
 
 635         pt01.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 636         pt01.setTargets(new ArrayList<PfConceptKey>());
 
 637         pt01.setTriggers(new ArrayList<JpaToscaTrigger>());
 
 638         serviceTemplate.getPolicyTypes().getConceptMap().put(pt01.getKey(), pt01);
 
 640         new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 642         assertThatThrownBy(() -> {
 
 643             new SimpleToscaProvider().getPolicyTypes(pfDao, "hello", "0.0.1");
 
 644         }).hasMessageMatching("policy types for hello:0.0.1 do not exist");
 
 646         JpaToscaServiceTemplate gotSt =
 
 647             new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion());
 
 649         assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey()));
 
 650         assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName()));
 
 651         assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName(), null));
 
 652         assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName(), pt01.getVersion()));
 
 653         assertEquals(1, gotSt.getPolicyTypes().getAll(null).size());
 
 654         assertEquals(1, gotSt.getPolicyTypes().getAll(null, null).size());
 
 655         assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), null).size());
 
 656         assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), pt01.getVersion()).size());
 
 658         JpaToscaPolicyType pt02 = new JpaToscaPolicyType(new PfConceptKey("p0:0.0.2"));
 
 659         pt02.setMetadata(new TreeMap<String, String>());
 
 660         pt02.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 661         pt02.setTargets(new ArrayList<PfConceptKey>());
 
 662         pt02.setTriggers(new ArrayList<JpaToscaTrigger>());
 
 663         serviceTemplate.getPolicyTypes().getConceptMap().put(pt02.getKey(), pt02);
 
 665         new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
 
 666         gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), null);
 
 668         assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey()));
 
 669         assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName()));
 
 670         assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName(), null));
 
 671         assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName(), pt01.getVersion()));
 
 672         assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName(), pt02.getVersion()));
 
 673         assertEquals(2, gotSt.getPolicyTypes().getAll(null).size());
 
 674         assertEquals(2, gotSt.getPolicyTypes().getAll(null, null).size());
 
 675         assertEquals(2, gotSt.getPolicyTypes().getAll(pt01.getName(), null).size());
 
 676         assertEquals(1, gotSt.getPolicyTypes().getAll(pt01.getName(), pt02.getVersion()).size());
 
 680     void testGetPoliciesCornerCases() throws PfModelException {
 
 681         assertThatThrownBy(() -> {
 
 682             new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1");
 
 683         }).hasMessageMatching("service template not found in database");
 
 685         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 686         serviceTemplate.setDataTypes(new JpaToscaDataTypes());
 
 687         JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
 
 688         dt0.setConstraints(new ArrayList<JpaToscaConstraint>());
 
 689         dt0.setMetadata(new TreeMap<String, String>());
 
 690         dt0.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 691         serviceTemplate.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
 
 693         new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 695         assertThatThrownBy(() -> {
 
 696             new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1");
 
 697         }).hasMessageMatching("policies for hello:0.0.1 do not exist");
 
 699         serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
 
 701         JpaToscaPolicyType pt01 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1"));
 
 702         pt01.setMetadata(new TreeMap<String, String>());
 
 703         pt01.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 704         pt01.setTargets(new ArrayList<PfConceptKey>());
 
 705         pt01.setTriggers(new ArrayList<JpaToscaTrigger>());
 
 706         serviceTemplate.getPolicyTypes().getConceptMap().put(pt01.getKey(), pt01);
 
 708         serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
 
 709         serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
 
 711         JpaToscaPolicy p01 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.1"));
 
 712         p01.setType(pt01.getKey());
 
 713         p01.setMetadata(new TreeMap<String, String>());
 
 714         p01.setProperties(new LinkedHashMap<String, String>());
 
 715         p01.setTargets(new ArrayList<PfConceptKey>());
 
 716         serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p01.getKey(), p01);
 
 718         new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
 
 720         assertThatThrownBy(() -> {
 
 721             new SimpleToscaProvider().getPolicies(pfDao, "hello", "0.0.1");
 
 722         }).hasMessageMatching("policies for hello:0.0.1 do not exist");
 
 724         JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion());
 
 726         assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getKey())));
 
 727         assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getName())));
 
 728         assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), null)));
 
 729         assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p01.getVersion())));
 
 730         assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(null).size());
 
 731         assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(null, null).size());
 
 732         assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), null).size());
 
 733         assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), p01.getVersion()).size());
 
 735         JpaToscaPolicy p02 = new JpaToscaPolicy(new PfConceptKey("p0:0.0.2"));
 
 736         p02.setType(pt01.getKey());
 
 737         p02.setType(pt01.getKey());
 
 738         p02.setMetadata(new TreeMap<String, String>());
 
 739         p02.setProperties(new LinkedHashMap<String, String>());
 
 740         p02.setTargets(new ArrayList<PfConceptKey>());
 
 741         serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p02.getKey(), p02);
 
 743         new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
 
 744         gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), null);
 
 746         assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getKey()));
 
 747         assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName()));
 
 748         assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), null));
 
 749         assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p01.getVersion()));
 
 750         assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p02.getVersion()));
 
 751         assertEquals(2, gotSt.getTopologyTemplate().getPolicies().getAll(null).size());
 
 752         assertEquals(2, gotSt.getTopologyTemplate().getPolicies().getAll(null, null).size());
 
 753         assertEquals(2, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), null).size());
 
 754         assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), p02.getVersion()).size());
 
 758     void testNonNullsDataType() {
 
 759         assertThatThrownBy(() -> {
 
 760             new SimpleToscaProvider().getServiceTemplate(null);
 
 761         }).hasMessageMatching(DAO_IS_NULL);
 
 763         assertThatThrownBy(() -> {
 
 764             new SimpleToscaProvider().appendToServiceTemplate(null, null);
 
 765         }).hasMessageMatching(DAO_IS_NULL);
 
 767         assertThatThrownBy(() -> {
 
 768             new SimpleToscaProvider().appendToServiceTemplate(null, new JpaToscaServiceTemplate());
 
 769         }).hasMessageMatching(DAO_IS_NULL);
 
 771         assertThatThrownBy(() -> {
 
 772             new SimpleToscaProvider().appendToServiceTemplate(pfDao, null);
 
 773         }).hasMessageMatching("^incomingServiceTemplateFragment is marked .*on.*ull but is null$");
 
 775         assertThatThrownBy(() -> {
 
 776             new SimpleToscaProvider().getDataTypes(null, null, null);
 
 777         }).hasMessageMatching(DAO_IS_NULL);
 
 779         assertThatThrownBy(() -> {
 
 780             new SimpleToscaProvider().createDataTypes(null, null);
 
 781         }).hasMessageMatching(DAO_IS_NULL);
 
 783         assertThatThrownBy(() -> {
 
 784             new SimpleToscaProvider().createDataTypes(null, new JpaToscaServiceTemplate());
 
 785         }).hasMessageMatching(DAO_IS_NULL);
 
 787         assertThatThrownBy(() -> {
 
 788             new SimpleToscaProvider().createDataTypes(pfDao, null);
 
 789         }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL);
 
 791         assertThatThrownBy(() -> {
 
 792             new SimpleToscaProvider().updateDataTypes(null, null);
 
 793         }).hasMessageMatching(DAO_IS_NULL);
 
 795         assertThatThrownBy(() -> {
 
 796             new SimpleToscaProvider().updateDataTypes(null, new JpaToscaServiceTemplate());
 
 797         }).hasMessageMatching(DAO_IS_NULL);
 
 799         assertThatThrownBy(() -> {
 
 800             new SimpleToscaProvider().updateDataTypes(pfDao, null);
 
 801         }).hasMessageMatching(TEMPLATE_IS_NULL);
 
 803         assertThatThrownBy(() -> {
 
 804             new SimpleToscaProvider().deleteDataType(null, null);
 
 805         }).hasMessageMatching(DAO_IS_NULL);
 
 807         assertThatThrownBy(() -> {
 
 808             new SimpleToscaProvider().deleteDataType(null, new PfConceptKey());
 
 809         }).hasMessageMatching(DAO_IS_NULL);
 
 811         assertThatThrownBy(() -> {
 
 812             new SimpleToscaProvider().deleteDataType(pfDao, null);
 
 813         }).hasMessageMatching("^dataTypeKey is marked .*on.*ull but is null$");
 
 817     void testNotNullsPolicyTypes() {
 
 818         assertThatThrownBy(() -> {
 
 819             new SimpleToscaProvider().getPolicyTypes(null, null, null);
 
 820         }).hasMessageMatching(DAO_IS_NULL);
 
 822         assertThatThrownBy(() -> {
 
 823             new SimpleToscaProvider().createPolicyTypes(null, null);
 
 824         }).hasMessageMatching(DAO_IS_NULL);
 
 826         assertThatThrownBy(() -> {
 
 827             new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate());
 
 828         }).hasMessageMatching(DAO_IS_NULL);
 
 830         assertThatThrownBy(() -> {
 
 831             new SimpleToscaProvider().createPolicyTypes(pfDao, null);
 
 832         }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL);
 
 834         assertThatThrownBy(() -> {
 
 835             new SimpleToscaProvider().updatePolicyTypes(null, null);
 
 836         }).hasMessageMatching(DAO_IS_NULL);
 
 838         assertThatThrownBy(() -> {
 
 839             new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate());
 
 840         }).hasMessageMatching(DAO_IS_NULL);
 
 842         assertThatThrownBy(() -> {
 
 843             new SimpleToscaProvider().updatePolicyTypes(pfDao, null);
 
 844         }).hasMessageMatching(TEMPLATE_IS_NULL);
 
 846         assertThatThrownBy(() -> {
 
 847             new SimpleToscaProvider().deletePolicyType(null, null);
 
 848         }).hasMessageMatching(DAO_IS_NULL);
 
 850         assertThatThrownBy(() -> {
 
 851             new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey());
 
 852         }).hasMessageMatching(DAO_IS_NULL);
 
 854         assertThatThrownBy(() -> {
 
 855             new SimpleToscaProvider().deletePolicyType(pfDao, null);
 
 856         }).hasMessageMatching("^policyTypeKey is marked .*on.*ull but is null$");
 
 858         assertThatThrownBy(() -> {
 
 859             new SimpleToscaProvider().getPolicies(null, null, null);
 
 860         }).hasMessageMatching(DAO_IS_NULL);
 
 862         assertThatThrownBy(() -> {
 
 863             new SimpleToscaProvider().createPolicies(null, null);
 
 864         }).hasMessageMatching(DAO_IS_NULL);
 
 866         assertThatThrownBy(() -> {
 
 867             new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate());
 
 868         }).hasMessageMatching(DAO_IS_NULL);
 
 870         assertThatThrownBy(() -> {
 
 871             new SimpleToscaProvider().createPolicies(pfDao, null);
 
 872         }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL);
 
 874         assertThatThrownBy(() -> {
 
 875             new SimpleToscaProvider().updatePolicies(null, null);
 
 876         }).hasMessageMatching(DAO_IS_NULL);
 
 878         assertThatThrownBy(() -> {
 
 879             new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate());
 
 880         }).hasMessageMatching(DAO_IS_NULL);
 
 882         assertThatThrownBy(() -> {
 
 883             new SimpleToscaProvider().updatePolicies(pfDao, null);
 
 884         }).hasMessageMatching(TEMPLATE_IS_NULL);
 
 886         assertThatThrownBy(() -> {
 
 887             new SimpleToscaProvider().deletePolicy(null, null);
 
 888         }).hasMessageMatching(DAO_IS_NULL);
 
 890         assertThatThrownBy(() -> {
 
 891             new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
 
 892         }).hasMessageMatching(DAO_IS_NULL);
 
 894         assertThatThrownBy(() -> {
 
 895             new SimpleToscaProvider().deletePolicy(pfDao, null);
 
 896         }).hasMessageMatching("^policyKey is marked .*on.*ull but is null$");
 
 900     void testDeleteServiceTemplate() throws PfModelException {
 
 901         assertThatThrownBy(() -> {
 
 902             new SimpleToscaProvider().deleteServiceTemplate(null);
 
 903         }).hasMessageMatching("^dao is marked .*on.*ull but is null$");
 
 905         assertThatThrownBy(() -> {
 
 906             new SimpleToscaProvider().deleteServiceTemplate(pfDao);
 
 907         }).hasMessage("service template not found in database");
 
 909         PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1");
 
 910         JpaToscaDataType dataType0 = new JpaToscaDataType();
 
 911         dataType0.setKey(dataType0Key);
 
 912         dataType0.setConstraints(new ArrayList<JpaToscaConstraint>());
 
 913         dataType0.setMetadata(new TreeMap<String, String>());
 
 914         dataType0.setProperties(new LinkedHashMap<String, JpaToscaProperty>());
 
 916         JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
 
 917         serviceTemplate.setDataTypes(new JpaToscaDataTypes());
 
 918         serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
 
 920         JpaToscaServiceTemplate createdServiceTemplate =
 
 921             new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
 
 923         assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size());
 
 924         assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key));
 
 925         assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
 
 927         JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteServiceTemplate(pfDao);
 
 929         assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
 
 933     void testNullParameters() {
 
 934         assertThatThrownBy(() -> {
 
 935             new SimpleToscaProvider().getCascadedDataTypes(null, null, null);
 
 936         }).hasMessageMatching("^dbServiceTemplate is marked .*on.*ull but is null$");
 
 939     private void createPolicyTypes() throws CoderException, PfModelException {
 
 941             new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
 
 942         String yamlAsJsonString = new StandardCoder().encode(yamlObject);
 
 944         ToscaServiceTemplate toscaServiceTemplatePolicyType =
 
 945             standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
 947         assertNotNull(toscaServiceTemplatePolicyType);
 
 948         new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);