Merge "Add safe entity delete, fix multiple entity get"
[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
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         assertEquals(2,
203                 ((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
204                         .getValidValues().size());
205
206         JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
207         assertEquals(METRICS, firstDataTypeSecondProperty.getKey().getParentKeyName());
208         assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
209         assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName());
210         assertTrue(firstDataTypeSecondProperty.isRequired());
211         assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
212
213         JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
214         assertEquals(METRICS, firstDataTypeThirdProperty.getKey().getParentKeyName());
215         assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
216         assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName());
217         assertTrue(firstDataTypeThirdProperty.isRequired());
218         assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
219
220         JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
221         assertEquals(METRICS, firstDataTypeFourthProperty.getKey().getParentKeyName());
222         assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
223         assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName());
224         assertTrue(firstDataTypeFourthProperty.isRequired());
225         assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
226
227         JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
228         assertEquals(METRICS, firstDataTypeFifthProperty.getKey().getParentKeyName());
229         assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
230         assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName());
231         assertTrue(firstDataTypeFifthProperty.isRequired());
232         assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
233
234         JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
235         assertEquals(METRICS, firstDataTypeSixthProperty.getKey().getParentKeyName());
236         assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
237         assertEquals("list", firstDataTypeSixthProperty.getType().getName());
238         assertTrue(firstDataTypeSixthProperty.isRequired());
239         assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
240         assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
241         assertEquals(THRESHOLDS, firstDataTypeSixthProperty.getEntrySchema().getType().getName());
242
243         Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
244         assertEquals(TCA, secondDataType.getKey().getName());
245         JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
246         assertEquals(DATATYPE_ROOT, secondDataTypeVal.getDerivedFrom().getName());
247         assertEquals(VERSION_000, secondDataTypeVal.getDerivedFrom().getVersion());
248         assertTrue(secondDataTypeVal.getProperties().size() == 2);
249         Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
250
251         JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
252         assertEquals(TCA, secondDataTypeFirstProperty.getKey().getParentKeyName());
253         assertEquals("domain", secondDataTypeFirstProperty.getKey().getLocalName());
254         assertEquals(STRING_TEXT, secondDataTypeFirstProperty.getType().getName());
255         assertTrue(secondDataTypeFirstProperty.isRequired());
256         assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
257         assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
258         assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
259         assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() instanceof JpaToscaConstraintLogical);
260         assertEquals("measurementsForVfScaling",
261                 ((JpaToscaConstraintLogical) (secondDataTypeFirstProperty.getConstraints().iterator().next()))
262                         .getCompareTo());
263
264         JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
265         assertEquals(TCA, secondDataTypeSecondProperty.getKey().getParentKeyName());
266         assertEquals("metricsPerEventName", secondDataTypeSecondProperty.getKey().getLocalName());
267         assertEquals("list", secondDataTypeSecondProperty.getType().getName());
268         assertTrue(secondDataTypeSecondProperty.isRequired());
269         assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
270                 secondDataTypeSecondProperty.getDescription());
271         assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
272         assertEquals(METRICS, secondDataTypeSecondProperty.getEntrySchema().getType().getName());
273
274         Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
275         assertEquals(THRESHOLDS, thirdDataType.getKey().getName());
276         JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
277         assertEquals(DATATYPE_ROOT, thirdDataTypeVal.getDerivedFrom().getName());
278         assertEquals(VERSION_000, thirdDataTypeVal.getDerivedFrom().getVersion());
279         assertTrue(thirdDataTypeVal.getProperties().size() == 7);
280         Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
281
282         JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
283         assertEquals(THRESHOLDS, thirdDataTypeFirstProperty.getKey().getParentKeyName());
284         assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
285         assertEquals(STRING_TEXT, thirdDataTypeFirstProperty.getType().getName());
286         assertTrue(thirdDataTypeFirstProperty.isRequired());
287         assertEquals("Closed Loop Control Name associated with the threshold",
288                 thirdDataTypeFirstProperty.getDescription());
289
290         JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
291         assertEquals(THRESHOLDS, thirdDataTypeSecondProperty.getKey().getParentKeyName());
292         assertEquals("closedLoopEventStatus", thirdDataTypeSecondProperty.getKey().getLocalName());
293         assertEquals(STRING_TEXT, thirdDataTypeSecondProperty.getType().getName());
294         assertTrue(thirdDataTypeSecondProperty.isRequired());
295         assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
296         assertNotNull(thirdDataTypeSecondProperty.getConstraints());
297         assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
298         assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
299                 thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
300         assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
301                 .next() instanceof JpaToscaConstraintValidValues);
302         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
303                 .getValidValues().size() == 2);
304
305         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
306         assertEquals(THRESHOLDS, thirdDataTypeThirdProperty.getKey().getParentKeyName());
307         assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName());
308         assertEquals(STRING_TEXT, thirdDataTypeThirdProperty.getType().getName());
309         assertTrue(thirdDataTypeThirdProperty.isRequired());
310         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
311         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
312         assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
313         assertEquals(
314                 "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
315                 thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
316         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
317                 .getValidValues().size() == 5);
318
319         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
320         assertEquals(THRESHOLDS, thirdDataTypeFourthProperty.getKey().getParentKeyName());
321         assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName());
322         assertEquals(STRING_TEXT, thirdDataTypeFourthProperty.getType().getName());
323         assertTrue(thirdDataTypeFourthProperty.isRequired());
324         assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
325                 thirdDataTypeFourthProperty.getDescription());
326         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
327         assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
328         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
329                 .getValidValues().size() == 43);
330
331         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
332         assertEquals(THRESHOLDS, thirdDataTypeFifthProperty.getKey().getParentKeyName());
333         assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName());
334         assertEquals(STRING_TEXT, thirdDataTypeFifthProperty.getType().getName());
335         assertTrue(thirdDataTypeFifthProperty.isRequired());
336         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
337         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
338         assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
339         assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
340                 thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
341         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
342                 .getValidValues().size() == 5);
343         ;
344
345         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
346         assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName());
347         assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName());
348         assertEquals("integer", thirdDataTypeSixthProperty.getType().getName());
349         assertTrue(thirdDataTypeSixthProperty.isRequired());
350         assertEquals("Threshold value for the field Path inside CEF message",
351                 thirdDataTypeSixthProperty.getDescription());
352
353         JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
354         assertEquals(THRESHOLDS, thirdDataTypeSeventhProperty.getKey().getParentKeyName());
355         assertEquals("version", thirdDataTypeSeventhProperty.getKey().getLocalName());
356         assertEquals(STRING_TEXT, thirdDataTypeSeventhProperty.getType().getName());
357         assertTrue(thirdDataTypeSeventhProperty.isRequired());
358         assertEquals("Version number associated with the threshold", thirdDataTypeSeventhProperty.getDescription());
359     }
360
361     private void verifyCollectorInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
362
363         // Sanity check the entire structure
364         assertNotNull(serviceTemplate);
365         LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
366         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
367
368         // Check tosca_definitions_version
369         assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
370
371         // Check policy_types
372         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
373         assertTrue(policyTypesConceptMap.size() == 2);
374         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
375
376         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
377         assertEquals(MONITORING, firstPolicyType.getKey().getName());
378         assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
379         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
380         assertEquals("a base policy type for all policies that govern monitoring provisioning",
381                 firstPolicyType.getValue().getDescription());
382
383         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
384         assertEquals(DCAE, secondPolicyType.getKey().getName());
385         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
386         assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
387         assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
388
389         Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
390
391         JpaToscaProperty firstProperty = propertiesIter.next();
392         assertEquals(DCAE, firstProperty.getKey().getParentKeyName());
393         assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion());
394         assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
395         assertEquals(STRING_TEXT, firstProperty.getType().getName());
396         assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
397
398         JpaToscaProperty secondProperty = propertiesIter.next();
399         assertEquals(DCAE, secondProperty.getKey().getParentKeyName());
400         assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion());
401         assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
402         assertEquals(STRING_TEXT, secondProperty.getType().getName());
403         assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
404     }
405
406     private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
407         ToscaServiceTemplate toscaServiceTemplate = serviceTemplate.toAuthorative();
408         return coder.encode(toscaServiceTemplate);
409     }
410 }