Merge "Remove legacy operational policy from models"
[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.tcagen2.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         assertEquals(2, policyTypesConceptMap.size());
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.tcagen2", secondPolicyType.getKey().getName());
163         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
164         assertEquals(MONITORING, secondPolicyType.getValue().getDerivedFrom().getName());
165         assertEquals(1, secondPolicyType.getValue().getProperties().size());
166
167         JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
168         assertEquals("onap.policies.monitoring.tcagen2", 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         assertEquals(3, dataTypesConceptMap.size());
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         assertEquals(6, firstDataTypeVal.getProperties().size());
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         assertEquals(1, firstDataTypeFirstProperty.getConstraints().size());
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         assertEquals(2, secondDataTypeVal.getProperties().size());
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         assertEquals(1, secondDataTypeFirstProperty.getConstraints().size());
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         assertEquals(7, thirdDataTypeVal.getProperties().size());
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         assertEquals(1, thirdDataTypeSecondProperty.getConstraints().size());
293         assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
294                 thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
295         assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
296                 .next() instanceof JpaToscaConstraintValidValues);
297         assertEquals(2,
298                 ((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
299                     .getValidValues().size());
300
301         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
302         assertEquals(THRESHOLDS, thirdDataTypeThirdProperty.getKey().getParentKeyName());
303         assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName());
304         assertEquals(STRING_TEXT, thirdDataTypeThirdProperty.getType().getName());
305         assertTrue(thirdDataTypeThirdProperty.isRequired());
306         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
307         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
308         assertEquals(1, thirdDataTypeThirdProperty.getConstraints().size());
309         assertEquals(
310                 "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
311                 thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
312         assertEquals(5,
313                 ((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
314                     .getValidValues().size());
315
316         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
317         assertEquals(THRESHOLDS, thirdDataTypeFourthProperty.getKey().getParentKeyName());
318         assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName());
319         assertEquals(STRING_TEXT, thirdDataTypeFourthProperty.getType().getName());
320         assertTrue(thirdDataTypeFourthProperty.isRequired());
321         assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
322                 thirdDataTypeFourthProperty.getDescription());
323         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
324         assertEquals(1, thirdDataTypeFourthProperty.getConstraints().size());
325         assertEquals(43,
326                 ((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
327                     .getValidValues().size());
328
329         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
330         assertEquals(THRESHOLDS, thirdDataTypeFifthProperty.getKey().getParentKeyName());
331         assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName());
332         assertEquals(STRING_TEXT, thirdDataTypeFifthProperty.getType().getName());
333         assertTrue(thirdDataTypeFifthProperty.isRequired());
334         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
335         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
336         assertEquals(1, thirdDataTypeFifthProperty.getConstraints().size());
337         assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
338                 thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
339         assertEquals(5,
340                 ((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
341                     .getValidValues().size());
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_1_0", serviceTemplate.getToscaDefinitionsVersion());
369
370         // Check policy_types
371         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
372         assertEquals(2, policyTypesConceptMap.size());
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("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
386         assertEquals(2, secondPolicyType.getValue().getProperties().size());
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 }