Fix Sonar Issues models-tosca-simple
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaSchemaDefinitionTest.java
index e7163f7..a8d4f34 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,7 +32,6 @@ import java.util.ArrayList;
 import java.util.List;
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfValidationResult;
 
 /**
  * DAO test for ToscaEntrySchema.
@@ -44,7 +43,7 @@ public class JpaToscaSchemaDefinitionTest {
     private static final String A_DESCRIPTION = "A Description";
 
     @Test
-    public void testEntrySchemaPojo() {
+    public void testEntrySchemaNull() {
         assertNotNull(new JpaToscaSchemaDefinition(new PfConceptKey()));
         assertNotNull(new JpaToscaSchemaDefinition(new JpaToscaSchemaDefinition(new PfConceptKey())));
 
@@ -53,7 +52,10 @@ public class JpaToscaSchemaDefinitionTest {
 
         assertThatThrownBy(() -> new JpaToscaSchemaDefinition((JpaToscaSchemaDefinition) null))
                 .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
+    }
 
+    @Test
+    public void testEntrySchema() {
         PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
         JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey);
 
@@ -95,28 +97,46 @@ public class JpaToscaSchemaDefinitionTest {
         new JpaToscaSchemaDefinition(typeKey).clean();
         tes.clean();
         assertEquals(tdtClone0, tes);
+    }
+
+    @Test
+    public void testEntrySchemaValidation() {
+        PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
+        JpaToscaSchemaDefinition tes = setUpJpaToscaSchemaDefinition(typeKey);
 
-        assertTrue(new JpaToscaSchemaDefinition(typeKey).validate(new PfValidationResult()).isValid());
-        assertTrue(tes.validate(new PfValidationResult()).isValid());
+        assertTrue(new JpaToscaSchemaDefinition(typeKey).validate("").isValid());
+        assertTrue(tes.validate("").isValid());
 
         tes.setType(PfConceptKey.getNullKey());
-        assertFalse(tes.validate(new PfValidationResult()).isValid());
+        assertFalse(tes.validate("").isValid());
         tes.setType(null);
-        assertFalse(tes.validate(new PfValidationResult()).isValid());
+        assertFalse(tes.validate("").isValid());
         tes.setType(typeKey);
-        assertTrue(tes.validate(new PfValidationResult()).isValid());
+        assertTrue(tes.validate("").isValid());
 
         tes.setDescription("");
 
-        assertFalse(tes.validate(new PfValidationResult()).isValid());
+        assertFalse(tes.validate("").isValid());
         tes.setDescription(A_DESCRIPTION);
-        assertTrue(tes.validate(new PfValidationResult()).isValid());
+        assertTrue(tes.validate("").isValid());
 
         tes.getConstraints().add(null);
-        assertFalse(tes.validate(new PfValidationResult()).isValid());
+        assertFalse(tes.validate("").isValid());
         tes.getConstraints().remove(null);
-        assertTrue(tes.validate(new PfValidationResult()).isValid());
+        assertTrue(tes.validate("").isValid());
+
+        assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
+    }
+
+    private JpaToscaSchemaDefinition setUpJpaToscaSchemaDefinition(PfConceptKey typeKey) {
+        JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey);
+        tes.setDescription(A_DESCRIPTION);
+
+        List<JpaToscaConstraint> constraints = new ArrayList<>();
+        JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
+        constraints.add(lsc);
+        tes.setConstraints(constraints);
 
-        assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+        return tes;
     }
 }