2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.acm.participant.intermediary.main.parameters;
24 import java.time.Instant;
25 import java.util.LinkedHashMap;
26 import java.util.List;
28 import java.util.TreeMap;
29 import java.util.UUID;
30 import org.onap.policy.clamp.acm.participant.intermediary.handler.DummyParticipantParameters;
31 import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
34 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
35 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
36 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
37 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
38 import org.onap.policy.common.endpoints.parameters.TopicParameters;
39 import org.onap.policy.common.utils.coder.Coder;
40 import org.onap.policy.common.utils.coder.CoderException;
41 import org.onap.policy.common.utils.coder.StandardCoder;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
45 * Class to hold/create all parameters for test cases.
47 public class CommonTestData {
48 public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
49 public static final String DESCRIPTION = "Participant description";
50 public static final long TIME_INTERVAL = 2000;
51 public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
52 public static final Coder CODER = new StandardCoder();
53 public static final UUID AC_ID_0 = UUID.randomUUID();
54 public static final UUID AC_ID_1 = UUID.randomUUID();
55 public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
58 * Get ParticipantIntermediaryParameters.
60 * @return ParticipantIntermediaryParameters
62 public static ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
64 return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
65 ParticipantIntermediaryParameters.class);
66 } catch (final CoderException e) {
67 throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
72 * Get ParticipantParameters.
74 * @return ParticipantParameters
76 public static DummyParticipantParameters getParticipantParameters() {
78 return CODER.convert(getParametersMap(PARTICIPANT_GROUP_NAME), DummyParticipantParameters.class);
79 } catch (final CoderException e) {
80 throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
85 * Returns a property map for a Parameters map for test cases.
87 * @param name name of the parameters
88 * @return a property map suitable for constructing an object
90 public static Map<String, Object> getParametersMap(final String name) {
91 final Map<String, Object> map = new TreeMap<>();
92 map.put("intermediaryParameters", getIntermediaryParametersMap(name));
97 * Returns a property map for a intermediaryParameters map for test cases.
99 * @param name name of the parameters
100 * @return a property map suitable for constructing an object
102 public static Map<String, Object> getIntermediaryParametersMap(final String name) {
103 final Map<String, Object> map = new TreeMap<>();
104 map.put("name", name);
105 map.put("participantId", getParticipantId());
106 map.put("description", DESCRIPTION);
107 map.put("reportingTimeIntervalMs", TIME_INTERVAL);
108 map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
109 var supportedElementType = new ParticipantSupportedElementType();
110 supportedElementType.setTypeName("org.onap.policy.clamp.acm.HttpAutomationCompositionElement");
111 supportedElementType.setTypeVersion("1.0.0");
112 map.put("participantSupportedElementTypes", List.of(supportedElementType));
118 * Returns a property map for a TopicParameters map for test cases.
120 * @param isEmpty boolean value to represent that object created should be empty or not
121 * @return a property map suitable for constructing an object
123 public static Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
124 final Map<String, Object> map = new TreeMap<>();
126 map.put("topicSources", TOPIC_PARAMS);
127 map.put("topicSinks", TOPIC_PARAMS);
133 * Returns topic parameters for test cases.
135 * @return topic parameters
137 public static TopicParameters getTopicParams() {
138 final var topicParams = new TopicParameters();
139 topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
140 topicParams.setTopicCommInfrastructure("dmaap");
141 topicParams.setServers(List.of("localhost"));
146 * Returns participantId for test cases.
148 * @return participant Id
150 public static UUID getParticipantId() {
151 return PARTCICIPANT_ID;
154 public static UUID getRndParticipantId() {
155 return UUID.randomUUID();
158 public static ToscaConceptIdentifier getDefinition() {
159 return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3");
163 * Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
165 * @return automationCompositionMap
167 * @throws CoderException if there is an error with .json file.
169 public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
170 var automationCompositions = getTestAutomationCompositions();
171 var automationComposition = automationCompositions.getAutomationCompositionList().get(1);
172 Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
173 automationCompositionMap.put(automationComposition.getInstanceId(), automationComposition);
174 return automationCompositionMap;
178 * Returns List of AutomationComposition for test cases.
180 * @return AutomationCompositions
182 * @throws CoderException if there is an error with .json file.
184 public static AutomationCompositions getTestAutomationCompositions() {
186 var automationCompositions =
187 new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
188 AutomationCompositions.class);
189 automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
190 automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
191 return automationCompositions;
192 } catch (Exception e) {
193 throw new RuntimeException("cannot read TestAutomationCompositions.json");
198 * Return a AutomationCompositionStateChange.
200 * @param participantId the participantId
201 * @param instanceId th AutomationComposition Id
202 * @param deployOrder a DeployOrder
203 * @param lockOrder a LockOrder
204 * @return a AutomationCompositionStateChange
206 public static AutomationCompositionStateChange getStateChange(UUID participantId, UUID instanceId,
207 DeployOrder deployOrder, LockOrder lockOrder) {
208 var stateChange = new AutomationCompositionStateChange();
209 stateChange.setStartPhase(0);
210 stateChange.setAutomationCompositionId(instanceId);
211 stateChange.setParticipantId(participantId);
212 stateChange.setMessageId(UUID.randomUUID());
213 stateChange.setDeployOrderedState(deployOrder);
214 stateChange.setLockOrderedState(lockOrder);
215 stateChange.setTimestamp(Instant.ofEpochMilli(3000));