54f1930395d2e76641b0033cc2841e30a55742e9
[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.sim.parameters.ParticipantSimParameters;
29 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
31 import org.onap.policy.common.endpoints.parameters.TopicParameters;
32 import org.onap.policy.common.utils.coder.Coder;
33 import org.onap.policy.common.utils.coder.CoderException;
34 import org.onap.policy.common.utils.coder.StandardCoder;
35
36 public class CommonTestData {
37     public static final Coder CODER = new StandardCoder();
38     public static final String DESCRIPTION = "Participant description";
39     public static final long TIME_INTERVAL = 2000;
40     public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
41
42     /**
43      * Get ParticipantSimParameters.
44      *
45      * @return ParticipantSimParameters
46      */
47     public static ParticipantSimParameters getParticipantSimParameters() {
48         try {
49             return CODER.convert(getParticipantSimParametersMap(), ParticipantSimParameters.class);
50         } catch (final CoderException e) {
51             throw new RuntimeException("cannot create ParticipantSimParameters from map", e);
52         }
53     }
54
55     /**
56      * Returns a property map for a ParticipantSimParameters map for test cases.
57      *
58      * @return a property map suitable for constructing an object
59      */
60     private static Map<String, Object> getParticipantSimParametersMap() {
61         final Map<String, Object> map = new TreeMap<>();
62
63         map.put("intermediaryParameters", getIntermediaryParametersMap());
64         return map;
65     }
66
67     /**
68      * Returns a property map for a intermediaryParameters map for test cases.
69      *
70      * @return a property map suitable for constructing an object
71      */
72     private static Map<String, Object> getIntermediaryParametersMap() {
73         final Map<String, Object> map = new TreeMap<>();
74         map.put("name", "Participant parameters");
75         map.put("reportingTimeIntervalMs", TIME_INTERVAL);
76         map.put("description", DESCRIPTION);
77         map.put("participantId", getParticipantId());
78         map.put("clampAutomationCompositionTopics", getTopicParametersMap());
79         map.put("participantSupportedElementTypes", new ArrayList<>());
80
81         return map;
82     }
83
84     /**
85      * Returns a property map for a TopicParameters map for test cases.
86      *
87      * @return a property map suitable for constructing an object
88      */
89     private static Map<String, Object> getTopicParametersMap() {
90         final Map<String, Object> map = new TreeMap<>();
91         map.put("topicSources", TOPIC_PARAMS);
92         map.put("topicSinks", TOPIC_PARAMS);
93         return map;
94     }
95
96     /**
97      * Returns topic parameters for test cases.
98      *
99      * @return topic parameters
100      */
101     private static TopicParameters getTopicParams() {
102         final TopicParameters topicParams = new TopicParameters();
103         topicParams.setTopic("policy-acruntime-participant");
104         topicParams.setTopicCommInfrastructure("NOOP");
105         topicParams.setServers(List.of("localhost"));
106         return topicParams;
107     }
108
109     /**
110      * Returns participantId for test cases.
111      *
112      * @return participant Id
113      */
114     public static UUID getParticipantId() {
115         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c01");
116     }
117
118     /**
119      * Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
120      *
121      * @return automationCompositionMap
122      *
123      * @throws CoderException if there is an error with .json file.
124      */
125     public static Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
126         var automationComposition = getTestAutomationComposition();
127         return Map.of(automationComposition.getInstanceId(), automationComposition);
128     }
129
130     /**
131      * Returns List of AutomationComposition for test cases.
132      *
133      * @return AutomationCompositions
134      *
135      * @throws CoderException if there is an error with .json file.
136      */
137     public static AutomationComposition getTestAutomationComposition() {
138         var automationComposition = new AutomationComposition();
139         automationComposition.setInstanceId(UUID.randomUUID());
140         var element = new AutomationCompositionElement();
141         element.setId(UUID.randomUUID());
142         automationComposition.setElements(Map.of(element.getId(), element));
143         return automationComposition;
144     }
145 }