diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2022-03-21 12:38:52 +0000 |
---|---|---|
committer | Adheli Tavares <adheli.tavares@est.tech> | 2022-03-22 13:04:37 +0000 |
commit | 0a78930e107a44c3b4119a321c680692154f90f5 (patch) | |
tree | b3cd4d3850d092001e5b3f179ff41bc2eb465ab3 /participant/participant-impl/participant-impl-policy | |
parent | e5a316e5c8aeaae1ba4aead0a71b6baf2f8cc5c1 (diff) |
Clean up unit tests
- use the unified test reference folder
- fix some sonar lint issues
Issue-ID: POLICY-3945
Change-Id: I33e30332d911f02c32937316bac6d2d331ac6346
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-policy')
10 files changed, 70 insertions, 400 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java index c17d2c53d..091e3c13c 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,7 @@ package org.onap.policy.clamp.acm.participant.policy.endtoend; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.Instant; import java.util.Collections; @@ -49,12 +49,12 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(locations = {"classpath:application_test.properties"}) +@ActiveProfiles("test") class ParticipantMessagesTest { private static final Object lockit = new Object(); @@ -65,7 +65,7 @@ class ParticipantMessagesTest { private ParticipantHandler participantHandler; @Test - void testSendParticipantRegisterMessage() throws Exception { + void testSendParticipantRegisterMessage() { final ParticipantRegister participantRegisterMsg = new ParticipantRegister(); participantRegisterMsg.setParticipantId(getParticipantId()); participantRegisterMsg.setTimestamp(Instant.now()); @@ -73,15 +73,15 @@ class ParticipantMessagesTest { synchronized (lockit) { ParticipantMessagePublisher participantMessagePublisher = - new ParticipantMessagePublisher(); + new ParticipantMessagePublisher(); participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); assertThatCode(() -> participantMessagePublisher.sendParticipantRegister(participantRegisterMsg)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } } @Test - void testReceiveParticipantRegisterAckMessage() throws Exception { + void testReceiveParticipantRegisterAckMessage() { final ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck(); participantRegisterAckMsg.setMessage("ParticipantRegisterAck message"); participantRegisterAckMsg.setResponseTo(UUID.randomUUID()); @@ -91,12 +91,12 @@ class ParticipantMessagesTest { ParticipantRegisterAckListener participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler); assertThatCode(() -> participantRegisterAckListener.onTopicEvent(INFRA, TOPIC, null, - participantRegisterAckMsg)).doesNotThrowAnyException(); + participantRegisterAckMsg)).doesNotThrowAnyException(); } } @Test - void testSendParticipantDeregisterMessage() throws Exception { + void testSendParticipantDeregisterMessage() { final ParticipantDeregister participantDeregisterMsg = new ParticipantDeregister(); participantDeregisterMsg.setParticipantId(getParticipantId()); participantDeregisterMsg.setTimestamp(Instant.now()); @@ -104,15 +104,15 @@ class ParticipantMessagesTest { synchronized (lockit) { ParticipantMessagePublisher participantMessagePublisher = - new ParticipantMessagePublisher(); + new ParticipantMessagePublisher(); participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); assertThatCode(() -> participantMessagePublisher.sendParticipantDeregister(participantDeregisterMsg)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } } @Test - void testReceiveParticipantDeregisterAckMessage() throws Exception { + void testReceiveParticipantDeregisterAckMessage() { final ParticipantDeregisterAck participantDeregisterAckMsg = new ParticipantDeregisterAck(); participantDeregisterAckMsg.setMessage("ParticipantDeregisterAck message"); participantDeregisterAckMsg.setResponseTo(UUID.randomUUID()); @@ -120,14 +120,14 @@ class ParticipantMessagesTest { synchronized (lockit) { ParticipantDeregisterAckListener participantDeregisterAckListener = - new ParticipantDeregisterAckListener(participantHandler); + new ParticipantDeregisterAckListener(participantHandler); assertThatCode(() -> participantDeregisterAckListener.onTopicEvent(INFRA, TOPIC, null, - participantDeregisterAckMsg)).doesNotThrowAnyException(); + participantDeregisterAckMsg)).doesNotThrowAnyException(); } } @Test - void testReceiveParticipantUpdateMessage() throws Exception { + void testReceiveParticipantUpdateMessage() { ParticipantUpdate participantUpdateMsg = TestListenerUtils.createParticipantUpdateMsg(); synchronized (lockit) { @@ -140,7 +140,7 @@ class ParticipantMessagesTest { } @Test - void testSendParticipantUpdateAckMessage() throws Exception { + void testSendParticipantUpdateAckMessage() { final ParticipantUpdateAck participantUpdateAckMsg = new ParticipantUpdateAck(); participantUpdateAckMsg.setMessage("ParticipantUpdateAck message"); participantUpdateAckMsg.setResponseTo(UUID.randomUUID()); @@ -150,12 +150,12 @@ class ParticipantMessagesTest { ParticipantMessagePublisher participantMessagePublisher = new ParticipantMessagePublisher(); participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); assertThatCode(() -> participantMessagePublisher.sendParticipantUpdateAck(participantUpdateAckMsg)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } } @Test - void testParticipantStatusHeartbeat() throws Exception { + void testParticipantStatusHeartbeat() { final ParticipantStatus heartbeat = participantHandler.makeHeartbeat(true); synchronized (lockit) { ParticipantMessagePublisher publisher = new ParticipantMessagePublisher(); diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java index 0d114db8d..6b2ddf7e3 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,6 @@ import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -46,7 +45,7 @@ class AutomationCompositionElementHandlerTest { new ToscaConceptIdentifier(ID_NAME, ID_VERSION); @Test - void testHandlerExceptions() { + void testHandlerDoesNotThrowExceptions() { AutomationCompositionElementHandler handler = getTestingHandler(); assertDoesNotThrow(() -> handler @@ -76,7 +75,7 @@ class AutomationCompositionElementHandlerTest { .handleStatistics(automationCompositionElementId)); } - AutomationCompositionElementHandler getTestingHandler() { + private AutomationCompositionElementHandler getTestingHandler() { var api = Mockito.mock(PolicyApiHttpClient.class); var pap = Mockito.mock(PolicyPapHttpClient.class); var handler = new AutomationCompositionElementHandler(api, pap); @@ -87,7 +86,7 @@ class AutomationCompositionElementHandlerTest { return handler; } - AutomationCompositionElement getTestingAcElement() { + private AutomationCompositionElement getTestingAcElement() { var element = new AutomationCompositionElement(); element.setDefinition(automationCompositionId); element.setDescription("Description"); diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java index b5cd9d442..ac6451260 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/CommonTestData.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,9 @@ package org.onap.policy.clamp.acm.participant.policy.main.parameters; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; -import org.onap.policy.clamp.acm.participant.policy.main.parameters.ParticipantPolicyParameters; import org.onap.policy.common.endpoints.parameters.TopicParameters; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -38,7 +36,7 @@ public class CommonTestData { public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup"; public static final String DESCRIPTION = "Participant description"; public static final long TIME_INTERVAL = 2000; - public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams()); + public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams()); public static final Coder CODER = new StandardCoder(); @@ -154,7 +152,7 @@ public class CommonTestData { final TopicParameters topicParams = new TopicParameters(); topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT"); topicParams.setTopicCommInfrastructure("dmaap"); - topicParams.setServers(Arrays.asList("localhost")); + topicParams.setServers(List.of("localhost")); return topicParams; } @@ -164,18 +162,7 @@ public class CommonTestData { * @return participant Id */ public static ToscaConceptIdentifier getParticipantId() { - final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0"); - return participantId; + return new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0"); } - /** - * Nulls out a field within a JSON string. - * - * @param json JSON string - * @param field field to be nulled out - * @return a new JSON string with the field nulled out - */ - public String nullifyField(String json, String field) { - return json.replace(field + "\"", field + "\":null, \"" + field + "Xxx\""); - } } diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/ParticipantPolicyParametersTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/ParticipantPolicyParametersTest.java index 89b2bce58..8e822ea9a 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/ParticipantPolicyParametersTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/parameters/ParticipantPolicyParametersTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat; import javax.validation.Validation; import javax.validation.ValidatorFactory; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.acm.participant.policy.main.parameters.ParticipantPolicyParameters; class ParticipantPolicyParametersTest { private final CommonTestData commonTestData = new CommonTestData(); diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java index 8543bf98a..c74480fba 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,13 +32,13 @@ import org.springframework.boot.test.autoconfigure.actuate.metrics.AutoConfigure import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @AutoConfigureMetrics @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(locations = {"classpath:application_test.properties"}) +@ActiveProfiles("test") class ActuatorControllerTest extends CommonActuatorController { private static final String HEALTH_ENDPOINT = "health"; @@ -54,36 +54,36 @@ class ActuatorControllerTest extends CommonActuatorController { } @Test - void testGetHealth_Unauthorized() throws Exception { + void testGetHealth_Unauthorized() { assertUnauthorizedActGet(HEALTH_ENDPOINT); } @Test - void testGetMetrics_Unauthorized() throws Exception { + void testGetMetrics_Unauthorized() { assertUnauthorizedActGet(METRICS_ENDPOINT); } @Test - void testGetPrometheus_Unauthorized() throws Exception { + void testGetPrometheus_Unauthorized() { assertUnauthorizedActGet(PROMETHEUS_ENDPOINT); } @Test - void testGetHealth() throws Exception { + void testGetHealth() { Invocation.Builder invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); } @Test - void testGetMetrics() throws Exception { + void testGetMetrics() { Invocation.Builder invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); } @Test - void testGePrometheus() throws Exception { + void testGePrometheus() { Invocation.Builder invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java index 689977e3c..f83184024 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 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,9 +50,8 @@ public class CommonActuatorController { * * @param endpoint the target endpoint * @return a request builder - * @throws Exception if an error occurs */ - protected Invocation.Builder sendActRequest(final String endpoint) throws Exception { + protected Invocation.Builder sendActRequest(final String endpoint) { return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, true); } @@ -61,9 +60,8 @@ public class CommonActuatorController { * * @param endpoint the target endpoint * @return a request builder - * @throws Exception if an error occurs */ - protected Invocation.Builder sendNoAuthActRequest(final String endpoint) throws Exception { + protected Invocation.Builder sendNoAuthActRequest(final String endpoint) { return sendFqeRequest(httpPrefix + ACTUATOR_ENDPOINT + endpoint, false); } @@ -73,10 +71,8 @@ public class CommonActuatorController { * @param fullyQualifiedEndpoint the fully qualified target endpoint * @param includeAuth if authorization header should be included * @return a request builder - * @throws Exception if an error occurs */ - protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) - throws Exception { + protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) { final Client client = ClientBuilder.newBuilder().build(); client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); @@ -95,9 +91,8 @@ public class CommonActuatorController { * Assert that GET call to actuator endpoint is Unauthorized. * * @param endPoint the endpoint - * @throws Exception if an error occurs */ - protected void assertUnauthorizedActGet(final String endPoint) throws Exception { + protected void assertUnauthorizedActGet(final String endPoint) { Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke(); assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus()); } diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java index a29831d56..1d6cb272b 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,31 +22,19 @@ package org.onap.policy.clamp.acm.participant.policy.main.utils; import static org.junit.Assert.assertTrue; -import java.io.File; import java.io.FileNotFoundException; import java.time.Instant; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; -import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.clamp.models.acm.utils.AcmUtils; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -59,123 +47,9 @@ import org.slf4j.LoggerFactory; public final class TestListenerUtils { private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - private static final Coder CODER = new StandardCoder(); private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class); /** - * Method to create a automationComposition from a yaml file. - * - * @return AutomationComposition automation composition - */ - public static AutomationComposition createAutomationComposition() { - AutomationComposition automationComposition = new AutomationComposition(); - Map<UUID, AutomationCompositionElement> elements = new LinkedHashMap<>(); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionRead(); - Map<String, ToscaNodeTemplate> nodeTemplatesMap = - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { - AutomationCompositionElement acElement = new AutomationCompositionElement(); - acElement.setId(UUID.randomUUID()); - - ToscaConceptIdentifier acElementParticipantId = new ToscaConceptIdentifier(); - acElementParticipantId.setName(toscaInputEntry.getKey()); - acElementParticipantId.setVersion(toscaInputEntry.getValue().getVersion()); - acElement.setParticipantId(acElementParticipantId); - - acElement.setDefinition(acElementParticipantId); - acElement.setState(AutomationCompositionState.UNINITIALISED); - acElement.setDescription(toscaInputEntry.getValue().getDescription()); - acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); - elements.put(acElement.getId(), acElement); - } - automationComposition.setElements(elements); - automationComposition.setName("PMSHInstance0"); - automationComposition.setVersion("1.0.0"); - - ToscaConceptIdentifier definition = new ToscaConceptIdentifier(); - definition.setName("PMSHInstance0"); - definition.setVersion("1.0.0"); - automationComposition.setDefinition(definition); - - return automationComposition; - } - - /** - * Method to create AutomationCompositionStateChange message from the arguments passed. - * - * @param automationCompositionOrderedState automationCompositionOrderedState - * @return AutomationCompositionStateChange message - */ - public static AutomationCompositionStateChange createAutomationCompositionStateChangeMsg( - final AutomationCompositionOrderedState automationCompositionOrderedState) { - final AutomationCompositionStateChange acStateChangeMsg = new AutomationCompositionStateChange(); - - ToscaConceptIdentifier automationCompositionId = new ToscaConceptIdentifier(); - automationCompositionId.setName("PMSHInstance0"); - automationCompositionId.setVersion("1.0.0"); - - ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(); - participantId.setName("org.onap.PM_Policy"); - participantId.setVersion("0.0.0"); - - acStateChangeMsg.setAutomationCompositionId(automationCompositionId); - acStateChangeMsg.setParticipantId(participantId); - acStateChangeMsg.setTimestamp(Instant.now()); - acStateChangeMsg.setOrderedState(automationCompositionOrderedState); - - return acStateChangeMsg; - } - - /** - * Method to create AutomationCompositionUpdateMsg. - * - * @return AutomationCompositionUpdate message - */ - public static AutomationCompositionUpdate createAutomationCompositionUpdateMsg() { - final AutomationCompositionUpdate acUpdateMsg = new AutomationCompositionUpdate(); - ToscaConceptIdentifier automationCompositionId = new ToscaConceptIdentifier("PMSHInstance0", "1.0.0"); - ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0"); - - acUpdateMsg.setAutomationCompositionId(automationCompositionId); - acUpdateMsg.setParticipantId(participantId); - acUpdateMsg.setMessageId(UUID.randomUUID()); - acUpdateMsg.setTimestamp(Instant.now()); - - Map<UUID, AutomationCompositionElement> elements = new LinkedHashMap<>(); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionRead(); - TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate); - Map<String, ToscaNodeTemplate> nodeTemplatesMap = - toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { - if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(), - toscaServiceTemplate)) { - AutomationCompositionElement acElement = new AutomationCompositionElement(); - acElement.setId(UUID.randomUUID()); - var acParticipantType = - ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - - acElement.setParticipantId(acParticipantType); - acElement.setParticipantType(acParticipantType); - - acElement.setDefinition( - new ToscaConceptIdentifier(toscaInputEntry.getKey(), toscaInputEntry.getValue().getVersion())); - acElement.setState(AutomationCompositionState.UNINITIALISED); - acElement.setDescription(toscaInputEntry.getValue().getDescription()); - acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - elements.put(acElement.getId(), acElement); - } - } - - List<ParticipantUpdates> participantUpdates = new ArrayList<>(); - for (AutomationCompositionElement element : elements.values()) { - AcmUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate); - AcmUtils.prepareParticipantUpdate(element, participantUpdates); - } - acUpdateMsg.setParticipantUpdatesList(participantUpdates); - return acUpdateMsg; - } - - /** * Method to create participantUpdateMsg. * * @return ParticipantUpdate message @@ -212,23 +86,9 @@ public final class TestListenerUtils { return participantUpdateMsg; } - /** - * Method to create AutomationCompositionUpdate using the arguments passed. - * - * @param jsonFilePath the path of the automation composition content - * @return AutomationCompositionUpdate message - * @throws CoderException exception while reading the file to object - */ - public static AutomationCompositionUpdate createParticipantAcUpdateMsgFromJson(String jsonFilePath) - throws CoderException { - AutomationCompositionUpdate automationCompositionUpdateMsg = - CODER.decode(new File(jsonFilePath), AutomationCompositionUpdate.class); - return automationCompositionUpdateMsg; - } - private static ToscaServiceTemplate testAutomationCompositionRead() { Set<String> automationCompositionDirectoryContents = - ResourceUtils.getDirectoryContents("src/test/resources/utils/servicetemplates"); + ResourceUtils.getDirectoryContents("clamp/acm/test"); boolean atLeastOneAutomationCompositionTested = false; ToscaServiceTemplate toscaServiceTemplate = null; @@ -310,11 +170,9 @@ public final class TestListenerUtils { throw new FileNotFoundException(automationCompositionFilePath); } - ToscaServiceTemplate serviceTemplate = - yamlTranslator.fromYaml(automationCompositionString, ToscaServiceTemplate.class); - return serviceTemplate; + return yamlTranslator.fromYaml(automationCompositionString, ToscaServiceTemplate.class); } catch (FileNotFoundException e) { - LOGGER.error("cannot find YAML file", automationCompositionFilePath); + LOGGER.error("cannot find YAML file {}", automationCompositionFilePath); throw new IllegalArgumentException(e); } } diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml new file mode 100644 index 000000000..3388f01a5 --- /dev/null +++ b/participant/participant-impl/participant-impl-policy/src/test/resources/application-test.yaml @@ -0,0 +1,24 @@ +participant: + intermediaryParameters: + reportingTimeInterval: 120000 + description: Participant Description + participantId: + version: 1.0.0 + name: org.onap.PM_CDS_Blueprint + participantType: + version: 1.0.0 + name: org.onap.PM_CDS_Blueprint + clampAutomationCompositionTopics: + topicSources: + - + topic: POLICY-ACRUNTIME-PARTICIPANT + servers: + - localhost + topicCommInfrastructure: dmaap + fetchTimeout: 15000 + topicSinks: + - + topicCommInfrastructure: dmaap + servers: + - localhost + topic: POLICY-ACRUNTIME-PARTICIPANT diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties deleted file mode 100644 index 932d9f2c3..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/application_test.properties +++ /dev/null @@ -1,28 +0,0 @@ -spring.security.user.name=participantUser -spring.security.user.password=zb!XztG34 -server.servlet.context-path=/onap/policy/clamp/acm/policyparticipant -server.error.path=/error -server.http-port=8085 - -participant.policyApiParameters.clientName=api -participant.policyApiParameters.hostname=localhost -participant.policyApiParameters.port=6969 -participant.policyApiParameters.userName=policyadmin -participant.policyApiParameters.password=zb!XztG34 -participant.policyApiParameters.https=false -participant.policyApiParameters.allowSelfSignedCerts=true -participant.intermediaryParameters.reportingTimeInterval: 120000 -participant.intermediaryParameters.description: Participant Description -participant.intermediaryParameters.participantId.name: org.onap.PM_Policy -participant.intermediaryParameters.participantId.version: 1.0.0 -participant.intermediaryParameters.participantType.name: org.onap.policy.acm.PolicyAutomationCompositionParticipant -participant.intermediaryParameters.participantType.version: 2.3.1 -participant.intermediaryParameters.clampAutomationCompositionTopics.name=Automation Composition Topics -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSources[0].topic=POLICY-ACRUNTIME-PARTICIPANT -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSources[0].servers[0]=localhost -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSources[0].topicCommInfrastructure=dmaap -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSources[0].fetchTimeout=15000 -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSinks[0].topic=POLICY-ACRUNTIME-PARTICIPANT -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSinks[0].servers[0]=localhost -participant.intermediaryParameters.clampAutomationCompositionTopics.topicSinks[0].topicCommInfrastructure=dmaap -management.endpoints.web.exposure.include=health,metrics,prometheus diff --git a/participant/participant-impl/participant-impl-policy/src/test/resources/utils/servicetemplates/pm_automation_composition_tosca.yaml b/participant/participant-impl/participant-impl-policy/src/test/resources/utils/servicetemplates/pm_automation_composition_tosca.yaml deleted file mode 100644 index 3d14cf572..000000000 --- a/participant/participant-impl/participant-impl-policy/src/test/resources/utils/servicetemplates/pm_automation_composition_tosca.yaml +++ /dev/null @@ -1,164 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_3 -data_types: - onap.datatypes.ToscaConceptIdentifier: - derived_from: tosca.datatypes.Root - properties: - name: - type: string - required: true - version: - type: string - required: true -node_types: - org.onap.policy.clamp.acmParticipant: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - requred: false - org.onap.policy.clamp.acmAutomationCompositionElement: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - requred: false - participantType: - type: onap.datatypes.ToscaConceptIdentifier - requred: true - startPhase: - type: integer - required: false - constraints: - - greater-or-equal: 0 - metadata: - common: true - description: A value indicating the start phase in which this automation composition element will be started, - the first start phase is zero. Automation Composition Elements are started in their start_phase - order and stopped in reverse start phase order. Automation Composition Elements with the same start - phase are started and stopped simultaneously - org.onap.policy.clamp.acmAutomationComposition: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - requred: false - elements: - type: list - required: true - entry_schema: - type: onap.datatypes.ToscaConceptIdentifier - org.onap.policy.clamp.acmDCAEMicroserviceAutomationCompositionElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.acmAutomationCompositionElement - properties: - dcae_blueprint_id: - type: onap.datatypes.ToscaConceptIdentifier - requred: true - org.onap.policy.clamp.acmPolicyTypeAutomationCompositionElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.acmAutomationCompositionElement - properties: - policy_type_id: - type: onap.datatypes.ToscaConceptIdentifier - requred: true - org.onap.policy.clamp.acmCDSAutomationCompositionElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.acmAutomationCompositionElement - properties: - cds_blueprint_id: - type: onap.datatypes.ToscaConceptIdentifier - requred: true -topology_template: - node_templates: - org.onap.dcae.acmDCAEMicroserviceAutomationCompositionParticipant: - version: 2.3.4 - type: org.onap.policy.clamp.acmParticipant - type_version: 1.0.1 - description: Participant for DCAE microservices - properties: - provider: ONAP - org.onap.policy.acmPolicyAutomationCompositionParticipant: - version: 2.3.1 - type: org.onap.policy.clamp.acmParticipant - type_version: 1.0.1 - description: Participant for DCAE microservices - properties: - provider: ONAP - org.onap.ccsdk.cds.acmCdsAutomationCompositionParticipant: - version: 2.2.1 - type: org.onap.policy.clamp.acmParticipant - type_version: 1.0.1 - description: Participant for DCAE microservices - properties: - provider: ONAP - org.onap.domain.pmsh.PMSH_DCAEMicroservice: - version: 1.2.3 - type: org.onap.policy.clamp.acmDCAEMicroserviceAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for DCAE microservice for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.dcae.acmDCAEMicroserviceAutomationCompositionParticipant - version: 2.3.4 - dcae_blueprint_id: - name: org.onap.dcae.blueprints.PMSHBlueprint - version: 1.0.0 - org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement: - version: 1.2.3 - type: org.onap.policy.clamp.acmPolicyTypeAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for monitoring policy for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.policy.acmPolicyAutomationCompositionParticipant - version: 2.3.1 - policy_type_id: - name: onap.policies.monitoring.pm-subscription-handler - version: 1.0.0 - org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement: - version: 1.2.3 - type: org.onap.policy.clamp.acmPolicyTypeAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element, operational policy for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.policy.acmPolicyAutomationCompositionParticipant - version: 2.3.1 - policy_type_id: - name: onap.policies.operational.pm-subscription-handler - version: 1.0.0 - org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement: - version: 1.2.3 - type: org.onap.policy.clamp.acmAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for CDS for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.ccsdk.cds.acmCdsAutomationCompositionParticipant - version: 3.2.1 - cds_blueprint_id: - name: org.onap.ccsdk.cds.PMSHCdsBlueprint - version: 1.0.0 - org.onap.domain.pmsh.PMSHAutomationCompositionDefinition: - version: 1.2.3 - type: org.onap.policy.clamp.acmAutomationComposition - type_version: 1.0.0 - description: Automation composition for Performance Management Subscription Handling - properties: - provider: Ericsson - elements: - - name: org.onap.domain.pmsh.PMSH_DCAEMicroservice - version: 1.2.3 - - name: org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement - version: 1.2.3 - - name: org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement - version: 1.2.3 - - name: org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement - version: 1.2.3 |