5499931a27f78a91402dabcc3dbddb5f36e29b68
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-2024 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.participant.sim.comm;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.TreeMap;
27 import java.util.UUID;
28 import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
29 import org.onap.policy.clamp.acm.participant.sim.parameters.ParticipantSimParameters;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
31 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
32 import org.onap.policy.common.endpoints.parameters.TopicParameters;
33 import org.onap.policy.common.utils.coder.Coder;
34 import org.onap.policy.common.utils.coder.CoderException;
35 import org.onap.policy.common.utils.coder.StandardCoder;
36
37 public class CommonTestData {
38     public static final Coder CODER = new StandardCoder();
39     public static final String DESCRIPTION = "Participant description";
40     public static final long TIME_INTERVAL = 2000;
41     public static final List<TopicParameters> SINK_TOPIC_PARAMS = List.of(getSinkTopicParams());
42     public static final List<TopicParameters> SOURCE_TOPIC_PARAMS = List.of(getSinkTopicParams(), getSyncTopicParams());
43
44     /**
45      * Get ParticipantSimParameters.
46      *
47      * @return ParticipantSimParameters
48      */
49     public static ParticipantSimParameters getParticipantSimParameters() {
50         try {
51             return CODER.convert(getParticipantSimParametersMap(), ParticipantSimParameters.class);
52         } catch (final CoderException e) {
53             throw new RuntimeException("cannot create ParticipantSimParameters from map", e);
54         }
55     }
56
57     /**
58      * Returns a property map for a ParticipantSimParameters map for test cases.
59      *
60      * @return a property map suitable for constructing an object
61      */
62     private static Map<String, Object> getParticipantSimParametersMap() {
63         final Map<String, Object> map = new TreeMap<>();
64
65         map.put("intermediaryParameters", getIntermediaryParametersMap());
66         return map;
67     }
68
69     /**
70      * Returns a property map for a intermediaryParameters map for test cases.
71      *
72      * @return a property map suitable for constructing an object
73      */
74     private static Map<String, Object> getIntermediaryParametersMap() {
75         final Map<String, Object> map = new TreeMap<>();
76         map.put("name", "Participant parameters");
77         map.put("reportingTimeIntervalMs", TIME_INTERVAL);
78         map.put("description", DESCRIPTION);
79         map.put("participantId", getParticipantId());
80         map.put("clampAutomationCompositionTopics", getTopicParametersMap());
81         map.put("participantSupportedElementTypes", new ArrayList<>());
82         map.put("topics", new Topics("policy-acruntime-participant", "acm-ppnt-sync"));
83
84         return map;
85     }
86
87     /**
88      * Returns a property map for a TopicParameters map for test cases.
89      *
90      * @return a property map suitable for constructing an object
91      */
92     private static Map<String, Object> getTopicParametersMap() {
93         final Map<String, Object> map = new TreeMap<>();
94         map.put("topicSources", SOURCE_TOPIC_PARAMS);
95         map.put("topicSinks", SINK_TOPIC_PARAMS);
96         return map;
97     }
98
99     /**
100      * Returns topic parameters for test cases.
101      *
102      * @return topic parameters
103      */
104     private static TopicParameters getSinkTopicParams() {
105         final TopicParameters topicParams = new TopicParameters();
106         topicParams.setTopic("policy-acruntime-participant");
107         topicParams.setTopicCommInfrastructure("NOOP");
108         topicParams.setServers(List.of("localhost"));
109         return topicParams;
110     }
111
112     /**
113      * Returns sync topic parameters for test cases.
114      *
115      * @return topic parameters
116      */
117     private static TopicParameters getSyncTopicParams() {
118         final TopicParameters topicParams = new TopicParameters();
119         topicParams.setTopic("acm-ppnt-sync");
120         topicParams.setTopicCommInfrastructure("NOOP");
121         topicParams.setServers(List.of("localhost"));
122         return topicParams;
123     }
124
125     /**
126      * Returns participantId for test cases.
127      *
128      * @return participant Id
129      */
130     public static UUID getParticipantId() {
131         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c01");
132     }
133
134     /**
135      * Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
136      *
137      * @return automationCompositionMap
138      *
139      * @throws CoderException if there is an error with .json file.
140      */
141     public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
142         var automationComposition = getTestAutomationComposition();
143         return Map.of(automationComposition.getInstanceId(), automationComposition);
144     }
145
146     /**
147      * Returns List of AutomationComposition for test cases.
148      *
149      * @return AutomationCompositions
150      *
151      * @throws CoderException if there is an error with .json file.
152      */
153     public static AutomationComposition getTestAutomationComposition() {
154         var automationComposition = new AutomationComposition();
155         automationComposition.setInstanceId(UUID.randomUUID());
156         var element = new AutomationCompositionElement();
157         element.setId(UUID.randomUUID());
158         automationComposition.setElements(Map.of(element.getId(), element));
159         return automationComposition;
160     }
161 }