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.AcElementRestart;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
34 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
35 import org.onap.policy.clamp.models.acm.concepts.DeployState;
36 import org.onap.policy.clamp.models.acm.concepts.LockState;
37 import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
38 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
39 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
40 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
41 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
42 import org.onap.policy.common.endpoints.parameters.TopicParameters;
43 import org.onap.policy.common.utils.coder.Coder;
44 import org.onap.policy.common.utils.coder.CoderException;
45 import org.onap.policy.common.utils.coder.StandardCoder;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
49 * Class to hold/create all parameters for test cases.
51 public class CommonTestData {
52 public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
53 public static final String DESCRIPTION = "Participant description";
54 public static final long TIME_INTERVAL = 2000;
55 public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
56 public static final Coder CODER = new StandardCoder();
57 public static final UUID AC_ID_0 = UUID.randomUUID();
58 public static final UUID AC_ID_1 = UUID.randomUUID();
59 public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
62 * Get ParticipantIntermediaryParameters.
64 * @return ParticipantIntermediaryParameters
66 public static ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
68 return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
69 ParticipantIntermediaryParameters.class);
70 } catch (final CoderException e) {
71 throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
76 * Get ParticipantParameters.
78 * @return ParticipantParameters
80 public static DummyParticipantParameters getParticipantParameters() {
82 return CODER.convert(getParametersMap(PARTICIPANT_GROUP_NAME), DummyParticipantParameters.class);
83 } catch (final CoderException e) {
84 throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
89 * Returns a property map for a Parameters map for test cases.
91 * @param name name of the parameters
92 * @return a property map suitable for constructing an object
94 public static Map<String, Object> getParametersMap(final String name) {
95 final Map<String, Object> map = new TreeMap<>();
96 map.put("intermediaryParameters", getIntermediaryParametersMap(name));
101 * Returns a property map for a intermediaryParameters map for test cases.
103 * @param name name of the parameters
104 * @return a property map suitable for constructing an object
106 public static Map<String, Object> getIntermediaryParametersMap(final String name) {
107 final Map<String, Object> map = new TreeMap<>();
108 map.put("name", name);
109 map.put("participantId", getParticipantId());
110 map.put("description", DESCRIPTION);
111 map.put("reportingTimeIntervalMs", TIME_INTERVAL);
112 map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
113 var supportedElementType = new ParticipantSupportedElementType();
114 supportedElementType.setTypeName("org.onap.policy.clamp.acm.HttpAutomationCompositionElement");
115 supportedElementType.setTypeVersion("1.0.0");
116 map.put("participantSupportedElementTypes", List.of(supportedElementType));
122 * Returns a property map for a TopicParameters map for test cases.
124 * @param isEmpty boolean value to represent that object created should be empty or not
125 * @return a property map suitable for constructing an object
127 public static Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
128 final Map<String, Object> map = new TreeMap<>();
130 map.put("topicSources", TOPIC_PARAMS);
131 map.put("topicSinks", TOPIC_PARAMS);
137 * Returns topic parameters for test cases.
139 * @return topic parameters
141 public static TopicParameters getTopicParams() {
142 final var topicParams = new TopicParameters();
143 topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
144 topicParams.setTopicCommInfrastructure("dmaap");
145 topicParams.setServers(List.of("localhost"));
150 * Returns participantId for test cases.
152 * @return participant Id
154 public static UUID getParticipantId() {
155 return PARTCICIPANT_ID;
158 public static UUID getRndParticipantId() {
159 return UUID.randomUUID();
162 public static ToscaConceptIdentifier getDefinition() {
163 return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3");
167 * Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
169 * @return automationCompositionMap
171 * @throws CoderException if there is an error with .json file.
173 public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
174 var automationCompositions = getTestAutomationCompositions();
175 var automationComposition = automationCompositions.getAutomationCompositionList().get(1);
176 Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
177 automationCompositionMap.put(automationComposition.getInstanceId(), automationComposition);
178 return automationCompositionMap;
182 * Returns List of AutomationComposition for test cases.
184 * @return AutomationCompositions
186 * @throws CoderException if there is an error with .json file.
188 public static AutomationCompositions getTestAutomationCompositions() {
190 var automationCompositions =
191 new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
192 AutomationCompositions.class);
193 automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
194 automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
195 return automationCompositions;
196 } catch (Exception e) {
197 throw new RuntimeException("cannot read TestAutomationCompositions.json");
202 * Return a AutomationCompositionStateChange.
204 * @param participantId the participantId
205 * @param instanceId th AutomationComposition Id
206 * @param deployOrder a DeployOrder
207 * @param lockOrder a LockOrder
208 * @return a AutomationCompositionStateChange
210 public static AutomationCompositionStateChange getStateChange(UUID participantId, UUID instanceId,
211 DeployOrder deployOrder, LockOrder lockOrder) {
212 var stateChange = new AutomationCompositionStateChange();
213 stateChange.setStartPhase(0);
214 stateChange.setAutomationCompositionId(instanceId);
215 stateChange.setParticipantId(participantId);
216 stateChange.setMessageId(UUID.randomUUID());
217 stateChange.setDeployOrderedState(deployOrder);
218 stateChange.setLockOrderedState(lockOrder);
219 stateChange.setTimestamp(Instant.ofEpochMilli(3000));
224 * Create a ParticipantRestartAc.
226 * @return a ParticipantRestartAc
228 public static ParticipantRestartAc createParticipantRestartAc() {
229 var participantRestartAc = new ParticipantRestartAc();
230 participantRestartAc.setAutomationCompositionId(AC_ID_0);
231 var acElementRestart = new AcElementRestart();
232 acElementRestart.setDefinition(getDefinition());
233 acElementRestart.setDeployState(DeployState.DEPLOYED);
234 acElementRestart.setLockState(LockState.LOCKED);
235 acElementRestart.setId(UUID.randomUUID());
236 participantRestartAc.getAcElementList().add(acElementRestart);
237 return participantRestartAc;