3c62a7424a150b298a66ec816c8775315f3dd013
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / serialization / MonitoringPolicyTypeSerializationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 Nordix Foundation.
4  *  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
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.simple.serialization;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.Iterator;
29 import java.util.Map;
30 import java.util.Map.Entry;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.utils.coder.CoderException;
35 import org.onap.policy.common.utils.coder.StandardCoder;
36 import org.onap.policy.common.utils.resources.ResourceUtils;
37 import org.onap.policy.models.base.PfConceptKey;
38 import org.onap.policy.models.base.PfValidationResult;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
40 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
41 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
42 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
43 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
44 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
45 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
46 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.yaml.snakeyaml.Yaml;
50
51 /**
52  * Test serialization of monitoring policy types.
53  *
54  * @author Chenfei Gao (cgao@research.att.com)
55  */
56 public class MonitoringPolicyTypeSerializationTest {
57
58     private static final String DATATYPE_ROOT = "tosca.datatypes.Root";
59
60     private static final String STRING_TEXT = "string";
61
62     private static final String DCAE = "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server";
63
64     private static final String MONITORING = "onap.policies.Monitoring";
65
66     private static final String THRESHOLDS = "onap.datatypes.monitoring.thresholds";
67
68     private static final String TCA = "onap.datatypes.monitoring.tca_policy";
69
70     private static final String METRICS = "onap.datatypes.monitoring.metricsPerEventName";
71
72     private static final String VERSION_100 = "1.0.0";
73
74     private static final String VERSION_000 = "0.0.0";
75
76     private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class);
77
78     private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
79     private static final String MONITORING_COLLECTORS_YAML =
80             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
81
82     private StandardCoder coder;
83
84     @Before
85     public void setUp() {
86         coder = new StandardCoder();
87     }
88
89     @Test
90     public void testDeserialization() throws Exception {
91         // TCA
92         JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
93         verifyTcaInputDeserialization(serviceTemplateFromYaml);
94
95         // Collector
96         serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
97         verifyCollectorInputDeserialization(serviceTemplateFromYaml);
98     }
99
100     @Test
101     public void testSerialization() throws Exception {
102         // TCA
103         JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
104         String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
105
106         ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
107                 coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
108
109         JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
110         serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
111         String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
112         assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
113
114         // Collector
115         JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
116                 deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
117         String serializedServiceTemplateCollector =
118                 serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
119         ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
120                 coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
121         JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
122         serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
123         String serializedServiceTemplateCollectorsOut =
124                 serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
125         assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
126     }
127
128     private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
129
130         Yaml yaml = new Yaml();
131         String policyTypeYaml = ResourceUtils.getResourceAsString(resourcePath);
132         Object yamlObject = yaml.load(policyTypeYaml);
133         String yamlAsJsonString = coder.encode(yamlObject);
134         ToscaServiceTemplate serviceTemplate = coder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
135
136         JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
137         jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
138         return jpaToscaServiceTemplate;
139     }
140
141     private void verifyTcaInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
142
143         // Sanity check the entire structure
144         assertNotNull(serviceTemplate);
145         LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
146         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
147
148         // Check tosca_definitions_version
149         assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
150
151         // Check policy_types
152         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
153         assertTrue(policyTypesConceptMap.size() == 2);
154         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
155
156         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
157         assertEquals(MONITORING, firstPolicyType.getKey().getName());
158         assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
159         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
160         assertEquals("a base policy type for all policies that govern monitoring provisioning",
161                 firstPolicyType.getValue().getDescription());
162
163         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
164         assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
165         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
166         assertEquals(MONITORING, secondPolicyType.getValue().getDerivedFrom().getName());
167         assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
168
169         JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
170         assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
171         assertEquals(VERSION_100, property.getKey().getParentKeyVersion());
172         assertEquals("tca_policy", property.getKey().getLocalName());
173         assertEquals("map", property.getType().getName());
174         assertEquals("TCA Policy JSON", property.getDescription());
175
176         JpaToscaEntrySchema entrySchema = property.getEntrySchema();
177         assertEquals(TCA, entrySchema.getType().getName());
178
179         // Check data_types
180         Map<PfConceptKey, JpaToscaDataType> dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap();
181         assertTrue(dataTypesConceptMap.size() == 3);
182         Iterator<Entry<PfConceptKey, JpaToscaDataType>> dataTypesIter = dataTypesConceptMap.entrySet().iterator();
183
184         Entry<PfConceptKey, JpaToscaDataType> firstDataType = dataTypesIter.next();
185         assertEquals(METRICS, firstDataType.getKey().getName());
186         JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
187         assertEquals(DATATYPE_ROOT, firstDataTypeVal.getDerivedFrom().getName());
188         assertEquals(VERSION_000, firstDataTypeVal.getDerivedFrom().getVersion());
189         assertTrue(firstDataTypeVal.getProperties().size() == 6);
190         Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
191
192         JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
193         assertEquals(METRICS, firstDataTypeFirstProperty.getKey().getParentKeyName());
194         assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
195         assertEquals(STRING_TEXT, firstDataTypeFirstProperty.getType().getName());
196         assertTrue(firstDataTypeFirstProperty.isRequired());
197         assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
198                 firstDataTypeFirstProperty.getDescription());
199         assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
200         assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
201                 firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getName());
202         assertTrue(((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
203                 .getValidValues().size() == 2);
204
205         JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
206         assertEquals(METRICS, firstDataTypeSecondProperty.getKey().getParentKeyName());
207         assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
208         assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName());
209         assertTrue(firstDataTypeSecondProperty.isRequired());
210         assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
211
212         JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
213         assertEquals(METRICS, firstDataTypeThirdProperty.getKey().getParentKeyName());
214         assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
215         assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName());
216         assertTrue(firstDataTypeThirdProperty.isRequired());
217         assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
218
219         JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
220         assertEquals(METRICS, firstDataTypeFourthProperty.getKey().getParentKeyName());
221         assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
222         assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName());
223         assertTrue(firstDataTypeFourthProperty.isRequired());
224         assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
225
226         JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
227         assertEquals(METRICS, firstDataTypeFifthProperty.getKey().getParentKeyName());
228         assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
229         assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName());
230         assertTrue(firstDataTypeFifthProperty.isRequired());
231         assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
232
233         JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
234         assertEquals(METRICS, firstDataTypeSixthProperty.getKey().getParentKeyName());
235         assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
236         assertEquals("list", firstDataTypeSixthProperty.getType().getName());
237         assertTrue(firstDataTypeSixthProperty.isRequired());
238         assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
239         assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
240         assertEquals(THRESHOLDS, firstDataTypeSixthProperty.getEntrySchema().getType().getName());
241
242         Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
243         assertEquals(TCA, secondDataType.getKey().getName());
244         JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
245         assertEquals(DATATYPE_ROOT, secondDataTypeVal.getDerivedFrom().getName());
246         assertEquals(VERSION_000, secondDataTypeVal.getDerivedFrom().getVersion());
247         assertTrue(secondDataTypeVal.getProperties().size() == 2);
248         Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
249
250         JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
251         assertEquals(TCA, secondDataTypeFirstProperty.getKey().getParentKeyName());
252         assertEquals("domain", secondDataTypeFirstProperty.getKey().getLocalName());
253         assertEquals(STRING_TEXT, secondDataTypeFirstProperty.getType().getName());
254         assertTrue(secondDataTypeFirstProperty.isRequired());
255         assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
256         assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
257         assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
258         assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() instanceof JpaToscaConstraintLogical);
259         assertEquals("measurementsForVfScaling",
260                 ((JpaToscaConstraintLogical) (secondDataTypeFirstProperty.getConstraints().iterator().next()))
261                         .getCompareTo());
262
263         JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
264         assertEquals(TCA, secondDataTypeSecondProperty.getKey().getParentKeyName());
265         assertEquals("metricsPerEventName", secondDataTypeSecondProperty.getKey().getLocalName());
266         assertEquals("list", secondDataTypeSecondProperty.getType().getName());
267         assertTrue(secondDataTypeSecondProperty.isRequired());
268         assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
269                 secondDataTypeSecondProperty.getDescription());
270         assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
271         assertEquals(METRICS, secondDataTypeSecondProperty.getEntrySchema().getType().getName());
272
273         Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
274         assertEquals(THRESHOLDS, thirdDataType.getKey().getName());
275         JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
276         assertEquals(DATATYPE_ROOT, thirdDataTypeVal.getDerivedFrom().getName());
277         assertEquals(VERSION_000, thirdDataTypeVal.getDerivedFrom().getVersion());
278         assertTrue(thirdDataTypeVal.getProperties().size() == 7);
279         Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
280
281         JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
282         assertEquals(THRESHOLDS, thirdDataTypeFirstProperty.getKey().getParentKeyName());
283         assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
284         assertEquals(STRING_TEXT, thirdDataTypeFirstProperty.getType().getName());
285         assertTrue(thirdDataTypeFirstProperty.isRequired());
286         assertEquals("Closed Loop Control Name associated with the threshold",
287                 thirdDataTypeFirstProperty.getDescription());
288
289         JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
290         assertEquals(THRESHOLDS, thirdDataTypeSecondProperty.getKey().getParentKeyName());
291         assertEquals("closedLoopEventStatus", thirdDataTypeSecondProperty.getKey().getLocalName());
292         assertEquals(STRING_TEXT, thirdDataTypeSecondProperty.getType().getName());
293         assertTrue(thirdDataTypeSecondProperty.isRequired());
294         assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
295         assertNotNull(thirdDataTypeSecondProperty.getConstraints());
296         assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
297         assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
298                 thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
299         assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
300                 .next() instanceof JpaToscaConstraintValidValues);
301         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
302                 .getValidValues().size() == 2);
303
304         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
305         assertEquals(THRESHOLDS, thirdDataTypeThirdProperty.getKey().getParentKeyName());
306         assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName());
307         assertEquals(STRING_TEXT, thirdDataTypeThirdProperty.getType().getName());
308         assertTrue(thirdDataTypeThirdProperty.isRequired());
309         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
310         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
311         assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
312         assertEquals(
313                 "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
314                 thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
315         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
316                 .getValidValues().size() == 5);
317
318         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
319         assertEquals(THRESHOLDS, thirdDataTypeFourthProperty.getKey().getParentKeyName());
320         assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName());
321         assertEquals(STRING_TEXT, thirdDataTypeFourthProperty.getType().getName());
322         assertTrue(thirdDataTypeFourthProperty.isRequired());
323         assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
324                 thirdDataTypeFourthProperty.getDescription());
325         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
326         assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
327         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
328                 .getValidValues().size() == 43);
329
330         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
331         assertEquals(THRESHOLDS, thirdDataTypeFifthProperty.getKey().getParentKeyName());
332         assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName());
333         assertEquals(STRING_TEXT, thirdDataTypeFifthProperty.getType().getName());
334         assertTrue(thirdDataTypeFifthProperty.isRequired());
335         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
336         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
337         assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
338         assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
339                 thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
340         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
341                 .getValidValues().size() == 5);
342         ;
343
344         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
345         assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName());
346         assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName());
347         assertEquals("integer", thirdDataTypeSixthProperty.getType().getName());
348         assertTrue(thirdDataTypeSixthProperty.isRequired());
349         assertEquals("Threshold value for the field Path inside CEF message",
350                 thirdDataTypeSixthProperty.getDescription());
351
352         JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
353         assertEquals(THRESHOLDS, thirdDataTypeSeventhProperty.getKey().getParentKeyName());
354         assertEquals("version", thirdDataTypeSeventhProperty.getKey().getLocalName());
355         assertEquals(STRING_TEXT, thirdDataTypeSeventhProperty.getType().getName());
356         assertTrue(thirdDataTypeSeventhProperty.isRequired());
357         assertEquals("Version number associated with the threshold", thirdDataTypeSeventhProperty.getDescription());
358     }
359
360     private void verifyCollectorInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
361
362         // Sanity check the entire structure
363         assertNotNull(serviceTemplate);
364         LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
365         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
366
367         // Check tosca_definitions_version
368         assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
369
370         // Check policy_types
371         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
372         assertTrue(policyTypesConceptMap.size() == 2);
373         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
374
375         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
376         assertEquals(MONITORING, firstPolicyType.getKey().getName());
377         assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
378         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
379         assertEquals("a base policy type for all policies that govern monitoring provisioning",
380                 firstPolicyType.getValue().getDescription());
381
382         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
383         assertEquals(DCAE, secondPolicyType.getKey().getName());
384         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
385         assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
386         assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
387
388         Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
389
390         JpaToscaProperty firstProperty = propertiesIter.next();
391         assertEquals(DCAE, firstProperty.getKey().getParentKeyName());
392         assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion());
393         assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
394         assertEquals(STRING_TEXT, firstProperty.getType().getName());
395         assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
396
397         JpaToscaProperty secondProperty = propertiesIter.next();
398         assertEquals(DCAE, secondProperty.getKey().getParentKeyName());
399         assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion());
400         assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
401         assertEquals(STRING_TEXT, secondProperty.getType().getName());
402         assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
403     }
404
405     private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
406         ToscaServiceTemplate toscaServiceTemplate = serviceTemplate.toAuthorative();
407         return coder.encode(toscaServiceTemplate);
408     }
409 }