diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator/src/test')
8 files changed, 123 insertions, 411 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.java index de6855d03..4cf9f1e3c 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/endtoend/ParticipantSimulatorTest.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. @@ -46,7 +46,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.AutomationComposi import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.clamp.acm.participant.simulator.main.parameters.CommonTestData; import org.onap.policy.clamp.acm.participant.simulator.main.rest.AbstractRestController; -import org.onap.policy.clamp.acm.participant.simulator.main.rest.TestListenerUtils; +import org.onap.policy.clamp.acm.participant.simulator.utils.TestListenerUtils; 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; @@ -62,12 +62,12 @@ import org.springframework.beans.factory.annotation.Value; 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; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(locations = {"classpath:application_test.properties"}) +@ActiveProfiles("test") class ParticipantSimulatorTest { private static final String PARTICIPANTS_ENDPOINT = "participants"; @@ -93,7 +93,7 @@ class ParticipantSimulatorTest { private static final Object lockit = new Object(); private boolean check = false; - private void setUp() throws Exception { + private void setUp() { synchronized (lockit) { if (!check) { check = true; @@ -103,32 +103,12 @@ class ParticipantSimulatorTest { AutomationCompositionUpdate automationCompositionUpdateMsg = TestListenerUtils.createAutomationCompositionUpdateMsg(); acUpdateListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionUpdateMsg); - } } } - private String getPath(String path) { - return "http://localhost:" + randomServerPort + "/onap/participantsim/v2/" + path; - } - - void testSwagger(String endPoint) { - final Client client = ClientBuilder.newBuilder().build(); - - client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); - client.register(GsonMessageBodyHandler.class); - client.register(HttpAuthenticationFeature.basic(user, password)); - - final WebTarget webTarget = client.target(getPath("api-docs")); - - Response response = webTarget.request(MediaType.APPLICATION_JSON).get(); - - assertThat(response.getStatus()).isEqualTo(200); - assertTrue(response.readEntity(String.class).contains("/onap/participantsim/v2/" + endPoint)); - } - @Test - void testEndParticipatsSwagger() { + void testEndParticipantsSwagger() { testSwagger(PARTICIPANTS_ENDPOINT); } @@ -154,7 +134,7 @@ class ParticipantSimulatorTest { } @Test - void testQuery_Unauthorized() throws Exception { + void testQuery_Unauthorized() { String path = PARTICIPANTS_ENDPOINT + "/org.onap.PM_CDS_Blueprint/1"; Response response = performRequest(path, true, null).get(); @@ -165,27 +145,8 @@ class ParticipantSimulatorTest { assertThat(response.getStatus()).isEqualTo(401); } - private Invocation.Builder performRequest(String endpoint, boolean includeAuth, UUID uuid) { - final Client client = ClientBuilder.newBuilder().build(); - - client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); - client.register(GsonMessageBodyHandler.class); - if (includeAuth) { - client.register(HttpAuthenticationFeature.basic(user, password)); - } - Invocation.Builder builder = client.target(getPath(endpoint)).request(MediaType.APPLICATION_JSON); - if (uuid != null) { - builder = builder.header(AbstractRestController.REQUEST_ID_NAME, uuid.toString()); - } - return builder; - } - - private Response performGet(String endpoint, UUID uuid) throws Exception { - return performRequest(endpoint, true, uuid).get(); - } - @Test - void testQueryParticipants() throws Exception { + void testQueryParticipants() { Participant participant = new Participant(); ToscaConceptIdentifier participantId = CommonTestData.getParticipantId(); participant.setDefinition(participantId); @@ -197,7 +158,7 @@ class ParticipantSimulatorTest { Response response = performGet( PARTICIPANTS_ENDPOINT + "/" + participant.getKey().getName() + "/" + participant.getKey().getVersion(), uuid); - checkResponseEntity(response, 200, uuid); + checkResponseEntity(response, uuid); Participant[] returnValue = response.readEntity(Participant[].class); assertThat(returnValue).hasSize(1); @@ -205,23 +166,8 @@ class ParticipantSimulatorTest { assertEquals(participant.getDefinition(), returnValue[0].getDefinition()); } - private <T> void checkResponseEntity(Response response, int status, UUID uuid) { - assertThat(response.getStatus()).isEqualTo(status); - assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_MINOR_NAME)).isEqualTo("0"); - assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_PATCH_NAME)).isEqualTo("0"); - assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_LATEST_NAME)).isEqualTo("1.0.0"); - assertThat(getHeader(response.getHeaders(), AbstractRestController.REQUEST_ID_NAME)).isEqualTo(uuid.toString()); - } - - private String getHeader(MultivaluedMap<String, Object> httpHeaders, String param) { - List<Object> list = httpHeaders.get(param); - assertThat(list).hasSize(1); - assertThat(list.get(0)).isNotNull(); - return (String) list.get(0); - } - @Test - void testQueryAutomationCompositionElements() throws Exception { + void testQueryAutomationCompositionElements() { setUp(); UUID uuid = UUID.randomUUID(); ToscaConceptIdentifier participantId = CommonTestData.getParticipantId(); @@ -229,19 +175,15 @@ class ParticipantSimulatorTest { // GET REST call for querying the automationComposition elements Response response = performGet(ELEMENTS_ENDPOINT + "/" + participantId.getName() + "/" + participantId.getVersion(), uuid); - checkResponseEntity(response, 200, uuid); + checkResponseEntity(response, uuid); Map<?, ?> returnValue = response.readEntity(Map.class); // Verify the result of GET automation composition elements with what is stored assertThat(returnValue).isEmpty(); } - private Response performPut(String endpoint, final Entity<?> entity, UUID uuid) throws Exception { - return performRequest(endpoint, true, uuid).put(entity); - } - @Test - void testUpdateParticipant() throws Exception { + void testUpdateParticipant() { setUp(); List<Participant> participants = participantIntermediaryApi.getParticipants( CommonTestData.getParticipantId().getName(), CommonTestData.getParticipantId().getVersion()); @@ -252,10 +194,10 @@ class ParticipantSimulatorTest { // PUT REST call for updating Participant Response response = performPut(PARTICIPANTS_ENDPOINT, Entity.json(participants.get(0)), uuid); - checkResponseEntity(response, 200, uuid); + checkResponseEntity(response, uuid); - TypedSimpleResponse<Participant> resp = - response.readEntity(new GenericType<TypedSimpleResponse<Participant>>() {}); + TypedSimpleResponse<Participant> resp = response.readEntity(new GenericType<>() { + }); assertNotNull(resp.getResponse()); // Verify the response and state returned by PUT REST call for updating participants assertEquals(participants.get(0).getDefinition(), resp.getResponse().getDefinition()); @@ -263,7 +205,7 @@ class ParticipantSimulatorTest { } @Test - void testUpdateAutomationCompositionElement() throws Exception { + void testUpdateAutomationCompositionElement() { setUp(); AutomationComposition automationComposition = TestListenerUtils.createAutomationComposition(); Map<UUID, AutomationCompositionElement> automationCompositionElements = @@ -276,13 +218,70 @@ class ParticipantSimulatorTest { automationCompositionElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); // PUT REST call for updating AutomationCompositionElement Response response = performPut(ELEMENTS_ENDPOINT, Entity.json(automationCompositionElement), uuid); - checkResponseEntity(response, 200, uuid); + checkResponseEntity(response, uuid); - TypedSimpleResponse<AutomationCompositionElement> resp = - response.readEntity(new GenericType<TypedSimpleResponse<AutomationCompositionElement>>() {}); + TypedSimpleResponse<AutomationCompositionElement> resp = response.readEntity(new GenericType<>() { + }); assertNotNull(resp.getResponse()); // Verify the response and state returned by PUT REST call for updating participants assertEquals(automationCompositionElement.getDefinition(), resp.getResponse().getDefinition()); assertEquals(AutomationCompositionOrderedState.PASSIVE, resp.getResponse().getOrderedState()); } + + private String getPath(String path) { + return "http://localhost:" + randomServerPort + "/onap/participantsim/v2/" + path; + } + + void testSwagger(String endPoint) { + final Client client = ClientBuilder.newBuilder().build(); + + client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); + client.register(GsonMessageBodyHandler.class); + client.register(HttpAuthenticationFeature.basic(user, password)); + + final WebTarget webTarget = client.target(getPath("api-docs")); + + Response response = webTarget.request(MediaType.APPLICATION_JSON).get(); + + assertThat(response.getStatus()).isEqualTo(200); + assertTrue(response.readEntity(String.class).contains("/onap/participantsim/v2/" + endPoint)); + } + + private Invocation.Builder performRequest(String endpoint, boolean includeAuth, UUID uuid) { + final Client client = ClientBuilder.newBuilder().build(); + + client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true"); + client.register(GsonMessageBodyHandler.class); + if (includeAuth) { + client.register(HttpAuthenticationFeature.basic(user, password)); + } + Invocation.Builder builder = client.target(getPath(endpoint)).request(MediaType.APPLICATION_JSON); + if (uuid != null) { + builder = builder.header(AbstractRestController.REQUEST_ID_NAME, uuid.toString()); + } + return builder; + } + + private Response performGet(String endpoint, UUID uuid) { + return performRequest(endpoint, true, uuid).get(); + } + + private void checkResponseEntity(Response response, UUID uuid) { + assertThat(response.getStatus()).isEqualTo(200); + assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_MINOR_NAME)).isEqualTo("0"); + assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_PATCH_NAME)).isEqualTo("0"); + assertThat(getHeader(response.getHeaders(), AbstractRestController.VERSION_LATEST_NAME)).isEqualTo("1.0.0"); + assertThat(getHeader(response.getHeaders(), AbstractRestController.REQUEST_ID_NAME)).isEqualTo(uuid.toString()); + } + + private String getHeader(MultivaluedMap<String, Object> httpHeaders, String param) { + List<Object> list = httpHeaders.get(param); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isNotNull(); + return (String) list.get(0); + } + + private Response performPut(String endpoint, final Entity<?> entity, UUID uuid) { + return performRequest(endpoint, true, uuid).put(entity); + } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandlerTest.java index 360485efa..87be88658 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/handler/AutomationCompositionElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/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. @@ -30,7 +30,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantInterme 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; @@ -44,7 +43,7 @@ class AutomationCompositionElementHandlerTest { new ToscaConceptIdentifier(ID_NAME, ID_VERSION); @Test - void testSimulatorHandlerExceptions() throws PfModelException { + void testSimulatorHandlerExceptions() { AutomationCompositionElementHandler handler = getTestingHandler(); assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(automationCompositionId, diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/CommonTestData.java index 6af454a42..fbedbe633 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/CommonTestData.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/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,7 +20,6 @@ package org.onap.policy.clamp.acm.participant.simulator.main.parameters; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -34,10 +33,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; * Class to hold/create all parameters for test cases. */ 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(); @@ -48,7 +46,7 @@ public class CommonTestData { */ public ParticipantSimulatorParameters getParticipantSimulatorParameters() { try { - return CODER.convert(getParticipantParameterGroupMap(PARTICIPANT_GROUP_NAME), + return CODER.convert(getParticipantParameterGroupMap(), ParticipantSimulatorParameters.class); } catch (final CoderException e) { throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e); @@ -58,11 +56,9 @@ public class CommonTestData { /** * Returns a property map for a ApexStarterParameterGroup map for test cases. * - * @param name name of the parameters - * * @return a property map suitable for constructing an object */ - public Map<String, Object> getParticipantParameterGroupMap(final String name) { + public Map<String, Object> getParticipantParameterGroupMap() { final Map<String, Object> map = new TreeMap<>(); map.put("intermediaryParameters", getIntermediaryParametersMap(false)); @@ -113,7 +109,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; } @@ -123,18 +119,6 @@ public class CommonTestData { * @return participant Id */ public static ToscaConceptIdentifier getParticipantId() { - final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0"); - return participantId; - } - - /** - * 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\""); + return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0"); } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java index c763d09a3..4e8aa5f46 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/parameters/TestParticipantSimulatorParameters.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. @@ -27,11 +27,12 @@ import javax.validation.ValidatorFactory; import org.junit.jupiter.api.Test; /** - * Class to perform unit test of {@link ParticipantParameterGroup}. + * Class to perform unit test of + * {@link org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters}. */ class TestParticipantSimulatorParameters { - private CommonTestData commonTestData = new CommonTestData(); - private ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); + private final CommonTestData commonTestData = new CommonTestData(); + private final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); @Test void testParticipantParameterGroup() { diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/utils/TestListenerUtils.java index f43400259..944aaa6b7 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/main/rest/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/simulator/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. @@ -18,36 +18,25 @@ * ============LICENSE_END========================================================= */ -package org.onap.policy.clamp.acm.participant.simulator.main.rest; +package org.onap.policy.clamp.acm.participant.simulator.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.acm.participant.simulator.main.parameters.CommonTestData; 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; @@ -60,9 +49,8 @@ import org.slf4j.LoggerFactory; public final class TestListenerUtils { private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - private static final Coder CODER = new StandardCoder(); - static CommonTestData commonTestData = new CommonTestData(); private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class); + private static final String TOSCA_TEMPLATE = "clamp/acm/test/pm_simple_ac_tosca.yaml"; /** * Method to create a automationComposition from a yaml file. @@ -72,7 +60,7 @@ public final class TestListenerUtils { public static AutomationComposition createAutomationComposition() { AutomationComposition automationComposition = new AutomationComposition(); Map<UUID, AutomationCompositionElement> elements = new LinkedHashMap<>(); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionRead(); + ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionYamlSerialization(); Map<String, ToscaNodeTemplate> nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { @@ -104,28 +92,6 @@ public final class TestListenerUtils { } /** - * 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("PMSHInstance0", "1.0.0"); - ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.0"); - - acStateChangeMsg.setAutomationCompositionId(automationCompositionId); - acStateChangeMsg.setParticipantId(participantId); - acStateChangeMsg.setTimestamp(Instant.now()); - acStateChangeMsg.setOrderedState(automationCompositionOrderedState); - - return acStateChangeMsg; - } - - /** * Method to create AutomationCompositionUpdateMsg. * * @return AutomationCompositionUpdate message @@ -141,7 +107,7 @@ public final class TestListenerUtils { acUpdateMsg.setTimestamp(Instant.now()); Map<UUID, AutomationCompositionElement> elements = new LinkedHashMap<>(); - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionRead(); + ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionYamlSerialization(); Map<String, ToscaNodeTemplate> nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) { @@ -172,88 +138,16 @@ public final class TestListenerUtils { return acUpdateMsg; } - /** - * Method to create participantUpdateMsg. - * - * @return ParticipantUpdate message - */ - public static ParticipantUpdate createParticipantUpdateMsg() { - final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate(); - ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); - ToscaConceptIdentifier participantType = - new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"); - - participantUpdateMsg.setParticipantId(participantId); - participantUpdateMsg.setTimestamp(Instant.now()); - participantUpdateMsg.setParticipantType(participantType); - participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000)); - participantUpdateMsg.setMessageId(UUID.randomUUID()); - - ToscaServiceTemplate toscaServiceTemplate = testAutomationCompositionRead(); - // Add policies to the toscaServiceTemplate - List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>(); - for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate() - .getNodeTemplates().entrySet()) { - if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(), - toscaServiceTemplate)) { - var acParticipantType = - ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - AcmUtils.prepareParticipantDefinitionUpdate(acParticipantType, toscaInputEntry.getKey(), - toscaInputEntry.getValue(), participantDefinitionUpdates, null); - } - } - - participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates); - 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/rest/servicetemplates"); - - boolean atLeastOneAutomationCompositionTested = false; - ToscaServiceTemplate toscaServiceTemplate = null; - - for (String automationCompositionFilePath : automationCompositionDirectoryContents) { - if (!automationCompositionFilePath.endsWith(".yaml")) { - continue; - } - atLeastOneAutomationCompositionTested = true; - toscaServiceTemplate = testAutomationCompositionYamlSerialization(automationCompositionFilePath); - } - - assertTrue(atLeastOneAutomationCompositionTested); - return toscaServiceTemplate; - } - - private static ToscaServiceTemplate testAutomationCompositionYamlSerialization( - String automationCompositionFilePath) { + private static ToscaServiceTemplate testAutomationCompositionYamlSerialization() { try { - String automationCompositionString = ResourceUtils.getResourceAsString(automationCompositionFilePath); + String automationCompositionString = ResourceUtils.getResourceAsString(TestListenerUtils.TOSCA_TEMPLATE); if (automationCompositionString == null) { - throw new FileNotFoundException(automationCompositionFilePath); + throw new FileNotFoundException(TestListenerUtils.TOSCA_TEMPLATE); } - 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 {}", TestListenerUtils.TOSCA_TEMPLATE); throw new IllegalArgumentException(e); } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/application-test.yaml b/participant/participant-impl/participant-impl-simulator/src/test/resources/application-test.yaml new file mode 100644 index 000000000..3388f01a5 --- /dev/null +++ b/participant/participant-impl/participant-impl-simulator/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-simulator/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties deleted file mode 100644 index ccc54581e..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties +++ /dev/null @@ -1,25 +0,0 @@ -spring.security.user.name=runtimeUser -spring.security.user.password=zb!XztG34 - -server.servlet.context-path=/onap/participantsim -server.error.path=/error - -participant.restServerParameters.host=0.0.0.0 -participant.restServerParameters.port=6969 -participant.restServerParameters.userName=runtimeUser -participant.restServerParameters.password=zb!XztG34 -participant.restServerParameters.https=false -participant.restServerParameters.aaf=false -participant.intermediaryParameters.reportingTimeInterval=120000 -participant.intermediaryParameters.description=Participant Description -participant.intermediaryParameters.participantId.name=org.onap.PM_CDS_Blueprint -participant.intermediaryParameters.participantId.version=1.0.0 -participant.intermediaryParameters.participantType.name=org.onap.PM_CDS_Blueprint -participant.intermediaryParameters.participantType.version=1.0.0 -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 diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/rest/servicetemplates/pm_automation_composition_tosca.yaml b/participant/participant-impl/participant-impl-simulator/src/test/resources/rest/servicetemplates/pm_automation_composition_tosca.yaml deleted file mode 100644 index 6e34c7cce..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/resources/rest/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.acm.Participant: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - requred: false - org.onap.policy.clamp.acm.AutomationCompositionElement: - 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.acm.AutomationComposition: - 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.acm.DCAEMicroserviceAutomationCompositionElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement - properties: - dcae_blueprint_id: - type: onap.datatypes.ToscaConceptIdentifier - requred: true - org.onap.policy.clamp.acm.PolicyTypeAutomationCompositionElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement - properties: - policy_type_id: - type: onap.datatypes.ToscaConceptIdentifier - requred: true - org.onap.policy.clamp.acm.CDSAutomationCompositionElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement - properties: - cds_blueprint_id: - type: onap.datatypes.ToscaConceptIdentifier - requred: true -topology_template: - node_templates: - org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant: - version: 2.3.4 - type: org.onap.policy.clamp.acm.Participant - type_version: 1.0.1 - description: Participant for DCAE microservices - properties: - provider: ONAP - org.onap.policy.acm.PolicyAutomationCompositionParticipant: - version: 2.3.1 - type: org.onap.policy.clamp.acm.Participant - type_version: 1.0.1 - description: Participant for DCAE microservices - properties: - provider: ONAP - org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant: - version: 2.2.1 - type: org.onap.policy.clamp.acm.Participant - 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.acm.DCAEMicroserviceAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for the DCAE microservice for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant - 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.acm.PolicyTypeAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for the monitoring policy for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.policy.acm.PolicyAutomationCompositionParticipant - 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.acm.PolicyTypeAutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for the operational policy for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.policy.acm.PolicyAutomationCompositionParticipant - 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.acm.AutomationCompositionElement - type_version: 1.0.0 - description: Automation composition element for CDS for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.PM_CDS_Blueprint - version: 1.0.0 - 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.acm.AutomationComposition - 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 |