Increase coverage above 90% for models 55/138755/2
authorwaynedunican <wayne.dunican@est.tech>
Thu, 15 Aug 2024 09:14:59 +0000 (10:14 +0100)
committerwaynedunican <wayne.dunican@est.tech>
Thu, 15 Aug 2024 13:26:30 +0000 (14:26 +0100)
Differences between local sonar scan (90.5) and sonarcloud (89.7) after merge
Pushing extra tests to ensure coverage is above 90 on sonarcloud

Issue-ID: POLICY-5069
Change-Id: I684204545044e08e852acdb995fce54ceefb0523
Signed-off-by: waynedunican <wayne.dunican@est.tech>
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypesTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java

diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypesTest.java
new file mode 100644 (file)
index 0000000..e18b525
--- /dev/null
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2024 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.openMocks;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
+
+class JpaToscaCapabilityTypesTest {
+
+    @Mock
+    private PfConceptKey mockKey;
+
+    @Mock
+    private Map<PfConceptKey, JpaToscaCapabilityType> mockConceptMap;
+
+    private JpaToscaCapabilityTypes jpaToscaCapabilityTypesUnderTest;
+
+    private AutoCloseable mockitoCloseable;
+
+    @BeforeEach
+    void setUp() {
+        mockitoCloseable = openMocks(this);
+        when(mockKey.getName()).thenReturn("testName");
+        when(mockKey.getVersion()).thenReturn("1.0.0");
+        jpaToscaCapabilityTypesUnderTest = new JpaToscaCapabilityTypes();
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        mockitoCloseable.close();
+    }
+
+    @Test
+    void testConstructors() {
+        jpaToscaCapabilityTypesUnderTest = new JpaToscaCapabilityTypes(mockKey);
+        assertNotNull(jpaToscaCapabilityTypesUnderTest);
+
+        jpaToscaCapabilityTypesUnderTest = new JpaToscaCapabilityTypes(mockKey, mockConceptMap);
+        assertNotNull(jpaToscaCapabilityTypesUnderTest);
+
+        JpaToscaCapabilityTypes jpaToscaCapabilityTypesCopy =
+            new JpaToscaCapabilityTypes(jpaToscaCapabilityTypesUnderTest);
+        assertNotNull(jpaToscaCapabilityTypesCopy);
+
+        Map<String, ToscaCapabilityType> testMap = new HashMap<String, ToscaCapabilityType>();
+        testMap.put("test1", new ToscaCapabilityType());
+        List<Map<String, ToscaCapabilityType>> testList = List.of(testMap);
+        JpaToscaCapabilityTypes jpaToscaCapabilityTypesList = new JpaToscaCapabilityTypes(testList);
+        assertNotNull(jpaToscaCapabilityTypesList);
+    }
+
+    @Test
+    void testValidate() {
+        assertThatCode(() -> jpaToscaCapabilityTypesUnderTest.validate("name")).doesNotThrowAnyException();
+    }
+}
index 228a4f8..fe44d05 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.when;
 import static org.mockito.MockitoAnnotations.openMocks;
 
+import java.util.ArrayList;
 import java.util.List;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaRequirement;
 
 class JpaToscaRequirementTest {
 
     @Mock
     private PfConceptKey mockKey;
-    @Mock
-    private List<Integer> mockOccurrences;
+
+    private final List<Integer> occurrences = new ArrayList<>();
 
     private JpaToscaRequirement jpaToscaRequirementUnderTest;
 
@@ -45,7 +50,10 @@ class JpaToscaRequirementTest {
     void setUp() {
         mockitoCloseable = openMocks(this);
         jpaToscaRequirementUnderTest = new JpaToscaRequirement(mockKey);
-        jpaToscaRequirementUnderTest.setOccurrences(mockOccurrences);
+        when(mockKey.getName()).thenReturn("testName");
+        when(mockKey.getVersion()).thenReturn("1.0.0");
+        occurrences.add(1);
+        jpaToscaRequirementUnderTest.setOccurrences(occurrences);
     }
 
     @AfterEach
@@ -53,6 +61,24 @@ class JpaToscaRequirementTest {
         mockitoCloseable.close();
     }
 
+    @Test
+    void testConstructor() {
+        JpaToscaRequirement requirementCopy = new JpaToscaRequirement(jpaToscaRequirementUnderTest);
+        assertNotNull(requirementCopy);
+
+        ToscaRequirement req = new ToscaRequirement();
+        req.setNode("nodeTest");
+        req.setCapability("capabilityTest");
+        List<Object> testOccurrences = new ArrayList<>();
+        testOccurrences.add(1);
+        req.setOccurrences(testOccurrences);
+        req.setName("nameTest");
+        req.setType("testType");
+        req.setTypeVersion("1.0.0");
+        requirementCopy = new JpaToscaRequirement(req);
+        assertNotNull(requirementCopy);
+    }
+
     @Test
     void testCapabilityGetterAndSetter() {
         final String capability = "capability";
@@ -67,10 +93,29 @@ class JpaToscaRequirementTest {
         jpaToscaRequirementUnderTest.setRelationship(relationship);
         assertThat(jpaToscaRequirementUnderTest.getRelationship()).isEqualTo(relationship);
 
-        assertThat(jpaToscaRequirementUnderTest.getOccurrences()).isEqualTo(mockOccurrences);
+        assertThat(jpaToscaRequirementUnderTest.getOccurrences()).isEqualTo(occurrences);
 
         assertThat(jpaToscaRequirementUnderTest.toString())
             .hasToString("JpaToscaRequirement(capability=capability, node=node, relationship=relationship, "
-                + "occurrences=mockOccurrences)");
+                + "occurrences=[1])");
+    }
+
+    @Test
+    void testToAuthorative() {
+        ToscaRequirement toAuthoritiveReq = jpaToscaRequirementUnderTest.toAuthorative();
+        assertNotNull(toAuthoritiveReq);
+    }
+
+    @Test
+    void testDeserialize() {
+        assertNotNull(jpaToscaRequirementUnderTest.deserializePropertyValue("occurences"));
+    }
+
+    @Test
+    void testClean() {
+        jpaToscaRequirementUnderTest.setCapability("capabilityTestValue");
+        jpaToscaRequirementUnderTest.setNode("nodeTestValue");
+        jpaToscaRequirementUnderTest.setRelationship("relationshipTestValue");
+        assertThatCode(() -> jpaToscaRequirementUnderTest.clean()).doesNotThrowAnyException();
     }
 }