Sonar Fixes policy/models, removing model-yaml
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / serialization / MonitoringPolicyTypeSerializationTest.java
index 270bc6c..4a8378f 100644 (file)
@@ -28,7 +28,6 @@ import static org.junit.Assert.assertTrue;
 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 +39,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;
@@ -75,7 +73,7 @@ public class MonitoringPolicyTypeSerializationTest {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class);
 
-    private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
+    private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.tcagen2.yaml";
     private static final String MONITORING_COLLECTORS_YAML =
             "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
 
@@ -146,11 +144,11 @@ 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();
-        assertTrue(policyTypesConceptMap.size() == 2);
+        assertEquals(2, policyTypesConceptMap.size());
         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
 
         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
@@ -161,24 +159,21 @@ public class MonitoringPolicyTypeSerializationTest {
                 firstPolicyType.getValue().getDescription());
 
         Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
-        assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
+        assertEquals("onap.policies.monitoring.tcagen2", secondPolicyType.getKey().getName());
         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
         assertEquals(MONITORING, secondPolicyType.getValue().getDerivedFrom().getName());
-        assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
+        assertEquals(1, secondPolicyType.getValue().getProperties().size());
 
         JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
-        assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
+        assertEquals("onap.policies.monitoring.tcagen2", property.getKey().getParentKeyName());
         assertEquals(VERSION_100, property.getKey().getParentKeyVersion());
-        assertEquals("tca_policy", property.getKey().getLocalName());
-        assertEquals("map", property.getType().getName());
+        assertEquals("tca.policy", property.getKey().getLocalName());
+        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);
+        assertEquals(3, dataTypesConceptMap.size());
         Iterator<Entry<PfConceptKey, JpaToscaDataType>> dataTypesIter = dataTypesConceptMap.entrySet().iterator();
 
         Entry<PfConceptKey, JpaToscaDataType> firstDataType = dataTypesIter.next();
@@ -186,7 +181,7 @@ public class MonitoringPolicyTypeSerializationTest {
         JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
         assertEquals(DATATYPE_ROOT, firstDataTypeVal.getDerivedFrom().getName());
         assertEquals(VERSION_000, firstDataTypeVal.getDerivedFrom().getVersion());
-        assertTrue(firstDataTypeVal.getProperties().size() == 6);
+        assertEquals(6, firstDataTypeVal.getProperties().size());
         Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
@@ -196,7 +191,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(firstDataTypeFirstProperty.isRequired());
         assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
                 firstDataTypeFirstProperty.getDescription());
