TOSCA Compliant Guard Policies
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / serialization / MonitoringPolicyTypeSerializationTest.java
index 20ba756..bf2030b 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,11 +24,11 @@ package org.onap.policy.models.tosca.simple.serialization;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.policy.common.utils.coder.CoderException;
@@ -40,7 +40,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -98,37 +97,31 @@ public class MonitoringPolicyTypeSerializationTest {
     }
 
     @Test
-    public void testSerialization() {
-        try {
-            // TCA
-            JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
-            String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
-
-            ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
-                    coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
-
-            JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
-            serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
-            String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
-            assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
-
-            // Collector
-            JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
-                    deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
-            String serializedServiceTemplateCollector =
-                    serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
-            ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
-                    coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
-            JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
-            serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
-            String serializedServiceTemplateCollectorsOut =
-                    serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
-            assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
-
-        } catch (Exception e) {
-            LOGGER.warn("No exception should be thrown", e);
-            fail("No exception should be thrown");
-        }
+    public void testSerialization() throws Exception {
+        // TCA
+        JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
+        String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
+
+        ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
+                coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
+
+        JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
+        serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
+        String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
+        assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
+
+        // Collector
+        JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
+                deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
+        String serializedServiceTemplateCollector =
+                serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
+        ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
+                coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
+        JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
+        serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
+        String serializedServiceTemplateCollectorsOut =
+                serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
+        assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
     }
 
     private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
@@ -152,7 +145,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
 
         // Check tosca_definitions_version
-        assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
+        assertEquals("tosca_simple_yaml_1_1_0", serviceTemplate.getToscaDefinitionsVersion());
 
         // Check policy_types
         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
@@ -161,9 +154,9 @@ public class MonitoringPolicyTypeSerializationTest {
 
         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
         assertEquals(MONITORING, firstPolicyType.getKey().getName());
-        assertEquals(VERSION_000, firstPolicyType.getKey().getVersion());
+        assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
-        assertEquals("a base policy type for all policies that governs monitoring provisioning",
+        assertEquals("a base policy type for all policies that govern monitoring provisioning",
                 firstPolicyType.getValue().getDescription());
 
         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
@@ -176,12 +169,9 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
         assertEquals(VERSION_100, property.getKey().getParentKeyVersion());
         assertEquals("tca_policy", property.getKey().getLocalName());
-        assertEquals("map", property.getType().getName());
+        assertEquals(TCA, property.getType().getName());
         assertEquals("TCA Policy JSON", property.getDescription());
 
-        JpaToscaEntrySchema entrySchema = property.getEntrySchema();
-        assertEquals(TCA, entrySchema.getType().getName());
-
         // Check data_types
         Map<PfConceptKey, JpaToscaDataType> dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap();
         assertTrue(dataTypesConceptMap.size() == 3);
@@ -196,8 +186,7 @@ public class MonitoringPolicyTypeSerializationTest {
         Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
-        assertEquals(METRICS,
-                firstDataTypeFirstProperty.getKey().getParentKeyName());
+        assertEquals(METRICS, firstDataTypeFirstProperty.getKey().getParentKeyName());
         assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, firstDataTypeFirstProperty.getType().getName());
         assertTrue(firstDataTypeFirstProperty.isRequired());
@@ -206,51 +195,46 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
         assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
                 firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getName());
-        assertTrue(((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
-                .getValidValues().size() == 2);
+        assertEquals(2,
+                ((JpaToscaConstraintValidValues) (firstDataTypeFirstProperty.getConstraints().iterator().next()))
+                        .getValidValues().size());
 
         JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
-        assertEquals(METRICS,
-                firstDataTypeSecondProperty.getKey().getParentKeyName());
+        assertEquals(METRICS, firstDataTypeSecondProperty.getKey().getParentKeyName());
         assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName());
         assertTrue(firstDataTypeSecondProperty.isRequired());
         assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
 
         JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
-        assertEquals(METRICS,
-                firstDataTypeThirdProperty.getKey().getParentKeyName());
+        assertEquals(METRICS, firstDataTypeThirdProperty.getKey().getParentKeyName());
         assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName());
         assertTrue(firstDataTypeThirdProperty.isRequired());
         assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
 
         JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
-        assertEquals(METRICS,
-                firstDataTypeFourthProperty.getKey().getParentKeyName());
+        assertEquals(METRICS, firstDataTypeFourthProperty.getKey().getParentKeyName());
         assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName());
         assertTrue(firstDataTypeFourthProperty.isRequired());
         assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
 
         JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
-        assertEquals(METRICS,
-                firstDataTypeFifthProperty.getKey().getParentKeyName());
+        assertEquals(METRICS, firstDataTypeFifthProperty.getKey().getParentKeyName());
         assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName());
         assertTrue(firstDataTypeFifthProperty.isRequired());
         assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
 
         JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
-        assertEquals(METRICS,
-                firstDataTypeSixthProperty.getKey().getParentKeyName());
+        assertEquals(METRICS, firstDataTypeSixthProperty.getKey().getParentKeyName());
         assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
         assertEquals("list", firstDataTypeSixthProperty.getType().getName());
         assertTrue(firstDataTypeSixthProperty.isRequired());
         assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
         assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
-        assertEquals(THRESHOLDS,
-                firstDataTypeSixthProperty.getEntrySchema().getType().getName());
+        assertEquals(THRESHOLDS, firstDataTypeSixthProperty.getEntrySchema().getType().getName());
 
         Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
         assertEquals(TCA, secondDataType.getKey().getName());
@@ -281,8 +265,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
                 secondDataTypeSecondProperty.getDescription());
         assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
-        assertEquals(METRICS,
-                secondDataTypeSecondProperty.getEntrySchema().getType().getName());
+        assertEquals(METRICS, secondDataTypeSecondProperty.getEntrySchema().getType().getName());
 
         Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
         assertEquals(THRESHOLDS, thirdDataType.getKey().getName());
@@ -352,7 +335,8 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
                 thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
         assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
-                .getValidValues().size() == 5);;
+                .getValidValues().size() == 5);
+        ;
 
         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
         assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName());
@@ -378,7 +362,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
 
         // Check tosca_definitions_version
-        assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion());
+        assertEquals("tosca_simple_yaml_1_1_0", serviceTemplate.getToscaDefinitionsVersion());
 
         // Check policy_types
         Map<PfConceptKey, JpaToscaPolicyType> policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap();
@@ -389,29 +373,26 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals(MONITORING, firstPolicyType.getKey().getName());
         assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
         assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
-        assertEquals("a base policy type for all policies that govern monitoring provision",
+        assertEquals("a base policy type for all policies that govern monitoring provisioning",
                 firstPolicyType.getValue().getDescription());
 
         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
-        assertEquals(DCAE,
-                secondPolicyType.getKey().getName());
+        assertEquals(DCAE, secondPolicyType.getKey().getName());
         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
-        assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
+        assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
         assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
 
         Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
 
         JpaToscaProperty firstProperty = propertiesIter.next();
-        assertEquals(DCAE,
-                firstProperty.getKey().getParentKeyName());
+        assertEquals(DCAE, firstProperty.getKey().getParentKeyName());
         assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion());
         assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, firstProperty.getType().getName());
         assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
 
         JpaToscaProperty secondProperty = propertiesIter.next();
-        assertEquals(DCAE,
-                secondProperty.getKey().getParentKeyName());
+        assertEquals(DCAE, secondProperty.getKey().getParentKeyName());
         assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion());
         assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
         assertEquals(STRING_TEXT, secondProperty.getType().getName());