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