From e7772aebff2f84a619788ddb287fbfcef8569964 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Thu, 27 Jun 2024 13:04:21 +0100 Subject: Code coverage and sonar fixes for ACM Code coverage and sonar fixes in classes that was not involved in recent implementations. Issue-ID: POLICY-5065 Change-Id: Ib23da6f242b0a7eaa98f14abc6617ff9e12e10d9 Signed-off-by: FrancescoFioraEst --- .../acm/concepts/AutomationCompositionsTest.java | 37 ++++++++++++++ .../JpaAutomationCompositionElementTest.java | 23 ++++++--- .../concepts/StringToMapConverterTest.java | 53 ++++++++++++++++++++ .../StringToServiceTemplateConverterTest.java | 58 ++++++++++++++++++++++ 4 files changed, 165 insertions(+), 6 deletions(-) create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverterTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java (limited to 'models/src/test/java/org/onap') diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java new file mode 100644 index 000000000..5262b1316 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java @@ -0,0 +1,37 @@ +/*- + * ============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.clamp.models.acm.concepts; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; +import org.junit.jupiter.api.Test; + +class AutomationCompositionsTest { + + @Test + void testAutomationCompositions() { + var ac0 = new AutomationCompositions(); + ac0.setAutomationCompositionList(List.of(new AutomationComposition())); + var ac1 = new AutomationCompositions(ac0); + assertEquals(ac0.getAutomationCompositionList(), ac1.getAutomationCompositionList()); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java index 2eda9a9b3..a6b3c0f80 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-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. @@ -48,6 +48,8 @@ class JpaAutomationCompositionElementTest { private static final String ELEMENT_ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e"; private static final String INSTANCE_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a"; + private static final PfConceptKey CONCEPT_KEY = new PfConceptKey(); + @Test void testJpaAutomationCompositionElementConstructor() { assertThatThrownBy(() -> { @@ -85,19 +87,19 @@ class JpaAutomationCompositionElementTest { }).hasMessageMatching("definition" + NULL_ERROR); assertThatThrownBy(() -> { - new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), + new JpaAutomationCompositionElement("key", "key", CONCEPT_KEY, null, LockState.LOCKED); }).hasMessageMatching("deployState" + NULL_ERROR); assertThatThrownBy(() -> { - new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), + new JpaAutomationCompositionElement("key", "key", CONCEPT_KEY, DeployState.UNDEPLOYED, null); }).hasMessageMatching("lockState" + NULL_ERROR); assertDoesNotThrow(() -> new JpaAutomationCompositionElement()); assertDoesNotThrow(() -> new JpaAutomationCompositionElement("key", "key")); assertDoesNotThrow(() -> new JpaAutomationCompositionElement("key", "key", - new PfConceptKey(), DeployState.UNDEPLOYED, LockState.LOCKED)); + CONCEPT_KEY, DeployState.UNDEPLOYED, LockState.LOCKED)); } @Test @@ -141,7 +143,7 @@ class JpaAutomationCompositionElementTest { } @Test - void testJpaAutomationCompositionElementCompareTo() { + void testJpaAcElementCompareTo() { var testJpaAcElement = createJpaAutomationCompositionElementInstance(); var otherJpaAcElement = @@ -152,6 +154,16 @@ class JpaAutomationCompositionElementTest { assertNotEquals(0, testJpaAcElement.compareTo(new DummyJpaAutomationCompositionElementChild())); + assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement)); + } + + @Test + void testJpaAutomationCompositionElementCompareTo() { + var testJpaAcElement = createJpaAutomationCompositionElementInstance(); + + var otherJpaAcElement = + new JpaAutomationCompositionElement(testJpaAcElement); + testJpaAcElement.setElementId("BadValue"); assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); testJpaAcElement.setElementId(ELEMENT_ID); @@ -205,7 +217,6 @@ class JpaAutomationCompositionElementTest { testJpaAcElement.setParticipantId(UUID.randomUUID().toString()); assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement)); - assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement)); } @Test diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverterTest.java new file mode 100644 index 000000000..67240047a --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverterTest.java @@ -0,0 +1,53 @@ +/*- + * ============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.clamp.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.base.PfModelRuntimeException; + +class StringToMapConverterTest { + + @Test + void testConvert() { + var stringToMapConverter = new StringToMapConverter(); + Map map = Map.of("key", List.of("value")); + var dbData = stringToMapConverter.convertToDatabaseColumn(map); + var result = stringToMapConverter.convertToEntityAttribute(dbData); + assertEquals(map, result); + } + + @Test + void testNull() { + var stringToMapConverter = new StringToMapConverter(); + var dbData = stringToMapConverter.convertToDatabaseColumn(null); + assertThat(dbData).isNull(); + var map = stringToMapConverter.convertToEntityAttribute(null); + assertThat(map).isNotNull(); + assertThatThrownBy(() -> stringToMapConverter.convertToEntityAttribute("1")) + .isInstanceOf(PfModelRuntimeException.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java new file mode 100644 index 000000000..98f22afcc --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java @@ -0,0 +1,58 @@ +/*- + * ============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.clamp.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate; +import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.models.base.PfModelRuntimeException; + +class StringToServiceTemplateConverterTest { + + private static final String TOSCA_SERVICE_TEMPLATE_YAML_PROP = + "clamp/acm/test/tosca-template-additional-properties.yaml"; + + @Test + void testConvert() { + var inputServiceTemplateProperties = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP); + var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplateProperties); + var stringToServiceTemplateConverter = new StringToServiceTemplateConverter(); + var dbData = stringToServiceTemplateConverter.convertToDatabaseColumn(docServiceTemplate); + var result = stringToServiceTemplateConverter.convertToEntityAttribute(dbData); + assertThat(docServiceTemplate.compareTo(result)).isEqualByComparingTo(0); + } + + @Test + void testNull() { + var stringToServiceTemplateConverter = new StringToServiceTemplateConverter(); + var dbData = stringToServiceTemplateConverter.convertToDatabaseColumn(null); + assertThat(dbData).isNull(); + var docServiceTemplate = stringToServiceTemplateConverter.convertToEntityAttribute(null); + assertThat(docServiceTemplate).isNotNull(); + docServiceTemplate = stringToServiceTemplateConverter.convertToEntityAttribute(""); + assertThat(docServiceTemplate).isNull(); + assertThatThrownBy(() -> stringToServiceTemplateConverter.convertToEntityAttribute("1")) + .isInstanceOf(PfModelRuntimeException.class); + } +} -- cgit 1.2.3-korg