diff options
author | waynedunican <wayne.dunican@est.tech> | 2024-08-15 10:14:59 +0100 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2024-08-15 14:26:30 +0100 |
commit | bb5e3fc4a145ad9f4beead971a62ce4b8b4b5eb5 (patch) | |
tree | 8d10db0ca8056c8b3a579379dd4bbdba58d7ca04 /models-tosca/src/test | |
parent | b7804abcf865dc58a01bed3f2be4756e731d9288 (diff) |
Increase coverage above 90% for models
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>
Diffstat (limited to 'models-tosca/src/test')
2 files changed, 136 insertions, 5 deletions
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 index 000000000..e18b5259e --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityTypesTest.java @@ -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(); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java index 228a4f822..fe44d0503 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaRequirementTest.java @@ -21,21 +21,26 @@ 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 @@ -54,6 +62,24 @@ class JpaToscaRequirementTest { } @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"; jpaToscaRequirementUnderTest.setCapability(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(); } } |