-        assertTrue(firstDataTypeFirstProperty.getConstraints().size() == 1);
+        assertEquals(1, firstDataTypeFirstProperty.getConstraints().size());
         assertEquals("org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues",
                 firstDataTypeFirstProperty.getConstraints().iterator().next().getClass().getName());
         assertEquals(2,
@@ -245,7 +240,7 @@ public class MonitoringPolicyTypeSerializationTest {
         JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
         assertEquals(DATATYPE_ROOT, secondDataTypeVal.getDerivedFrom().getName());
         assertEquals(VERSION_000, secondDataTypeVal.getDerivedFrom().getVersion());
-        assertTrue(secondDataTypeVal.getProperties().size() == 2);
+        assertEquals(2, secondDataTypeVal.getProperties().size());
         Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
@@ -255,7 +250,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(secondDataTypeFirstProperty.isRequired());
         assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
         assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
-        assertTrue(secondDataTypeFirstProperty.getConstraints().size() == 1);
+        assertEquals(1, secondDataTypeFirstProperty.getConstraints().size());
         assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() instanceof JpaToscaConstraintLogical);
         assertEquals("measurementsForVfScaling",
                 ((JpaToscaConstraintLogical) (secondDataTypeFirstProperty.getConstraints().iterator().next()))
@@ -276,7 +271,7 @@ public class MonitoringPolicyTypeSerializationTest {
         JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
         assertEquals(DATATYPE_ROOT, thirdDataTypeVal.getDerivedFrom().getName());
         assertEquals(VERSION_000, thirdDataTypeVal.getDerivedFrom().getVersion());
-        assertTrue(thirdDataTypeVal.getProperties().size() == 7);
+        assertEquals(7, thirdDataTypeVal.getProperties().size());
         Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
 
         JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
@@ -294,13 +289,14 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(thirdDataTypeSecondProperty.isRequired());
         assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
         assertNotNull(thirdDataTypeSecondProperty.getConstraints());
-        assertTrue(thirdDataTypeSecondProperty.getConstraints().size() == 1);
+        assertEquals(1, thirdDataTypeSecondProperty.getConstraints().size());
         assertEquals("JpaToscaConstraintValidValues(validValues=[ONSET, ABATED])",
                 thirdDataTypeSecondProperty.getConstraints().iterator().next().toString());
         assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator()
                 .next() instanceof JpaToscaConstraintValidValues);
-        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
-                .getValidValues().size() == 2);
+        assertEquals(2,
+                ((JpaToscaConstraintValidValues) (thirdDataTypeSecondProperty.getConstraints().iterator().next()))
+                    .getValidValues().size());
 
         JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
         assertEquals(THRESHOLDS, thirdDataTypeThirdProperty.getKey().getParentKeyName());
@@ -309,12 +305,13 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(thirdDataTypeThirdProperty.isRequired());
         assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
         assertNotNull(thirdDataTypeThirdProperty.getConstraints());
-        assertTrue(thirdDataTypeThirdProperty.getConstraints().size() == 1);
+        assertEquals(1, thirdDataTypeThirdProperty.getConstraints().size());
         assertEquals(
                 "JpaToscaConstraintValidValues(validValues=[LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL, EQUAL])",
                 thirdDataTypeThirdProperty.getConstraints().iterator().next().toString());
-        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
-                .getValidValues().size() == 5);
+        assertEquals(5,
+                ((JpaToscaConstraintValidValues) (thirdDataTypeThirdProperty.getConstraints().iterator().next()))
+                    .getValidValues().size());
 
         JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
         assertEquals(THRESHOLDS, thirdDataTypeFourthProperty.getKey().getParentKeyName());
@@ -324,9 +321,10 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
                 thirdDataTypeFourthProperty.getDescription());
         assertNotNull(thirdDataTypeFourthProperty.getConstraints());
-        assertTrue(thirdDataTypeFourthProperty.getConstraints().size() == 1);
-        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
-                .getValidValues().size() == 43);
+        assertEquals(1, thirdDataTypeFourthProperty.getConstraints().size());
+        assertEquals(43,
+                ((JpaToscaConstraintValidValues) (thirdDataTypeFourthProperty.getConstraints().iterator().next()))
+                    .getValidValues().size());
 
         JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
         assertEquals(THRESHOLDS, thirdDataTypeFifthProperty.getKey().getParentKeyName());
@@ -335,11 +333,12 @@ public class MonitoringPolicyTypeSerializationTest {
         assertTrue(thirdDataTypeFifthProperty.isRequired());
         assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
         assertNotNull(thirdDataTypeFifthProperty.getConstraints());
-        assertTrue(thirdDataTypeFifthProperty.getConstraints().size() == 1);
+        assertEquals(1, thirdDataTypeFifthProperty.getConstraints().size());
         assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
                 thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
-        assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
-                .getValidValues().size() == 5);
+        assertEquals(5,
+                ((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
+                    .getValidValues().size());
         ;
 
         JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
@@ -366,11 +365,11 @@ 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();
-        assertTrue(policyTypesConceptMap.size() == 2);
+        assertEquals(2, policyTypesConceptMap.size());
         Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
 
         Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
@@ -384,7 +383,7 @@ public class MonitoringPolicyTypeSerializationTest {
         assertEquals(DCAE, secondPolicyType.getKey().getName());
         assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
         assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
-        assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
+        assertEquals(2, secondPolicyType.getValue().getProperties().size());
 
         Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();