Changes for Checkstyle 8.32
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaPolicyTypeTest.java
index 2ed03fa..34cc504 100644 (file)
@@ -32,9 +32,9 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -187,4 +187,53 @@ public class JpaToscaPolicyTypeTest {
 
         assertNotNull(new JpaToscaEntityType<ToscaPolicyType>(new ToscaPolicyType()));
     }
+
+    @Test
+    public void testGetReferencedDataTypes() {
+        JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0", "0.0.1"));
+
+        assertTrue(pt0.getReferencedDataTypes().isEmpty());
+
+        pt0.setProperties(new LinkedHashMap<>());
+        assertTrue(pt0.getReferencedDataTypes().isEmpty());
+
+        JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0"));
+        prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION));
+        assertTrue(prop0.validate(new PfValidationResult()).isValid());
+
+        pt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
+        assertTrue(pt0.getReferencedDataTypes().isEmpty());
+
+        JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop1"));
+        prop1.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
+        assertTrue(prop1.validate(new PfValidationResult()).isValid());
+
+        pt0.getProperties().put(prop1.getKey().getLocalName(), prop1);
+        assertEquals(1, pt0.getReferencedDataTypes().size());
+
+        JpaToscaProperty prop2 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop2"));
+        prop2.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
+        assertTrue(prop2.validate(new PfValidationResult()).isValid());
+
+        pt0.getProperties().put(prop2.getKey().getLocalName(), prop2);
+        assertEquals(1, pt0.getReferencedDataTypes().size());
+
+        JpaToscaProperty prop3 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4"));
+        prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
+        prop3.setEntrySchema(new JpaToscaEntrySchema());
+        prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1"));
+        assertTrue(prop3.validate(new PfValidationResult()).isValid());
+
+        pt0.getProperties().put(prop3.getKey().getLocalName(), prop3);
+        assertEquals(3, pt0.getReferencedDataTypes().size());
+
+        JpaToscaProperty prop4 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4"));
+        prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
+        prop4.setEntrySchema(new JpaToscaEntrySchema());
+        prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1"));
+        assertTrue(prop4.validate(new PfValidationResult()).isValid());
+
+        pt0.getProperties().put(prop4.getKey().getLocalName(), prop4);
+        assertEquals(3, pt0.getReferencedDataTypes().size());
+    }
 }