Restructure for authorative 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 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 com.google.gson.Gson;
30 import com.google.gson.JsonSyntaxException;
31
32 import java.io.IOException;
33 import java.util.Iterator;
34 import java.util.Map;
35 import java.util.Map.Entry;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.policy.common.utils.resources.ResourceUtils;
39 import org.onap.policy.models.base.PfConceptKey;
40 import org.onap.policy.models.base.PfValidationResult;
41 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString;
42 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
43 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
44 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
45 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
46 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
47 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
48 import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.yaml.snakeyaml.Yaml;
52
53 /**
54  * Test serialization of monitoring policy types.
55  *
56  * @author Chenfei Gao (cgao@research.att.com)
57  */
58 public class MonitoringPolicyTypeSerializationTest {
59
60     private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class);
61
62     private static final String MONITORING_TCA_YAML = "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml";
63     private static final String MONITORING_COLLECTORS_YAML =
64             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
65
66     private Gson gson;
67
68     @Before
69     public void setUp() {
70         gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
71     }
72
73     @Test
74     public void testDeserialization() {
75         try {
76             // TCA
77             JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
78             verifyTcaInputDeserialization(serviceTemplateFromYaml);
79
80             // Collector
81             serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
82             verifyCollectorInputDeserialization(serviceTemplateFromYaml);
83
84         } catch (Exception e) {
85             fail("No exception should be thrown");
86         }
87     }
88
89     @Test
90     public void testSerialization() {
91         try {
92             // TCA
93             JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
94             String serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml);
95             JpaToscaServiceTemplate serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1,
96                     JpaToscaServiceTemplate.class);
97             String serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson);
98             assertEquals(serializedServiceTemplate1, serializedServiceTemplate2);
99
100             // Collector
101             serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
102             serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml);
103             serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, JpaToscaServiceTemplate.class);
104             serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson);
105             assertEquals(serializedServiceTemplate1, serializedServiceTemplate2);
106
107         } catch (Exception e) {
108             fail("No exception should be thrown");
109         }
110     }
111
112     private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath)
113             throws JsonSyntaxException, IOException {
114
115         Yaml yaml = new Yaml();
116         String policyTypeYaml = ResourceUtils.getResourceAsString(resourcePath);
117         Object yamlObject = yaml.load(policyTypeYaml);
118         String yamlAsJsonString = new Gson().toJson(yamlObject);
119         JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class);
120         return serviceTemplate;
121     }
122
123     private void verifyTcaInputDeserialization(JpaToscaServiceTemplate serviceTemplate) {
124
125         // Sanity check the entire structure
126         assertNotNull(serviceTemplate);
127         LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
128         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
129
130         // Check tosca_definitions_version
131         assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
132
133         // Check policy_types
134         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
135         assertTrue(policyTypesConceptMap.size() == 2);
136         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
137
138         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
139         assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName());
140         assertEquals("1.0.0", firstPolicyType.getKey().getVersion());
141         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
142         assertEquals("a base policy type for all policies that governs monitoring provisioning",
143                 firstPolicyType.getValue().getDescription());
144
145         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
146         assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
147         assertEquals("1.0.0", secondPolicyType.getKey().getVersion());
148         assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
149         assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
150
151         JpaToscaProperty property = secondPolicyType.getValue().getProperties().iterator().next();
152         assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
153         assertEquals("1.0.0", property.getKey().getParentKeyVersion());
154         assertEquals("tca_policy", property.getKey().getLocalName());
155         assertEquals("map", property.getType().getName());
156         assertEquals("TCA Policy JSON", property.getDescription());
157
158         JpaToscaEntrySchema entrySchema = property.getEntrySchema();
159         assertEquals("map", entrySchema.getKey().getParentKeyName());
160         assertEquals("1.0.0", entrySchema.getKey().getParentKeyVersion());
161         assertEquals("entry_schema", entrySchema.getKey().getLocalName());
162         assertEquals("onap.datatypes.monitoring.tca_policy", entrySchema.getType().getName());
163
164         // Check data_types
165         Map<PfConceptKey, JpaToscaDataType> dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap();
166         assertTrue(dataTypesConceptMap.size() == 3);
167         Iterator<Entry<PfConceptKey, JpaToscaDataType>> dataTypesIter = dataTypesConceptMap.entrySet().iterator();
168
169         Entry<PfConceptKey, JpaToscaDataType> firstDataType = dataTypesIter.next();
170         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataType.getKey().getName());
171         JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
172         assertEquals("tosca.datatypes.Root", firstDataTypeVal.getDerivedFrom().getName());
173         assertEquals("1.0.0", firstDataTypeVal.getDerivedFrom().getVersion());
174         assertTrue(firstDataTypeVal.getProperties().size() == 6);
175         Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().iterator();
176
177         JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
178         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFirstProperty.getKey()
179                 .getParentKeyName());
180         assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
181         assertEquals("string", firstDataTypeFirstProperty.getType().getName());
182         assertTrue(firstDataTypeFirstProperty.isRequired());
183         assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
184                 firstDataTypeFirstProperty.getDescription());
185         assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
186         assertEquals("valid_values", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey()
187                 .getLocalName());
188         assertEquals("string", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey()
189                 .getParentKeyName());
190         assertTrue(firstDataTypeFirstProperty.getConstraints().iterator().next()
191                 instanceof JpaToscaConstraintValidValues);
192         assertTrue(((JpaToscaConstraintValidValues)(firstDataTypeFirstProperty.getConstraints().iterator().next()))
193                 .getValidValues().size() == 2);
194
195         JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
196         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSecondProperty.getKey()
197                 .getParentKeyName());
198         assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
199         assertEquals("string", firstDataTypeSecondProperty.getType().getName());
200         assertTrue(firstDataTypeSecondProperty.isRequired());
201         assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty
202                 .getDescription());
203
204         JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
205         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeThirdProperty.getKey()
206                 .getParentKeyName());
207         assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
208         assertEquals("string", firstDataTypeThirdProperty.getType().getName());
209         assertTrue(firstDataTypeThirdProperty.isRequired());
210         assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
211
212         JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
213         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFourthProperty.getKey()
214                 .getParentKeyName());
215         assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
216         assertEquals("string", firstDataTypeFourthProperty.getType().getName());
217         assertTrue(firstDataTypeFourthProperty.isRequired());
218         assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
219
220         JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
221         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFifthProperty.getKey()
222                 .getParentKeyName());
223         assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
224         assertEquals("string", firstDataTypeFifthProperty.getType().getName());
225         assertTrue(firstDataTypeFifthProperty.isRequired());
226         assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
227
228         JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
229         assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSixthProperty.getKey()
230                 .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("entry_schema", firstDataTypeSixthProperty.getEntrySchema().getKey().getLocalName());
237         assertEquals("list", firstDataTypeSixthProperty.getEntrySchema().getKey().getParentKeyName());
238         assertEquals("onap.datatypes.monitoring.thresholds", firstDataTypeSixthProperty.getEntrySchema().getType()
239                 .getName());
240
241         Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
242         assertEquals("onap.datatypes.monitoring.tca_policy", secondDataType.getKey().getName());
243         JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
244         assertEquals("tosca.datatypes.Root", secondDataTypeVal.getDerivedFrom().getName());
245         assertEquals("1.0.0", secondDataTypeVal.getDerivedFrom().getVersion());
246         assertTrue(secondDataTypeVal.getProperties().size() == 2);
247         Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().iterator();
248
249         JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
250         assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeFirstProperty.getKey().getParentKeyName());
251         assertEquals("domain", secondDataTypeFirstProperty.getKey().getLocalName());
252         assertEquals("string", secondDataTypeFirstProperty.getType().getName());
253         assertTrue(secondDataTypeFirstProperty.isRequired());
254         assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
255         assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
256         assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
257         assertEquals("string", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey()
258                 .getParentKeyName());
259         assertEquals("equal", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey().getLocalName());
260         assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next()
261                 instanceof JpaToscaConstraintLogicalString);
262         assertEquals("measurementsForVfScaling", ((JpaToscaConstraintLogicalString)(secondDataTypeFirstProperty
263                 .getConstraints().iterator().next())).getCompareToString());
264
265         JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
266         assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeSecondProperty.getKey().getParentKeyName());
267         assertEquals("metricsPerEventName", secondDataTypeSecondProperty.getKey().getLocalName());
268         assertEquals("list", secondDataTypeSecondProperty.getType().getName());
269         assertTrue(secondDataTypeSecondProperty.isRequired());
270         assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
271                 secondDataTypeSecondProperty.getDescription());
272         assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
273         assertEquals("list", secondDataTypeSecondProperty.getEntrySchema().getKey().getParentKeyName());
274         assertEquals("onap.datatypes.monitoring.metricsPerEventName",
275                 secondDataTypeSecondProperty.getEntrySchema().getType().getName());
276         assertEquals("entry_schema", secondDataTypeSecondProperty.getEntrySchema().getKey().getLocalName());
277
278         Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
279         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataType.getKey().getName());
280         JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
281         assertEquals("tosca.datatypes.Root", thirdDataTypeVal.getDerivedFrom().getName());
282         assertEquals("1.0.0", thirdDataTypeVal.getDerivedFrom().getVersion());
283         assertTrue(thirdDataTypeVal.getProperties().size() == 7);
284         Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().iterator();
285
286         JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
287         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFirstProperty.getKey().getParentKeyName());
288         assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
289         assertEquals("string", thirdDataTypeFirstProperty.getType().getName());
290         assertTrue(thirdDataTypeFirstProperty.isRequired());
291         assertEquals("Closed Loop Control Name associated with the threshold", thirdDataTypeFirstProperty
292                 .getDescription());
293
294         JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
295         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSecondProperty.getKey().getParentKeyName());
296         assertEquals("closedLoopEventStatus", thirdDataTypeSecondProperty.getKey().getLocalName());
297         assertEquals("string", thirdDataTypeSecondProperty.getType().getName());
298         assertTrue(thirdDataTypeSecondProperty.isRequired());
299         assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
300         assertNotNull(thirdDataTypeSecondProperty.getConstraints());
301         assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
302         assertEquals("string", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey()
303                 .getParentKeyName());
304         assertEquals("valid_values", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey()
305                 .getLocalName());
306         assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator().next()
307                 instanceof JpaToscaConstraintValidValues);
308         assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeSecondProperty.getConstraints().iterator().next()))
309                 .getValidValues().size() == 2);
310
311         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
312         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeThirdProperty.getKey().getParentKeyName());
313         assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName());
314         assertEquals("string", thirdDataTypeThirdProperty.getType().getName());
315         assertTrue(thirdDataTypeThirdProperty.isRequired());
316         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
317         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
318         assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
319         assertEquals("string", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey()
320                 .getParentKeyName());
321         assertEquals("valid_values", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey()
322                 .getLocalName());
323         assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeThirdProperty.getConstraints().iterator().next()))
324                 .getValidValues().size() == 5);
325
326         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
327         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFourthProperty.getKey().getParentKeyName());
328         assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName());
329         assertEquals("string", thirdDataTypeFourthProperty.getType().getName());
330         assertTrue(thirdDataTypeFourthProperty.isRequired());
331         assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
332                 thirdDataTypeFourthProperty.getDescription());
333         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
334         assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
335         assertEquals("string", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey()
336                 .getParentKeyName());
337         assertEquals("valid_values", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey()
338                 .getLocalName());
339         assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFourthProperty.getConstraints().iterator().next()))
340                 .getValidValues().size() == 43);
341
342         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
343         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFifthProperty.getKey().getParentKeyName());
344         assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName());
345         assertEquals("string", thirdDataTypeFifthProperty.getType().getName());
346         assertTrue(thirdDataTypeFifthProperty.isRequired());
347         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
348         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
349         assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
350         assertEquals("string", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey()
351                 .getParentKeyName());
352         assertEquals("valid_values", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey()
353                 .getLocalName());
354         assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFifthProperty.getConstraints().iterator().next()))
355                 .getValidValues().size() == 5);;
356
357         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
358         assertEquals("onap.datatypes.monitoring.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", thirdDataTypeSixthProperty
363                 .getDescription());
364
365         JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
366         assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSeventhProperty.getKey().getParentKeyName());
367         assertEquals("version", thirdDataTypeSeventhProperty.getKey().getLocalName());
368         assertEquals("string", 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("onap.policies.Monitoring", firstPolicyType.getKey().getName());
390         assertEquals("1.0.0", 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("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
397                 secondPolicyType.getKey().getName());
398         assertEquals("1.0.0", 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().iterator();
403
404         JpaToscaProperty firstProperty = propertiesIter.next();
405         assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
406                 firstProperty.getKey().getParentKeyName());
407         assertEquals("1.0.0", firstProperty.getKey().getParentKeyVersion());
408         assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
409         assertEquals("string", firstProperty.getType().getName());
410         assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
411
412         JpaToscaProperty secondProperty = propertiesIter.next();
413         assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
414                 secondProperty.getKey().getParentKeyName());
415         assertEquals("1.0.0", secondProperty.getKey().getParentKeyVersion());
416         assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
417         assertEquals("string", secondProperty.getType().getName());
418         assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
419     }
420
421     private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) {
422         return gson.toJson(serviceTemplate);
423     }
424 }