Merge "Fix simple sonar issues in models-tosca"
[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 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 import static org.junit.Assert.fail;
28
29 import java.util.Iterator;
30 import java.util.Map;
31 import java.util.Map.Entry;
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() {
102         try {
103             // TCA
104             JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
105             String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
106
107             ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
108                     coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
109
110             JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
111             serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
112             String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
113             assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
114
115             // Collector
116             JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
117                     deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
118             String serializedServiceTemplateCollector =
119                     serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
120             ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
121                     coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
122             JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
123             serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
124             String serializedServiceTemplateCollectorsOut =
125                     serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
126             assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
127
128         } catch (Exception e) {
129             LOGGER.warn("No exception should be thrown", e);
130             fail("No exception should be thrown");
131         }
132     }
133
134     private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
135
136         Yaml yaml = new Yaml();
137         String policyTypeYaml = ResourceUtils.getResourceAsString(resourcePath);
138         Object yamlObject = yaml.load(policyTypeYaml);
139         String yamlAsJsonString = coder.encode(yamlObject);
140         ToscaServiceTemplate serviceTemplate = coder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
141
142         JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
143         jpaToscaServiceTemplate.fromAuthorative(serviceTemplate);
144         return jpaToscaServiceTemplate;
145     }
146
147     private void verifyTcaInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
148
149         // Sanity check the entire structure
150         assertNotNull(serviceTemplate);
151         LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
152         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
153
154         // Check tosca_definitions_version
155         assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
156
157         // Check policy_types
158         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
159         assertTrue(policyTypesConceptMap.size() == 2);
160         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
161
162         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
163         assertEquals(MONITORING, firstPolicyType.getKey().getName());
164         assertEquals(VERSION_000, firstPolicyType.getKey().getVersion());
165         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
166         assertEquals("a base policy type for all policies that governs monitoring provisioning",
167                 firstPolicyType.getValue().getDescription());
168
169         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
170         assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
171         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
172         assertEquals(MONITORING, secondPolicyType.getValue().getDerivedFrom().getName());
173         assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
174
175         JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
176         assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
177         assertEquals(VERSION_100, property.getKey().getParentKeyVersion());
178         assertEquals("tca_policy", property.getKey().getLocalName());
179         assertEquals("map", property.getType().getName());
180         assertEquals("TCA Policy JSON", property.getDescription());
181
182         JpaToscaEntrySchema entrySchema = property.getEntrySchema();
183         assertEquals(TCA, entrySchema.getType().getName());
184
185         // Check data_types
186         Map<PfConceptKey, JpaToscaDataType> dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap();
187         assertTrue(dataTypesConceptMap.size() == 3);
188         Iterator<Entry<PfConceptKey, JpaToscaDataType>> dataTypesIter = dataTypesConceptMap.entrySet().iterator();
189
190         Entry<PfConceptKey, JpaToscaDataType> firstDataType = dataTypesIter.next();
191         assertEquals(METRICS, firstDataType.getKey().getName());
192         JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
193         assertEquals(DATATYPE_ROOT, firstDataTypeVal.getDerivedFrom().getName());
194         assertEquals(VERSION_000, firstDataTypeVal.getDerivedFrom().getVersion());
195         assertTrue(firstDataTypeVal.getProperties().size() == 6);
196         Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
197
198         JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
199         assertEquals(METRICS,
200                 firstDataTypeFirstProperty.getKey().getParentKeyName());
201         assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
202         assertEquals(STRING_TEXT, firstDataTypeFirstProperty.getType().getName());
203         assertTrue(firstDataTypeFirstProperty.isRequired());
204         assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
205                 firstDataTypeFirstProperty.getDescription());
206         assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
207         assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
208                 firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getCanonicalName());
209         assertTrue(((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
210                 .getValidValues().size() == 2);
211
212         JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
213         assertEquals(METRICS,
214                 firstDataTypeSecondProperty.getKey().getParentKeyName());
215         assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
216         assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName());
217         assertTrue(firstDataTypeSecondProperty.isRequired());
218         assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
219
220         JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
221         assertEquals(METRICS,
222                 firstDataTypeThirdProperty.getKey().getParentKeyName());
223         assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
224         assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName());
225         assertTrue(firstDataTypeThirdProperty.isRequired());
226         assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
227
228         JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
229         assertEquals(METRICS,
230                 firstDataTypeFourthProperty.getKey().getParentKeyName());
231         assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
232         assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName());
233         assertTrue(firstDataTypeFourthProperty.isRequired());
234         assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
235
236         JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
237         assertEquals(METRICS,
238                 firstDataTypeFifthProperty.getKey().getParentKeyName());
239         assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
240         assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName());
241         assertTrue(firstDataTypeFifthProperty.isRequired());
242         assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
243
244         JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
245         assertEquals(METRICS,
246                 firstDataTypeSixthProperty.getKey().getParentKeyName());
247         assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
248         assertEquals("list", firstDataTypeSixthProperty.getType().getName());
249         assertTrue(firstDataTypeSixthProperty.isRequired());
250         assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
251         assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
252         assertEquals(THRESHOLDS,
253                 firstDataTypeSixthProperty.getEntrySchema().getType().getName());
254
255         Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
256         assertEquals(TCA, secondDataType.getKey().getName());
257         JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
258         assertEquals(DATATYPE_ROOT, secondDataTypeVal.getDerivedFrom().getName());
259         assertEquals(VERSION_000, secondDataTypeVal.getDerivedFrom().getVersion());
260         assertTrue(secondDataTypeVal.getProperties().size() == 2);
261         Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
262
263         JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
264         assertEquals(TCA, secondDataTypeFirstProperty.getKey().getParentKeyName());
265         assertEquals("domain", secondDataTypeFirstProperty.getKey().getLocalName());
266         assertEquals(STRING_TEXT, secondDataTypeFirstProperty.getType().getName());
267         assertTrue(secondDataTypeFirstProperty.isRequired());
268         assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
269         assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
270         assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
271         assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() instanceof JpaToscaConstraintLogical);
272         assertEquals("measurementsForVfScaling",
273                 ((JpaToscaConstraintLogical) (secondDataTypeFirstProperty.getConstraints().iterator().next()))
274                         .getCompareTo());
275
276         JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
277         assertEquals(TCA, secondDataTypeSecondProperty.getKey().getParentKeyName());
278         assertEquals("metricsPerEventName", secondDataTypeSecondProperty.getKey().getLocalName());
279         assertEquals("list", secondDataTypeSecondProperty.getType().getName());
280         assertTrue(secondDataTypeSecondProperty.isRequired());
281         assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
282                 secondDataTypeSecondProperty.getDescription());
283         assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
284         assertEquals(METRICS,
285                 secondDataTypeSecondProperty.getEntrySchema().getType().getName());
286
287         Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
288         assertEquals(THRESHOLDS, thirdDataType.getKey().getName());
289         JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
290         assertEquals(DATATYPE_ROOT, thirdDataTypeVal.getDerivedFrom().getName());
291         assertEquals(VERSION_000, thirdDataTypeVal.getDerivedFrom().getVersion());
292         assertTrue(thirdDataTypeVal.getProperties().size() == 7);
293         Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
294
295         JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
296         assertEquals(THRESHOLDS, thirdDataTypeFirstProperty.getKey().getParentKeyName());
297         assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
298         assertEquals(STRING_TEXT, thirdDataTypeFirstProperty.getType().getName());
299         assertTrue(thirdDataTypeFirstProperty.isRequired());
300         assertEquals("Closed Loop Control Name associated with the threshold",
301                 thirdDataTypeFirstProperty.getDescription());
302
303         JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
304         assertEquals(THRESHOLDS, thirdDataTypeSecondProperty.getKey().getParentKeyName());
305         assertEquals("closedLoopEventStatus", thirdDataTypeSecondProperty.getKey().getLocalName());
306         assertEquals(STRING_TEXT, thirdDataTypeSecondProperty.getType().getName());
307         assertTrue(thirdDataTypeSecondProperty.isRequired());
308         assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
309         assertNotNull(thirdDataTypeSecondProperty.getConstraints());
310         assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
311         assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
312                 thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
313         assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
314                 .next() instanceof JpaToscaConstraintValidValues);
315         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
316                 .getValidValues().size() == 2);
317
318         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
319         assertEquals(THRESHOLDS, thirdDataTypeThirdProperty.getKey().getParentKeyName());
320         assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName());
321         assertEquals(STRING_TEXT, thirdDataTypeThirdProperty.getType().getName());
322         assertTrue(thirdDataTypeThirdProperty.isRequired());
323         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
324         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
325         assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
326         assertEquals(
327                 "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
328                 thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
329         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
330                 .getValidValues().size() == 5);
331
332         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
333         assertEquals(THRESHOLDS, thirdDataTypeFourthProperty.getKey().getParentKeyName());
334         assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName());
335         assertEquals(STRING_TEXT, thirdDataTypeFourthProperty.getType().getName());
336         assertTrue(thirdDataTypeFourthProperty.isRequired());
337         assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
338                 thirdDataTypeFourthProperty.getDescription());
339         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
340         assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
341         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
342                 .getValidValues().size() == 43);
343
344         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
345         assertEquals(THRESHOLDS, thirdDataTypeFifthProperty.getKey().getParentKeyName());
346         assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName());
347         assertEquals(STRING_TEXT, thirdDataTypeFifthProperty.getType().getName());
348         assertTrue(thirdDataTypeFifthProperty.isRequired());
349         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
350         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
351         assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
352         assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
353                 thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
354         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
355                 .getValidValues().size() == 5);;
356
357         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
358         assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName());
359         assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName());
360         assertEquals("integer", thirdDataTypeSixthProperty.getType().getName());
361         assertTrue(thirdDataTypeSixthProperty.isRequired());
362         assertEquals("Threshold value for the field Path inside CEF message",
363                 thirdDataTypeSixthProperty.getDescription());
364
365         JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
366         assertEquals(THRESHOLDS, thirdDataTypeSeventhProperty.getKey().getParentKeyName());
367         assertEquals("version", thirdDataTypeSeventhProperty.getKey().getLocalName());
368         assertEquals(STRING_TEXT, thirdDataTypeSeventhProperty.getType().getName());
369         assertTrue(thirdDataTypeSeventhProperty.isRequired());
370         assertEquals("Version number associated with the threshold", thirdDataTypeSeventhProperty.getDescription());
371     }
372
373     private void verifyCollectorInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
374
375         // Sanity check the entire structure
376         assertNotNull(serviceTemplate);
377         LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
378         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
379
380         // Check tosca_definitions_version
381         assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
382
383         // Check policy_types
384         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
385         assertTrue(policyTypesConceptMap.size() == 2);
386         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
387
388         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
389         assertEquals(MONITORING, firstPolicyType.getKey().getName());
390         assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
391         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
392         assertEquals("a base policy type for all policies that govern monitoring provision",
393                 firstPolicyType.getValue().getDescription());
394
395         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
396         assertEquals(DCAE,
397                 secondPolicyType.getKey().getName());
398         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
399         assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
400         assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
401
402         Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
403
404         JpaToscaProperty firstProperty = propertiesIter.next();
405         assertEquals(DCAE,
406                 firstProperty.getKey().getParentKeyName());
407         assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion());
408         assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
409         assertEquals(STRING_TEXT, firstProperty.getType().getName());
410         assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
411
412         JpaToscaProperty secondProperty = propertiesIter.next();
413         assertEquals(DCAE,
414                 secondProperty.getKey().getParentKeyName());
415         assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion());
416         assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
417         assertEquals(STRING_TEXT, secondProperty.getType().getName());
418         assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
419     }
420
421     private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) throws CoderException {
422         ToscaServiceTemplate toscaServiceTemplate = serviceTemplate.toAuthorative();
423         return coder.encode(toscaServiceTemplate);
424     }
425 }