diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-27 13:04:21 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-06-27 13:21:58 +0000 |
commit | e7772aebff2f84a619788ddb287fbfcef8569964 (patch) | |
tree | 26e4ad98a563522fbcc1c8b5aa276cbe2b49ebe7 | |
parent | 56b2759cee1931b3d3fb2da5197e47c32982cd19 (diff) |
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 <francesco.fiora@est.tech>
15 files changed, 287 insertions, 28 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java index 1802f814c..76443ab37 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 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. @@ -40,9 +40,9 @@ public class AutomationCompositions { /** * Copy constructor, does a deep copy. * - * @param otherAutomationCompositions the other element to copy from + * @param other the other element to copy from */ - public AutomationCompositions(final AutomationCompositions otherAutomationCompositions) { - this.automationCompositionList = PfUtils.mapList(automationCompositionList, AutomationComposition::new); + public AutomationCompositions(final AutomationCompositions other) { + this.automationCompositionList = PfUtils.mapList(other.automationCompositionList, AutomationComposition::new); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java index 572332eeb..e675e2387 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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. @@ -42,7 +42,10 @@ public class DocToscaCapabilityAssignment extends DocToscaWithTypeAndStringPrope @Serial private static final long serialVersionUID = 1L; + @SuppressWarnings("squid:S1948") private Map<@NotNull String, @NotNull Object> attributes; + + @SuppressWarnings("squid:S1948") private List<@NotNull Object> occurrences; /** diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java index c8484654b..b931d4e0a 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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. @@ -59,6 +59,7 @@ public class DocToscaEntity<T extends ToscaEntity> extends Validated @SerializedName("derived_from") private String derivedFrom; + @SuppressWarnings("squid:S1948") private Map<@NotNull @NotBlank String, @NotNull @NotBlank Object> metadata = new LinkedHashMap<>(); @NotBlank diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java index 2904962fc..5a252b8d2 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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,7 @@ public class DocToscaParameter implements PfAuthorative<ToscaParameter>, Seriali @SerializedName("type_version") private String typeVersion; + @SuppressWarnings("squid:S1948") private Object value; /** diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java index b47ef56aa..774f045f5 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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. @@ -60,6 +60,7 @@ public class DocToscaProperty implements PfAuthorative<ToscaProperty>, Serializa @SerializedName("default") @NotBlank + @SuppressWarnings("squid:S1948") private Object defaultValue; private boolean required = false; @@ -208,7 +209,7 @@ public class DocToscaProperty implements PfAuthorative<ToscaProperty>, Serializa return result; } - result = entrySchema.compareTo(other.entrySchema); + result = ObjectUtils.compare(entrySchema, other.entrySchema); if (result != 0) { return result; } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java index fd67fb68d..9d3cc1051 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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. @@ -42,6 +42,8 @@ public class DocToscaRequirement extends DocToscaWithTypeAndStringProperties<Tos private String capability; private String node; private String relationship; + + @SuppressWarnings("squid:S1948") private List<Object> occurrences; public DocToscaRequirement(ToscaRequirement toscaRequirement) { diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java index 9a6d60c1c..bcb63a2f1 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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. @@ -33,6 +33,7 @@ import lombok.NoArgsConstructor; import lombok.NonNull; import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.clamp.models.acm.document.base.DocConceptKey; +import org.onap.policy.clamp.models.acm.document.base.DocUtil; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; @@ -49,6 +50,7 @@ public class DocToscaWithToscaProperties<T extends ToscaWithToscaProperties> ext @Serial private static final long serialVersionUID = 1L; + @SuppressWarnings("squid:S1948") private Map<@NotNull @NotBlank String, @NotNull @Valid DocToscaProperty> properties; /** @@ -121,4 +123,20 @@ public class DocToscaWithToscaProperties<T extends ToscaWithToscaProperties> ext referencedDataTypes.removeAll(set); return referencedDataTypes; } + + @Override + public int compareTo(final DocToscaEntity<T> otherConcept) { + if (this == otherConcept) { + return 0; + } + + int result = super.compareTo(otherConcept); + if (result != 0) { + return result; + } + + final var other = (DocToscaWithToscaProperties<T>) otherConcept; + + return DocUtil.compareMaps(properties, other.properties); + } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java index 55b7364c9..2d62e36ea 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022,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. @@ -50,6 +50,7 @@ public class DocToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjec @SerializedName("type_version") private String typeVersion; + @SuppressWarnings("squid:S1948") private Map<String, Object> properties; /** 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<String, Object> 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); + } +} diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java index 1b0fe60d9..39db8c3e1 100644 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java @@ -57,7 +57,12 @@ class MessageHandlerTest { var bridge = createMockElementService(ElementType.BRIDGE); var messageHandler = createMessageHandler(List.of(starter, bridge)); - assertThatThrownBy(() -> messageHandler.getActiveService()) + assertThatThrownBy(() -> messageHandler.active(null)) + .isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> messageHandler.update(null)) + .isInstanceOf(NullPointerException.class); + + assertThatThrownBy(messageHandler::getActiveService) .isInstanceOf(AutomationCompositionRuntimeException.class); var elementConfig = new ElementConfig(); diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessagePublisherTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessagePublisherTest.java new file mode 100644 index 000000000..dafb01651 --- /dev/null +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessagePublisherTest.java @@ -0,0 +1,54 @@ +/*- + * ============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.acm.element.handler; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.messages.kafka.element.ElementMessage; +import org.onap.policy.clamp.models.acm.messages.kafka.element.ElementMessageType; +import org.onap.policy.common.endpoints.event.comm.TopicSink; + + +class MessagePublisherTest { + + @Test + void testActiveEmpty() { + var messagePublisher = new MessagePublisher(); + var list = List.<TopicSink>of(); + assertThatThrownBy(() -> messagePublisher.active(list)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void testPublishMsg() { + var topic = mock(TopicSink.class); + var messagePublisher = new MessagePublisher(); + messagePublisher.active(List.of(topic)); + messagePublisher.publishMsg(new ElementMessage(ElementMessageType.STATUS)); + messagePublisher.stop(); + verify(topic).send(any()); + } +} diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java index 5ccee7b31..453ccc916 100644 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation. + * Copyright (C) 2022-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. @@ -45,6 +45,8 @@ class ActuatorControllerTest extends CommonActuatorController { private static final String PROMETHEUS_ENDPOINT = "onap/policy/clamp/acelement/v2/prometheus"; private static final String SWAGGER_ENDPOINT = "onap/policy/clamp/acelement/v2/v3/api-docs"; + private static final String WRONG_ENDPOINT = "onap/policy/clamp/acelement/v2/wrong"; + @LocalServerPort private int randomServerPort; @@ -76,28 +78,40 @@ class ActuatorControllerTest extends CommonActuatorController { @Test void testGetHealth() { var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test void testGetMetrics() { var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test void testGetPrometheus() { var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test void testGetSwagger() { var invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } + } + + @Test + void testWrongEndPoint() { + var invocationBuilder = super.sendActRequest(WRONG_ENDPOINT); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus()); + } } } |